Skip to content

Ask a turn-end question with listable answers as a choice the user presses - #6202

Merged
max-sixty merged 5 commits into
mainfrom
grind/5404-turn-end-choice
Nov 16, 2026
Merged

max-sixty merged 5 commits into
mainfrom
grind/5404-turn-end-choice

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

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 Let an agent's thread message hold HTML in its Markdown, and drop --markup #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 Keep the turn-end check a quick check that answers from what it holds #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 Let an agent's thread message hold HTML in its Markdown, and drop --markup #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

…esses

When an agent's reply left the user a question with a short, fixed set of
answers and put nothing On Me, the turn-end check opened a thread asking it
in words with an obligation. A clarifying reply such as "how stale can a
result get?" then answered it, On Me moved it to Done while the decision was
still open, and `1`-`9` couldn't answer it. `threads.md` ("Ask for a pick")
already has the agent ask such a question with an `lf-options choose` group.

The fork's answer (`clerk.ANSWER`) gains an optional `options` list per ask:
each answer the agent offered, with a `title` saying what choosing it does, a
`detail` line, and `recommended` for the one the agent advised. Where it is
present, `clerk._choice` writes the group "Ask for a pick" shows, with fresh
ids and the fork's words escaped as text, and the thread opens with it in its
markup in place of the obligation. `open_thread` checks it as it checks an
agent's `--markup` (`check_markup`). An `again` ask with options is posted in
its earlier question's thread with the choice (`thread.ask_again` takes
`markup`), which reopens a closed thread. An ask with no options stays a
question in words, as a step the user takes does.

The fork reads the "Ask for a pick" paragraph with the rest of the agent's
guidance (`GUIDANCE`), and `turn-end-check.md` maps it to `options`. The title
check that stops a second thread on an asked subject now also counts a thread
the agent opened with a widget that asks. The agent's line names the choice
and its markup, so it knows the option ids a pick will name.

The next fork's On Me line for a choice in a thread message read
"decision: " with no words, since the widget has no prompt of its own. It now
reads "decision in the agent's message in "<thread>": <the message's words>".

Eval (`leaf-dev eval run 'turn-end-check/ask-*' --harness claude-code
--repeat 3 --base`): `ask-question`, whose reply offers LRU or TTL, now
expects a choice, 0/3 on base (asked in words) and 3/3 here. The new
`ask-choice`, a three-way timing question with the agent's advice, is 0/3 on
base and 2/3 here, every head run asking with three options and tagging the
advised one; the failure is the judge finding the question in the same
paragraph as the status. Steps stay in words (`ask-step` 3/3 both arms, now
labelled `choice: false`). The other ask cases score the same on both arms,
and the 12 other turn-end cases pass once on each. Over the ask cases the fork
cost 1.03x base (95% interval 1.01-1.05), took 0.92x the time (0.82-1.00) and
wrote 0.96x the output (0.82-1.12); the cost is the ~400 tokens the prompt
gains.

Closes #5404

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One architectural point, inline on _choice: core now writes the default package's lf-options markup. The PR body already lists this as a call to reverse; the inline note gives the reason against the layer invariant and two ways to avoid it.

Comment thread src/leaf/clerk.py Resolved
…question

Review of the turn-end choice found four gaps, each now covered by a test in
tests/model/test_clerk.py that fails on the previous commit:

- A choice the user closed without picking dropped out of the next fork's
  view, since `page_facts` listed only questions asked in words, and the title
  check then silently dropped a same-title ask. The fork now sees every
  question a thread message asked, choices included, under the id
  `thread.ask_again` takes (`message:<id>`, the message holding a widget), and
  an ask naming it is asked again in its thread: with its choice, or in words
  as a new question.
- `ask_again` with markup skipped the check that its `question` names one the
  thread asks, so an ask naming the agent's plain reply in a user's thread
  posted a choice there. `thread_questions` now reads what a thread asks, in
  words or by a widget (`message_questions`), and a name outside it is refused
  with `unasked-obligation` on either path, so the ask opens its own thread.
- The fork read a widget in a message by the message's words even where the
  widget asks its own question, so an `lf-ask` headed "Which cache should we
  use?" read as "Please answer below." It now reads the widget's prompt, and
  the message's words only where the widget has none.
