Skip to content

Show what z takes before taking it back - #3603

Merged
max-sixty merged 9 commits into
mainfrom
undo-show-then-take
Oct 22, 2026
Merged

max-sixty merged 9 commits into
mainfrom
undo-show-then-take

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Undo now shows a gesture before taking it back whenever the user couldn't see what it would change. This completes the undo design the user chose on 21 October (the "Show, then take" half; "Say what z takes" landed in #3586), so notes/undo-reach/ is deleted.

What the user sees.

  • When the gesture z (or the menu's Undo row, its touch route) would take back is out of view, or the agent has already picked it up, the first press only shows it. It opens the thread, travels to the widget as its fragment so Back returns, or opens the message holding an agent-sent widget. It then says "Press again to undo: resolved “…” · 21d ago". The second press takes it back.
  • Another key, a press on the page, or a scroll taking the shown place out of view clears the arm. Modifier keys, wheel scrolls that keep it in view, and presses in Leaf's chrome don't, which lets the menu route work in two presses.
  • A gesture in view and not picked up is taken in one press as before. So is a gesture this tab holds a reversal for, since taking it back already lands the user on it.
  • A resolved thread in the floating panel now shows a passing notice in place of its fixed "Resolved · reopen to reply" line. Without that, "Press again" wasn't visible there.

How.

  • browser_undo_candidates (served_state/document.py) marks picked_up from delivery.opened_input_ids: the opened-pickup evidence the workflows read as Delivered, which had no callers until now.
  • undo.js holds the armed state.
  • No protocol bump: picked_up is optional, and earlier runtimes ignore it.

Evidence.

  • New browser tests in test_render_outbox.py cover:
    • an old resolve below the fold, shown then taken, with nothing written to the log on the first press;
    • the arm clearing on a key and on a scroll;
    • a picked-up gesture in view showing first;
    • the menu route taking two presses.
  • All fail on the base runtime; the in-view control passes on both.
  • A new process test checks that an opened pickup marks the gesture and a queued one doesn't.
  • After merging main: pnpm run test:runtime (519), outbox -k "undo or z_" (23), the floating panel -k menu (15) and the process undo tests pass, and check:browser is clean. Three existing tests now press twice, as the new behavior asks.
  • Hand-checked in a review-a-plan preview with a 21-day-old resolve below the fold, and with a picked-up one.

events.md's Undo section, the undo.js header, the history.undo description and docs/how-it-works.html#undo describe it. Redo and a Changes panel move to a TODO item that points at the deleted note.

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

max-sixty and others added 2 commits October 22, 2026 12:09
`z` no longer takes back a gesture the user cannot see. Where the gesture's
place is out of view, or the agent has already picked it up, the first press
(or the leaf's menu Undo) shows that place and says "Press again to undo:
resolved “Feeder” · 21d ago"; the second press withdraws it. This completes
the undo design the user chose on 21 October ("Show, then take", after "Say
what z takes" in #3586).

Behavior:
- Showing works as an `lf-activity` row's link does: a thread opens, and an
  element is travelled to as its fragment and focused. A widget an agent sent
  in a message opens its message.
- The arm clears on any other key, a press on the page, or a scroll taking
  what was shown out of view; the next press then shows again. A modifier
  alone, a wheel that keeps it in view, and presses in Leaf's chrome keep it,
  so the menu row (the touch route) works in two presses through the leaf.
- A target in view and not picked up is taken on the first press, as before.
  So is a gesture this tab holds a reversal for (a thread settled from a
  view), since taking it back already lands the user on it.
- Approvals and a to-do's Done have no place on the page; picked up, they
  arm with the notice alone.
- A resolved thread's line in the panel now says a passing notice, on one
  line, instead of always "Resolved · reopen to reply"; without this the
  notice was unseen while the panel showed the thread `z` had opened.

Served state: each undo candidate a delivery handed into an agent's turn
carries `picked_up`, read from the opened pickups (`delivery.opened_input_ids`,
the Delivered stage the workflows read). It is an optional field, so no
protocol bump: a runtime vendored earlier reads the undo list's `event`,
`coordinate`, `newest` and `gesture` by name and ignores it (undo.js, the
widget Undo's coordinate filter). The build moved the baseline without
needing --accept-served.

Tests whose behavior changed: the fresh-tab naming test now presses the menu
row twice; the candidate-applying test and the tally's Next-then-z step press
`z` once to show the target (covered by the panel, or in a tab Next left) and
again to take it.

Evidence: four new browser tests (old resolve below the fold, a picked-up
choice in view, the arm clearing on a key and a scroll, the menu route) fail
on the base runtime and pass here; the in-view control passes on both. A
process test covers `picked_up`. Hand-checked in a review-a-plan preview,
light and dark.

The undo-reach note is deleted; its Redo and Changes panel analysis moves to
a TODO item pointing at `fa3aad5e0:notes/undo-reach/README.md`.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

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

A quick second z can withdraw a gesture before the first press has shown it. arm() makes the next press eligible while show() is still awaiting the thread opening. I reproduced two keydowns in one browser task: the thread was outside the viewport after both presses, yet the undo was posted. Gate the second press on the destination actually being visible so the withdrawal follows the reveal.

Comment thread skills/leaf/assets/runtime/undo.js Resolved
…e applying test's showing

A second z in the same task as the first could withdraw the gesture before
the first press's reveal finished, so the user never saw it. The arm now
takes only after the reveal resolves. The candidate-applying test relied on
the panel covering the suggestion, which CI's layout didn't; it now marks
the gesture picked up, so the first press shows it wherever it lies.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@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 fragment route can still take back a gesture before its destination is visible. show() calls location.assign() and resolves without waiting for the hash navigation to scroll. With an action on #picks below the fold, I dispatched z, awaited two microtasks, and dispatched z again in the same browser task: #picks was still outside the viewport before the second press, but an undo event was admitted. Check that the destination is visible when the armed press is taken. The new test covers the thread opening path, whose show() awaits its destination.

Comment thread browser/runtime/undo.js Resolved
The fragment route assigned the hash and returned, so a second z in the
same task could take the gesture back before the trip scrolled it into
view. Showing now navigates through the Navigation API and waits for the
trip to finish.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
leaf-agent previously approved these changes Oct 22, 2026
# Conflicts:
#	dist/kernel/kernel.json
#	notes/undo-reach/README.md
leaf-agent
leaf-agent previously approved these changes Oct 22, 2026
leaf-agent
leaf-agent previously approved these changes Oct 22, 2026
leaf-agent
leaf-agent previously approved these changes Oct 22, 2026
@max-sixty
max-sixty merged commit df84f3f into main Oct 22, 2026
3 checks passed
@max-sixty
max-sixty deleted the undo-show-then-take branch October 22, 2026 22:17
max-sixty added a commit that referenced this pull request Oct 25, 2026
`test_another_key_or_a_scroll_away_puts_the_shown_gesture_back_to_showing`
pressed `z` on a choice already in view and scrolled the window away in
the next breath. The arm starts watching what a press showed only once
the press's fragment travel has finished, and clears on a scroll only
after a pass has read it in view, so a scroll in that window leaves the
arm standing and the next `z` takes the choice back. On a fast host
(this Mac, the macOS runner) the test's scroll won that race every time;
on the slower Linux runner the travel finished first. No user scrolls
within the few milliseconds of that window.

The test now waits for the press's travel to finish and for the pass
after it, and for the pass after its own scroll, before pressing again.
Introduced with the test in #3603. The behavior protected is unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Nov 19, 2026
Undo now takes back the user's newest gesture in one press of ⌘Z (Ctrl+Z
off a Mac), and where its place was out of view, goes there once the
page shows the withdrawal; Back returns to where the user pressed. This
replaces "show, then take" from #3603, where a first press showed an
out-of-view gesture and a second took it, and moves undo off bare `z`.
max-sixty chose both today: taking at once, after a review found that
the state behind showing had been patched seven times in four weeks and
that a missed visibility reading cost a press that took nothing; and ⌘Z,
after a word typed onto the page undid work.

What one press does, before and after (each row run with `leaf-dev
probe` on this branch in Chromium, and each choice row in Firefox too):

| When the user presses undo | main (`z`) | this PR (⌘Z) |
| --- | --- | --- |
| The gesture is in view | takes it | takes it |
| It is out of view | shows it, says "Press again to undo"; a second
press takes it | takes it, then goes to it |
| Right after the Escape that closes a panel over it | reads the closing
panel as covering it: scrolls 543 px, adds `#near`, takes nothing |
takes it, no scroll |
| The user's choice is still being sent | does nothing, says nothing (10
ms at 1× CPU, over 100 ms at 8×, plus server time) | takes it at once by
its pending id, as the widget's Undo does |
| Two quick presses, a message or resolve still being sent, two choices
still being sent, a held drag | the press waits | unchanged |

Visibility is read with each cover where it comes to rest (`seenRect`'s
`rest`, which `uncovered` already took), and it now decides only whether
the press travels. The armed state, its input and scroll watches, and
`landedAway` are gone. The `undo.js` header, `events.md` "Undo" and
how-it-works' Undo paragraph say what undo does now.

**Undo moves from `z` to ⌘Z.** Someone who thought they were typing in a
box and typed onto the page undid work: on this branch `zazu` after a
pick took the pick and an older comment, and `zazu` just after a
passage's first comment took that comment back (main took one gesture in
each). max-sixty picked the platform's undo chord over keeping `z`, ⇧Z
and `g Z`, and kept Resolve on `r`. A text box keeps every letter with a
modifier (`keyboard/text-entry.js`), so ⌘Z undoes typing inside a box
and a gesture outside one. Probed in Firefox: `zazu` after a pick or a
first comment now sends nothing, ⌘Z after each sends the undo, and ⌘Z in
a reply box undoes its typing and sends nothing. A chord isn't a printed
key, so the startup hold doesn't keep one: a ⌘Z pressed before the
page's history arrives does nothing, where a held `z` waited for it. The
docs, examples and tests name ⌘Z, and the notice's key chip spells it
`⌘z`, or `Ctrl+z` off a Mac.

Review found three more defects, fixed here, each with a test that fails
without its fix:
- An undo of an action whose POST had answered, before any reading held
it, drew nothing until its own round trip: `framework/application.js`
withdrew the action under the log's id while the page drew it under its
pending id. This held for the widget's own Undo too.
- Taking back a comment whose card was closed flashed the card open. A
comment's place is now its passage.
- The travel to an element ignored input made after the press; it now
checks the press's intent, as the thread routes do.

**The undo's notice.** A survey of what the panel says after each press
([#6439](#6439)) found four
defects in it, each on main too, fixed here:
- "Undid: commented “…”" was a verb with its "I" left out, which the
glossary's voice rule forbids; it now says "Undone: …".
- "· 72d ago" after it read as when the undo happened. The age now
follows the gesture's words with no separator, "Undone: resolved
“Feeder” 21d ago", and the command reference's "Undo: …" line reads the
same way.
- In a thread open in the panel, a notice with no press of its own
replaced "Reply…" and left `c` alone at the field's end. The field now
ends it in "Reply…" and `c`, as the page's field ends one in "Comment…"
and `c`. In a narrow panel the notice's age is then cut by the field's
ellipsis; the live region still hears it whole.
- Undoing a resolve announced a cut-off fragment of the agent's reply
before the notice: the resolve had marked the reply read, so its undo
made it unread again, and news counted a version the first time a tab
saw it unread. A version a tab has already seen read is no longer news
when it turns unread (`semantic-news.js`).

Taking at once also means undo takes an accepted action whose reading
failed to commit, by its attempt, as that action's own Undo would.
`test_an_accepted_event_is_not_retried_when_its_state_cannot_render`,
written for main's hold, failed on this branch for that reason; it now
checks that an older gesture's Undo still waits.

This replaces #6402, whose test waited out the Escape case; under this
change that test passes as written.

Still open, found in review and not probed: an undo pressed inside the
140 ms scroll glide `t` starts reads the choice where the glide stands,
not where it lands, so it may revert unseen. Covers are read at rest and
glides aren't. The fix is to read both where they come to rest, in
`scroll-containers.js`' `seenLanded`.

How loudly an undo shows what it took follows in its own PR: max-sixty
picked an accent ring on what the undo changed, with the notice held
until the next key.

Checks: the 85 browser and journey tests that press undo, call the
harness's `undo` or read the words above (100 cases with parameters; all
pass, the one above after its update), each new test failing without its
fix; `pnpm run test:runtime` (1,052 pass) and `pnpm run check:browser`;
pre-commit on every changed file.

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