Skip to content

feat(session-flow): shape-4 handoff with a tool-owned byte budget (Track B) - #17677

Merged
kyle-sexton merged 45 commits into
mainfrom
feat/handoff-shape-4
Nov 21, 2026
Merged

kyle-sexton merged 45 commits into
mainfrom
feat/handoff-shape-4

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Closes #17838

Summary

Problem: writing a handoff fights the size cap, trimming to fit has dropped binding decisions, and the validator lets some losses pass. Intent: "basically a smart compaction so that you can continue the session in another ... without it losing quality"

This branch builds shape 4: the hot file keeps every binding entry whole, fill owns the byte budget and moves only observations, suggested skills and direction changes to the hop file behind exact pointers, and the five reader skills read sections through save_point.py read and chain. HANDOFF_SHAPE is now 4, so a bare new writes shape 4 (--shape 3 keeps the old layout). It merges once, after the resume eval passes on this exact tree; the Hold: line keeps it from merging until then.

Fix

  • handoff_chain.py holds the section tables for shapes 2 to 4 and the chain reader; save_point.py gains shape-4 new, fill (fit, moves, slot budgets, OVER-CAP), amend, read, chain and the id_reuse check.
  • Writer instructions drop what the script now owns (section order, size classes, carry rules, retry policy); retro, orient, find-handoff, reanchor and continue-in-background read through the CLI.
  • The resume-eval harness seeds shape-4 chains with size steering, builds its unit tests as the after arm, and hop_chain.py --budget projects a 56-hop shape-4 chain through fill.

Verification

  • pytest plugins/session-flow/scripts/tests plugins/session-flow/scripts/harness: 659 and 208 passed.
  • bash plugins/session-flow/scripts/harness/hop_chain.test.sh: PASS; the shape-4 projection holds every hop under the 24,600-byte cap with no section moved (newest 11,903 bytes), and shapes 2 and 3 generate byte-identical chains to before the refactor.
  • scripts/check-changed-skills.sh: 6 skills checked, 0 failed; scripts/run-ruff.sh check clean on the changed Python.
  • Left out: the resume-eval batch and its gates (Phase 9, waiting on the A/A margin) and the live reader-skill evals.

Related

Acceptance criteria

  • AC2: A rule id retired at an earlier hop and reused for a different rule makes validate exit 1.
  • AC3: Oversized text the session wrote in any slot, the resumption brief and below-the-rails note included, gives a size FAIL that names the slot, never UNVALIDATED. Scope: this holds on shapes 3 and 4, the shapes with slot budgets (shape 4 is the default). On shape 3, a core section over the cap with no budgeted slot to blame keeps its UNVALIDATED verdict. Shape 2 gets no slot-size check. Both are legacy layouts this PR leaves as they are.
  • AC4: Before writing, the tool states the remaining byte budget; when non-binding content does not fit, it moves to the hop file with a pointer, and the handoff validates with no retry loop.
  • AC5: When binding content alone exceeds the cap, the tool still writes the file and the resume prompt and prints one line naming the oversized section and how to shrink it.
  • AC6: The hot file holds, whole: the goal block, current rules, standing preferences, decisions in force, open questions, what was just done, what comes next, completion criteria, pending commands, environment to re-establish, and a review section holding the files to read now and history pointers that each name an exact hop file and section; only observations, suggested skills and direction changes may move to the hop file.
  • AC10: Retro walks a chain's hop files and reconstructs every hop's journey, and orient, find-handoff, reanchor and continue-in-background read the new layout without error, before the smaller hot file ships.
  • AC12: If a predecessor handoff is missing or unreadable, the new handoff still writes, its resume prompt emits, and the missing link is named.
  • AC13: While a chain is open, nothing in it is deleted or shrunk; a finished chain shrinks without losing anything retro reads, and nothing is deleted automatically.
  • AC14: Each UNVERIFIED mark in a handoff names the command or source that settles it.

Remaining

  • Eight same-task re-* eval cases, re-shape3-near-cap among them, drop their shape: 3 pin on purpose, so each arm seeds its own shape on the same content: before writes shape 3 and after writes shape 4. re-transition-3-to-4 keeps the explicit shape-3 path.
  • The headless resume-eval gate (PLAN.md AC8) is not code in this PR: Phase 9 runs it on this exact tree once the A/A sets the margin, and the PR merges only when it passes. The Hold: line and the do-not-merge label stand until then.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KeBVgaqsQksryU8CarAPiU

kyle-sexton and others added 27 commits November 19, 2026 01:53
…one chain reader

handoff_chain.py holds the section table of each handoff shape and one walk
of a chain's hot files and hop files. save_point.py reads its shape-3
sections, binding and carried sets, id families and retire headings from
that table, and parse_transcript.py --chain-from walks the chain through
read_chain.

validate now fails a file stamped checks: 3 when it reuses an id retired at
this hop or any earlier one for a different entry (kind id_reuse). Writers
stamp checks: 3; older files keep their verdicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d tidy

handoff_chain.py gains the shape-4 section table (binding sections first,
Direction changes, Observations and Suggested skills movable) and a
journey reader that rebuilds every hop of a chain from its hot files and,
where a hot file is gone, from the copy the next hop's file holds.

save_point.py validates shape 4 while new still writes shape 3: binding
sections stay whole, move and history pointers must name a hop file and
heading on disk, and binding content over the cap fails naming the
section instead of passing UNVALIDATED. Files stamped checks: 3 fail an
UNVERIFIED mark with no settle clause, and the marks new writes carry
one. New read and chain commands print a section or the whole chain.
new --previous writes past a missing or unreadable predecessor, recording
previous_status, and refuses to continue a shape-4 chain as shape 3.

tidy_work.py clean shrinks a finished shape-3 or shape-4 chain to its
newest hot file and its hop files. parse_transcript.py --chain-from gets
session ids from hop files too, and emits each hop's sections.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	plugins/session-flow/scripts/tests/test_save_point.py
Retro, orient, find-handoff, reanchor and continue-in-background read a
handoff's sections by name through save_point.py read and walk a chain
through save_point.py chain, so shape 2, 3 and 4 files read alike.
structure.md states the shape-4 order, the moved-section form and the
reader contract. Each hop the chain reader reports now carries its date.

The four reader eval cases now scaffold a shape-4 handoff whose
Observations moved to its hop file, each with a probe only that moved
section answers, and a new retro case reads a shrunk chain's hops from
its hop files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s hot file

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…marks matchable

validate follows a whole move of Direction changes when it looks for the
fold pointer, so a shape-4 hop at 4 or later with every movable section
moved validates.

new no longer appends a settle clause to an entry it carries past a failed
predecessor: one comment line at the top of the section names the settle
command for every such mark, and the entries keep the text older
validators match. A mark the session writes still needs its own clause.

The five reader skills read each section they use through save_point.py
read, and structure.md lists what each reader calls. The reanchor and
continue-in-background probes now need the detail only the moved section
holds, and the emit test checks the shape-4 OVER-CAP notice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The section settle comment now covers an UNVERIFIED (predecessor failed
validation) mark only on an entry tagged before this file's hop whose text
the predecessor holds, so a mark written this hop with the tool's prefix
still needs its own settle clause.

reanchor's flow reads links through save_point.py chain and read for
shapes 3 and 4, and structure.md's reanchor row states its fallback when
validate cannot run. The reanchor probe now needs the 45-second window
only the moved section holds. Tests cover an under-cap shape-4 emit and
every hop file left after a shrink.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a lost link

The section settle comment now exempts a carried UNVERIFIED mark only when
the whole entry, continuation lines included, is one the predecessor
holds, so a multi-line entry carried past a failed predecessor validates.
With no predecessor read (missing or unreadable), nothing was carried, so
every such mark needs its own settle clause; only a shallow check that
skips reading the predecessor still decides by the hop tag alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s held nothing

The carried-mark check takes a shape-2 file's hop from its chain, never
from an unchecked hop key, and a predecessor recorded missing or
unreadable counts as holding nothing in the shallow check too, so new
and the predecessor downgrade no longer treat a forged mark as settled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… note

`new --shape 4` writes the shape-4 skeleton and prints its byte budget on
stderr; a bare `new --previous` continues a shape-4 chain as shape 4 while
HANDOFF_SHAPE stays 3. `fill` on shape 4 moves whole Observations, Suggested
skills and Direction changes sections to the hop file behind a pointer until
the hot file is under the cap, validates, writes once, and prints the verdict
and the resume prompt; binding content alone over the cap is written with one
OVER-CAP line, and a file past one Read page tells the reader to page.
`amend` takes shape-4 files.

On shapes 3 and 4 the Resumption brief and the below-the-rails note get byte
budgets (the 7-day corpus 95th percentile): the first over-budget fill writes
nothing and names the slot, the second writes, and validate FAILs the slot on
files stamped checks 3 instead of passing UNVALIDATED.

