Repository navigation
Keep the turn-end check a quick check that answers from what it holds - #6079
Merged
Merged
Conversation
Max's direction on 2026-11-15: turn-end checks need to be fairly brief
and mainly use the cache, so they can't go off and do research; they are
a check rather than a review.
`clerk.py`'s header records it as the user's fourth principle, dated:
the fork answers from the conversation it inherits and the page facts
Leaf hands it, and does no research, so each thing Leaf asks of it must
be one those two settle. `turn-end-check.md`, which the fork reads
verbatim, now says the check is a quick one that runs at every turn
end, that every tool call is denied, and to name only what the
conversation and the page state settle, leaving out an item it could
confirm only by reading a file, running a command or searching.
No code changes, since Claude Code already enforces the part code can.
In 2.1.325's source, `$.model.fork` denies every tool call ("A model
fork cannot use tools"), stops after two requests (`maxTurns: 2`), and
writes neither the cache nor the transcript. `ModelForkRequest` takes
only `prompt` and `effort`, and the request must keep the session's
tools to read the cache, so Leaf has no further lever. Effort stays at
the session's, as #5960 chose for the cache.
What the fork does now, from the `turn_end_check` notes of 37 Opus 5.5
forks in five real sessions since #5960:
- median 5.6 s (p90 15.8 s, max 28 s), 281 output tokens (p90 1,416),
$0.235 at list price (p90 $0.43);
- 94% of input tokens read from the cache (median 248k in, 24k not
cached); the uncached part is 38% of a fork's cost;
- one request each: on the 32 whose session transcripts remain, input
over the main thread's context is a median 1.11 and at most 1.20,
where a denied tool call and a second request would show about 2. No
answer was refused.
`leaf-dev eval run 'turn-end-check*' --harness claude-code --base
--repeat 3`, then `ask-follow-up` and `ask-question` six more times
each:
- `answered`, `labels-found`, `edits-land` and `guardrails-held` pass
in every run on both arms, so the check catches what it caught.
- The judge's `items-right` passed 54 of 57 on main and 53 of 57 here.
`ask-follow-up` passed 7 of 9 on main and 5 of 9 here, every failure
on both arms one of the same two wording faults; `ask-question` 8 of
9 and 9 of 9.
- Output was 0.92 times main's (95% interval 0.83–1.02 over the 15
cases), time 0.98 times, cost the same.
`tests/model/test_clerk.py` passes.
leaf-agent
approved these changes
Nov 15, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 16, 2026
…esses (#6202) When an agent's reply leaves the user a question with a short, fixed set of answers and puts nothing On Me, the turn-end check now opens the thread with those answers as an `lf-options choose` group, the way `threads.md` ("Ask for a pick") tells the agent to ask. Before, it asked in words with an obligation. A clarifying reply such as "how stale can a result get?" then answered the question, On Me moved it to Done while the decision was still open, and `1`–`9` couldn't answer it. Part 2 of the issue (On Me answering a thread's choice) landed in #6056. ## What changes - **The fork writes the choice in its message.** The fork already writes each ask's `text` as the agent's guidance has the agent write a message. It now also reads `threads.md`'s "Ask for a pick" and #6208's paragraph on HTML in a message (`clerk.GUIDANCE`), so where the agent offered answers the user picks among, the text holds the `lf-options` group, as an agent's own `leaf thread` message would. Nothing in core names the widget, and the fork's answer schema is unchanged. "Ask for a pick" now names the group's elements in its own sentence (`<lf-options id="…" choose>` holding an `<lf-option id="…">` for each answer), since the fork reads the paragraph without the example below it. - **Leaf posts the text as the agent's command does.** `_ask` checks the text as an agent's (`checked_text(..., html=True)`) and draws its HTML (`thread.drawn_markup`), and `open_thread` validates that with `check_markup` and marks the message `html`. A widget in it that asks (`thread.markup_asks`) asks the question, and otherwise the message carries an obligation, so HTML that asks nothing, such as a `<details>` quote, still leaves the question On Me. - **A refused choice is still asked.** The fork has no next attempt, so where Leaf refuses the HTML, the ask is posted again in words with `--obligation`, showing the HTML as text, and the agent's line says why. Before, a refusal reached `apply_answer`'s re-raise and the ask was lost. - **Asking again.** The fork's page facts now list every question a thread message asked and On Me no longer holds, choices included. A choice is named by the message holding it (`thread.widget_question`), the id `thread.ask_again` takes. An `again` ask goes into that question's thread and reopens it: with its choice where the text holds one, under its own id where it was first asked in words, and as a new question in words otherwise. `thread_questions` reads what a thread asks. Its words part is `obligations.questions_in_words`, which admission's `_named_question_error` now reads too, so `leaf thread reply --obligation <id>` and the fork agree on which questions a thread asks. An `again` naming anything else is refused with `unasked-obligation`, so the ask opens its own thread. - **Dedupe.** `_ask` already skipped an ask whose title matched a thread the agent opened to ask something. It now also counts a thread opened with a widget that asks (`thread.widget_asks`, through the cached `thread_context.logged_fragment`). - **The agent's line** names the question's id: the reply's own where a closed choice is asked anew in words. - **The fork's view of On Me** for a widget in a thread message used to read `decision: ` with no words. It now reads `decision in the agent's message in "<thread>": <words>`: the widget's own prompt where it has one, such as an `lf-ask` heading, and otherwise the message's text. ## Evidence `leaf-dev eval run 'turn-end-check/ask-*' --harness claude-code --repeat 3 --base`, on this branch against main with #6208 (`ed71a3cc9a`). A question label's `choice` (`fork_eval.py`, check `choices-right`) says whether the ask must be asked by a widget in its text or in words. `ask-question`, whose reply offers "the LRU cache … or the TTL cache", now expects a choice. The new `ask-choice` leaves a three-way timing question with the agent's advice ("I'd go tonight"). `ask-step` and `ask-follow-up` expect words. | case | main | this branch | |---|---|---| | ask-question (two answers, `choice: true`) | 0/3 | 3/3 | | ask-choice (three answers and advice, new) | 0/3 | 3/3 | | ask-step (a command to run, `choice: false`) | 3/3 | 3/3 | | ask-follow-up (`choice: false`) | 2/3 | 2/3 | | ask-on-me, ask-answered, ask-step-done | 3/3 each | 3/3 each | - Main's failures on `ask-question` and `ask-choice` are all `choices-right`: it asked in words, and the judge passed its wording. - Every head run of those two cases wrote a valid `lf-options choose` group with new ids, so none fell back to words. Every `ask-choice` run marked "tonight" as recommended, in the option's words rather than the tag. - No step became a choice: all six head runs of `ask-step` and `ask-follow-up` asked in words. - `ask-follow-up` fails once on each arm, on the wording faults #6079 described: a reply asked for that the agent could check itself, and the agent's inference that the flag "went to dev". - Head over main, paired by case, with 95% bootstrap intervals: fork cost 1.07× (1.03–1.11), wall time 1.14× (0.95–1.33), output 1.19× (0.91–1.46). - The prompt gains about 515 tokens (9,281 → 9,795 on `ask-answered`), the two paragraphs of `threads.md` the fork now reads. A live fork reads the conversation from the cache: over 325 live forks in 10 days, a median of 17,500 input tokens were uncached beside 257,000 cache reads. So the added prompt is about 1% of a fork's cost. - A fork that asks with a choice writes the group, about 400 more output tokens, about $0.01. It often also lists each option's case in words above the group, which the judge passed and "Ask for a pick" advises against. - This round's paid runs cost about $9: $4.90 for the forks at list price, about $3.10 for the Opus judge, and a one-run sanity check before #6208 landed. Rendered with `leaf-dev probe evals/turn-end-check/pages/reindex-staged.html --log <the fork's ask from a run> --do press:m --shot`, the thread card shows the message, then the three options with digits 1–3, and the footer reads "Your turn · 1 of 1 waiting on me · Options". ## Tests - `tests/model/test_clerk.py`: - `test_an_ask_with_listable_answers_is_a_choice_the_user_presses`: the message is `html` with no obligation, the choice is On Me, a reply in words leaves it open, and the agent's line, the next fork's On Me line and the title dedupe all hold. - `test_a_choice_leaf_refuses_is_asked_in_words`: a choice reusing a taken id is asked in words with an obligation, and the agent hears why. - `test_a_closed_choice_asked_again_with_html_leaf_refuses_is_asked_in_words`: the same refusal on a re-ask lands in words in the earlier question's thread. `ask_again` returns None where the thread can't take the question and lets an HTML refusal through, so the title check can't drop the ask. - `test_a_question_asked_again_with_listable_answers_is_a_choice_in_its_thread`, `test_a_choice_the_user_closed_is_asked_again_in_its_thread` (as a choice and in words), `test_an_ask_again_naming_a_message_that_asks_nothing_opens_its_own_thread`, `test_a_widget_in_a_message_reads_as_its_own_question`. - `dev/tests/test_evals.py`: the replay test hands an ask whose text holds a choice through the arm's Leaf and checks `choices-right`. - Ran `tests/model/test_clerk.py`, `test_thread_titles.py`, `test_thread_reading.py`, `test_obligations.py`, `interact_contract/test_admission.py`, the `unasked-obligation` cases of `test_todos.py`, and `dev/tests/test_evals.py`. ## Not verified - A live Claude Code session's fork. The evals replay constructed conversations through the real fork path. ## Calls to reverse - A refused choice is posted in words with its HTML shown as text, rather than with the HTML removed. - An `again` ask with a choice is posted as a choice in the earlier question's thread, rather than in words under the question's id. A closed choice re-asked without one becomes a new question in words in its thread. - `ask-question` now requires a choice, so base fails it by design. Closes #5404
max-sixty
added a commit
that referenced
this pull request
Nov 17, 2026
… choice the user presses (#6220) A ready pull request now reaches the user as a choice they press ("Merge #812" / "Hold off for now") rather than a message telling them to run `/merge-pr` and reply. The turn-end check's reference named "a merge waiting on the user's approval" as a step asked in words, and an agent's "Merging is yours: run `/merge-pr`" read to the fork as a command for the user. On 44 real pages since 2026-11-01, none of 88 merge or landing asks was a choice (72 by the fork, 16 by agents), and 17 of the 21 the user answered in words said "yes" or the merge command. The rule now lives once, in a new paragraph of `conversation-loop.md` ("The On lists") that the fork reads through `clerk.GUIDANCE`: an action the agent takes once the user agrees is a permission, asked as options, even where the user could start it with a command they'd type to the agent; an action only the user can take is a step, asked in words. `turn-end-check.md` drops its copy of the step rule and adds that the fork marks an option recommended only where the agent advised it, since early runs marked "Merge" recommended unprompted. **Evidence** (Claude Code fork, 3 runs per arm): the new `ask-permission` case, Max's closeout cut down, is asked as a choice 0/3 on main, 0/3 with only the merge example deleted, and 6/6 here. `ask-step`, a command only the user can run, stays in words 3/3. `ask-follow-up` passes 6/9 here against 7/9 on main, failing on both arms on the #6079 wording faults. `closeout-asks-take-their-route` now requires landings as options; both arms pass 3/3. Runs cost about $10. **To weigh:** a step whose report has listable answers ("Works" / "Still broken") still asks for a reply in words; that is a separate call this PR leaves alone. Asked for by Max in a comment on a Leaf page. Tests: `tests/model/test_clerk.py`, `dev/tests/test_evals.py`, `test_product_page.py`, `test_interact_layer.py`. > _This was written by Claude Code on behalf of max-sixty_
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Max's direction on 2026-11-15: turn-end checks need to be fairly brief and mainly use the cache, so they can't go off and do research; they are a check rather than a review.
What changes
src/leaf/clerk.py: the header records it as the user's fourth principle, dated. The fork answers from the conversation it inherits and the page facts Leaf hands it, and does no research, so each thing Leaf asks of it must be one those two settle. This bounds checks added later, such as the three the sweep page proposes.skills/leaf/references/turn-end-check.md, which the fork reads verbatim: the check is a quick one that runs at every turn end, every tool call is denied, and the fork names only what the conversation and the page state settle, leaving out an item it could confirm only by reading a file, running a command or searching.No code changes, since Claude Code already enforces the part code can. In 2.1.325's source,
$.model.forkdenies every tool call ("A model fork cannot use tools"), stops after two requests (maxTurns: 2), and writes neither the cache nor the transcript.ModelForkRequesttakes onlypromptandeffort, and the request must keep the session's tools to read the cache, so Leaf has no further lever. Effort stays at the session's, as #5960 chose for the cache.What the fork does now
From the
turn_end_checknotes in page diagnostics on this machine: 37 Opus 5.5 forks in five real sessions since #5960 landed (2026-11-14 13:00 PT).Every fork took one request: on the 32 whose session transcripts remain, its input over the main thread's context at the request it resent is a median 1.11 and at most 1.20, where a denied tool call and a second request would show about 2. No answer was refused. For comparison, before #5440 the same kind of fork, at the session's effort without the request to answer straight away, wrote a median 968 output tokens in 12.6 s (175 forks).
Scores
leaf-dev eval run 'turn-end-check*' --harness claude-code --base --repeat 3, thenturn-end-check/ask-follow-upandturn-end-check/ask-questionwith--repeat 6, so 3 runs per arm of most cases and 9 of those two.answered,labels-found,edits-landandguardrails-heldpass in every run on both arms, so the check catches what it caught and names nothing new where it shouldn't.items-right. Eachask-follow-upfailure, on both arms, is one of the same two wording faults in the re-asked step: it repeats the agent's chat inference that the user's command "went to dev", which the judge reads as unsupported because it dates the conversation by today rather than the transcript's 3 November, or it asks for a reply the agent could check itself. 5/9 against 7/9 is within what three-run arms vary by (Fisher's exact p ≈ 0.6). Main'sask-questionfailure named an unshown item the ask already covered.The eval's forks cost about $11.50 at list price, plus the judge.
Checks
tests/model/test_clerk.pypasses, and pre-commit passes on both files.Not verified: the forks' behaviour in a live session after this lands, which the next real sessions'
turn_end_checknotes will show.