Skip to content

Summarize a long thread in a fork beside the line fork - #6318

Merged
max-sixty merged 2 commits into
mainfrom
summary-fork
Nov 17, 2026
Merged

max-sixty merged 2 commits into
mainfrom
summary-fork

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

In Claude Code, a fork now writes a long thread's summary, started beside the line fork when the user writes in the thread. Before, the agent wrote it when a delivery carried summary_hint, and followed the hint in 14 of the 23 threads that carried one.

  • Modular: forks.ask returns beside, a list of further forks to make at the line fork's moment. The hooks module starts each one at once (besideFork) and hands back its answer, which Leaf routes by the duty its basis names (forks.BESIDE). A new duty needs a Python module and a BESIDE entry, and no module change.
  • Second to answering: it's a separate fork, so the line and the handover never wait for it. The cost is one more conversation read from the cache on each message where a hint is due.
  • Who owns the hint: a delivery leaves it out only for a thread whose newest message Leaf kept back for a line fork. Other deliveries keep it, and a fork that fails hands the agent the range.
  • Writing the summary: Leaf writes it as the agent's summary and tells the agent. It writes nothing where the summary would no longer be in force under the rules that cancel any summary: a newer summary, or an edit or take-back in the range.

Where to look: src/leaf/summary_fork.py (its header gives the decisions and the gap left open), thread_context.summary_hint (moved out of batch_threads unchanged), and the threads.md split, which gives what a summary holds a paragraph of its own so the fork can quote it.

Max asked for this. Codex reviewed it twice. Its findings are fixed or recorded in the header, and the commit message says how.

Tests: focused model and module tests, each checked to fail without its change. New summary-fork eval: 3/3. The threads.md split, base beside head: 8/8.

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

Leaf suggests a range of a long thread to summarize, and summarizing it was the
agent's chore in the turn that answers the user. On this machine's surviving
deliveries, 23 threads carried a hint and 14 of them were later summarized. Max
asked that a fork do it, at the line fork's moment ("the line fork is better
timed"), second to answering, and modular enough that other forks could run at
other points.

- `forks.ask` now returns `beside`: further forks to make at the line fork's
  moment, each `{prompt, basis}`. The hooks module starts each at once beside the
  line fork (`besideFork`) and hands its answer back with its basis; `leaf hook
  --fork` routes it to the duty the basis names (`forks.BESIDE`). A new duty at
  this moment needs a Python module and a `BESIDE` entry, and no module change.
- `summary_fork` is the one duty. Where Leaf suggests a range of the kept-back
  message's thread (`thread_context.summary_hint`, extracted from
  `batch_threads`), it asks a fork to summarize that range from the whole thread,
  following the agent's own guidance for what a summary holds, which threads.md
  now gives as a paragraph of its own. Leaf writes the answer as the agent's
  summary (`thread.cmd_summarize`, which takes a `fence`) and tells the agent
  through `clerk.queue`.
- The hint is the fork's for a thread whose newest delivered message Leaf kept
  back for a line fork (a `held` pickup names it), so that delivery leaves it
  out and the agent spends no step on it. Any other delivery carries the hint as
  before, and a fork that fails hands the agent the range, so the summary always
  has an owner.
- The fence writes nothing once the page is no longer the session's, or where
  the summary, had it been written as the fork was asked, would no longer be in
  force by `events.active_summaries`: a summary written in the thread since, or
  an edit or take-back of a message in its range.

Why a fork of its own rather than part of the line fork's answer: a fork's answer
arrives whole, so a summary's few hundred words would hold the working line and
the handover back by seconds. It costs one more read of the conversation from the
cache on each message that has a hint due, about what the agent's own summarize
command costs in its turn.

Codex reviewed the first version and found three things, all addressed:
- The hint was dropped for every delivery while the lane was up, which left a
  thread with no owner when a follow-up arrived after the handover. It now
  follows the held pickup, with the fallback on failure.
- The fence checked only for a newer summary. It now asks whether the summary
  would still be in force, so an edit or take-back in the range drops it.
- The range was compulsory, so the fork couldn't leave out messages whose
  wording still matters. I tried offering it the earlier ends admission takes,
  with that guidance moved beside the summary's content: in 3 of 3 runs the
  fork then dropped the range's last question from its prose while still
  folding it. Without the option it kept that question in 3 of 3, so the range
  stays the hint's, which already keeps the newest exchange whole.

A second Codex pass confirmed the fence and found one remaining gap: a line turn
that lapses, or whose step fails, before the module asks its forks leaves the
hint with no owner until the thread's next kept-back message. Of the 85 messages
Leaf kept back on this machine's pages, every one got its fork asked, so the
header names the gap rather than adding a mechanism for it.

The threads.md split, scored with `leaf-dev eval run
'thread-summary-takes-in-earlier-summaries*' --harness claude-code --base
--repeat 2`, passed 8/8 across base and head.

Evals: `leaf-dev eval run summary-fork --harness claude-code` (new, a 13-message
thread whose range takes in a summary that leaves out a decision its originals
hold) passed 3/3, each summary keeping that decision, in 9-14 s with 600-1,100
output tokens. A smoke run on the real thread that prompted this
(compact-when-done-release, ddcc98b1, 18 messages, one summary in force) gave a
correct summary in 23 s.

Co-Authored-By: Claude Code <[email protected]>
leaf-agent
leaf-agent previously approved these changes Nov 17, 2026
A tool hook with nothing to deliver imports forks, which imports summary_fork, and
it runs at every turn, so it may load no runtime dependency but click. The page
readings summary_fork takes (events, revision_artifact, thread_context) pulled in
pywhatwgurl and turbohtml; they're now imported inside the functions that read
them, which test_codex_tool_hook_reads_a_quiet_page_without_the_page_model holds.

Co-Authored-By: Claude Code <[email protected]>
@max-sixty
max-sixty merged commit d9f1af5 into main Nov 17, 2026
5 checks passed
@max-sixty
max-sixty deleted the summary-fork branch November 17, 2026 22:35
max-sixty added a commit that referenced this pull request Nov 17, 2026
…e length (#6317)

The Forks page (`/forks/`) was a chapter of How it works at its own
address: it called itself "how it works", linked back there, and was
split off only because #5961 gave a half-built design a page of its own.
This moves it into How it works as a **Forks** tab between Threads and
Keys (`/how-it-works/#forks`), deletes `docs/forks.html`, and rewrites
the tab for a reader of that guide at half the length (about 4,900 words
to 2,500).

The tab describes only what is built. The planned parts (the three-way
sort, a to-do for significant work, a standing fork per session) move to
`notes/fork-replies.md`, step 4. It opens with why forks exist, as three
metric tiles: the session's own first words in a thread take a median 35
s and 140 s at p90 on real pages, against 2.4 s for a fork's working
line. Terms are defined where they first appear instead of in a
glossary. One diagram draws the three states a waiting thread is in, as
`forks.py`'s header names them, where two overlapped. Diagrams that
restated a table or paragraph are gone, the endings flowchart included,
whose table now reads in the order Leaf applies it. Function names move
to "Where each rule is written". The tab says "working line" as Workflow
and Progress do. It carries the summary fork that #6318 added to the old
page while this was open. The reasons for telling the main thread in
queued lines rather than the fork's SendMessage move into `forks.py`'s
header, which already held the tab's other decision records.

Worth a look: the tab strip, whose tenth tab puts Runtime behind the
overflow chevron at a 1440 px window, and whether the planned parts
belong in the note rather than on the site.

Max asked why Forks wasn't in How it works, then for the tab to be
improved. Two fresh reads of the rendered tab checked its claims against
`forks.py` and `holding.py`, and their findings are fixed.
`tests/model/test_product_page.py` and `tests/model/test_forks.py` pass;
the tab's three diagrams draw at 1440 and 390 px with no sideways
scroll, broken anchors or duplicate ids.

> _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