Skip to content

Say when a compaction rewrote the conversation a fork resends - #6554

Merged
max-sixty merged 2 commits into
mainfrom
agent-a04bdbcf33cd34ffc
Nov 20, 2026
Merged

max-sixty merged 2 commits into
mainfrom
agent-a04bdbcf33cd34ffc

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

After a compaction, each fork's diagnostic request named the main thread's request from before it, its rows and message count, while $.model.fork resent the compacted conversation, so a replay cut at those rows reproduced a context the fork never read. The hooks module learned rows only from session.append on doors that leave out the compaction's, and no turn.step follows a compaction between turns.

The module now reads rows from Claude Code ($.session.messages, after the row read before) at each main-thread step and each fork, and drops its six session.append handlers. Where a compaction or rewind dropped that row, Claude Code denies the read, and the fork's request holds the model, the effort and rewritten: true, with no rows; a replay then cuts at the fork's time. A probe in Claude Code 2.1.329 matched each named row against the transcript before and after a compaction.

For the reviewer:

  • A hook on session.compact or on the compaction door would hear each compaction, but 2.1.329's builtin cc-plugin-sec-default passes both past a person's plugins on a machine with managed settings, and Claude Code then tells the user the hook was skipped. That is read in its source; this Mac has no managed settings to measure it on.
  • Claude Code before 2.1.326 refuses these reads: the step's hook fails in the debug log and forks carry no request there. The CI pin (2.1.325) shows the two type errors as warnings until it moves past 2.1.326.
  • notes/fork-replies.md no longer says $.model.fork has nothing to fork after a compaction or an away summary, which held on 2.1.318; it keeps the one unexplained case. It now also records how Claude Code shows each kind of fork on screen, including that its agent list names a spawned fork fork.

Max asked for the fix and the note. Tests: the module's process tests, with a new one for a fork after a compaction that fails without the fix. The claude-code journey passed its first 12 steps twice, each fork naming the newest row stored before it, and both runs stopped at boundary, from a race in that step this change doesn't touch: the boundary comment was handed over between the agent's edit and its reply to the first comment, and the turn Escape left woke asking whether to finish both. #6556 removes the race.

This was written by Claude Code on behalf of max-sixty

After a compaction, each fork's diagnostic `request` named the main thread's request from before it: its rows (`sent`, `row`) were the last before the compaction and its `messages` the pre-compaction count, while `$.model.fork` resent the compacted conversation. A replay cut at those rows reproduced a context the fork never read. Of this machine's 158 line forks with usage, six followed a sparkjoy compaction with no main-thread request in between. Each fork's prompt (117k-143k tokens) matched the main thread's next request within 1.1-2.4k and read the same cached tokens, while the requests `resent` named held 206k-348k. The module learned rows only from `session.append` on six doors, which leave out the compaction's, and no `turn.step` follows a compaction between turns.

The module now reads rows from Claude Code instead: the newest row at each main-thread step (`sent`), and the rows since at each fork (`row`), each read on from the row read before with `$.session.messages({ after })`. Where a compaction or rewind dropped that row, Claude Code denies the read, and the fork's `request` holds the request's model and effort with `rewritten: true`, and no rows or count; a replay cuts the transcript at the fork's time. Forks until the second request after a rewrite say the same, since the first request's newest row may be one the compaction kept, which keeps its id and its place before the compaction in the transcript. Of the 382 compactions in this machine's transcripts from 15 to 19 November, 368 kept at most the last turn's final reply and the rows after it, 13 kept nothing, and one, an auto-compaction mid-turn, kept the turn's last tool calls; a compaction that keeps the row read before goes unseen, as that one would have. `$.session.usage().context.tokens` is absent from a compaction until the next response (probed at 2.1.329), which could catch that case at a fork between turns; it is left out as a second signal for one compaction in hundreds. The six `session.append` handlers, and the door list kept to avoid Claude Code's skipped-hook notice, are gone. `clerk`, `forks`, `summary_fork` and `carrier` note `request` as before, and point to the module for where a replay cuts.

A hook on the compaction itself was the alternative. Claude Code 2.1.329's builtin `cc-plugin-sec-default`, which seats itself outermost on a machine with managed settings and for Team and Enterprise organizations, passes `session.compact`, and `session.append` on the `attachment`, `hook-context` and `compaction` doors, past a person's plugins (`PASSED_OVER_EVENTS` and `PASSED_OVER_DOORS` in its source). Claude Code then tells the user, for a person's plugin, `its <event> hook was skipped. "cc-plugin-sec-default" runs first and sent the event on past it.` This was read in the binary: this Mac has no managed settings, so the notice on those two hooks is inferred from that source and from the `tool-message` notice #5816 measured.

