Skip to content

Handoff: show a handoff's first message as one gray line (#1529) - #1536

Merged
scuttletoby merged 3 commits into
mainfrom
handoff-gray-line-1529
Dec 1, 2026
Merged

scuttletoby merged 3 commits into
mainfrom
handoff-gray-line-1529

Conversation

@scuttletoby

@scuttletoby scuttletoby commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

Part of #1529.

What changes

  • A handoff's first message is one gray line. It reads "Context handed off to a fresh session · Handoff N", centred, in place of the "Handoff N" divider and the message bubble. A click opens the full text that was passed on (scrolls inside at most 24 rem); a second click closes it. Works for both sources (agent and command): both send the same first message.
  • The agent source's write-turn prompt shows nothing. It is known by its server id (handoff-write:<thread>:<run> with its marks) and the line asking for the [T3 handoff notes] marker; a typed look-alike keeps upstream's look.
  • Display only. Stored items keep their full text, so t3_thread_read, the handoff itself and exports read everything. While thread find is open, the closed text stays mounted (hidden) so find still reads it, and a match in it opens it (beforematch via upstream's findRevealRef), as upstream's folded automation prompts do. It is the row's only find copy: the fork element marks the upstream siblings it hides with CSS (the bubble) with upstream's data-thread-find-ignore, so each match counts once and find never steps to text it cannot show. The write prompt's hidden bubble gets the same opt-out.
  • Reuse. No upstream file changes: the existing HO5 element first in UserMessageRow now hides all later siblings with CSS (upstream's "New session" divider, a model-switch line and the bubble), and the line is upstream's TimelineSystemDivider with its action button (the same component upstream uses for "New session" and its other system lines). The seam's why in .github/fork-seams.json is updated.

State question: where does the open/closed state live?

In the row's own React state only: it is not stored, not synced and starts closed on every load. Nothing on the server or in settings changes; no new setting (the line shows wherever handoff messages exist).

What is left for #1529 (needs a follow-up PR)

  • The write turn's notes reply (the old session's [T3 handoff notes] message) still shows as a normal message. Hiding it needs new lines in an upstream file (TimelineAssistantRows.tsx), and a seam line must be announced in one PR before another adds it (docs/fork/updates.md, "Adding a seam line"). This PR announces them: one element first in AssistantTimelineRow and one in AssistantMetaTimelineRow that hide their later siblings. Plan for the follow-up: the notes reply shows as one gray line that opens its text, or nothing once its handoff's first message is in the thread (one line in total).
  • The minimap hover preview still shows the handoff message's text. Also announced: one call after the minimap's push in timelineMinimapItems.ts that relabels the handoff's item and drops the write turn's.
  • Calm sidebar previews: the calm sidebar (and the sidebar's hover card) shows no message text today (title, role badge, project, environment, status), so nothing there shows the handoff's text; nothing to change.

Tests

  • apps/web/src/components/fork/handoff/handoffDivider.browser.test.tsx (extended, not added): the first message shows exactly one visible line and opens/closes its full text; the write prompt (also with :fallback and :fallback:loud) shows nothing; a typed write prompt joins the existing table of look-alikes that keep upstream's look; with find open, a handoff has exactly one find match and beforematch opens it, and the write prompt has none. 8 pass locally (these fail on main: main shows "Handoff N" plus the bubble).
  • vp run check:changed: format, lint, knip, typecheck, tests pass.
  • Fork checks run locally: schema, upstream-files and seam checks pass, plus their 201 self-tests.

🤖 Generated with Claude Code

scuttletoby and others added 2 commits November 30, 2026 07:06
The handoff's first message now shows one gray, centred line
("Context handed off to a fresh session · Handoff N") instead of the
divider and a page of text; a click opens the full text passed on. The
agent source's write-turn prompt shows nothing. Display only: stored
items keep their text. Uses the existing HO5 element in UserMessageRow,
which now hides all later siblings with CSS.

Announces the seam lines the notes reply and the minimap preview need
(TimelineAssistantRows.tsx, timelineMinimapItems.ts) for the follow-up.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: Claude Opus 5.5 (medium) · read at: 11734c5

blocker: none
major: thread find cannot show a match in the handoff text, and counts each match twice. While find is open the row has two find scopes holding the same text: the fork's closed panel (hidden, in handoffDivider.tsx) and upstream's bubble body (data-thread-find-text, UserMessageBody), which [&~*]:hidden hides with display: none. When find steps to a match, revealFolded sends beforematch to the [hidden] panel, but the panel has no findRevealRef listener (upstream's automation fold, plan card and workflow block all add one), so it stays closed. The bubble copy is under a CSS-hidden ancestor that is neither [hidden] nor data-thread-find-fold, so it can never be shown. Result: the match counter shows 2N for the handoff row and every step lands on invisible text. Fix: pass ref={findRevealRef(() => setOpen(true))} to the panel, and drop the panel's own find copy. Either remove data-thread-find-text from the panel or keep upstream's bubble out of find, so the row has exactly one scope. One assertion added to the existing open/close test covers both (one scope, revealed after beforematch).

The machine was full for about 20 minutes, so this browser test was written but not run. The evidence above is from the code:

const screen = await renderRow(handoffRow(), /* findActive */ true);
const scopes = [...screen.container.querySelectorAll("[data-thread-find-text]")]
  .filter((e) => e.textContent?.includes("Recent conversation"));
const fold = screen.container.querySelector("[data-fork-handoff-line] [hidden]")!;
fold.dispatchEvent(new Event("beforematch"));
// expected { scopes: 1, revealed: true }; the code gives { scopes: 2, revealed: false }

minor: the PR body says the hidden panel works "as upstream's folded automation prompts do". It does not yet: upstream's fold also opens itself on beforematch (see the major above).

Checked and fine:

  • No false match. A handoff needs the server id handoff:<this thread>:<run> (typed messages get a random client id), freshContext, and the [T3 handoff N] header on the first line. The write prompt needs handoff-write:<this thread>: plus the server's line. The look-alike table covers typed text, other threads, ids with no run and missing headers.
  • Both sources (agent and command) send the same first message, so both get the line.
  • The hook cannot hide a normal message. Each timeline row is its own wrapper div in MessagesTimeline, and [&~*]:hidden reaches only later siblings inside UserMessageRow's fragment, the same row. Label returns null (no element, so nothing is hidden) for every other message.

State question:

  • Runs again or re-renders: pure derivation from the row; same output.
  • Virtualized remount: the row starts closed again. That is intended: the state lives only in the row and is not stored.
  • Stops half-way: a handoff whose first message never landed has no row; a write prompt with no notes still shows nothing.
  • Old threads: text from before the [T3 handoff N] header, or with no projected item, threadId or text, falls back to upstream's look (tested).
  • Empty text: no header, so upstream's look.
  • Stored data: unchanged; t3_thread_read and exports still see the full text.

Tests: the change extends the existing file with one row per behaviour, and they fail on main. No bloat.

🤖 Generated with Claude Code

While thread find is open, the handoff row held its text twice: the line's
closed panel and upstream's bubble, hidden with CSS. Find counted each match
twice and could step to the bubble's copy, which it cannot show, and the panel
never opened on a match.

The panel now opens on `beforematch` (findRevealRef), like upstream's folded
automation prompts, and the fork element marks the scopes of the upstream
siblings it hides with upstream's `data-thread-find-ignore`, kept on across
re-renders by a MutationObserver on the row. The write turn's prompt gets the
same opt-out, so its hidden text is not found either.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scuttletoby

Copy link
Copy Markdown
Owner Author

Fix round r1 (head 6715a02), answering the code lens.

  • major (thread find): the panel now has ref={findRevealRef(() => setOpen(true))}, so a match in it opens it. The row now has one find copy: the fork element (handoffDivider.tsx, useHiddenSiblingsOutOfFind) marks the find scopes of the upstream siblings it hides with CSS with upstream's own data-thread-find-ignore, and a MutationObserver on the row keeps the mark on when upstream remounts the bubble (for example its folded body mounting when find opens). The write turn's prompt gets the same opt-out, so its hidden text is not found either. No upstream line changes: a new early return in UserMessageRow would need a seam line announced in main first.
  • minor (PR body): the "as upstream's folded automation prompts do" claim is now true; the body says how.
  • Test: one new row in handoffDivider.browser.test.tsx: with find open, "Recent conversation" gives exactly one range, and beforematch on its fold opens the panel; the write prompt gives no range. Failed before the fix (expected 2 to have a length of 1), 8/8 pass after.
  • Checks: vp run check:changed: format, knip, typecheck, tests and react compiler pass; lint passed after adding the reasoned disable comment the effect rule asks for (the effect keeps DOM nodes outside React in step). Fork checks (schema, upstream-files, seam) pass locally.

State question: the mark is re-applied on every mutation under the row and removed with the elements; a remount starts fresh and is marked again before find reads it (layout effect). Old or plain messages render no fork element, so nothing is marked.

🤖 Generated with Claude Code

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: Gemini 4 Neon (high) · read at: 6715a02

blocker: none
major: none

round 1, fixed: thread find now gets one scope per handoff row and opens the panel on beforematch (findRevealRef(() => setOpen(true))), while hidden upstream siblings (for both handoff rows and write-turn prompts) get data-thread-find-ignore via useHiddenSiblingsOutOfFind. The PR body's description of the fold now matches the implementation.

minor: HandoffLine keeps max-h-96 overflow-auto while ctx.findActive is true (already present in round 1), whereas upstream's AutomationMessageRow and UserTimelineRow drop that cap while find is active (!ctx.findActive && "max-h-96 overflow-auto") so useThreadFindNavigation can scroll the outer timeline to matches below 24 rem. Worth aligning in a follow-up, not a fix-round issue.

Checked on the fix (6715a0287608bf0705804b41071134cf0225ae12):

  • One find range per handoff, none for write prompt: HandoffLine's panel carries data-thread-find-text="true" inside the fork wrapper (data-fork-handoff-line), while useHiddenSiblingsOutOfFind marks every [data-thread-find-text] element on or inside later siblings (own.nextElementSibling onward) with data-thread-find-ignore="". collectThreadFindRanges checks data-thread-find-ignore on the scope element itself at entry to visit(scope), so hidden upstream bubbles yield zero ranges for both HandoffLine and HandoffWrite.
  • beforematch reveal: findRevealRef(() => setOpen(true)) is attached directly to the [hidden] panel (where revealFolded dispatches non-bubbling beforematch), matching upstream's AutomationMessageRow and UserTimelineRow, and React 19 ref cleanup removes the listener on unmount.
  • useLayoutEffect + MutationObserver: apply() runs synchronously in useLayoutEffect before paint and before useThreadFindHighlights's useEffect, and re-runs on { childList: true, subtree: true } mutations under the row wrapper whenever upstream mounts or remounts a find scope (which also triggers useThreadFindHighlights's observer on attributeFilter: [..., "data-thread-find-ignore"]). No loop (attributes is not observed, apply() only calls setAttribute when missing, never mutates childList), no leak (observer.disconnect() on unmount).
  • Lint disable: // oxlint-disable-next-line t3code/no-unreasoned-state-sync is justified per the rule's own criteria (syncing external sibling DOM nodes and a MutationObserver outside this component's React subtree while mounted, avoiding upstream file edits).
  • No upstream line changed: diff touches only fork files, docs, and .github/fork-seams.json (zero upstream source lines changed).
  • Tests: one concise, behaviour-named test added to the existing handoffDivider.browser.test.tsx covering single range, beforematch reveal, and zero ranges for the write prompt. No test bloat.

State question:

  • Runs again / re-renders / virtualized remount: useLayoutEffect re-applies data-thread-find-ignore synchronously on every fresh mount, and MutationObserver catches any later sibling subtree remount while mounted; open resets to false on remount as intended. Note that useHiddenSiblingsOutOfFind does not strip data-thread-find-ignore on unmount, which is safe here because MessagesTimeline keys rows by row.id without recycleItems and a user message's handoff identity is immutable once projected.
  • Stops half-way: if findActive toggles off while closed, the panel unmounts and findRevealRef's cleanup removes the listener; if HandoffLine unmounts before any mutation arrives, observer.disconnect() stops observation cleanly.
  • Old or empty state: non-handoff, old, or partial rows still return null from Label, mounting no effect, no observer, and marking nothing.

@scuttletoby scuttletoby added the fork:merge-ready Merge conveyor: lenses done, merge when green (PRs) label Dec 1, 2026
@scuttletoby
scuttletoby merged commit 4415b1a into main Dec 1, 2026
30 checks passed
@scuttletoby
scuttletoby deleted the handoff-gray-line-1529 branch December 1, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork:merge-ready Merge conveyor: lenses done, merge when green (PRs)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant