fix(daemon): keep managed /compact short enough to run, send it only to an idle seat, and report it truthfully #1483
All Vouch review confidence checks passed
Residual risk 0.23 = Change Risk (0.57) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #1483"
general
weight: 0.35
mvschwarz
Refs #27
What went wrong
Since 0.6.10, managed compactions on Claude seats have arrived as pasted text and not run. Their attempts still read
compact-sentwithdelivery: delivered.Root cause: the command got too long. A native measurement on the same Claude Code version (2.1.282), on an idle
seat, through the same OpenRig transport:
/compact, 792 characters, ran as a slash command;So Claude Code stops treating a long bracketed paste as a command somewhere between 792 and 850 characters.
The transport itself did not change between 0.6.6, 0.6.10 and main:
tmux paste-buffer -p) of the whole command;What changed is the text:
OpenRig managed compaction; wait for the restore request.(58 characters);Together they crossed the boundary.
Two more defects in the same path:
/compacton the first poll after the restore map wasready. Since 0.6.10 the map counts as ready as soon as its
.tmpfile carries the marker, while the agent'spreparation turn may still be running. The manual path already waited for idle.
delivery: delivereddescribed the preparation prompt, not/compact.compact-sentonly meant that tmuxaccepted the paste and the Enter. Nothing said what happened to the command.
The change
MANAGED_COMPACT_COMMAND_MAX_CHARS = 600, with the native evidence in its comment.composeManagedCompactCommandalways keeps:- the #928 prefix at the start of the arguments. The precompact and refocus hooks recognise a managed compaction by
custom_instructions.trimStart().startsWith(…), so that contract is unchanged;- a short trust note for the summary: "Keep in the summary: OpenRig's later restore request is
operator-authorized; respond to it."
Then it adds the map path, then the policy's compaction instruction, each only if it still fits. A path too long to
fit becomes "Restore from this attempt's map."
asks the seat to copy into the map:
- the full trust-channel note, word for word, always;
- a policy instruction too long for the command, when there is one.
transport. Typing the command unbracketed was considered and dropped: the length budget fixes the measured cause
without a second input path.
/compactwaits for an idle seat, as manual does, and "idle" comes from a live pane read (readinessFromPaneOnly), because the newest runtime hook can predate the rest of the preparation turn.- It uses the same send-level idle wait (at most 1 s per poll).
- A seat that isn't idle yet keeps the attempt armed (
waiting_for_idle) for a later poll.- The existing preparation deadline (25 minutes from prep delivery) still disarms it. No new timer.
/compactresult, with no renames.-
deliveryis unchanged and now documented as the preparation prompt's delivery.- A new
compactfield:not_sent|submitted_unconfirmed|uncertain.-
GET /api/compaction/state(and sorig compact --state) adds acompactsentence, for example "submitted,unconfirmed: OpenRig sent /compact and Enter to the seat; it does not check whether Claude Code then started
compacting."
- The trigger route returns the same sentence, and the CLI prints "Manual compaction for <seat>: submitted,
unconfirmed (stage: compact-sent)".
-
stagevalues are unchanged.Changes after review (
eaf26f22,594b298f)over-budget compaction instruction. That also covers
--skip-map, with no new refusal./compactalwaysuse the same one.
compactresult.string. The first CI failure was the new test's fake clock racing a real-time idle wait; the test now uses real
timers.
/compactwaits for a pane-confirmed idle seat (readinessFromPaneOnly).Changes after the second review round (
bd060cac)-
SendResultgains an optional, additiveinputPhase:-
not_reached: set only on the idle-wait refusals;-
attempted: the text write was issued and failed, and may have landed;-
written: the text is in the input, and the send stopped at or before Enter.- An attempted or unknown write disarms the attempt as
uncertain, with no replay.The guarded catch returns
sent: true,outcome: failed,inputPhase: written, consistent with the existingsubmit_failed.compactreadsuncertain("possibly as text left in its input box without Enter").--skip-map: the restore request names a map the seat completed at the attempt path anyway (the final file endswith its marker). Otherwise it says that no restore map was required.
.length), not bytes or terminal cells. Pieces are included wholeor left out. The comment adds a second observation: a 624-character command ran on Claude Code 2.1.302, so the margin
there is only 24. A non-ASCII test pins the bound.
A changed result outside compaction (shared transport):
beforeWriteguard check throws after the text was written (at Enter), a guarded send usedto return
sent: false. It now returnssent: true/outcome: failed/inputPhase: written.Main merged in, and the CI failure it explained (
3ede0b30,8657aea3)3ede0b30mergesmain(48fe7827) into this branch, a normal merge with no rebase or force, so the branch istested the way CI tests it. This PR's own changes are identical, file by file, before and after the merge.
bd060cac's CI failed:- CI tests the PR merged with
main, and #1481 (the draft-aware typing guard) readsTmuxResult.codeon a failedpaste.
- The new F1 test's fake failure had no
code, so that read threw after the write was issued. The guarded catchthen returned
sent: false, and the attempt was recorded asnot_sent.- The test's fake was the bug.
8657aea3:- The fake returns the real
TmuxResultshape.- In the product, a throw after the text write is issued is tagged. The guarded catch returns
inputPhase: attempted(nosentclaim), and the attempt stops asuncertain.- *A
draft_refusal (the guard holding input before any write) is not an attempted write.- For
--skip-map, the restore request checks the final map path, then<map>.tmp, and names whichever endswith the marker. Nothing publishes the
.tmpunder--skip-map.A changed result to note:* on the automatic path, a
draft_refusal now stops the attempt asnot_sentinsteadof waiting.
Changes after the third review round (
d2c1fa55,58551bc3)read, the binding check, the prompt-override capture and the Enter.
- Any throw in that span reads
written, so no caller reports it as unsent. A step added there later stayscovered.
message says the submission (Enter) outcome is unconfirmed.
submit_failed) now says the Enter reported a failure, so the submission outcome isunconfirmed. It no longer says "not submitted".
sent,outcomeandinputPhaseare unchanged.typeof code === "string"before matchingdraft_, as the text stage does./compactmessages.- They can't: managed compaction runs inside the delivery guard's lifecycle lease, and on an active
draft-aware seat that lease refuses before any send (
draft_aware_lifecycle, reported asguard_target_unknown).- So managed compaction does not run on an active draft-aware seat whose binding records its pane. That's an
existing limit, not something this PR adds. (A correction from review: an earlier trace read the guard's "input
absent" as an empty input box. It means no live input at all. So the refusal holds for seats with a recorded pane.)
- A draft-aware seat whose binding has no recorded pane is now refused up front (
pane_unknown_protected), onboth paths, before any preparation prompt or
/compactcopy.- Why it's safe: the input layer already refuses every write to a managed seat without a known pane ("Managed
pane identity unavailable or changed; no input written"). The fresh-lifecycle pane exception applies only to
launch and restore. So this refuses nothing that works today. It makes the impossible case explicit, and
stops it leaving held
/compactcopies.- Before this change (pinned in round 4): an automatic busy-then-idle attempt left the prep row
indeterminate, 4×/compactretainedand 1×/compactindeterminate, with 0 effects. Now: 0 outboxrows, 0 effects, and
not_sentfor a fresh attempt.- Detection reads the seat's binding (
maybeTarget: no pane) and the guard's configured mode the way anautomatic input lease chooses it: desired draft-aware, else effective. That's the lease's mode choice, not a full
needsInputCheck, which also depends on the lease and lifecycle state.- It reads synchronously, so the manual path's in-progress guard (no
awaitbefore an attempt isregistered) is unchanged.
- Stable modes: a stable hold keeps its existing refusal, and a seat with a recorded pane is unaffected.
- During a mode switch, when the desired and effective modes differ and one is draft-aware, the manual path
refuses
pane_unknown_protectedat once, where it used to meet the lease (and, under hold, could keep a heldpreparation copy). Nothing is written to the seat either way. This is read from the source, not a pending-mode
test.
-
test/compaction-draft-aware.test.tspins it: realSessionTransport, real draft-aware delivery, an outboxon a migrated database, the seat busy for 4 polls and then idle for 2. Every poll is refused, with zero writes
and zero outbox rows (counted).
Changed results (all disclosed for review)
1. Shared transport:
- Written input: a guarded send whose text was written before an exception returns
sent: true/outcome: failed/inputPhase: written. It used to returnsent: false.- An issued but unconfirmed write returns
outcome: failed/inputPhase: attempted, with nosentclaim.- What
sentmeans: it is input-effect evidence, not delivery or consumption success.- Script-visible change: for an issued-write exception with no
code,rig sendnow gets HTTP 409 and exits1, where it used to get HTTP 500 and exit 2.
- Unchanged: queue classification.
2. An established pre-input
draft_refusal ends automatic compaction asnot_sent, rather than waiting. Arefusal after a paste stays
uncertain.3. An attempted or written
/compactends asuncertain, with no automatic replay. Only a positively knownpre-input idle deferral re-arms, within the existing deadline.
4.
--skip-map: the restore request names a map completed at this attempt's path (the final file, then the.tmp,matched on the attempt's marker). Otherwise it says no map was required.
5. Wording:
-
compactresults say "possibly as text left in its input box without Enter".- A failed Enter receipt (
submit_failed), on every send: "the Enter reported a failure, so the submissionoutcome is unconfirmed". It used to say "not submitted".
- A written-input exception: "Enter was not sent" only when the throw came before the Enter key reached the
adapter. Otherwise "the submission (Enter) outcome is unconfirmed".
- The CLI notes the daemon-restart limit.
6. Automatic
/compactwaits for a pane-confirmed idle seat, bounded by the existing preparation deadline.7. A compaction-only refusal (
pane_unknown_protected) for a running draft-aware seat whose binding records no tmuxpane, on both paths, before any preparation or
/compact.- The manual trigger: HTTP 409 with "Refused: … its tmux pane is not recorded … no preparation or /compact was
sent". Before: HTTP 502 (
send_failed), withindeterminaterows.- Script-visible:
rig compactexits 1, where it exited 2, and the response carries nopreparationorcompactfield for this refusal.- The automatic path: it returns the reason and begins nothing; a fresh attempt leaves the state null, with no
outbox rows or input effects.
- An attempt already under way is stopped, and keeps its earlier
compactevidence. Already stopped or/compact-sent attempts aren't rewritten, and no old outbox rows are cleared.- During a mode switch the manual path's reason can differ, as described above.
- The input layer already refused this case, so no working compaction is lost.
Tests (current head)
test/compaction-command-submission.test.ts(new) covers:- the 600-code-unit budget (ASCII, non-ASCII, long paths and instructions);
- the overflow carried in the map or the restore request;
- the instruction captured at attempt start;
- the idle wait (busy, then idle; never idle until the deadline);
- truthful
compactresults;-
--skip-map(final path,.tmp, none).SessionTransportand a recording tmux, these cases each make no second/compactwrite:- a preparation-deadline stop before the first paste:
not_sent, 0 writes (a deadline control, not a transportrefusal);
- an issued text write that throws:
uncertain, 1 write, 0 Enters;- a failed paste receipt after an idle wait:
uncertain, and later polls don't write again;- a deadline or cancel between the paste and Enter;
- a binding read throwing after the paste:
written, "Enter was not sent";- the Enter key throwing:
written, "outcome is unconfirmed";- a failed Enter receipt;
- a no-
codereceipt.test/compaction-draft-aware.test.ts(new):- existing-behaviour controls, green before this PR's fixes:
- automatic on a recorded-pane draft-aware seat: no sends and no outbox rows;
- manual: the preparation prompt is delivered outside the lease, then the
/compactlease refuses, with no/compacteffect or row;- the pane-less cases, flipped in
2b0541cf: the automatic busy ×4 then idle case and the manual case both givepane_unknown_protected, 0 outbox rows (all counted) and 0 effects. Both were red at34083df8;- a control: a draft-aware seat with a recorded pane isn't affected by the pane check.
A real zero-input refusal through the real
SessionTransport: the pane stuck in a tmux mode givespane_in_mode, 0 writes, 0 Enters andnot_sent, and clearing it sends nothing more. It's an existing-behaviourcontrol.
The deadline cases are named as deadline cases, not transport refusals.
Every other behavioural test was shown failing first, at the head before its fix. The issued-write test also
fails when its exception tagging is removed.
Updated existing assertions: the enforcer, the route and
session-transport.test.ts(the Enter-failure wording).Run locally at
58551bc3:- the related suites;
- CLI
send/compact;- lint, typecheck and build: green.
- The full daemon suite: 17900 passed, 8 failed. Seven are known host-environment failures on the build machine.
One is a
tmux-control-nativelisting test that passes alone (load).CI runs on every push. See the checks.
Native: NOT RUN on our box
own, because this box has no Claude login.
The Claude Code version is a confound. Claude Code updates itself, and the threshold could move between
versions. The 600-character budget leaves about 190 characters of margin under the measured 792. If a later Claude
Code lowers the boundary, this constant is the one place to change.
Follow-ups (not in this PR)
Confirming that compaction ran. For example, Claude Code's compaction indicator in the pane, or the compactboundary in the session transcript. Claude Code's strings are unverified, so
compactstays atsubmitted_unconfirmed, with noconfirmedvalue yet.With
--skip-mapno map is required, so the full trust note is carried only if the seat completed a map anyway.The restore request already states that it is operator-authorized, and the short note stays in the command.
A daemon restart loses the queued restore stage and the restore carry.* Both are held in memory only. After a
restart there may be no restore request at all. The attempt's restore map stays on disk at the attempt path.
🤖 Generated with Claude Code
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
Bug FixesCompaction status now distinguishes commands that were not sent, submitted without confirmation, or possibly delivered, without implying compaction has run.
Automatic and manual compaction wait for an idle session before sending. Automatic attempts can retry after a confirmed idle deferral.
Compaction requests preserve key trust instructions within the command length limit and include overflow details in preparation or restore prompts.
Restore prompts identify the relevant map when available or state when no map is required.
Documentation
Updated
/compacthelp text to explain prompt delivery, compaction status, and when restore and audit prompts follow.<!-- end of auto-generated comment: release notes by coderabbit.ai -->