Repository navigation
Fix two CI flakes: a job claim renewed twice on one clock reading, and keepCompany's context closing into the next test - #1048
Merged
Merged
Conversation
…ne clock reading both land A heartbeat and the renewal that records the owner's binding can run on the same millisecond (the owner resolving just as the heartbeat's timer fires). Storage refuses a renewal that does not move the claim's expiry on, so the second one failed as a conflict: the attempt was dropped as claim-lost (or, the other way round, counted a heartbeat-lost failure) and the job sat running until its claim expired and was claimed again, spending a second attempt. CI hit it as the runner test "renews a claim after delayed owner resolution" ending with attempts 2. Both renewals now go through one helper that renews to at least a millisecond past the claim's current expiry. The test drives the runner's injectable scheduler and lands the owner on the first heartbeat's clock reading, which failed every time before the change.
keepCompany closed its second writer's context from the page context's close event without waiting for it, so that close could still be running when the next test began. Playwright starts a trace chunk in every context still open as a test starts, and with the conversation-plan suite's retain-on-failure tracing a context that was closing just then failed the next test before its first line: "_wrapApiCall: Target page, context or browser has been closed" in 0ms, always right after a test that kept company (decision-prose and decision-evidence on main). The join fixture now closes every context the test opened, keepCompany's included, and waits for them; keepCompany no longer closes its own.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two CI flakes, each fixed at its cause and covered by a test or a reproduction. One commit for each.
1. A background job claim renewed twice on one clock reading (a real runner bug)
apps/server/src/jobs/runner.test.ts"renews a claim after delayed owner resolution without reclaiming the attempt" failed on #1043 (run 46540622380) withattempts: 2, failures: 0and only attempt 2's progress.Cause.
JobRunnerrenews a claim from two places: the heartbeat timer, and#executeonce the owner resolves, to record the owner's binding. When both run on the same millisecond (the owner resolving just as the heartbeat fires), storage refuses the second renewal, because a renewal must move the expiry on (expiresAt <= found.claimExpiresAtinstorage/memory/jobs.ts:238andstorage/postgres/jobs.ts:427). If the binding renewal comes second, the attempt is dropped asclaim-lostand the job staysrunninguntil its claim expires, then is claimed again, which spends a second attempt. That matches the CI signature. If the heartbeat comes second, aheartbeat-lostfailure is counted instead. The race predates #1043 and #1044: the runner has not changed since August. CI exposed it because CI's slower timers let the 100 ms heartbeat and the 150 ms owner sleep fire together.Evidence. Stalling the event loop for 80 ms across the first heartbeat reproduced the CI failure 10 out of 10 times:
attempts 2,failures 0, and a 1775 ms runtime against CI's 1780 ms. Logging the renewals showed both at the same millisecond, with the second refused as "changed before its claim renewal". Without a stall, 200 runs passed.Fix. Both renewals now go through one
#renewhelper, which renews to at least 1 ms past the claim's current expiry. The test now drives the runner's injectableRunnerSchedulerinstead ofBun.sleep, and resolves the owner on the clock reading of the first heartbeat.2. "conversation plan": keepCompany's context still closing when the next test starts (a test problem)
Main runs 46540012615 and 46490446036 each failed one test in 0 ms with
Error: _wrapApiCall: Target page, context or browser has been closedand no stack. The failure was in the test's first hook, which only touches files (decision-prose.e2e.ts:347anddecision-evidence.e2e.ts:348). In both runs the test before it usedkeepCompany.Cause.
keepCompany(e2e/jev-wire.ts) closed its second writer's context from the page context'scloseevent and did not wait for that close. As each test starts, Playwright starts a trace chunk in every context it still lists (playwright/lib/index.js:637and:720). A context whose close was finishing at that moment madetracing.startChunkfail the next test. Only this job runs withtrace: "retain-on-failure"andretries: 0. The main suite traces only on a retry.Evidence.
Fix. The
joinfixture now closes every context the test opened, keepCompany's included, and waits for them.keepCompanyno longer closes its own.Verification
bun run fix,bun run ciandbun run typesare clean.bun test: everything passes except two tests that fail only on this machine, whose global git config requires a signing key. Both pass withGIT_CONFIG_GLOBAL=/dev/null.