Skip to content

Let undo take back a rewrite until the agent answers it - #5221

Merged
max-sixty merged 7 commits into
mainfrom
empty-message-edit
Nov 3, 2026
Merged

max-sixty merged 7 commits into
mainfrom
empty-message-edit

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

A saved rewrite couldn't be taken back. edit was never among the kinds the log lets undo withdraw, and since a rewrite is the user's newest gesture it also ended z's walk: after any rewrite z did nothing at all, silently, even over a resolve made before it. A deletion, the rewrite to no words that #5057 added, was therefore final.

z now takes back a rewrite, a deletion included, until the agent answers it. Before, after a resolve and then a rewrite, z did nothing. Now the first press says "Press again to undo: edited “I do think green is nice”" (opening the thread on the message when it isn't on screen), and the second gives the message those words back.

The rule

A rewrite is a turn, so it follows the rule a reaction already follows: the user takes it back while no answer stands on it. Once the agent answers, it may have acted on the words the rewrite left. In the case an independent review reproduced, the user deleted "Build blue", the agent removed the blue work, and undoing the deletion would have brought the request back without the agent hearing of it. So the door refuses an undo of an answered rewrite (answered-edit), and the user says what changes in a new turn.

Rejected: delivering that undo as a new turn the agent answers. Leaf would then have to count an undo as a turn wherever it decides whose turn a thread is.

Changes

  • Log (events.py, event_contracts.py, kernel registry): edit is undoable, refused once answered. A rewrite's base is checked against the latest edit still in force, so the next rewrite after an undo lands on the restored words. An undone edit counts as a change to its message for summary staleness. The agent's undo clause says undoing an edit takes that rewrite back.
  • Browser: the restored words show in the press, before the log answers (foldThreads, unedited). z names a rewrite by the words it gives back. A rewrite's place is its message, not its thread's marker, so z shows the message before taking the rewrite when it's out of view.
  • Protocol 39: a Leaf at 38 checks base against the withdrawn edit, so it would refuse every later rewrite of that message.

Tests

  • test_a_rewrite_lands_only_on_the_words_it_was_written_over: undoing a rewrite restores the words and the earlier edited, the next rewrite lands on the restored revision, and an answered rewrite is refused.
  • test_an_emptied_rewrite_keeps_nothing_and_saved_deletes_its_message: z on a deleted message, with the log's answer held back, brings the words back in the press; they stay after a reload.
  • thread-workflow.test.mjs: the browser's fold of an undo over Python's reading of two rewrites matches Python's reading after the undo (new readings in served_records.py).
  • The layer contract snapshot records the new undo clause.

Each new assertion fails without its fix.

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

A saved rewrite could not be taken back: `edit` was not among the kinds the
log lets `undo` withdraw, so `z` refused it, and since a rewrite is the
user's newest gesture it also ended `z`'s walk, leaving `z` silent after any
rewrite, even over a resolve made before it. A deletion, the rewrite to no
words, was therefore final.

`edit` is now undoable. Withdrawing one gives its message back the words it
replaced, under the rewrite before it, which every fold already did by
skipping withdrawn events. What changes with it:

- Admission measures a rewrite's `base` against the latest edit still in
  force, so the next rewrite after an undo lands on the restored words.
- A summary over a message counts an undone edit as a change to its words.
- The browser draws the restored words in the press (`foldThreads`), and
  `z` names the gesture "edited a message in …" or "deleted a message in
  …", showing the message first when it is out of view or picked up.
- The agent's `undo` clause says undoing an edit gives its message back the
  words it replaced.

Protocol 39: a Leaf at 38 measures `base` against the withdrawn edit, so it
would refuse every later rewrite of that message.

Tests: the rewrite-base test undoes a rewrite and checks the message, its
`edited` and which `base` lands; the deletion browser test presses `z` with
the log held and sees the words return, then after a reload; a runtime test
folds an undo over Python's reading of two rewrites and matches Python's
reading after the undo.
…ad's marker

A rewrite changes only its message's words, so the thread's passage or margin
marker in view showed nothing of what z took back: z restored a deleted
message inside a closed thread in one press, unseen. Its place is now the
message, so z opens the thread on it first and the next press takes it.
…s words

Once the agent answers a rewrite it may act on the words it left: a user
deleted "Build blue", the agent removed the blue work, and undoing the
deletion brought the request back without telling the agent, since the undo
changed nothing the agent owed (found by an independent Codex review). A
rewrite is a turn, so it now follows the rule a reaction follows: the user
takes it back while no answer stands on it (`answered-edit`), and after
that says what changes in a new turn. The undo clause says an undone edit
takes that rewrite back, which holds when a later rewrite still stands.

`z` named a rewrite by its thread, "deleted a message in “…”", so the first
press didn't say what would come back. It now quotes the words the undo
gives the message again: "Press again to undo: deleted “I do think green is
nice”".
# Conflicts:
#	dist/kernel/kernel.json
# Conflicts:
#	dist/kernel/kernel.json
leaf-agent
leaf-agent previously approved these changes Nov 3, 2026
UndoReading sorted every thread's turns by seq to find answered rewrites,
which also read threads with none, and failed on a unit test's hand-built
events that carry no seq. It now reads owed turns once per thread that
holds a rewrite.
@max-sixty
max-sixty merged commit b76f665 into main Nov 3, 2026
4 checks passed
@max-sixty
max-sixty deleted the empty-message-edit branch November 3, 2026 18:31
max-sixty added a commit that referenced this pull request Nov 4, 2026
)