- Option words render as the message's inline Markdown
  (`passages.markdown_dialect`), so a command in backticks shows as code, and
  HTML in them stays text.

The title check reads each opening's markup through the cached
`thread_context.logged_fragment` rather than parsing it again.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One point on this push, inline on thread_questions.

Comment thread src/leaf/thread.py Resolved
When the fork asks again, in words, a choice the user closed without picking,
Leaf posts a new question in its thread under the reply's own id
(`obligation: true`). The agent's line named it "as message:<the choice's
message>", an id `leaf thread reply --obligation` refuses at admission. `_told`
now names a reply asking in words by the id it holds (`question_ids`), and
names the earlier question only where the reply carries the choice.

`thread.widget_question` is now the one home of the rule that a widget's
question is named by the message holding it, which `message_questions` and the
fork's page facts both read.

The words case of `test_a_choice_the_user_closed_is_asked_again_in_its_thread`
checks the line and fails on the previous commit.
@max-sixty
max-sixty marked this pull request as ready for review November 16, 2026 19:30

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This overlaps #6208, which is open and removes --markup along with the logged message's markup field. That PR moves a message's HTML into its text and sets html: true only on text written with a leaf thread command, so the clerk's messages keep their tags as words. The choice path here depends on the field it removes: _put and ask_again pass markup=, the ask_again docstring cites leaf thread reply --markup, and _told quotes record['markup']. Whichever PR lands second has to rebuild how the fork's choice is posted. That rebuild is also the natural place to settle the open thread on _choice, which keeps this from approval: core clerk.py writes the default package's lf-options markup, against root AGENTS.md, "Keep the layer open".

Merges main, where #6208 made an agent's thread message one Markdown body
whose HTML draws, and moves the turn-end check's choice onto it, as Tend's
review of #6202 asked.

Core no longer authors the `default` package's `lf-options` markup:
`clerk._choice` and the answer's `options` field are gone. The fork writes the
group in its ask's text, as `threads.md` ("Ask for a pick") has the agent
write one, and reads that paragraph and #6208's paragraph on HTML in a
message with the rest of the agent's guidance (`GUIDANCE`). "Ask for a pick"
now names the group's elements in its own sentence, since the fork reads the
paragraph without the example below it.

Leaf posts the text as the agent's `leaf thread` command does (`html` on
`open_thread` and `ask_again`). A widget in it that asks takes the question
(`thread.markup_asks`), and otherwise the message carries an obligation. Where
Leaf refuses the HTML, the fork has no next attempt, so the ask is posted again
in words, its HTML shown as text, and the agent's line says why; before, a
refused choice reached `apply_answer`'s re-raise and the ask was lost.

Admission's `_named_question_error` and `thread.thread_questions` now read a
thread's questions asked in words through one helper,
`obligations.questions_in_words`, so `leaf thread reply --obligation <id>` and
the fork's `again` agree on what a thread asks.
@max-sixty
max-sixty marked this pull request as ready for review November 16, 2026 20:34

@leaf-agent leaf-agent left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Edited: this replaces this review's original text, which said the description still described the earlier options design. In fact the description had been rewritten for this commit at 20:34, three minutes before this review posted, and its Evidence section scores this head. That claim was wrong.

One finding remains, in _ask_one (src/leaf/clerk.py). A re-asked choice whose HTML Leaf refuses can be dropped without a trace, and "A refused choice is still asked" exists to prevent exactly that.

When ask_again is refused for its HTML, which check_markup does inside _compose_and_append, _ask_one's except Rejected: pass treats that as "can't ask it in that thread" and falls through to if title.casefold() in asked_in: return None. If the earlier question's thread carries the same title, as it does when the fork re-asks under the title it first gave, that returns None. The outer words fallback in _ask never runs. Nothing goes On Me and the agent hears nothing, so a choice the user closed is silently not asked again.

I reproduced it by appending this to test_a_choice_the_user_closed_is_asked_again_in_its_thread's setup, re-asking with choice=caches(), whose cache id the first choice already took:

wrote = clerk_model.take_answer(
    "s1", reply(page, "LRU or TTL", again=question, choice=caches()), basis["basis"]
)["wrote"]
assert wrote  # fails: []

