Skip to content

test(daemon-client): stop waiting out the contention budget in real time - #4856

Merged
thymikee merged 1 commit into
0.22from
fix/0.22-daemon-client-contention-test-real-wait
Nov 20, 2026
Merged

thymikee merged 1 commit into
0.22from
fix/0.22-daemon-client-contention-test-real-wait

Conversation

@thymikee

@thymikee thymikee commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Same commit as #4855, cherry-picked onto 0.22. The patch is identical, so the next 0.22 rebase of main drops it rather than conflicting.

daemon-client-ensure-explicit-lifecycle.test.ts proved the contention budget by exhausting it. ensureDaemon judges a contended state directory once per attempt and waits JUDGE_AGAIN_DELAY_MS between attempts, for ceil(DAEMON_TEARDOWN_GRACE_MS / JUDGE_AGAIN_DELAY_MS) = 300 attempts. The file already mocks sleep, so the waits were free — but every attempt re-reads the registration, and one read of a held lock runs one host process-table snapshot. 300 snapshots of a registration the case keeps alive and unchanged is the real wall clock, and it is what broke the slow-test gate and the 5 s test timeout in the Stryker dry run (see #4855).

The two daemon-lifecycle-contended tests now read that lock inspection once, from the real host, and replay it for the rest of the loop, scoped to that one lock path, and assert the attempt budget through the waits it asks for instead of waiting it out. No production change, no new option.

Measured locally, solo file, --project unit-core, base and head on the same install and machine:

Test base 7216f2a2a6 head
reports contention when the daemon keeps changing under it 731 ms 172–215 ms
a quiesce the daemon never hears is judged again 726 ms 158–202 ms

Validation

Head c241f8ca5a, focused checks (no local check:affected, per task):

  • the two tests, 5 consecutive full-file runs: green, well under 500 ms
  • whole file: 24 passed; packages/daemon-client: 40 files, 352 passed (the 3 gate warnings left are pre-existing, other files)
  • pnpm typecheck, pnpm check:layering, pnpm format, fallow audit --base origin/0.22: clean
  • mutation: ENSURE_ATTEMPTS halved → 2 failed | 22 passed (150 judge-again waits of 250ms must just cover the 75000ms teardown grace (37500ms)), reverted by hand

Unresolved, as on #4855: unrelated tests here still do 1–5 real 100–250 ms probe waits (max 1.1 s). Bounding those means the virtual clock daemon-client-ensure-drain.test.ts already has — separate work.

`ensureDaemon` judges a contended state directory once per attempt and waits
`JUDGE_AGAIN_DELAY_MS` between attempts, for `ceil(DAEMON_TEARDOWN_GRACE_MS /
JUDGE_AGAIN_DELAY_MS)` attempts. The file already mocks `sleep`, so the waits
cost nothing, but every attempt re-reads the registration, and one read of a
held lock runs one host process-table snapshot. 300 snapshots of a
registration the case keeps alive and unchanged is what made these two tests
the slowest in the file and pushed them past the slow-test budget on 2-core
runners, and to the 5 s test timeout inside the Stryker dry run.

Read the registration's lock inspection once, from the real host, and replay
it for the rest of the loop, scoped to that one lock path. The budget is now
asserted through the waits it asks for instead of being waited out, so
shrinking the loop in production fails these tests.
@github-actions

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.19 MB 6.19 MB 0 B
Package (unpacked) 6.19 MB 6.19 MB 0 B
Package (download) 1.89 MB 1.89 MB -4 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 27.0 ms 27.8 ms +0.8 ms
CLI --help 54.4 ms 50.1 ms -4.2 ms

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of c241f8c

No open findings.

Reviewed with this repository's own Sentinel configuration (357e0d4a7513).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@thymikee

Copy link
Copy Markdown
Member Author

The change at c241f8c looks correct, with no problems found in the diff. It only touches tests, and all 14 checks pass. There are no conflicts. Not verified here: the tests and the mutation were not run locally.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 20, 2026
@thymikee
thymikee merged commit 6d9beca into 0.22 Nov 20, 2026
14 checks passed
@thymikee
thymikee deleted the fix/0.22-daemon-client-contention-test-real-wait branch November 20, 2026 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant