diff --git a/packages/paperclip-runner/src/control-plane/durable-prp-control-plane.test.ts b/packages/paperclip-runner/src/control-plane/durable-prp-control-plane.test.ts index 01695a68a53..240eb894062 100644 --- a/packages/paperclip-runner/src/control-plane/durable-prp-control-plane.test.ts +++ b/packages/paperclip-runner/src/control-plane/durable-prp-control-plane.test.ts @@ -108,9 +108,6 @@ function fillAndRetireCommandJournal(core: DurablePrpControlPlane): void { } it("keeps room to retire a session whose work filled the command journal", async () => { - // A long run can journal one semantic tool result per call until the work - // bound is reached. The next run must still be able to stop, drain, suspend - // and close that session, or every successor fails predecessor retirement. const root = mkdtempSync(resolve(tmpdir(), "runner-full-journal-retirement-")); const core = new DurablePrpControlPlane({ stateDirectory: root, identity, expectedRunnerVersion, expectedRunnerDigest }); let reopened: DurablePrpControlPlane | undefined; @@ -128,6 +125,27 @@ it("keeps room to retire a session whose work filled the command journal", async } }); +it("bounds the retirement reserve and leaves the journal unchanged when it is full", async () => { + const root = mkdtempSync(resolve(tmpdir(), "runner-full-journal-reserve-bound-")); + const core = new DurablePrpControlPlane({ stateDirectory: root, identity, expectedRunnerVersion, expectedRunnerDigest }); + try { + fillAndRetireCommandJournal(core); + for (let index = 504; index < 563; index += 1) { + core.queueCommand("runner.suspend", {}, `command_retire_suspend_${index}`); + } + expect(core.store.state.commands).toHaveLength(563); + expect(core.queueCommand("session.close", {}, "command_retire_last").controllerSeq).toBe(564); + expect(core.store.state.commands).toHaveLength(564); + const before = JSON.stringify(core.store.state.commands); + expect(() => core.queueCommand("runner.suspend", {}, "command_retire_overflow")).toThrow("command_journal_full"); + expect(() => core.queueCommand("session.snapshot")).toThrow("command_journal_full"); + expect(JSON.stringify(core.store.state.commands)).toBe(before); + } finally { + await core.stop(); + rmSync(root, { recursive: true, force: true }); + } +}); + it("checkpoints a retired session whose work filled the command journal", async () => { const root = mkdtempSync(resolve(tmpdir(), "runner-full-journal-checkpoint-")); const core = new DurablePrpControlPlane({ stateDirectory: root, identity, expectedRunnerVersion, expectedRunnerDigest }); diff --git a/packages/paperclip-runner/src/control-plane/durable-prp-control-plane.ts b/packages/paperclip-runner/src/control-plane/durable-prp-control-plane.ts index 17dadd7e85a..5f0d290fbf9 100644 --- a/packages/paperclip-runner/src/control-plane/durable-prp-control-plane.ts +++ b/packages/paperclip-runner/src/control-plane/durable-prp-control-plane.ts @@ -67,10 +67,6 @@ const maxFrameBytes = 1024 * 1024; const maxCommandBytes = Math.floor((maxFrameBytes - 4 * 1024) / 2); const RUN_ATTACH_ENVELOPE_BYTES = 32 * 1024; const maxCommands = 500; -// Work commands (tool results, turns, reads) stop at maxCommands. A session -// whose work fills that bound must still be stoppable and retirable by the -// next run, so these commands keep a separate bounded reserve. Each close -// attempt issues at most a stop, a drain and a few suspends. const retirementCommandTypes = new Set([ "turn.stop", "runner.drain", "runner.suspend", "runner.shutdown", "session.close", "session.destroy", "run.cancel", ]);