Probes in an interactive Claude Code 2.1.329, with a module that compacted between turns through `$.session.compact()` and the module's own `newestRow` and `resends`: before the compaction the fork's request was `{messages: 15, sent: <the tool's result>, row: <the final reply>}`, matching the transcript. After it the `after` read denied, the fork quoted the summary as its earliest message, and the request was `rewritten`. In the next turn the first step read no row and the second the tool result after the boundary, and the turn-end fork named it and the reply. A read took 1-5 ms, the first 37 ms. Claude Code 2.1.325 refuses `last` and `after` ("takes { agentId, as } or nothing (not last)"): the step's hook fails in the debug log, the module stays loaded, and a fork carries no request. The CI pin's `claude plugin validate .` (2.1.325) reports the two type errors as warnings and passes, until the pin moves past 2.1.326.

`notes/fork-replies.md` said `$.model.fork` has nothing to fork after a compaction or Claude Code's away summary, as measured on 2.1.318. On 2.1.327-328 forks after both resend: the compacted conversation after a compaction, and the full conversation after an away summary (8 of 10 such forks read at least 90% from cache). One `nothing-to-fork` after a compaction stays unexplained (page gh-needs-me, session cfdfabd1, 19 Nov 12:53 PT, with no restart visible in the transcript); it is the only one whose session showed an away summary before the compaction. The note now also records how Claude Code shows each kind of fork on screen, from a claude-code journey on 2.1.329 with its tmux pane captured every 0.5 s (19 Nov 14:55-15:03 PT) and a `leaf-dev journey session` for the busy case.

Max asked for the fix and for the note on how Claude Code shows forks. Tests: the module's process tests, with the driver now standing in for `$.session.messages`, and a new one for a fork after a compaction, which fails when the module ignores the deny. The claude-code agent journey passed its 12 steps through `withdrawn` twice on this branch, every one of its 26 forks in the first run naming as `row` the newest row stored before it, and both runs stopped at `boundary`: the boundary comment's line fork answered in 2.4 and 3.0 s, so its tool boundary came after the first comment's edit and before its reply, and the turn Escape left woke asking whether to finish both. With the base module the line fork took 3.7 s, the boundary came after the reply, the step passed, and the run stopped at "Claude Code exited" after `compacting`.
@max-sixty
max-sixty merged commit ed5e058 into main Nov 20, 2026
5 checks passed
@max-sixty
max-sixty deleted the agent-a04bdbcf33cd34ffc branch November 20, 2026 02:44
max-sixty added a commit that referenced this pull request Nov 20, 2026
… ask for the release on the page (#6556)

Two steps of the claude-code journey stopped on what the agent chose
rather than on what Leaf did.

**`boundary`** stopped in 2 of the 9 runs recorded since #6463 made each
delivery comment a rewording, which the wake's turn answers with an Edit
and then a `leaf thread reply`. Where the light fork handed `boundary`
over between the Edit and the reply, Escape left `first-wake` edited but
unanswered, and the woken agent asked whether to finish both rather than
finishing. The session's settings now add a PreToolUse hook beside the
slow one, which holds a `leaf thread reply` that isn't `--ephemeral`
while the step asks. The step holds the wake's answer, sends `boundary`,
waits for its line fork's `hand_over`, then releases the answer with the
slow hooks armed, so the handover lands after the answer however the
agent batches its calls and however long the fork takes. The step also
checks directly that a prompt after Escape names `boundary` as owed.

**`release`** asked the agent to record a release "on the board", whose
columns hold only defects. Agents put it in a status tile beside the
board in 73 of the 74 earlier runs on this machine, but two sandboxed
runs of this branch in a row asked where it belonged, which the step
counts as a failure. The ask now says "on the page"; where the page
shows it stays the agent's call.

To weigh: the hook matches `thread reply` in the command text, so an
answer posted some other way wouldn't be held and the old race would
return for it.

Found in #6554's journey runs; nobody has read it yet beyond Leaf's
review of the first commit. `leaf-dev journey run claude-code` passed
all 17 steps, once plain (answer held 3.8 s while the fork handed
`boundary` over) and once with `--sandbox` after the release change;
`dev/tests/model/test_journey.py` and pre-commit pass.

> _This was written by Claude Code on behalf of max-sixty_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants