Skip to content

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

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

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

Conversation

@thymikee

@thymikee thymikee commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

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.

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 357e0d4a75 head
reports contention when the daemon keeps changing under it 686–1092 ms 169–221 ms
a quiesce the daemon never hears is judged again 692–1083 ms 155–207 ms

On 2-core CI runners these two ran 4.7–5.1 s, past the 2.5 s slow-test budget (2x hard limit), and hit
the 5000 ms test timeout inside the mutation gate's Stryker dry run: Mutants (kernel-errors-3) and
(kernel-errors-4) failed three times on #4846, and the Coverage slow-test gate failed once on #4828.

Validation

Head f251a06471, 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, no slow-test entries from this file; packages/daemon-client: 40 files, 351 passed (the 3 gate warnings left are pre-existing, other files)
  • pnpm typecheck, pnpm check:layering, pnpm format, fallow audit --base origin/main, pnpm check:production-exports: clean
  • mutation: ENSURE_ATTEMPTS halved → 2 failed | 22 passed (150 judge-again waits of 250ms must just cover the 75000ms teardown grace (37500ms)); an off-by-one losing one attempt → the same 2 failures (74750 ms). Both reverted by hand; git status clean.

Unresolved: unrelated tests in this file still do 1–5 real 100–250 ms probe/poll waits (max 1.1 s,
a live daemon on another transport is quiesced). 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

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.47 MB 6.47 MB +18 B
Package (unpacked) 6.47 MB 6.47 MB +18 B
Package (download) 1.97 MB 1.97 MB 0 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 47.2 ms 30.8 ms -16.5 ms
CLI --help 128.2 ms 66.0 ms -62.2 ms

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of f251a06

No open findings.

2 findings below minor hidden (user_settings.min_severity).

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

This PR is ready at f251a06. The change is test-only and touches no production route. CI is green: 19 checks, none failing. There are no conflicts. Nothing else must happen before merge. Not verified here: the tests and the author's mutations were not run locally, and the timing figures are the author's own measurements. Not blocking, and fine to take or leave: the inspectProcessLock mock in daemon-client-ensure-explicit-lifecycle.test.ts only intercepts imports of the @agent-device/host-kit/file specifier, so if a reader resolves the lock through another path the replay would stop applying and the tests would get slow again without failing, and a call-count assertion would catch that; also registrationLockStaysAsRecorded would fail at setup, not at the behavior, on a host where the process table cannot see the child.

@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 0922cf2 into main Nov 20, 2026
19 checks passed
@thymikee
thymikee deleted the fix/daemon-client-contention-test-real-wait branch November 20, 2026 20:11
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