Keep the latest workspace response through harness compaction, so a run does not leave its workspace
No issue: found while building clai2's /sandbox (#13592), reproduced with a test.
A run finds its workspace from the latest ModelResponse's workspace_ref. Harness compaction keeps the newest messages, and when those are only requests (a large user turn, or a clai2 !command before /compact), every response goes and the next run quietly leaves its workspace. In clai2 a sandboxed conversation then runs, and edits files, on the user's machine.
The fix: find_safe_cutoff and find_token_cutoff (compaction/_shared.py) move the cutoff back to the latest response when the kept tail has none and that response names a workspace. That keeps at most one more message, which only requests follow.
Who it reaches: only harness compaction (sliding window, summarizing, relevance; nothing else calls these helpers), and only histories whose responses carry a workspace_ref. Relevance compaction already started its tail at a response, so it is unchanged in practice. When summarizing compaction trims the messages it preserves, the trim can keep that one response beyond retained_tail_slots.
pax had its own copy of this fix (_keeping_workspace in builtin_plugins/compaction.py, from #13592), which added an empty response naming the workspace after /compact. With harness compaction keeping the response, that copy never runs, so it is removed and the two pax tests now check that /compact keeps the latest workspace response.
Tests: test_the_latest_workspace_response_is_kept (sliding window and summarizing, by tokens, zero tokens and messages) fails without the fix.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.
Summary by cubic
Fixes harness compaction so a run no longer silently leaves its workspace when the kept tail has no responses.
A run finds its workspace from the latest ModelResponse's workspace_ref. Compaction could cut a history to end in only requests—for example, a large user turn after the last response—and the next run would then execute outside the workspace. find_safe_cutoff and find_token_cutoff now move the cutoff back to keep the latest response when it names a workspace, retaining at most one extra message. The test covers the tokens, messages, and zero-token legacy cutoff paths.
- Only harness compaction paths are affected; relevance compaction already started its tail at a response and is unchanged in practice.
- Summarizing compaction's trim may keep that response beyond
retained_tail_slots, whatever its size. - pax's workaround of appending an empty workspace response after
/compactis removed; its tests now assert/compactkeeps the latest response, anddocs/harness/compaction.mdand the compactionREADME.mddocument the behavior.