diff --git a/src/cron/isolated-agent/run.meta-error-status.test.ts b/src/cron/isolated-agent/run.meta-error-status.test.ts index 50738a22345..a6b6fb8b980 100644 --- a/src/cron/isolated-agent/run.meta-error-status.test.ts +++ b/src/cron/isolated-agent/run.meta-error-status.test.ts @@ -2,10 +2,15 @@ import { describe, expect, it } from "vitest"; import { CommandLaneTaskTimeoutError } from "../../process/command-queue.js"; import { + makeIsolatedAgentTurnJob, makeIsolatedAgentTurnParams, setupRunCronIsolatedAgentTurnSuite, } from "./run.suite-helpers.js"; -import { loadRunCronIsolatedAgentTurn, runWithModelFallbackMock } from "./run.test-harness.js"; +import { + cleanupDirectCronSessionMock, + loadRunCronIsolatedAgentTurn, + runWithModelFallbackMock, +} from "./run.test-harness.js"; const runCronIsolatedAgentTurn = await loadRunCronIsolatedAgentTurn(); @@ -68,10 +73,20 @@ describe("runCronIsolatedAgentTurn - meta.error status propagation", () => { attempts: [], }); - const result = await runCronIsolatedAgentTurn(makeIsolatedAgentTurnParams()); + const result = await runCronIsolatedAgentTurn( + makeIsolatedAgentTurnParams({ + job: makeIsolatedAgentTurnJob({ deleteAfterRun: true }), + }), + ); expect(result.status).toBe("error"); expect(result.error).toBe("cron isolated agent run aborted"); + expect(cleanupDirectCronSessionMock).toHaveBeenCalledWith({ + job: expect.objectContaining({ deleteAfterRun: true }), + agentSessionKey: "agent:default:cron:test", + sessionId: "test-session-id", + retireReason: "cron-delete-after-run-aborted", + }); }); it("surfaces cron timeout result when the cron-nested lane watchdog fires", async () => { diff --git a/src/cron/isolated-agent/run.ts b/src/cron/isolated-agent/run.ts index 5ee43ba28b8..9e45e4046d8 100644 --- a/src/cron/isolated-agent/run.ts +++ b/src/cron/isolated-agent/run.ts @@ -1081,6 +1081,13 @@ async function finalizeCronRun(params: { if (finalRunResult.meta?.aborted === true && !cronPayloadOutcome.hasFatalErrorPayload) { const metaErrorMessage = normalizeOptionalString(finalRunResult.meta.error?.message); const error = metaErrorMessage ?? "cron isolated agent run aborted"; + const { cleanupDirectCronSession } = await loadCronDeliveryRuntime(); + await cleanupDirectCronSession({ + job: prepared.input.job, + agentSessionKey: prepared.agentSessionKey, + sessionId: prepared.currentRunSessionId(), + retireReason: "cron-delete-after-run-aborted", + }); return prepared.withRunSession({ status: "error", error,