mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 06:03:51 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Native agent runs use a Runner. Core keeps a durable journal of the commands that it sends to the Runner. > - The journal stops at 500 commands. A long run adds one semantic tool result to the journal for each tool call, so the journal can become full. > - The next run on the same sandbox must retire that session. It must queue `turn.stop`, `runner.drain`, `runner.suspend` and `session.close`. The full journal rejects these commands. > - Each successor run then fails with `native_predecessor_retirement_unproven` (`command_journal_full`). The task stays stuck until a person intervenes. > - This pull request keeps a separate, bounded reserve in the journal for retirement commands only. > - The benefit is that the next run can always stop and close a session whose work filled the journal. ## Linked Issues or Issue Description **What happened?** A long native run (Codex app-server) made almost 500 tool calls. Its Core command journal became full. Three automatic successor runs on the same sandbox then failed in `retireWarmPredecessor`. The error was "The previous run's session on this sandbox could not be retired (Durable PRP command journal bound exceeded: command_journal_full.)". The stack ends in `DurablePrpControlPlane.queueCommand` from `awaitRunnerSuspensionBarrier`. **Expected behavior** The next run retires the old session and continues. A full work journal must not block the commands that stop and close the session. **Steps to reproduce** 1. Create a `DurablePrpControlPlane`. 2. Queue 500 `semantic_tool.result` commands. 3. Queue `turn.stop`, `runner.drain`, `runner.suspend` or `session.close`. 4. On `master`, each of these throws `command_journal_full`. **Paperclip version or commit** `986af44e94` (`master`). The failure was seen on release `3f882fc589`. **Agent adapter(s) involved** Codex (native Runner, `paperclip_runner` adapter). The journal is not adapter-specific. Related: #20727 (a draft about the other journal bound, `command_payload_too_large`). This PR does not change that bound. ## What Changed - `durable-prp-control-plane.ts`: work commands still stop at 500 (`maxCommands`). - Retirement commands (`turn.stop`, `runner.drain`, `runner.suspend`, `runner.shutdown`, `session.close`, `session.destroy`, `run.cancel`) can use 64 more slots (`retirementCommandReserve`). Reads such as `session.snapshot` cannot use the reserve, so readiness polls cannot consume it. - The saved-state check and the checkpoint check accept up to 564 commands. Without this change, a retired journal cannot load again. - Three tests: one fills the journal and retires it, then reopens the local state. One does the same with checkpoint persistence and decodes the checkpoint. One fills the reserve to 564 commands and checks that a 565th retirement command and a read are both rejected without changing the journal. ## Verification - Red before the fix: `npx vitest run src/control-plane/durable-prp-control-plane.test.ts -t "command journal"` failed with `command_journal_full` on `turn.stop`. - Green after the fix: the same command passes (2 tests). - Each load bound is necessary: when I put back the old bound in the two validation checks, both tests fail. - Reserve bound: with the hard-cap check removed, the boundary test fails (`expected [Function] to throw an error`). - After review fixes (3c6fe49e80): `durable-prp-control-plane.test.ts` passes (238 tests). - Affected suites (3e72d97be6): `durable-prp-control-plane.test.ts`, `durable-prp-checkpoint-records.test.ts` and `warm-attachment-readiness.test.ts` pass (248 tests). - The Rust Runner has no command-count bound. It compacts its own journal, so it accepts the extra controller sequences. - Not run locally: the full suite and `pnpm verify` (its selection step did not finish in 5 minutes on this machine). CI supplies this coverage. ## Risks - Low risk. Work commands keep the same 500 bound. The journal can grow by a maximum of 64 small retirement commands. - A run whose work fills the journal still stops its own work at 500 commands. This PR does not change that limit. It only makes sure that the next run can retire the session. - An older Core build that loads a journal with more than 500 commands rejects that state. This can only occur after a rollback, and it fails closed as before. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use (shell, file edit, Sentry and Paperclip tools) in Claude Code. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: paperclipbugbot <356415228+paperclipbugbot@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>