Everything On me is now answered by the widget or thread that asks it.
Leaf no longer puts a to-do on the user with a Done of its own, so a
widget is never given an answer it doesn't declare. A step such as
trying a build is asked in a thread, and the user's reply or a 👍 answers
it.

Before, `leaf task create <subject> --on user` put a to-do on the user
on any thread, element or widget that had no open obligation, and the
turn-end check did the same for each step it found. On me then offered
that item a generic Done: on an `lf-code` block or a paragraph, the only
answer was a check mark the widget never offered. This reverses the
user's 2026-10 choice to keep such to-dos for steps.

## The rule, and where it lives

- **On me holds obligations only.** Each comes from a widget that
declares `x-awaits` (any widget: bundled, from a package or the page's
own), an agent message sent with `--obligation`, or an update to send
again. On the page, each is answered only through its source: the
widget's declared actions, or a reply or settling reaction in the
thread. A multi-select `lf-options` keeps its Done, since that is the
widget's own control. An answer the user gives elsewhere, such as in
chat, the agent still records with `leaf task end`.
- **Content that asks nothing** (a paragraph, a chart) and a step the
user takes get a thread whose message carries `--obligation`.
- The rule is stated in `obligations.py`'s header, the `x-awaits` key in
`browser/registry.json`, How it works ("On me and the agent's list",
with a new paragraph on what can ask), `conversation-loop.md` ("The On
lists", where the to-do row becomes an "action the user takes" row asked
in a thread) and `authoring-on-me.md`. `todos.py`'s header records the
decision.

## What goes

- **Protocol 39 → 40.** A `todo` event has no `owner`; `todo_end` is the
agent's alone, is no longer browser-postable or undoable, and its
handling clause for the user's Done is gone. A Leaf at 39 would misread
a 40 log and the reverse, hence the bump. (`main` took 38 → 39 for an
undoable edit in #5221.)
- **Model.** `user_task_obligations`, the `todo` obligation source,
`--on`, the `duplicate-obligation`/`users-question`/`agents-todo`
refusals, and `owner` on served to-dos. `queues.on_user` rows are
`widget`, `message` or `update`; to-do rows stay on On <agent>.
- **Clerk.** The fork's answer has no `kind`. Every ask, a step
included, is a thread question whose message says what to do and asks
for a reply. `turn-end-check.md` (#4900) asks the fork that way, and the
fork eval (`dev/leaf_dev/fork_eval.py`,
`evals/workflows/fork_eval.yaml`) labels the step cases as questions.
- **Browser.** The To-do Done on panel rows, On me cards and a thread's
head; the `x` key and its "On a to-do waiting on me" stance;
`queueActions.done` (public package API); local `todo_end` folding and
its undo words; `offers`; `showOnMe`, which #5223 had extended to land
`m` on a page to-do's card; the `done` action face and `checked` icon. A
stance's exit is always Close's ✕, since no stance names another action
now. The margin card's grid loses the row the to-do header held;
`leaf-dev probe review-a-plan --do drive:card-by-keyboard --base`
measures identical child boxes in both arms.

## A cost this keeps

A reply answers a step's question whatever it says. A to-do stayed open
until Done, so "where do I get the build?" left the step On me; now that
reply answers the question, and a plan step naming it reads done until
the agent asks again with `--obligation` and points the step at the new
question. `conversation-loop.md` tells the agent to ask again, and the
clerk's header records the trade.

## Tests and evals

Behavior changed on purpose:

- `todo-on-the-user` becomes `step-on-the-user-takes-a-thread` (pass: a
thread message with `--obligation`).
- `closeout-asks-take-their-route` now requires the `/reload-plugins`
step as a thread question.
- `on-lists-read-todo-records` puts the phone build on the user as a
question.
- Tests that protected to-dos on the user (their Done, `x`, undo of
Done, the To-do placeholder, the thread-head line, and #5223's page
to-do on its card) are deleted. Tests that used one as a convenient On
me item now use a question in a thread.

On the candidate tree (Claude Code, 2 runs each):
`step-on-the-user-takes-a-thread` 2/2, `closeout-asks-take-their-route`
2/2, `on-lists-read-todo-records` 1/2. The failed run listed both user
items correctly and failed on the agent side, doubting that the
benchmark re-run was under way. No base arm was run: the base
instructions route a step through `leaf task create --on user`, which
these rubrics now fail by construction.

`pnpm run check:browser`, `pnpm run test:runtime` (775) and the model
selections covering to-dos, the clerk, obligations, hooks, undo and the
protocol pass, as do the resolved browser tests and #5232's
Back-from-an-obligation tests.
`test_an_item_arriving_above_takes_its_walk_place_and_moves_no_card_read`
fails here and on `main` alike since #5318: the card read moves down by
the new card's height (116px on `main`, 95px here), so the list no
longer holds its place when an item arrives 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