Skip to content

Stop /autoplan getting stuck between phases after a long session is compacted - #4200

Closed
vilano93 wants to merge 3 commits into
garrytan:mainfrom
vilano93:fix/autoplan-keeps-history-after-compaction
Closed

vilano93 wants to merge 3 commits into
garrytan:mainfrom
vilano93:fix/autoplan-keeps-history-after-compaction

Conversation

@vilano93

@vilano93 vilano93 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

/autoplan now keeps working after Claude Code compacts a long session, so a run no longer gets stuck between two phases.

Why (in your own words)

In a long /autoplan run on Claude Code 2.1.317, the design phase closed normally and the next phase could never start. Every entry was refused with cross_phase_batch ("one message enters two phases"), even when the Read was alone in its message, and retrying could not help. The cause is the compaction, not the message. Its boundary named a logicalParentUuid that never reaches the session file, while the preserved tail stays in place. The tail no longer equals the logical parent, so the 2.1.300 handling did not apply, the boundary was orphaned, and every record after it was silently dropped. The guard then took the last Reads before the compaction for the current message. The change continues such a boundary from the preserved tail. I do not know why Claude Code leaves that record out; the reader only stops depending on it.

Live evidence

Regression tests before the fix, on a boundary of that shape:

$ bun test test/autoplan-compaction-preserved-segment.test.ts
(fail) ... a boundary whose logical parent was never written continues from the preserved tail
(fail) ... the next phase entry passes after a compaction whose logical parent was never written
  "permissionDecision": "deny" ... (code close_incomplete, Claude Code 2.1.292)
 11 pass
 2 fail

That run had 13 tests; review added 4 more, see Scope.

After the fix, rebased on current main:

$ bun test test/autoplan-compaction-preserved-segment.test.ts
 17 pass
 0 fail

Replay of the real 2.1.317 session journal, cut just before the first refused Read and evaluated with evaluatePayloadPublication. Only counts and tool names are shown, the journal itself stays private:

BEFORE (installed guard)  events 200  last: Read methodology.md (design phase)  allow=false
AFTER  (this branch)      events 260  last: Bash `true autoplan-published design`  no cross_phase_batch

The AFTER run first returned allow=true. Repeated on the final commit it returns close_stale, the same as on the commit before the review fixes: the plan file changed after the journal cut, so the guard correctly refuses a stale packet. The refusal this PR fixes is gone in both.

The boundary in that journal: logicalParentUuid occurs nowhere in the file, preservedSegment.tailUuid equals the last entry of preservedMessages.uuids and is a node written before the boundary.

Scope

  • Changed: preservedUuids accepts a list whose last entry is the segment's tail, without requiring the tail to be the logical parent. ownedCausalOrder resumes from the preserved tail when the logical parent is absent from the file. A logical parent that is the list's own tail may be unflushed and still supplies no ownership, covered by a test. A cycling boundary whose list omits its logical parent stays refused, and a resumed fork that begins with the boundary stays a genesis root; both were widened by the first commit and restored after review, each with a test seen red first. A mismatched tail and a list with no record in the file are also covered; the mismatch test fails when the tail check is removed. Adds a CHANGELOG fragment.
  • Verified live by: the journal replay above, the eight guard and transcript test files compared with and without the fix (the same six tests fail on both in my scratch checkout, none only with the fix), bun run typecheck.
  • Known limit: a logical parent that is not the list's tail and is merely late is treated as never written until it lands, then the boundary re-attaches to it. The trace stays ordered and no record is lost.
  • Did NOT test: a fresh live /autoplan run through a new compaction with this branch installed. bun run test:quick fails locally in areas this change does not touch (browse, CSO and Bun resolution tests, from a checkout under /private/tmp with no built binaries), so the fork CI is the full free-suite signal. The /ship test lane did not pass locally: it hit the 600 s pregate limit, and CI carry does not accept fork runs. The setup was a manual bun install --frozen-lockfile rather than bin/dev-setup, and this branch was not symlinked as the live install.

Liveness proof (required for external contributors)

SCR-20261109-ioyp

Checklist

  • Liveness screenshot attached (GSTACK PR typed live into a real surface) or PR author is @garrytan (owner exemption)
  • This is not a generated-file-only diff (I edited the source/template and regenerated)
  • No ETHOS.md edits, and no changes to voice / founder perspective / YC references
  • New public command / external service / host adapter has an accepted issue linked (or N/A)
  • Linked issue or reproduction: reproduction above

🤖 Generated with Claude Code

A compaction boundary can name a logical parent that never reaches the
session file while its preserved tail stays in place. The ownership walk
dropped every later record, so the guard read an older phase's Reads as
the current message and denied each retry as cross_phase_batch.

Continue such a boundary from the preserved tail. A logical parent that
is the list's own tail may be unflushed and still supplies no ownership.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trunk-io

trunk-io Bot commented Nov 9, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

vilano93 and others added 2 commits November 9, 2026 10:03
Review of the compaction fix found two inputs it had widened by accident:
a boundary whose logical parent cycles back without being the list's tail,
and a resumed fork whose first record is the boundary. Both behave as before
again. Adds tests for a mismatched tail and for a list with no record in the file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vilano93
vilano93 marked this pull request as ready for review November 9, 2026 09:41
@capy-ai

capy-ai Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Thanks @vilano93, this is a clear diagnosis backed by a real replay. On main at 119ed92, preservedUuids still requires preservedSegment.tailUuid to equal the boundary's logicalParentUuid, so a 2.1.317 boundary whose logical parent never reaches the file is dropped. We're picking this up: a crew lane will rewrite it on current main and credit you as co-author, and we'll close this PR when that lands.

capy-ai Bot added a commit that referenced this pull request Nov 9, 2026
* Keep /autoplan working after a Claude Code 2.1.317 compaction (#4200)

On 2.1.317 a compact boundary's logicalParentUuid names a record the
session file never receives, and the preserved list ends with the last
record kept in place. The journal reader required that tail to equal the
logical parent, so the boundary became an orphan, every later record was
dropped, and each phase entry was refused on every retry.

The reader now accepts a preserved list whose last entry is the segment's
tail, and continues a boundary whose logical parent is absent from the
file from that tail. The 2.1.300 path is unchanged: when the tail is the
logical parent it still needs the boundary cycle, so an unflushed tail
supplies no ownership. A boundary that opens the file stays a resumed
fork's root, and lists naming no node of this session still continue
nothing.

Co-authored-by: vilano93 <[email protected]>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Say the troubleshooting guide's compaction note covers Claude Code 2.1.317

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

---------

Co-authored-by: vilano93 <[email protected]>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai

capy-ai Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Thanks @vilano93. We rewrote this fix on current main in #4226 (merged as 1cc98fc), with you credited as co-author. /autoplan now continues from the last kept record when a Claude Code 2.1.317 compaction names a parent record that was never written. Closing this one in favor of it.

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.

1 participant