Skip to content

Handoff: fold request, notes, and handoff into one gray line with tokens (#1529) - #1565

Merged
scuttletoby merged 4 commits into
mainfrom
feat/1529-handoff-one-line-part3
Dec 1, 2026
Merged

scuttletoby merged 4 commits into
mainfrom
feat/1529-handoff-one-line-part3

Conversation

@scuttletoby

Copy link
Copy Markdown
Owner

Fixes #1529. Follow-up to #1536.

What changes

  • One gray line in total (request + notes reply + handoff message):
    • The write turn's prompt (handoff-write:<thread>:<run>, "Sent by T3 Code") stays hidden with no bubble.
    • The old session's [T3 handoff notes] assistant reply (and its AssistantMetaTimelineRow action/timestamp bar) is hidden once the handoff's first message is in the thread, or shown as a single collapsible Handoff notes gray line before the handoff message arrives. Non-write-turn assistant replies starting with [T3 handoff notes] keep upstream's look.
    • The handoff's first message renders one centered gray line with a fold chevron (ChevronDownIcon), closed by default. Clicking folds out the hidden items (handoff request, [T3 handoff notes] reply, and the handoff message with its Handoff N header inside) and clicking again folds them back.
  • Line text & token count:
    • Drops the Handoff N counter from the collapsed line (Context handed off).
    • Shows the estimated handoff token count (Context handed off · ~4.20K tokens, using upstream's ~4 UTF-8 bytes/token estimate and @t3tools/shared/usageFormat's formatTokens; omitted when 0/unavailable).
  • Thread find:
    • Hidden upstream siblings (write prompt, notes reply, handoff bubble) are marked with upstream's data-thread-find-ignore (cleaned up on unmount) so thread find counts each hidden item once inside the single findRevealRef panel and opens the fold on beforematch. When a handoff is retried (:retry1), only the first handoff message for that source run attaches the request and notes reply so find never duplicates them.
  • Minimap hover preview:
    • timelineMinimapItems.ts drops the write turn (prompt + notes reply) and shows the short Context handed off · ~... tokens label instead of the raw handoff text.
  • Display only & seams:

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

In each row's own React state only (useState(false)): not persisted, not synced, and starts closed on every load. Thread companion lookup reads from the existing quiet thread projection atom (and falls back cleanly when absent or partial).

Verification

  • vp test run apps/web/src/components/fork/handoff/handoffDivider.browser.test.tsx apps/web/src/components/chat/timelineMinimapItems.test.ts: 18/18 passed (11 browser tests in Chromium + 7 minimap unit tests).
  • vp fmt & vp lint on all changed files: 0 warnings, 0 errors.
  • vp run @t3tools/web#typecheck: passed.
  • Local fork checks (fork-schema-check, fork-upstream-files-check, fork-seam-check --config-ref origin/main, fork-test-names-check) + 201 fork-checks self-tests + 33 fork-changes-list tests: all passed.

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: GPT-6.2 Sol (high) · read at: c0a5c36
blocker: none
major: Find can count a request or notes match but cannot open it after the handoff completes. The server still returns the original message ID (ThreadFind.ts:117–128, 243–247), while the panel puts both texts under the fresh message's row ID (handoffDivider.tsx:430–449, 475–485). The highlighter requires the selected row ID and occurrence before it dispatches beforematch (threadFindHighlights.ts:389–405). The same failure applies to account/fallback IDs and to a handoff that later retries. The existing browser test bypasses selection by dispatching beforematch itself. Extend it to drive the actual Find selection and assert the fold opens for a match unique to the request and a match unique to the notes.
major: A retry still displays a second gray divider and produces duplicate Find hits for the identical handoff body. The server resends the exact original text (HandoffService.ts:1485–1495), and the first-owner guard drops only companions from the retry (handoffDivider.tsx:290–300, 475–485). The test seeds identical bodies but only counts phrases unique to the request and notes (handoffDivider.browser.test.tsx:235–242, 298–307). Also, the real agent-source body embeds the old reply's notes (handoffMessage.ts:132–141), which the fixture omits. Keep the full stored records and give the folded view and Find one consistent treatment of repeated handoff text. Check the handoff-body match as well as companion matches in the existing case.
major: A normal assistant reply with the marker gets folded and loses its action/timestamp bar when its run and prompt are missing from the projection. The classifier returns unknown for this partial state (handoffDivider.tsx:185–203), but both renderers proceed unless the answer is confirmed other (handoffNotes.tsx:40–49, 88–99). Older history can load turn items separately from run records. Require a confirmed write turn before changing either row, and extend the normal-reply case with a missing run and prompt.
minor: Companion lookup is quadratic in the loaded run count per rendered handoff. Each fold calls an array search for every run before the panel is opened (handoffDivider.tsx:158–169, 309–320, 469–475). Index runs by ID once per projection and reuse the classification.
minor: Move the pure minimap case at handoffDivider.browser.test.tsx:375–411 into timelineMinimapItems.test.ts. Fold the standalone DOM Find check at lines 413–425 into the complete handoff case so the suite exercises Find behavior once at the browser layer.

State question answered: Open state is local and reset on remount. A confirmed orphan write turn with marked notes gets a closed, revealable notes panel. Before any notes arrive, the request has no accessible panel. Once the handoff arrives, the companions move to its panel and the server still selects their old Find IDs. A retry reuses the body with a distinct ID. Old or partial user rows fall back to the normal timeline when the signature is missing, and empty or whitespace-only text has no token label. Confirmed non-write replies and typed look-alikes with ordinary message IDs stay visible. The minimap uses the same compact label and drops the write turn. Both announced seams match the added source lines. Findings are from the pinned source and fixture review.

@scuttletoby

Copy link
Copy Markdown
Owner Author

Round-1 review fixes pushed at af2d68591479b559acd76ff1f8bb2e31cc94ac26:

  • Thread Find opening relocated request/notes (major): Preserved each relocated companion section's original data-timeline-row-id (request.id including :account/:fallback/:loud marks, and each note.id) inside HandoffFoldDivider, with data-thread-find-text="true" placed on section text only (excluding synthetic titles). Extended handoffDivider.browser.test.tsx to drive useThreadFindHighlights directly and assert the closed fold opens and activates ranges for matches unique to the request, unique to the notes, and in the handoff body (plus relocated request selection on orphan notes).
  • Retry divider & duplicate Find hits (major): Collapsed any subsequent handoff row for the same (threadId, sourceRunId) carrying the identical handoff body (:retry1) into a hidden row (HandoffDuplicateHidden, out of Find) so only one gray divider and one handoff-body Find copy exist; collapsed the identical retry in forkHandoffMinimapItem too while keeping its assistant preview. Updated the test fixture to realistic agent-source handoff text embedding the old reply's notes and verified both handoff-body and companion Find matches.
  • Partial history with [T3 handoff notes] (major): Required writeTurn.kind === "write" (not merely !== "other") in both HandoffNotesMatched and HandoffNotesMetaMatched, so normal replies whose run and prompt are absent from partial history stay visible with their action/timestamp bar. Extended the normal-reply browser test with a missing-run/prompt case.
  • Quadratic run lookup (minor): Cached a per-projection ProjectionHandoffIndex in a WeakMap<ThreadStructure, ProjectionHandoffIndex> (indexing runs by ID, write-turn classifications, first handoff owners, write candidates, and assistant message IDs once per projection) with a lazy full-projection fallback reader.
  • Test layout (minor): Moved the pure minimap test out of handoffDivider.browser.test.tsx into apps/web/src/components/fork/handoff/handoff.logic.test.tsx (kept in a fork file rather than upstream timelineMinimapItems.test.ts to avoid adding unannounced upstream seam lines) and folded the standalone DOM Find test into the complete handoff browser case.

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: GPT-6.2 Sol (high) · read at: af2d685
blocker: none
major: Find can still land on a hidden request or notes row when the handoff's fold is outside the virtual list's mounted window. The folded section keeps the correct DOM ID (handoffDivider.tsx:537–550), but MessagesTimeline.tsx:1377–1390 passes the original row's list index and useThreadFindNavigation.ts:98–126 materializes that row when no range exists. The test at handoffDivider.browser.test.tsx:257–275, 337–364 mounts every row and calls the highlighter directly. Resolve the visible owner for list navigation while retaining the original ID for highlight selection. Exercise the selection with the owner outside the mounted window.
major: Thread Find still reports duplicate handoff-body matches after retry and the extra hit cannot be opened. HandoffService.ts:1485–1495 persists the same body under a second ID. ThreadFind.ts:443–481 keeps and counts both records, and the client looks up the returned retry ID after HandoffDuplicateHidden has removed its searchable text (handoffDivider.tsx:576–606). The DOM range count at handoffDivider.browser.test.tsx:331–335 bypasses the RPC that supplies the toolbar's total and selected ID. Apply the same identical-retry rule to Find's results and check the returned count and selected ID.

round 1, fixed: Relocated sections keep the original request and notes IDs. With the owning fold mounted, the highlighter opens it and selects the requested text.
round 1, fixed: An identical retry renders one gray divider and the minimap fixture keeps one entry with the retry's assistant preview.
round 1, fixed: The notes and meta overrides both require a confirmed write turn. A marker-prefixed ordinary reply keeps its body and meta row when the run and prompt are missing.
round 1, fixed: The WeakMap indexes runs and companion candidates per projection, removing the nested run lookup.
round 1, fixed: Minimap logic is tested at the unit layer and the DOM check is folded into the handoff browser case.

State question answered. A failed handoff can retry with the full stored body. The timeline collapses it, while the Find RPC still returns both IDs. A confirmed orphan write turn with marked notes can open its own fold before the handoff arrives. While only the request exists, it stays hidden without a fold. A remount resets the fold. Partial history without a confirmed write turn preserves ordinary replies and their meta bars. Old rows missing the fresh-message signature retain upstream rendering, and an empty token estimate emits no count. Both source additions match the announced seams. Two capacity-gated source-level checks reproduced selection of the retry ID and list navigation to the old companion index when no range is mounted.

@scuttletoby

Copy link
Copy Markdown
Owner Author

Fix round 2 pushed at 22226aeb4194b551663397c28a5c886b07d6b82b (zero new upstream seam lines):

  1. Offscreen fold owner during Thread Find (handoffDivider.tsx, handoffNotes.tsx): Added useRedirectFindToOwner on hidden HandoffWrite, HandoffNotesHidden, and HandoffDuplicateHidden rows. When useThreadFindNavigation materializes a hidden companion or duplicate-retry row while its visible fold owner (handoff.id, or orphan notes.id) is outside LegendList's mounted window, the hidden row redirects LegendList (scrollToIndex) to the owner row so the fold mounts, opens on beforematch, and highlights under the original data-timeline-row-id.
  2. Retried handoff Find selection (handoffDivider.tsx, docs/fork/handoff.md): ProjectionHandoffIndex now tracks collapsed identical :retry1 ids (duplicateRetryIdsByKey). When server Thread Find selects a collapsed :retry1 id, HandoffDuplicateHidden redirects to the single visible handoff fold if offscreen and HandoffLine binds the handoff section's data-timeline-row-id (and section key) to that selected retry id so the fold opens and highlights the exact occurrence instead of landing on an un-openable hidden row; stepping away restores the single handoff.id range with no duplicate DOM highlights.
    • Server Find count note: Upstream apps/server/src/orchestration-v2/ThreadFind.ts (and useThreadFind.ts) have no announced seam in .github/fork-seams.json, and HandoffService.ts must persist the full retry text for the fresh session. Deduplicating the server RPC's totalMatches count itself requires a separate seam announcement PR on ThreadFind.ts; meanwhile the client handles a server-selected retry match cleanly and non-breakingly.
  3. Tests (handoffDivider.browser.test.tsx): Upgraded the Find selection checks to run through a virtualized 3-row window driven by real useThreadFindNavigation + ThreadFindTimelineContext (using upstream's rows.findIndex), exercising offscreen selection for request, notes, handoff body, identical :retry1 (plus switching back to handoff.id), and orphan-notes request matches.

Verified locally: failing-first repro on both offscreen tests, then 16/16 passing (handoffDivider.browser.test.tsx + handoff.logic.test.tsx), vp fmt, vp lint --report-unused-disable-directives, @t3tools/web typecheck, and all fork-checks.yml scripts + fork-test-names-check.cjs.

@scuttletoby scuttletoby added the fork:merge-ready Merge conveyor: lenses done, merge when green (PRs) label Dec 1, 2026
@scuttletoby
scuttletoby merged commit e7b6876 into main Dec 1, 2026
28 checks passed
@scuttletoby
scuttletoby deleted the feat/1529-handoff-one-line-part3 branch December 1, 2026 15:31
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.

Handoff: show a handoff as one gray line, not a page of text

1 participant