With a different title it does recover, but only after first trying to open a new thread with the same refused HTML. One way to close both paths: let a markup refusal from ask_again propagate to _ask, where it takes the words route, and keep except Rejected: pass for refusals of the thread itself (owes a reply, unasked question).

Tend's review of #6202 found that when the turn-end fork asked a closed
choice again with a choice whose HTML Leaf refuses, `_ask_one` took the
refusal from `ask_again` as "this thread can't take the question" and fell
through to the title check, which dropped the ask, since the earlier
question's thread carries its title. Nothing went On Me and the agent heard
nothing.

`thread.ask_again` now returns None where the thread can't take the question
(it owes the user a reply, or names no question asked there) and lets a
refusal of the HTML propagate, so `_ask` posts the ask again in words in that
thread and tells the agent why. A different title no longer first tries the
refused HTML in a new thread either.

`test_a_closed_choice_asked_again_with_html_leaf_refuses_is_asked_in_words`
re-asks with the id the first choice took; it wrote nothing before this change.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The description's "Asking again" bullet still says an again naming anything else "is refused with unasked-obligation". Since 27afebe, ask_again returns None there and the ask opens its own thread, as the Tests section already says. The description becomes main's commit message, so that sentence is worth updating before merge.

@max-sixty
max-sixty merged commit bff177b into main Nov 16, 2026
5 checks passed
@max-sixty
max-sixty deleted the grind/5404-turn-end-choice branch November 16, 2026 21:03
max-sixty added a commit that referenced this pull request Nov 17, 2026
…#6218)

Every message an agent posts now reads as Markdown with HTML, whichever
way it reaches the page, so the log drops the `html` field #6208 added.
Before, only text the agent wrote with a `leaf thread` command, and the
turn-end check's asks, drew its HTML, and the field marked those
messages; a Codex turn's final message, progress lines and failure
receipts kept their tags as words. Readers that need to know whether a
message holds HTML now derive it from the text
(`thread_context.logged_fragment`, cached), and the server adds it to
each served thread message, so the browser runtime is unchanged. A
user's message still shows tags as words.

Max asked why the field existed at all. It existed so Leaf could post
agent text without reading its HTML. Reading every agent message the
same way keeps one rule, and each path that posts agent text now meets a
refusal the way the agent's own command does:

- **A Codex final message** with a stray tag, such as `Vec<String>`
outside backticks, is refused (`unclosed tags: <string>`), and the
existing correction delivery asks the agent to fix it and answer again.
In exchange, a final message can hold HTML: a `<details>` quote, a table
or a choice draws. The turn writer's delivery clause drops "Reply
explicitly too for other HTML, which your final message shows as text",
which is no longer true.
- **Progress lines** (a Codex opening, a fork's working line,
`--ephemeral`) may now carry formatting HTML such as `<em>`; they still
refuse a widget, since the answer replaces the line. Before,
`--ephemeral` refused any HTML.
- **The turn-end check's asks** (#6202): where Leaf refused an ask's
HTML, it posted the ask again with the HTML shown as raw text. That
fallback needed the field. Now any ask Leaf refuses, for HTML or for a
picture the page hasn't got, is not posted, and the agent gets the
message and the refusal as a line it owes, which wakes it to ask the
user itself; the fork's other asks are still posted. Before, a missing
picture in one ask dropped the whole answer without telling the agent.
- **Edits**: the rules that a message drawing HTML keeps its words and
that an edit adds no HTML move from `leaf thread edit` into the append
door, so an edit a sample's fixture carries meets them too.
- **Protocol 48** (#6216 took 47): a Leaf at 47 would draw a new log's
HTML messages as text and miss their widgets. Delivery records are
unchanged.

The `html` parameter that ran through `open_thread`, `post_reply`,
`post_response`, `_compose_and_append`, `ask_again` and the clerk is
gone with the field.

Reviewed by Codex; its three findings (progress lines refusing
formatting, edits bypassing the rule through fixtures, clerk refusals
not reaching the agent) are fixed here. Ran `uv run pytest tests/model
tests/process`, `pnpm run test:runtime`, `pnpm run check`, and nine
browser and journey tests covering a choice in a thread, an export, a
reply's widget and the shipped logs.

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

Questions with a few listable answers should be choices the user can press, from the thread and from On me

2 participants