Repository navigation
Hold the reader's focus through a conversation card repaint - #662
Conversation
An open card's thread render re-appended the retained Resolve control to the header it already sat in. The move detaches and reinserts the node, so a reader standing on that control was dropped to the body on every repaint - and a repaint needs no gesture, a clock tick alone asks for one. Reconcile the header through setChildren, which the runtime already uses to retain children without moving a node in place.
leaf-agent
left a comment
There was a problem hiding this comment.
The runtime change verifies. Reverting setChildren(actions, [resolve]) back to actions.append(resolve) makes the new test fail with exactly the unexpected value "inactive" the description reports, so it pins the fix and not its arrangement, and the same-pattern claim holds: every other .append( under skills/leaf/assets/runtime/ either runs on a branch that just created the node or already guards on position — margin-entries.js's badge (if (control.lastChild !== badge)) and conversation/acknowledgments.js's line (if (line.parentElement !== host || line.nextSibling !== null)).
What the file-at-a-time verification could not see is that test_resolve_acknowledges_the_press_and_recovers_a_refusal[panel] — the other parameterization of the case this PR was opened for — has an intermittent failure of its own. Running tests/test_render_conversations.py and tests/test_render_margin.py in one invocation reddened it in two of five runs on this head, always on the panel branch's last assertion, expect(page.locator(f'.lf-threads > .lf-thread[data-id="{root}"]')).to_have_count(0), with the card still in the list after the five-second wait.
It is not this change: the same pair reproduces it with the runtime line reverted and the new test kept. The assertion is a bet on timing, because removal from .lf-threads is the fold-out's rather than the resolution's — renderPanel in conversation/thread-list.js keeps a resolved card the fold missed as a hidden child (node.hidden = …; wanted.push(node); continue;), which reads the same to a reader but counts one here, so the count only reaches zero when foldOut runs and its motion completes. I could not catch the failing frame to say which of the two fold branches it misses, so the mechanism is inferred; the ownership is measured.
Nothing here blocks this PR's gates — the everyday suite does not run these files, and the complete suite is green at the merge base (run 34728547881). The open question is whether the panel assertion should be waiting for the fold at all, or asserting that the card is not shown; that decides product intent about whether a resolved card has to leave the list, so it belongs in its own change against the test rather than here. I can chase it if that is the reading you want.
Runs behind the ownership claim
Each run is uv run pytest <selection> -q with the repository's default -n 2 --dist loadgroup, on this sandbox's Linux.
| tree | selection | result |
|---|---|---|
merge base efe59c38 |
both files (179) | 179 passed |
this head d117485b |
both files (180) | [panel] failed |
| this head | both files (180) | [panel] failed |
| this head | both files (180) | 180 passed, three times — two of those carried a temporary dump on the failing assertion, which never fired |
this head, setChildren line reverted |
both files (180) | [panel] failed, and the new test failed as expected |
| merge base | [panel]'s case + margin file (104) |
104 passed |
| this head | [panel]'s case + margin file (104) |
104 passed |
| this head | conversations file alone (78) | 78 passed |
The nightly
cirun on main failed ontests/test_render_conversations.py::test_resolve_acknowledges_the_press_and_recovers_a_refusal[inline], timing out for 30s on the**/api/eventrequest that the restored Resolve control's Enter press should have sent (run 34723553049). The press landed ondocument.body: the page had taken the reader off the control between the test'sfocus()and its keypress.The cause is one line in the inline conversation seat.
conversationThreadNoderetains the Resolve control and its.lf-thread-headacross a repaint, then callsactions.append(resolve)— and appending a node to the parent it already sits in still detaches and reinserts it, which blurs it to the body. Every repaint of an open card re-runs that render, and a repaint needs no gesture: a relative timestamp ageing or a receipt phase landing is enough. The thread's own focus-restoration guard cannot see this, because it asks whether the node is still inside the thread, and the node is — only the focus is gone.So this is not confined to the test. A reader who tabs to Resolve on a margin card and waits a moment before pressing loses their place with no visible cause, which is what made the nightly's timing-dependent press fail intermittently.
The fix reconciles the header through
setChildren, the runtime's existing helper for exactly this —skills/leaf/assets/CLAUDE.mdstates thatruntime/dom-children.js"reconciles retained children without moving nodes already in place", and this call site was the one place bypassing it. A search of the runtime found no other append of a node that may already be in position; the two nearby candidates (thread-card.js's anchor status,version.js's revision marker) append only on the branch where the node does not yet exist.The new test states the contract directly rather than re-timing the nightly's press: it opens the card, focuses Resolve, dispatches
lf-actions— the margin's own repaint door, whose render runs synchronously inside that call — and asserts both that focus is still on the control and that Enter still appends the resolve event. It fails on the unfixed runtime withunexpected value "inactive"and passes with it.Verification
tests/test_render_conversations.pyin full (78 passed), including the originally failing case.tests/test_render_margin.pyandtests/test_render_drafts.py(185 passed) — the other browser files that drive the margin card./tmpfor the two session cases, and the umask case).tests/CLAUDE.mdnames the IPv6 pair as unrunnable in a container.The evidence for the mechanism came from instrumenting the page with focus and mutation listeners across the second press:
focusouton the Resolve button with no matchingfocusin,document.activeElementback at the body, and the.lf-thread-headchildList records for the re-append arriving in the same batch.