Skip to content

Let an agent edit the HTML in its own thread messages, at page protocol 49 - #6246

Merged
max-sixty merged 12 commits into
mainfrom
stop-second-guessing-agents
Nov 17, 2026
Merged

max-sixty merged 12 commits into
mainfrom
stop-second-guessing-agents

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

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

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.
…ol 49

`leaf thread edit` refused any edit of an agent's message holding HTML, and
any edit adding HTML, in case the user had acted on a widget in it. It now
takes them as it takes words:

- Every reading of a message's elements follows its latest wording in force
  (`thread_context.thread_structure`): the widget index, the questions On Me
  lists, data bindings, deliveries and the served `html` flag. A gesture's
  words (`gesture_words`) read the wording the user saw when they made it, so
  a relabelled option doesn't rewrite what the record says they chose.
- An edit's HTML meets the gates a new message's does (`check_markup`, the
  browser render gate) under the newest revision, which the edit now names as a
  message holding HTML does. That new optional field is the protocol bump.
- An id any wording of a message held stays reserved to that message
  (`ThreadStructure.holders`), as page revisions keep theirs, so a recorded
  answer can't attach to another message's widget.
- Where the message holds a widget the user has acted on, the edit goes in
  with advice saying where their answer now shows (`edit-answered-widget`).
- The browser prepares an island per wording, so a drawing holding back the
  edit keeps its own, and the adopted reading decides which island a
  message's widgets answer for (`islandChange`), retiring the ids the old
  island held. An edit redraws the island, losing typed values or focus
  inside it, a rare path left to redraw.

AGENTS.md "Leaf's role" now says a reasonable choice is the agent's to make:
Leaf refuses only input that breaks a guarantee whatever the agent meant, and
otherwise accepts it and says what it did. Scored before and after on six
design questions (3 runs each): the edit freeze went from refused 3/3 to
accepted 3/3, and both guarantee-breaking guardrails stayed refused 6/6.

Behavior changes: test_an_agent_message_drawing_html_keeps_its_words becomes
test_an_agent_edit_rewrites_its_messages_html; the stream-placeholder browser
test now edits its reply's HTML and checks the island follows.
Each island lives until reload, one per edit of a message holding HTML, and a
gesture a tab made before an edit reached it reads in the edit's words: both
rare paths left as they are rather than carrying a mechanism.
…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.

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

edit-answered-widget decides kept from the widget's own id alone, so an edit that keeps <lf-options id="ship"> but replaces the option the user picked tells the agent their answer "shows on the markup this edit leaves there". It doesn't. The recorded value names ship-now, which is no longer drawn, so the widget shows no pick while the question still counts as answered. This advice is the only thing that tells the agent what an edit did to the user's decision, which is the guarantee the new "Leaf's role" paragraph rests on. The PR's test passes only because the relabel renames ship-tonight back to ship-now. The suggestions below compare the ids the latest action rests on (meaning.depends: widget, unit and recorded options) against the new markup. With them, an edit that drops the picked option reports kept: false, as removing the widget does. A test case that relabels without keeping the chosen id would pin this down.

Comment thread src/leaf/thread.py Resolved
Comment thread src/leaf/thread.py Resolved
…cond-guessing-agents

# Conflicts:
#	tests/browser/threads/test_agent_replies.py
edit-answered-widget read the widget's id alone, so an edit keeping the
widget but dropping the option the user chose said their answer still
showed. It now compares the ids the latest action rests on (meaning.depends)
with the new markup.

@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 meaning.depends comparison now fails in the opposite direction when the user wrote their own option. Leaf records an option the user adds through lf-options' add verb in the log, not in the agent's markup: its id is the action's unit (meaning.creates), and events.action_rests_on treats it as resting "whether or not a document holds it yet". So after the user adds ship-mine and picks it, any edit that keeps <lf-options id="ship"> reports kept: false and tells the agent "this edit removes what it chose". But the added option and the pick both still show. Before this push the advice was right in this case, because kept checked only the widget id.

