test(agents): assert compaction disposal ordering without wall-clock races (#157036)

Related: #156872

## What Problem This Solves

Fixes intermittent compaction lifecycle test failures on busy CI runners.

## User Impact

No user-visible behavior changes. The test still checks that resources survive disposal work and that expired compaction work cannot write.

## Why This Change Was Made

`e789666d` introduced a 50 ms resume-to-disposer assertion while moving cold worker preparation into running-task admission. That measured interval still includes awaited durable terminal settlement and publication through SQLite workers, so scheduler contention can exceed 50 ms without a disposal regression. Replace the clock with an assertion in the existing terminal-task observer that disposal has not started before terminal publication. Keep the existing disposal-entry, resource lifetime, factory shutdown, and write-authority checks.

## Evidence

- Same whole-file command under 96 CPU load workers: original failed only the deferred factory-service latency assertion (54.55 ms; 7/8 cases passed); replacement passed 8/8. Command wall times were 170.83 s and 186.70 s under load.
- Whole file passed 20/20 consecutive runs (160 cases); command wall 22.59–23.78 s, mean 22.87 s, with one Vitest worker.
- Negative controls: closing the resource database at deferred disposer entry failed both deferred cases' resource/read assertions; bypassing the queued transcript write guard failed the timeout, caller-abort, and success-tail stale-write assertions. All mutations were removed.
- Test-only change: one ordering assertion added, seven timing lines removed; no production changes.

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
This commit is contained in:
Ayaan Zaidi 2026-09-24 10:46:18 +05:30 • committed by GitHub
parent 6cf4b810c0
commit ba068dc06c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -177,8 +177,6 @@ it.for([
const values: unknown[] = [];
let lateWriteBlocked = false;
let disposalCalls = 0;
let resumedAt = 0;
let disposalLatency = 0;
let physicalDisposals = 0;
let workSignal: AbortSignal | undefined;
let backendSignal: AbortSignal | undefined;
@ -282,7 +280,6 @@ it.for([
: pending;
},
async dispose() {
disposalLatency = performance.now() - resumedAt;
disposalCalls++;
disposalEntered.resolve();
const capturedSignal =
@ -325,6 +322,7 @@ it.for([
event.task.taskKind === CONTEXT_ENGINE_TURN_MAINTENANCE_TASK_KIND &&
isTerminalTaskStatus(event.task.status)
) {
expect.soft(disposalCalls).toBe(0);
taskSettled.resolve(event.task.status);
}
})
@ -396,7 +394,6 @@ it.for([
if (factory === "none") {
expect.soft(workSignal?.aborted ?? false).toBe(false);
}
resumedAt = performance.now();
resume.resolve();
if (deferred) {
// Worker bookkeeping publishes before engine disposal can start.
@ -406,9 +403,6 @@ it.for([
await Promise.allSettled(work.slice(0, 1));
}
await racePromiseWithAbortSignal(disposalEntered.promise, signal);
if (deferred) {
expect.soft(disposalLatency).toBeLessThan(50);
}
await withTestTimeout(
cleanupTailEntered.promise,
1_000,