Repository navigation
Description
What happened
idle schedules and armed or paused Goals allow production handoff and recover in the successor fails intermittently when the runner is under CPU contention.
The failing assertion is the second handoff's exact-handle proof, at packages/runtime-host/src/__tests__/execution-composition.test.ts:204:
const prepared = await composition.prepareHandoff!('old-host', new AbortController().signal);
assert.ok(prepared);
assert.equal(await prepared.seal(), true);
const proof = await prepared.residencies();
assert.ok(proof);
assert.equal(residencies.hasDrainResidenciesExcept(proof), false); // observed trueBetween seal() and the proof snapshot, a drain residency existed that the proof did not cover.
HostKernel applies the same check at packages/runtime-host/src/server/host-kernel.ts:965 as one of the guards a handoff must clear before it commits, and that guard fails closed: an unproven drain residency makes the handoff return false. The production consequence of this window is therefore a declined handoff, not a committed bad one. The test asserts the stronger property that the window does not open at all.
I have not isolated which residency appears. The test arms Goals and creates scheduled tasks, so a scheduler tick landing between the seal and the snapshot is one candidate, but I have not confirmed it.
How to reproduce
Intermittent, and so far only under CPU contention.
Observed once in 15 executions of the full Runtime Host suite on a GitHub-hosted ubuntu-24.04 runner with two busy loops occupying two of the four cores. The same suite on the same runner image did not fail in 41 executions without that contention — 32 on an otherwise idle runner, and 9 run directly after the workspace test batch that ci.yml schedules immediately before this suite.
npm ci
npm run build
for i in 1 2; do ( while :; do :; done ) & done
npm --workspace @maka/runtime-host run test:distEnvironment
- Commit:
17fa03647 - Runner: GitHub-hosted
ubuntu-24.04, 4 cores, 16 GB - Node.js: 24
- Surface: Runtime Host
Logs, screenshots, or additional context
✖ idle schedules and armed or paused Goals allow production handoff and recover in the successor (540.416382ms)
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
true !== false
at .../dist/__tests__/execution-composition.test.js:297:20
at async withCompositionRoot (.../execution-composition.test.js:3045:9)
at async TestContext.<anonymous> (.../execution-composition.test.js:225:5)
actual: true,
expected: false,
operator: 'strictEqual',
Round totals: tests 2104, pass 2084, fail 1, cancelled 0, skipped 19.
Activity
ggbdpq commentedon Sep 24, 2026
take
ggbdpq commentedon Sep 24, 2026
I took this earlier today and am releasing the claim (
untake) — I could not reproduce the window within a local budget, but the analysis narrowed the suspects enough that it may save the next person some reading.Where the unproven residency can come from. The proof in
execution-composition.tsaggregates exactly four sources:goalHold.residencies(prepared.executions),prepared.residencies()(per held active root turn: itsactive.residencyplus message residencies),scheduleHold.residencies(), anddailyReviewHold.residencies(). All three coordinators stop their timers when the hold lands and their holds wait out in-flight work, so post-hold tick starts are excluded. The one drain handle that can be alive at proof time yet outside all four sources isactive.residencyof a root execution that is not in the held set — i.e. a root turn that started afterRootTurnCoordinator.prepareHandoff's bounded convergence passes (three) stopped chasing new executions but beforeseal()/the proof snapshot. The convergence loop's own comment ("Natural completion can hand a queued follow-up to a fresh root while gates converge. Bound that convergence; never chase an endless queue.") describes exactly this admission.RootTurnCoordinator'sresidencies()/seal()only validate the held executions, so an unheld execution's residency sails through the proof.Why contention makes it rare. The gap needs a tick/start to straddle the last convergence pass and the seal. Under contention the passes stretch, widening the window; on an idle runner it closes before anything lands in it.
Repro notes. I instrumented the test's failing assertion (registry snapshot +
drainCounton failure) and ran the single test 15× under two busy loops with no reproduction, then the fullexecution-composition.test.jsfile under three busy loops, also without a hit — consistent with the report's 1/15 full-suite rate needing suite-scale load. The instrumentation is oneif (residencies.hasDrainResidenciesExcept(proof)) console.log(...)before the failing assert and is worth keeping until this is fixed; the snapshot's label diffs against the expected[daily-review 1, goal 2, scheduled-task 1]will name the culprit directly.Two candidate fixes, needing a design call:
seal()— after the held seals resolve, re-scan#executionsfor unheld entries and either wait them out or fold them into the hold. Airtight, but waiting on a freshly started turn could stall the handoff for the turn's whole duration, which changes handoff latency semantics.residencies()re-checkresidencies.hasDrainResidenciesExcept(proof)before returning and returnundefinedon a mismatch, converting the lying proof into a declined handoff. This matches the fail-closed production behavior already inhost-kernel.tsand makes the test'sassert.ok(proof)/retry path the arbiter, but the test as written would then need to tolerate a declined handoff, weakening what it pins.I lean toward (1) with a bounded wait for the unheld executions to reach terminal (they are, by the test's own premise, idle-host ticks that should finish quickly), but that is a semantic change a maintainer should rule on.
ggbdpq commentedon Sep 24, 2026
untake
sunrioa commentedon Sep 26, 2026
I traced the unproven residency. It is the
hosted-executiondrain residency thatHostWorkHubResultCoordinatortakes when its timer fires, and no handoff hold covers it.The path
createCapturedExecutionCompositionawaitscomposition.recover(), and recovery ends by starting the WorkHub result coordinator (execution-composition.ts#L3119-L3122).start()schedules a reconcile 100 ms later.hosted-executiondrain residency and releases it only afterreconcile()settles (workhub-result-coordinator.ts#L117-L158). The coordinator has noholdForHandoff(), andprepareHandoffholds only Goals, scheduled tasks and Daily Review (execution-composition.ts#L3159-L3203), so this residency is never part of the proof.cancelled.cancel()releases the Daily Review hold, which starts a scheduler pass that awaitsreadConfig()(daily-review-coordinator.ts#L188-L195,#L506-L508). The secondprepareHandoffwaits for that pass insettled(). That wait is real I/O, so the event loop turns there and a due timer can run; the rest of both handoffs is microtasks. This is why only the second proof fails.reconcile()is still running when the test checks the second proof, andhasDrainResidenciesExcept(proof)returnstrue.Why only under contention
In a normal run, the second check comes about 8 ms after the WorkHub coordinator starts, so the 100 ms timer fires long after the handoff, and instrumented local runs never take a
hosted-executionresidency while the test runs. The window opens only when the stretch between recovery and the handoff slows to about 100 ms. It closes again at larger slowdowns, because the timer then fires beforewaitFor(drainCount === 0)and the test waits it out. That narrow band fits one failure in 15 runs under load.Reproduction
Shortening the 100 ms startup delay moves the timer across the handoff without waiting for contention to stretch the test. Sweeping the delay from 1 ms to 20 ms in 0.5 ms steps (macOS arm64,
mainat538c37cb6, one run per value), the test failed at 7, 8, 8.5 and 9 ms and passed at every other value. All four failures were at the second proof, and in each one the only unproven handle was thehosted-executionresidency taken by the WorkHub timer, which fired between the start and the end of thatreadConfig()wait.Production impact
HostKernelruns the same check before committing a handoff and returnsfalsewhen it fails (host-kernel.ts#L950-L961). A handoff that overlaps a WorkHub reconcile is therefore declined, not committed. The reconcile runs 100 ms after start or after a relevant notification, and every 5 s or 60 s while it has pending targets. This is a liveness cost, not a safety one.Proposed fix
Give
HostWorkHubResultCoordinatoraholdForHandoff()like the other timer-driven coordinators: stop its timer, keepnotify()from scheduling while held, havesettled()wait for an in-flightreconcile(), and reschedule on release if work is pending.prepareHandoffwould then take and release it together with the other three holds. Making the test wait for the first reconcile would also make it pass, but it would hide the same interaction in production.fix(runtime-host): pause WorkHub result polling during handoff (apach…