Skip to content

fix(autoplan): treat the SessionStart hook preamble as a null parent - #3008

Closed
laurenbdaniels-coder wants to merge 1 commit into
garrytan:mainfrom
laurenbdaniels-coder:fix/autoplan-sessionstart-preamble
Closed

laurenbdaniels-coder wants to merge 1 commit into
garrytan:mainfrom
laurenbdaniels-coder:fix/autoplan-sessionstart-preamble

Conversation

@laurenbdaniels-coder

Copy link
Copy Markdown
Contributor

Why (in your own words)

In any Claude Code session that has at least one SessionStart hook (common once a few plugins are installed), /autoplan can't get past its publication guard: every phase file write and every reviewer dispatch is refused. At startup, Claude Code writes a chain of attachment records for its SessionStart hooks at the top of the session journal, starting from a null root, and parents the user's first message on the last of those attachments. The ownership check in lib/claude-public-transcript.ts requires the first conversation record to be a root user message (parentUuid === null), so it never finds an owned root and the hook sees an empty transcript.

This change treats that hook preamble as transparent. A new helper, sessionStartPreamble, returns the UUIDs of same-session, same-cwd, non-sidechain, non-agent SessionStart attachments that carry no message and whose whole chain reaches a null root through other such attachments. In both the owned causal path (ownedCausalLines) and the scan's origin check, a parent in that set stands in for parentUuid === null and nothing else. The competing-root check counts user messages parented on the preamble as roots too, so a second root can't hide behind it.

Live evidence

Reading the real journal of an affected session (one where the guard was blocking) with readOwnedClaudePublicTranscript, before and after:

ORIGINAL  {"status":"missing","tool_uses":0,"tool_results":0,"user_turns":0}
PATCHED   {"status":"ready","tool_uses":43,"tool_results":42,"user_turns":4}

(The one-call gap is the call that was still in flight while the journal was read.)

New regression test, test/plan-count-sessionstart-preamble.test.ts, which models the record shape from that journal:

unpatched: 20 pass, 2 fail (preamble is transparent; scan follows a cwd change after the preamble)
patched:   22 pass, 0 fail

Existing guard and transcript suites (plan-count-cross-cwd-ancestry, plan-count-session-cwd, autoplan-publication-guard, autoplan-publication-hook, autoplan-publication-generation, periodic-fixture-selection) plus the new file, patched: 605 pass, 0 fail on 1.89.0.0, where I hit the bug; 379 pass, 0 fail on this branch's base (main at 1.91.9.0).

Full free suite, patched vs unpatched on 1.89.0.0: no failures introduced. The three tests that failed only in the patched run are timeouts; rerun on both copies, they fail identically.

Each condition in the new helper was mutation-checked (hook event, cwd, sidechain, agent, null-root chain, the ancestry-walk stop, the competing-root rule). Every mutant fails at least one test except dropping message != null, which survives because the root checks already handle a message-bearing record; I kept it as defense in depth. The agentId mutant is caught only through the scan's cross-cwd cases, since the owned path filters agent records before the helper runs.

Scope

  • Changed: lib/claude-public-transcript.ts (new helper plus two call sites), new test file.
  • Verified live by: running the reader on a real affected session journal (above).
  • Did NOT test: a full end-to-end /autoplan run on the patched install; paid evals; resumed sessions (SessionStart:resume), which I didn't examine; Windows. I haven't registered the new test in test/helpers/touchfiles-data.ts. Happy to add it wherever you want it tiered.

Liveness proof (required for external contributors)

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: autoplan publication guard blocks every session that has a SessionStart hook #3007

Fixes #3007

🤖 Generated with Claude Code

Claude Code writes a chain of SessionStart hook attachments from a null
root at the top of the session journal and parents the first user
message on the last of them. The owned-root anchor required that message
to have parentUuid === null, so any session with a SessionStart hook had
no owned transcript and the autoplan publication guard refused every
phase write and reviewer dispatch.

Admit only same-session, same-cwd, non-sidechain, non-agent SessionStart
attachments with no message whose chain reaches a null root. A parent in
that set stands in for a null parent at the root anchor and in the
competing-root check, and nothing else.

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

trunk-io Bot commented Sep 30, 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

@laurenbdaniels-coder

Copy link
Copy Markdown
Contributor Author
Screenshot 2026-09-30 at 2 30 27 PM

@laurenbdaniels-coder

Copy link
Copy Markdown
Contributor Author

/trunk merge

@trunk-io

trunk-io Bot commented Sep 30, 2026

Copy link
Copy Markdown

An error occurred while submitting your PR to the queue: Only users that are a part of this repo's Trunk organization or have write permissions to the repo can submit a PR to the queue

@capy-ai

capy-ai Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Thank you! Your SessionStart-preamble root rule landed in v1.91.13.0 (#3013, merged as f30b7b7), and you're credited as co-author.

@capy-ai capy-ai Bot closed this Oct 2, 2026
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.

autoplan publication guard blocks every session that has a SessionStart hook

1 participant