validate warns instead of failing when a closed hot file's predecessor is gone
and its hop file holds the predecessor's copy (a finished-chain shrink, AC13).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The second over-budget fill now writes only for the slots the first fill
refused; a slot newly over its budget is refused once on its own. `new`
clears a leftover marker beside the file it writes, and tidy_work keeps the
`.<handoff>.over-budget` marker with its handoff, removing it with the
handoff and never reporting it on its own.

The predecessor-gone WARN applies only to the chain's newest hot file, so a
closed file in the middle of a chain still FAILs when its predecessor is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A marker whose handoff was deleted by hand was reported unknown and kept
forever. It holds only slot names, so it now leaves once nothing keeps it
in flight. An orphan .slots.json can hold the only copy of its slot text
and stays unknown, as before.

The leftover-marker test now writes the current marker format, so its
fill assertion fails when new leaves a marker behind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A marker counts as an orphan only when nothing sits at its handoff's
name; one beside a symlinked handoff stays unknown and is never removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The handoff skill, save-point engine doc and structure doc no longer
restate section order, size handling, carry mechanics or the size retry
path: the ShapeSpec tables, new's budget line, fill's fit and slot-size
refusal, and validate's FAIL lines own them. The binding, retire and
resumption-brief judgment stays, and the writer is pointed at the
budget line new prints.

The rules-new and preference slot instructions now route a retired
rule or promoted preference through the slots' retire list instead of
a hand edit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… script

A slot_size FAIL that validate reports now says it is final after
fill's one-rewrite refusal, and the docs say the same. The carry FAILs
for a dropped entry point at the retire list of fill or amend instead
of a hand-written listing. The writer docs state once that they
describe shape 4, the shape new writes by default; the bash block no
longer prints the rails twice; save-point.md says fill prints the rails
on any verdict and a FAIL is repaired before emit. The Python-absent
fallback carries the shape-4 section list again, checked against the
ShapeSpec by a test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…back

The Python-absent fallback now says what a hand-writer must carry
without new, fill or retire: each section's copy-off-disk clause, the
predecessor's Retired entries and Folded lines kept verbatim, and how
to retire an entry by moving it under its retire heading with a reason
and a pointer. A test checks the retire headings against the ShapeSpec.
The structure doc's opening now frames shape 4 as the default, and
fill's refusal on an already-filled file names amend.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…en handoff

The Python-absent fallback now caps the Prior sessions table at
PRIOR_ROWS_KEPT and tells the hand-writer to carry and raise every id
floor, and its frontmatter block is the shape-4 one with all three
floor keys, checked by a test against the keys save_point.py writes.
Stale shape-3 wording in the structure doc is updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Carries #17596's tagged security/design decisions into Track B: the
decision-field check uses S3.id_spec("D") and id_of(prefix, ...), the
shape-3 decisions slot names DECISION_TAG_SHAPE, and the structure doc,
handoff skill and reanchor skill keep Track B's wording plus the tag rule.

The Phase 2 harness tests build with this checkout's save_point.py as if
it were the before tree; the next commit builds them as the after arm.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeBVgaqsQksryU8CarAPiU
This checkout's save_point.py is the after tree, with slot budgets and
id_reuse, so the shared fixture and the validate check honor the cases'
after-only expected_fail entries. The validate check now strips the
FAIL: prefix before matching, as the builder does, so an anchored
pattern matches. The reuse test states id_reuse on every hop that
carries the reused id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeBVgaqsQksryU8CarAPiU
The tag form lives in the decisions slot instruction, so the skill names
it there and stays under its line cap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeBVgaqsQksryU8CarAPiU
SEED_SHAPES gains 4, filled through the shape-3 path, whose hot-file
size steering reads each hop after fill has fit and moved its slots.
A test steers an 8-hop shape-4 chain to its target size with one hop
file per hop; shape 5 is now the unsupported example.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeBVgaqsQksryU8CarAPiU
…udget

fill_skeleton returns each slot's filler as well as writing it, so the
shape-4 projection fills through save_point.py fill and reports, per
hop, the hot-file size and the sections fill moved, or its OVER-CAP
line. Shapes 2 and 3 generate byte-identical chains to before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeBVgaqsQksryU8CarAPiU
…hape

