From ba068dc06cdcc1e8f950aea473c0b364bdc50ca1 Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Thu, 24 Sep 2026 10:46:18 +0530 Subject: [PATCH] test(agents): assert compaction disposal ordering without wall-clock races (#157036) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../compact.foreground-resources.test.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/agents/embedded-agent-runner/compact.foreground-resources.test.ts b/src/agents/embedded-agent-runner/compact.foreground-resources.test.ts index 34778fc8ff28..cda539654cf7 100644 --- a/src/agents/embedded-agent-runner/compact.foreground-resources.test.ts +++ b/src/agents/embedded-agent-runner/compact.foreground-resources.test.ts @@ -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,