Repository navigation
✅ server: scope unpriced deploy captures to job - #2139
cruzdanilo wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: af81d35 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen 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 |
|
Warning Review limit reachedYou'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. View limit details
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. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
cruzdanilo
left a comment
There was a problem hiding this comment.
One test-isolation nit. Source review only; I did not run the suite.
patitonar
left a comment
There was a problem hiding this comment.
from patitonar/claude-exa: reviewed at e75359f. no findings.
checked:
- every capture this test expects runs inside the job's own
queue.processspan.createWorkeropens it with"messaging.message.id": job.id(server/workers/worker.ts:51). the lifi rejection handler, "unaffordable deploy" and "stuck deploy" all run underprocessinserver/workers/poke/worker.ts, andfailedis replayed throughwithActiveSpan(scope.span, …). so the filter keeps all 5 of this job's captures and only drops ones from other jobs. idis${network.id}-${account}, andcreateRequest()gives each test a fresh account inbeforeEach. a job from another file can't share it.- the mock still calls the real
captureException, andbeforeEachrunsvi.restoreAllMocks(). later tests keep seeing the plain spy. this is the same pattern asspyScopeSetUserandspySpanSetAttribute. - the new
toStrictEqualchecks more than before: it now asserts the fullunaffordable deploypayload, not only the message. the "stuck deploy" payload check moved fromtoHaveBeenLastCalledWithinto the ordered list, so its position is still asserted. vitest run test/workers/poke.test.ts: 36/36 pass. servertsc --noEmit, eslint on the file and cspell pass.
Generated by Claude Code
e75359f to
e8b347e
Compare
e8b347e to
8867b9b
Compare
cruzdanilo
left a comment
There was a problem hiding this comment.
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.tsat e75359f: 36/36 pass.- foreign-job probe (one extra
poke.enqueuefor 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 aftervi.restoreAllMocks()(automocks fromvi.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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 firstawait 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: 1inserver/instrument.cjs, so thequeue.processspan always recordsmessaging.message.id; the lifi rejection handler runs in that span's async context; and thetry/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
8867b9b to
c126b98
Compare
|
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 Generated by Claude Code |
dieguezguille
left a comment
There was a problem hiding this comment.
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
| 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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
| }); | ||
| } | ||
|
|
||
| async function spyCaptures(...ids: string[]) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
| "lifi token 400", | ||
| "stuck deploy", | ||
| "lifi token 400", | ||
| expect(captures).toStrictEqual([ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
| Object.assign(chain, { testnet: false }); | ||
| Object.assign(chain, { id: 1 }); | ||
|
|
||
| const captures = await spyCaptures(`${network.id}-${account}`, `${network.id}-${next.account}`); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
c126b98 to
af81d35
Compare
nfmelendez
left a comment
There was a problem hiding this comment.
from nfmelendez/claude-exa: review of af81d35: no findings. three seats on different models; what we checked:
poke.test.tspasses 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.exaSendopens its ownforceTransactionspan, so captures inside the job's own deploy carried nomessaging.message.idand were dropped. forcingtraceTransactionto reject in "last native price" (two captures insideexaSend) passed at c126b98 and fails here with both "trace down" captures, as it should. - root spans from separate
enqueuecalls get distinct trace ids on @sentry/node 10.71.0, socaptured(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
failedhandler 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.tspublishes 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
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.id1,testnetfalse), point li.fi at a failing response and, in two of them, drop the keeper to 1 wei on the shared anvil. thepokequeue 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 inhooks/activity.test.tspublishes them). that job prices its own deploy on the anvil network and captures its own "lifi token …" and "unaffordable deploy". the tests read everycaptureExceptioncall, 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 infinally, becausevi.restoreAllMocks()keeps implementations onspy: trueautomocks.poke worker/queue.processspans andAccountFundedtracks, all scoped to its own job and account.shared queues and workers stay as they are.
checks
poke.test.ts: green on every runpnpm nx test:ts serverand eslint on the file: clean