Skip to content

Read every agent message's HTML, and drop the html field from the log - #6218

Merged
max-sixty merged 9 commits into
mainfrom
agent-message-html
Nov 17, 2026
Merged

max-sixty merged 9 commits into
mainfrom
agent-message-html

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

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 (Ask a turn-end question with listable answers as a choice the user presses #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 (Read no space before a closing mark or after an opening one where an element's words end, at page protocol 47 #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

An agent's message is Markdown with HTML whichever path posts it: a
`leaf thread` command, a Codex turn's final message or opening, a fork's
working line, a failure receipt or the turn-end check. #6208 read HTML
only in the first and last, and logged `html: true` to mark them. Readers
now derive it from the text (`thread_context.logged_fragment`), and the
server serves it on each thread message, so the browser is unchanged.

Behavior that changes:
- A Codex final message with a stray tag is refused, and the correction
  delivery asks the agent to answer again; HTML in it now draws.
- Progress lines may carry formatting HTML and still refuse a widget.
- The turn-end check hands any ask Leaf refuses (HTML, or a picture the
  page hasn't got) to the agent as an owed line instead of posting it with
  its HTML as raw text, or dropping the whole answer for a missing picture.
- The edit rules for HTML move from `leaf thread edit` to the append door.

Protocol 47: a Leaf at 46 would draw these messages' HTML as text.
leaf-agent
leaf-agent previously approved these changes Nov 16, 2026

@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 fixture still writes the removed field: tests/journeys/test_render_controls.py#L149, in _sample_containment_page's <script id="history">, has an agent reply with "html":true, "revision":1,. That script is the lf-sample's data-sample-events history, which now goes through the append door, and the reply record is additionalProperties: false with no html property. So the sample's history is refused, the child doesn't start, and the journey fails in the nightly tier the PR's own checks don't run. The PR drops this key from the other fixtures; this one was probably missed because it's written "html":true with no space. Deleting "html":true, from that line fixes it, since the text's <details> now reads as HTML anyway. A repo-wide search turns up no other copy. It's outside the diff, so I can't post it as a suggestion; I can push the one-line commit if you'd like.

…e body

#6225 put each test's widget into its message text and passed html=True, the
parameter this branch removes; every agent message now reads its HTML.
# Conflicts:
#	browser/runtime/kernel-registry.json
#	examples/developer/feature-gallery.html
#	examples/ship-review.jsonl
#	src/leaf/events.md
#	tests/browser/test_render_application_boundary.py
#	tests/journeys/test_interact_contract.py
#	tests/model/interact_contract/_regtest_outputs/test_layer_contract.test_each_route_hands_the_agent_what_the_snapshot_shows__0/snapshot.yaml
#	tests/model/interact_contract/test_admission.py
#	tests/model/test_clerk.py
#	tests/model/test_delivery.py
#	tests/model/test_forks.py
#	tests/model/test_interact_document.py
#	tests/model/test_obligations.py
#	tests/model/test_stop_guard.py
#	tests/model/test_workflows.py
#	tests/process/website_server/_regtest_outputs/test_app_server.test_hosted_agent_receives_the_response_instructions_and_delivery__0/snapshot.yaml
#	tests/process/website_server/test_turn_answers.py
The live-sample history in `_sample_containment_page` still gave its agent
reply `"html":true`, which the reply record no longer allows, so the sample's
history was refused and the journey couldn't start its child. Its `\n\n` also
reached the JSON as raw newlines, which the sample-json check refuses on main
too; the literal now escapes them.
@max-sixty
max-sixty merged commit 67d944f into main Nov 17, 2026
5 checks passed
@max-sixty
max-sixty deleted the agent-message-html branch November 17, 2026 07:24
max-sixty added a commit that referenced this pull request Nov 17, 2026
A reply that moves or detaches its thread checks the page against the log
plus a stand-in for the move, built from the reply's event. Since every agent
message's text reads as HTML (#6218), the stand-in's copy of the text put the
reply's widget ids into the log's message ids, so a reply whose id clashed with
the page was refused as "cannot reply while index.html is invalid" rather than
by the reply's own check, which names the clash. The stand-in now carries no
text.
max-sixty added a commit that referenced this pull request Nov 17, 2026
…ceptions (#6247)

An agent's thread message now reads its HTML exactly as CommonMark does,
as GitHub reads a comment. Max asked whether messages could hold HTML
following Markdown's standards, with no special exceptions; this drops
the three #6208 added (a custom element running to its closing tag
across blank lines, a literal `<code>`, and the `widget-in-paragraph`
refusal).

What changes for an agent writing a message:

| Writing | Before | Now |
|---|---|---|
| A choice whole on one line | its own block | drawn the same, inside
the paragraph Markdown puts around it |
| An `lf-ask` or data widget whole on one line | its own block |
refused: its heading or `<pre>` closes that paragraph early |
| A widget's opening tag alone on its line, after a blank line | its own
block | the same |
| A blank line inside a widget or `<details>` | kept | ends the block; a
split `<pre>` is refused (`split-pre`) |
| `<code class="language-math">\{x\}</code>` | kept as written |
Markdown reads the escapes, so it takes `\\{x\\}` |

Worth weighing: `split-pre` is the one new check. A blank line inside a
nested `<pre>` leaves well-formed HTML whose code silently lost its
blank lines and indents, which nothing else reports; it refuses a
`<pre>` holding any block, such as the `<p>` or `<ul>` Markdown draws
there. A refusal also now prints the drawn HTML lines its findings name.
Of 50 widget messages agents sent on local pages, 46 draw as before and
4 (one-line `lf-ask`s) would be refused. Python's message reading also
stops starting blocks on lines indented four spaces, matching the
browser. It also fixes a regression from #6218: a reply that moves its
thread checked the page against a stand-in event carrying the reply's
text, so a widget id clashing with the page was refused as an invalid
page rather than by the reply's own check.

Scored `thread-choice-takes-a-press` and `answer-quotes-what-it-cites`
on Claude Code (12/12, base and head), reviewed by a fresh subagent,
whose findings are fixed here. Ran model and process tests, `pnpm run
test:runtime`, `pnpm run check`, and the 22 browser and journey tests
holding edited messages.

> _This was written by Claude Code on behalf of max-sixty_
leaf-agent added a commit that referenced this pull request Nov 17, 2026
…TML in two stale tests (#6285)

Two tests on `main` assert behavior that a merged change deliberately
reversed. Both fail every time on current `main` and pass with this
change (run locally on `origin/main` at `66b3883a4`). The same failures
are in [run
44038409739](https://github.com/max-sixty/leaf/actions/runs/44038409739).

-
`tests/browser/test_render_gate.py::test_the_state_wait_covers_a_status_that_moves_neither_log_nor_data`
asserted `"Ready"` in the leaf's `aria-label`. #6262 changed the resting
line to "Claude awaits", so the label now reads `Page menu · Claude
awaits`. The test now looks for `awaits`. It still checks the same
thing: the status the server holds is on screen once the state wait
ends.
-
`tests/browser/projection/test_thread_replies.py::test_a_reply_renders_its_markdown_and_a_suggestion_shows_its_characters`
waited 120 s for a paragraph containing the literal text `<lf-callout>`.
#6218 (bisected) made every agent message read as Markdown with HTML, so
that block now draws as an `lf-callout` element. The test now checks for
the drawn `lf-callout > div`. The fixture's `Vec<T>` moves into a code
span, because #6218 refuses a stray tag in an agent message. The
`"Vec<T>" in text` check still passes, now from the code span.

Behavior no longer asserted: raw tags in an agent's reply showing as
characters, which #6218 removed on purpose. User messages and
suggestions still show tags as words. The suggestion subtest is
unchanged.

The run's third new failure,
`test_a_drag_that_overshoots_the_layer_is_not_a_passage`, has a
different cause (bisected to #6254) and is tracked separately.

Refs #3985 — automated triage

Co-authored-by: leaf-agent <[email protected]>
max-sixty added a commit that referenced this pull request Nov 17, 2026
…o-do end go in (#6271)

Three refusals that stopped a reasonable agent write now let it in and
say what it did, as Max picked on the survey of refusals that
second-guess agents:

- A reply by message id into a thread that owes an answer posts, with
advice naming what's still owed (`owed-response` becomes advice). A
`--ephemeral` progress line on a stale reference posts too, taking
nothing in hand (`superseded-progress` advice keeps the old refusal's
news, such as a withdrawn note). A stale reference on an actual answer
is still refused, so an unread newer message can't show as answered.
`progress-parent`, the same progress case at another door, is deleted as
unreachable.
- A CLI answer's retry key covers the whole write, so `--todo` and then
`--done` on one reference both go in (`redeclared-answer` deleted). The
`--done` reply posts in the thread without answering anything, and Leaf
names the to-do the earlier answer opened that's still open, for `leaf
task end`. Ending it automatically was tried and dropped: the reply and
the end were two appends, and a retry after a failure between them left
the to-do open for good. A reworded retry is now refused as already
answered, where it used to return the first reply silently.
- Any agent session may end any open to-do (`todo-execution` deleted).

Production code is −29 lines (−42 counting code alone); tests −24.
Shipped prose (`threads.md`, `conversation-loop.md`) is corrected for
facts only. Independent of #6246 and #6218; no schema change.

Tests: 11 focused `tests/model` files (788 passed) and the
reply-guidance regtests. Codex reviewed the first version; its two
findings are fixed in the second commit.

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Nov 17, 2026
…ol 49 (#6246)

An agent can now edit the HTML in its own thread message, as it edits
its words. #6208 froze any message holding HTML (`edit-holds-html`,
`edit-adds-html`) in case the user had acted on a widget in it; Max
asked to drop the freeze and at most warn about changing what the user
already picked. #6218 moved that refusal into the append door; this PR
removes it.

Every reading of a message's elements now follows its latest wording
(`thread_context.thread_structure`): widget index, On Me questions, data
bindings, deliveries, the browser's drawing. An edit's HTML meets the
gates a new message's does, under the newest revision, which the edit
now records — the reason for page protocol 49. Ids any wording held stay
reserved to that message, as revision ids are, so a recorded answer
can't attach to another message's widget. Where the message holds a
widget the user acted on, the edit goes in with advice saying whether
their answer still shows, judged by the ids it rests on
(`edit-answered-widget`). A gesture's words read the wording the user
saw, so a relabel doesn't rewrite their history row. The browser keeps
an island per wording and retires the old one's widget ids when the page
adopts the new reading (`islandChange`).

Calls to weigh: an edit redraws its island, so typed values or focus
inside it are lost, and a gesture made in a tab the edit hadn't reached
yet reads in the new wording; both rare paths, left without a mechanism.

AGENTS.md "Leaf's role" gains the principle. Scored on six design
questions, 3 runs each: the freeze went from refused 3/3 to accepted
3/3; both guarantee-breaking guardrails stayed refused 6/6.

Tests: model edit/obligation tests, the runtime island test, the
stream-placeholder browser test; focused model files and `pnpm run
check` pass. Codex reviewed twice; its findings are fixed or noted
above.

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