Eight same-task cases drop their shape-3 pin, so each arm seeds in the
shape its copy writes: before resumes 3 into 3, and after the flip the
after arm resumes 4 into 4 on the same content, the flow every session
runs once shape 4 is the default. re-transition-3-to-4 keeps its pin for
the one-time switch. re-oversized-brief's after-arm pattern also accepts
the OVER-CAP line shape 4 prints beside slot_size. With no script given,
seed_shape follows this checkout's HANDOFF_SHAPE, the script the build
runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeBVgaqsQksryU8CarAPiU
HANDOFF_SHAPE becomes 4, so a bare new writes shape 4 and continues an
older chain as shape 4. The default-shape tests now expect 4, the steered
shape-3 seeding test pins shape 3, and re-rule-after-size-fail's stated
size failure also accepts the OVER-CAP line shape 4 prints for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeBVgaqsQksryU8CarAPiU
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 20, 2026 18:16
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T18:27:10.139249Z 230615f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

test_save_point_settle.py runs git show to read the base validator, so it
exports GIT_CONFIG_GLOBAL and GIT_CONFIG_NOSYSTEM itself, as the
fixture-git-isolation check requires. The renamed shape-4 validation test
asserts the chain length before its loop, so an empty chain fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kyle-sexton and others added 2 commits November 20, 2026 13:55
The hot file restates "two schedulers never run the same job" three times,
so a run that never read the moved Observations could match "no double
runs". The grader now also needs "soak" and the four schedulers or the six
hours, which only the hop file holds, and the paraphrase is a fail sample.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`amend` with `sections` naming a section a shape-4 fill moved replaced the
hot file's lone pointer and left the `## <Section> (h<k>)` body in the hop
file orphaned. The rewrite now goes into that hop-file body, the old body is
kept under the Amended heading as for any rewrite, and the hot file keeps its
pointer. The guard against dropping an entry added this hop reads the moved
body, so a moved Direction changes rewrite that drops one is still refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kyle-sexton kyle-sexton added the do-not-merge Hard merge gate: do not merge while applied. label Nov 20, 2026
… gone

validate skipped every check against the predecessor whenever the
frontmatter carried previous_status, so a hand-added line hid a dropped
rule even with the predecessor readable beside the file. The skip now holds
only when the predecessor is missing or unreadable, or when the file still
starts its own chain at hop 1 the way new writes past a broken link;
otherwise validate fails naming previous_status.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the pr-verify-failed pr-verify failed this head; a pass at a new commit, or after a trusted body edit, removes it. label Nov 20, 2026
kyle-sexton and others added 2 commits November 20, 2026 15:58
tidy_work's keep_finished marked every member of a finished shape-3 or
shape-4 chain as shrinkable, shape-2 hot files included. No hop file
holds a shape-2 hop's sections, so clean --apply removed them and the
journey lost those session ids. A finished chain now keeps its shape-2
hot files; a 2-to-3-to-4 test closes, shrinks and reads every id back.

emit no longer repeats the OVER-CAP or UNVALIDATED notice when fill or
amend has already printed the verdict, so the operator sees one line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The test docstrings cited a local plan file that is not in the
repository; they now cite reference/structure.md. shape4_chain's
docstring no longer says the shape-4 writer does not exist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the pr-verify-failed pr-verify failed this head; a pass at a new commit, or after a trusted body edit, removes it. label Nov 20, 2026
…bsent

The settle test reads save_point.py at a pinned main commit with
git show; a shallow or pruned clone lacks it and the suite errored.
It now skips with the reason. A shape-4 writer test drops a name
that said the default shape is 3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the pr-verify-failed pr-verify failed this head; a pass at a new commit, or after a trusted body edit, removes it. label Nov 20, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

claude-review: 2 inline finding(s) on 9fbd9b58112f85d6e3625398b108b72b7ad14354; the summary is in this lane's pull request comment.

claude-lane: claude-review

Comment thread .lycheeignore Resolved
…r repos

The ignore matched any github.com/example/<name>.git URL. It now names
only the four placeholder repositories the parked reader-eval fixtures
use, so the link checker still checks every other URL under that owner.

Refs: #17838

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

claude-review: 1 inline finding(s) on b01ddef0aa915add19f48575c4a8cf4c2a0fcab9; the summary is in this lane's pull request comment.

claude-lane: claude-review

Comment thread .lycheeignore Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-path: owner-agent Post-merge accounting record (README.md, Merge paths)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shape-4 handoff: eval expectations and link ignore that change with it

1 participant