Skip to content

fix(activity): scope indexed transfers to the workspace - #144

Merged
selezenart merged 1 commit into
developfrom
fix/workspace-scoped-activity-transfers
Sep 13, 2026
Merged

selezenart merged 1 commit into
developfrom
fix/workspace-scoped-activity-transfers

Conversation

@selezenart

Copy link
Copy Markdown
Collaborator

Problem

Payment proof showed 11 committed settlements next to 40 unmatched transfers. The two numbers came from different scopes.

StudioWalletActivityPort.refresh sends the shared server wallet as a sender alongside the workspace's user wallets, so a stored observation payload carries transfers made for every workspace on the deployment. In JobLedger.activity, recorded_settlement_count and uncertain_job_count are SQL-scoped by workspace_id, but unmatched_transfer_count and the transfers list were taken from the whole observation payload. Other workspaces' activity was counted, and listed, as this workspace's unmatched evidence.

Change

JobLedger.activity now filters the observed transfers down to the ones this workspace can own, before they are matched, listed or counted. A transfer is kept when either:

  • its sender is a payer wallet recorded on a job in this workspace (user-wallet payments), or
  • its transaction hash is already recorded in this workspace on a settlement, on resumable_jobs.payment_transaction_hash, or on an attempt's provider_transaction_hash.

The attempt hash in that union is deliberate: a stranded server payment (funds sent, no settlement row) still has an attempt hash, so it stays visible as unmatched evidence rather than being filtered away with the foreign traffic.

Tests

  • The existing unmatched-activity test now carries a workspace payer wallet on the unmatched transfer, plus a foreign transfer that must not appear.
  • New test: a shared server wallet transfer with no workspace hash is excluded, and unmatched_transfer_count stays 0.

Verification

  • tsc -b clean
  • full unit suite: 81 files, 1064 tests passed
  • prettier clean

Not verified against a live Postgres: no database URL available locally and no integration test covers activity(). The new SQL is plain SQL and the columns are confirmed in migrations 007 and 009.

The Graph activity query is sent with the shared server wallet alongside
the workspace's user wallets, so a stored observation also carries
transfers made for other workspaces. Settlement and uncertain counts were
SQL-scoped to the workspace while the unmatched transfer count was taken
from the whole observation, so Payment proof reported one workspace's 11
settlements next to 40 unmatched transfers drawn from every workspace.

Filter the observed transfers to the ones this workspace can own before
they are matched, listed or counted: the sender is a workspace payer
wallet, or the transaction hash is already recorded on a workspace
settlement, job or attempt. The attempt hash keeps a stranded server
payment visible as unmatched evidence.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
oneshot a5aacd2 Sep 13 2026, 02:49 PM

@selezenart
selezenart marked this pull request as ready for review September 13, 2026 14:52
@selezenart
selezenart merged commit 96c1683 into develop Sep 13, 2026
5 checks passed
@selezenart
selezenart deleted the fix/workspace-scoped-activity-transfers branch September 13, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant