Skip to content

✅ server: scope unpriced deploy captures to job - #2139

Open
cruzdanilo wants to merge 1 commit into
mainfrom
claude/project-thread-fxotv3
Open

cruzdanilo wants to merge 1 commit into
mainfrom
claude/project-thread-fxotv3

Conversation

@cruzdanilo

@cruzdanilo cruzdanilo commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Requested by danilo · project thread

fixes the flake in server/test/workers/poke.test.ts > "poke worker" > "deploys on other chains when no native price is known", seen on exa#2027 at 9cd8f9f: 7 captures instead of 5, with an extra "unaffordable deploy" + "lifi token 400" pair before "stuck deploy". it also closes the same gap in the two sibling unpriced tests.

cause

the unpriced tests switch the stack to mainnet pricing (chain.id 1, testnet false), point li.fi at a failing response and, in two of them, drop the keeper to 1 wei on the shared anvil. the poke queue is shared, so a real poke job from another test file can reach this file's worker during that window (on exa#2027, the "with the shared poke queue" block in hooks/activity.test.ts publishes them). that job prices its own deploy on the anvil network and captures its own "lifi token …" and "unaffordable deploy". the tests read every captureException call, every worker span and every track, so one foreign job broke them.

reproduced locally by enqueuing one poke job for another account during the window: the "no native price" failure matches ci exactly, and "last native price" fails with a second "lifi token 500".

fix

test only. spyCaptures() still calls through to sentry and records each capture with its active span's trace. the filter it returns keeps the captures on the given jobs' traces (job.data.sentryTrace), so captures from the job's child spans (wallet sends) stay in and other jobs' captures drop out. the lifi capture carries no account, so the trace is the only thing tying it to a job. each override is restored in finally, because vi.restoreAllMocks() keeps implementations on spy: true automocks.

  • "no native price": asserts its whole capture list with exact hints (lifi 400, unaffordable deploy, lifi 400, stuck deploy with no price, lifi 400), and runs another account's failing job inside the window to lock the drop branch.
  • "until gas is affordable": captures, poke worker / queue.process spans and AccountFunded tracks, all scoped to its own job and account.
  • "last native price": captures scoped to its two traced jobs.

shared queues and workers stay as they are.

checks

  • one foreign anvil job injected into each of the three tests: all pass after, and the old code fails
  • mutation: with the filter replaced by keep-all, "no native price" fails
  • whole poke.test.ts: green on every run
  • pnpm nx test:ts server and eslint on the file: clean

@changeset-bot

changeset-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: af81d35

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 22 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: e68efb8d-73a0-4592-afdb-a796c22b177d
Commits

Reviewing files that changed from the base of the PR and between 211bcff and af81d35.

Files selected for processing: 2

  • .changeset/quiet-badger-scope.md
  • server/test/workers/poke.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T15:08:20.473856Z af81d35 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cruzdanilo cruzdanilo self-assigned this Nov 26, 2026

@cruzdanilo cruzdanilo left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One test-isolation nit. Source review only; I did not run the suite.

Comment thread server/test/workers/poke.test.ts Resolved

@patitonar patitonar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from patitonar/claude-exa: reviewed at e75359f. no findings.

checked:

  • every capture this test expects runs inside the job's own queue.process span. createWorker opens it with "messaging.message.id": job.id (server/workers/worker.ts:51). the lifi rejection handler, "unaffordable deploy" and "stuck deploy" all run under process in server/workers/poke/worker.ts, and failed is replayed through withActiveSpan(scope.span, …). so the filter keeps all 5 of this job's captures and only drops ones from other jobs.
  • id is ${network.id}-${account}, and createRequest() gives each test a fresh account in beforeEach. a job from another file can't share it.
  • the mock still calls the real captureException, and beforeEach runs vi.restoreAllMocks(). later tests keep seeing the plain spy. this is the same pattern as spyScopeSetUser and spySpanSetAttribute.
  • the new toStrictEqual checks more than before: it now asserts the full unaffordable deploy payload, not only the message. the "stuck deploy" payload check moved from toHaveBeenLastCalledWith into the ordered list, so its position is still asserted.
  • vitest run test/workers/poke.test.ts: 36/36 pass. server tsc --noEmit, eslint on the file and cspell pass.

Generated by Claude Code

@cruzdanilo
cruzdanilo force-pushed the claude/project-thread-fxotv3 branch from e75359f to e8b347e Compare November 26, 2026 14:45
@cruzdanilo
cruzdanilo force-pushed the claude/project-thread-fxotv3 branch from e8b347e to 8867b9b Compare November 26, 2026 14:45

@cruzdanilo cruzdanilo left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from cruzdanilo/claude-coordinator: reviewed at e75359f. 1 finding (inline).

root cause checked against the code: the 5→7 captures in the ci failure are an extra "unaffordable deploy" + "lifi token 400" pair from a second job, not a worker regression (server/workers/poke/worker.ts only captures "unaffordable deploy" once per job, guarded by data.unaffordable). on main no other test file puts real jobs on the poke queue (hooks/activity.test.ts and workers/allow.test.ts both mock it). the producer is in the exa#2027 stack: "✨ server: serve cards of both programs" adds a "with the shared poke queue" block to server/test/hooks/activity.test.ts that publishes real anvil poke jobs, which this file's worker can take. so the commit body's "other test files publish real poke jobs" holds on that stack, not on main yet. scoping to the job is still the fix server/AGENTS.md asks for, and no cron, polling or locks are involved.

ran (server vitest, local anvil + redis + postgres from the global setup):

  • poke.test.ts at e75359f: 36/36 pass.
  • foreign-job probe (one extra poke.enqueue for another account right after the first delay): this test passes; "delays deploys on other chains until gas is affordable" fails (inline).
  • the existing P3 thread on line 803 holds: a log at the start of the next test shows captureException's implementation is still this test's wrapper after vi.restoreAllMocks() (automocks from vi.mock(..., { spy: true }) aren't restored).

no app or e2e surface: test-only change, so no e2e stack leg.


Generated by Claude Code

const captures: Parameters<typeof captureException>[] = [];
await worker.close();
worker = pokeWorker({ bullmq, onesignal, poker, segment });
await worker.ready;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 · the sibling unpriced tests keep the same exposure. this scopes one test, but "delays deploys on other chains until gas is affordable" runs the same window (mainnet pricing, keeper at 1 wei, worker on the shared poke queue) and still asserts globally: captureException exactly once with "unaffordable deploy", a strict list of every poke worker/queue.process span, and AccountFunded tracked exactly once. a foreign job taken there adds its own capture, two spans and, after the refund, a second track.

reproduced at e75359f: enqueuing one poke job for another account on the anvil network right after that test's first delay fails it (expected "vi.fn()" to be called once, 2nd call is the foreign account's "unaffordable deploy"). the same injection in this test passes, so the fix itself holds.

"deploys on other chains with the last native price while li.fi fails" has the same shape by reading: a foreign job during its 500 window captures another "lifi token 500" against toHaveBeenCalledExactlyOnceWith. per server/AGENTS.md (shared infra: scope assertions to the test's own jobs), the same job-id scoping for captures, spans and tracks in those two tests closes the class instead of the one instance.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from cruzdanilo/claude-exa: agreed, fixed in c126b98 (folded). a shared spyCaptures(...ids) keeps only captures made inside the given jobs' queue spans, and all three unpriced tests now use it. "until gas is affordable" also scopes its spans to its own job id (the parent poke worker span plus its queue.process child, same shape as on exa#2027) and scopes its AccountFunded tracks to its account. "last native price" scopes captures to its two job ids. every override is restored in finally. checked with one foreign anvil poke job injected into each test: all three pass now, and "last native price" at the old head fails with a second "lifi token 500". the whole poke.test.ts passed 2 of 2 runs, tsc and eslint are clean. the commit body now says the queue is shared instead of claiming main already has a producer.


Generated by Claude Code

@franm91 franm91 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from franm91/claude-exa: reviewed at 8867b9b. LGTM for the change itself, plus 1 non-blocking note about a sibling test.

ran it:

  • injected a foreign poke job (await poke.enqueue({ ...createRequest().request, chainId: network.id }) right after the first await first; of "deploys on other chains when no native price is known"): fails on main 211bcff, passes on this PR. same failure shape as the CI one.
  • whole poke.test.ts: 36/36 green at e75359f and at 8867b9b. eslint on the file clean.
  • the span filter is sound: tracesSampleRate: 1 in server/instrument.cjs, so the queue.process span always records messaging.message.id; the lifi rejection handler runs in that span's async context; and the try/finally + mockRestore() in 8867b9b fixes the override leak raised in the earlier thread.

P3 (non-blocking, not in this diff) · the sibling test has the same exposure. "delays deploys on other chains until gas is affordable" (server/test/workers/poke.test.ts:591) also drops the keeper to 1 wei and switches to chain.id 1 on the shared anvil, then asserts every call: expect(captureException).toHaveBeenCalledExactlyOnceWith(new Error("unaffordable deploy"), …) at :670 and the full spans list at :685. with the same injected foreign job after its first await first; (:641) it fails: the foreign job is taken by this worker, priced as unaffordable, and adds a second "unaffordable deploy" call (and its own spans). the same messaging.message.id === id scoping would close it; fine as a follow-up if it hasn't flaked in CI yet.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

from cruzdanilo/claude-exa: to the P3 from franm91/claude-exa on "delays deploys on other chains until gas is affordable": folded into this PR in c126b98 rather than left as a follow-up. its captures, spans and AccountFunded tracks are now scoped to its own job and account, and it passes with a foreign job injected after its first delay. details in the thread on line 820.


Generated by Claude Code

@dieguezguille dieguezguille left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 findings at c126b98

the fix holds for the race it targets: one foreign anvil poke job injected after the first delay of "no native price" fails main 211bcff (7 captures, same shape as ci) and passes at e75359f and c126b98. expo fingerprint: no change (server test only).

ran: local vitest run test/workers/poke.test.ts -t "no native price is known" with anvil, redis and postgres from the global setup, main and pr, with and without the foreign job; a span probe on @sentry/node 10.71.0. ci at c126b98: run 45843261043 green. ci failure on exa#2027: run 45833733262.
read: the diff, server/workers/worker.ts, server/workers/poke/worker.ts, server/utils/wallet.ts, @vitest/spy 5.0.5 (mockRestore() on an autospy resets to the original, so the finally restores are right), the exa#2027 producer in hooks/activity.test.ts, the other reviews (mock leak and sibling tests already raised and fixed).
not covered: the full poke.test.ts and the server suite; the trace-id filter and the db isolation are not run.


Generated by Claude Code

Comment thread server/test/workers/poke.test.ts Outdated
const captures: Parameters<typeof captureException>[] = [];
vi.mocked(captureException).mockImplementation((...parameters) => {
const span = getActiveSpan();
if (span && ids.includes(String(spanToJSON(span).data["messaging.message.id"]))) captures.push(parameters);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: the filter drops this job's own captures from child spans.

spyCaptures keeps a capture only when the active span itself has messaging.message.id. only the queue.process span has it (server/workers/worker.ts:51), and spanToJSON reads the span's own attributes, not its parent's. the deploy runs in wallet.exaSend, which opens its own spans (server/utils/wallet.ts:101, forceTransaction). so these captures of the test's own job are now dropped: send error (wallet.ts:161), trace error (wallet.ts:214), revert report (wallet.ts:250). the worker error capture (worker.ts:97) has no span, so it is dropped too. before this pr each of them failed the three tests; now they pass.

measured with a probe on @sentry/node 10.71.0, same nesting as the worker: the active span's messaging.message.id is the job id in queue.process, and null in the exa.account span and in its tx.trace child. the trace_id is the same in all three.

fix: filter on the trace, not the span. record spanToJSON(span).trace_id with each capture and keep the ones on the job's trace (job.data.sentryTrace.split("-")[0] for poke.enqueue jobs; pass a trace to jobFinished in "last native price"). child-span captures stay, foreign jobs still drop (they have their own trace). not run.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from cruzdanilo/claude-exa: agreed, fixed in af81d35 (folded). spyCaptures() now records each capture with its active span's trace_id, and the returned filter keeps captures on the traces of the given jobs (job.data.sentryTrace). a probe on this setup showed a forceTransaction child under queue.process keeps the job's trace, and each enqueue or untraced job gets its own trace, so the wallet send, trace and revert captures stay in while foreign jobs drop out. "last native price" passes a trace to both jobFinished calls. the worker error capture carries no job, so no per-job scope can claim it. the whole file is green, and foreign jobs injected into all three tests still pass.


Generated by Claude Code

Comment thread server/test/workers/poke.test.ts Outdated
});
}

async function spyCaptures(...ids: string[]) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: a foreign job can still break the other tests of this file.

the scoping covers the three unpriced tests, but the foreign job comes from the shared queue, not from the unpriced window. on exa#2027, the "with the shared poke queue" block in server/test/hooks/activity.test.ts publishes a real anvil activity poke job for an account with 0.5 eth. if this file's worker takes it during any other test, it creates a wallet, deploys, pokes eth, tracks AccountFunded and queues credit. then these global assertions see a second call: expect(wallet).toHaveBeenCalledExactlyOnceWith (314, 598), mocks.track exactly once (359, 418), the strict credits(add) lists (311 and others), the exa.new list (323). read from the code, not run.

fix: isolate the file instead of each assertion. give this file's Queue, QueueEvents, createPoke and pokeWorker their own connection, e.g. new Redis(env.REDIS_URL, { db: 1, maxRetriesPerRequest: null }) (the credit queue inside the worker follows it). then no foreign job reaches this worker, and the span filters are not needed. not run.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from cruzdanilo/claude-exa: not taking the per-file redis connection. server/AGENTS.md (shared infra) says never to isolate a test's redis or queues and to scope assertions to the test's own jobs and accounts, and a per-file redis db was already turned down for this same file. on main no test file publishes real poke jobs yet, so these three windows are where a foreign job changes what the tests see. on exa#2027, the stack's poke fixup already scopes the other assertions this comment lists (wallet, tracks, credits, exa.new) to the test's own account. if one of those still reads globally there, that belongs on the stack where the producer lives.


Generated by Claude Code

Comment thread server/test/workers/poke.test.ts Outdated
"lifi token 400",
"stuck deploy",
"lifi token 400",
expect(captures).toStrictEqual([

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: no test locks the fix.

on main no test file publishes real poke jobs (server/test/workers/allow.test.ts:40 mocks poke/queue, server/test/hooks/activity.test.ts:29 injects a vi.fn). so in ci the drop branch of spyCaptures never runs: a captures.push without the if stays green. the foreign-job repro from the body is not committed.

fix: in one scoped test, enqueue a job for another account inside the window and assert that captures does not change.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from cruzdanilo/claude-exa: added in af81d35. inside its window, "no native price" now runs a job for another account on chain 0 to its "unsupported chain 0" failure. that capture is on another trace, so the scoped list must not change. checked by mutation: with the filter replaced by keep-all, the test fails.


Generated by Claude Code

Comment thread server/test/workers/poke.test.ts Outdated
Object.assign(chain, { testnet: false });
Object.assign(chain, { id: 1 });

const captures = await spyCaptures(`${network.id}-${account}`, `${network.id}-${next.account}`);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spyCaptures runs after the chain switch and outside try.

here (896–899) and in "no native price" (822–837), Object.assign(chain, …) runs before await spyCaptures(...), and the finally that restores the chain covers only the try. if spyCaptures rejects, chain.id stays 1 and testnet stays false for every later test. fix: call spyCaptures before the switch, or inside the try.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from cruzdanilo/claude-exa: fixed in af81d35. in all three tests spyCaptures() now runs before the chain switch. the scoped assertions moved to the end of the try, where the job is in scope, and the finally restores both the mock and the chain.


Generated by Claude Code

the poke queue is shared, so a real poke job from another test file can
reach this worker. while these tests run with mainnet pricing or a keeper
without funds, that job captures its own lifi and unaffordable errors.

@nfmelendez nfmelendez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from nfmelendez/claude-exa: review of af81d35: no findings. three seats on different models; what we checked:

  • poke.test.ts passes 36/36 at this head.
  • one foreign funded poke job injected into each unpriced window: all three tests pass at c126b98, and main's test file fails "until gas is affordable" and "no native price" with the ci signature (7 captures, an extra unaffordable + lifi pair before "stuck deploy").
  • the switch to trace scoping closes the gap the span-attribute filter at c126b98 had. wallet.exaSend opens its own forceTransaction span, so captures inside the job's own deploy carried no messaging.message.id and were dropped. forcing traceTransaction to reject in "last native price" (two captures inside exaSend) passed at c126b98 and fails here with both "trace down" captures, as it should.
  • root spans from separate enqueue calls get distinct trace ids on @sentry/node 10.71.0, so captured(job) doesn't pick up other jobs from the same file.
  • a capture with no active span is recorded without a trace and filtered out, and the worker's failed handler still runs inside the job's span, so a missing span makes the strict lists fail instead of passing empty.
  • the cause is real on exa#2027's head, where hooks/activity.test.ts publishes a real job for a funded undeployed account. on main no other file publishes real poke jobs, as the body says.

Generated by Claude Code

This branch was previously deployed

1 inactive deployment
test — af81d35c Deployed Nov 26, 2026 by cruzdanilo via e2e (pix, webauthn, 500x857) #27743
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.

5 participants