I reproduced it with a scratch copy of test_an_agent_edit_rewrites_its_messages_html: add {"option": "ship-mine", "text": "Mine"}, then choose ["ship-mine"], then an edit that keeps ship. The edit returned [('edit-answered-widget', {'kept': False})]. The suggestion below takes the ids the log's own actions created out of what the markup has to hold. A case like that one in the test would pin it.

Comment thread src/leaf/thread.py Resolved
The advice now takes the children the user created through the widget
(meaning.creates) out of the ids the markup must keep, since the log holds
them whatever the wording.
leaf-agent
leaf-agent previously approved these changes Nov 17, 2026
Base automatically changed from agent-message-html to main November 17, 2026 07:24
@max-sixty
max-sixty dismissed leaf-agent’s stale review November 17, 2026 07:24

The base branch was changed.

…agents

# Conflicts:
#	browser/runtime/kernel-registry.json
#	browser/runtime/shadow-tree.js
#	browser/types/contract.d.ts
#	build/browser/protocol-baseline.json
#	examples/developer/feature-gallery.html
#	examples/ship-review.jsonl
#	src/leaf/clerk.py
#	src/leaf/data_contracts.py
#	src/leaf/delivery.py
#	src/leaf/events.md
#	src/leaf/render-checks/widgets.js
#	src/leaf/served_state/state.schema.json
#	src/leaf/served_state/thread.py
#	src/leaf/thread.py
#	src/leaf/thread_context.py
#	src/leaf/validation/admission.py
#	tests/browser/test_render_application_boundary.py
#	tests/browser/threads/test_agent_replies.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_interact_product.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
leaf-agent
leaf-agent previously approved these changes Nov 17, 2026
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_
…agents

# Conflicts:
#	src/leaf/thread.py
#	tests/browser/threads/test_agent_replies.py
@max-sixty
max-sixty merged commit 7225dbb into main Nov 17, 2026
5 checks passed
@max-sixty
max-sixty deleted the stop-second-guessing-agents branch November 17, 2026 17:10
max-sixty added a commit that referenced this pull request Nov 17, 2026
…ol 50

Main took page protocol 49 for agent edits of their own message HTML
(#6246), so this branch's `held` pickup phase and the agent turn's `role`
take the protocol to 50: `$events.protocol`, the agent-turns record's
`since`, and the baseline rebuilt from main's at 49 with only the pickup
event and the agent-turns record changed, and the `forks` and
`fork-lane-start` records removed.

Conflicts kept both sides: `events.md` is main's table with the `held`
phase in the pickup row; `thread.py` keeps main's `import json` and drops
`Callable` with `Receipt.fence`; the `forks.py` header, the
`holding.authorize` docstring and `docs/forks.html` keep this branch's
line-turn hold in main's wording without dates or eval counts (#6212).
max-sixty added a commit that referenced this pull request Nov 17, 2026
Since #6246 an agent edits a message's HTML as it edits its words, and
every reading follows the message's latest wording. So the code's name
for that markup, "frozen", told every reader it can't change. This
renames that sense of the word throughout:

- `FrozenThreadReading` / `frozen_thread_reading` →
`ThreadMarkupReading` / `thread_markup_reading`; finding code
`frozen-settlement` → `message-settlement`.
- Comments, docstrings, contract prose (`events.md`, `validation.md`,
`skills/leaf/references/`), the served-state schema's descriptions and
finding words say "thread markup", "a message's markup" or "thread
widget". Four passages claiming the log freezes a message are reworded.
- In the browser, the prepared message an island holds is `prepared`,
not `frozen` (`state-application.js`, `thread/messages.js`).
- Tests, fixture ids and served-record keys use the same words.

"Frozen" stays where it means something else: immutable values, captured
snapshots and previews, saved deliveries, `uv --frozen`. No behavior,
event schema or protocol change; `protocol-baseline.json` moves only by
one field's description text.

Tests: the changed `tests/model` files and `test_interact_layer.py` (900
passed), `pnpm run test:runtime` (1008 passed), and collection of the
renamed browser and journey tests.

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