#58

Turn-as-unit transcript rendering: merge per-turn widgets in the renderer (follow-up to bookmark-FK crash fix)

Openparzival1lopened 7mo ago

Follow-up notes from the bookmark-FK crash fix on 2026-04-20. The crash was resolved by an id-layer alignment in the renderer — enough to unblock bookmarks — but it deliberately stopped short of the visual refactor the same investigation pointed at. Capturing the remaining work here so the design thread isn't lost.

1. What the interim fix shipped vs what it skipped

Already in the renderer (threadhop._parse_messages) and bookmark_toggle_selection:

  • Consecutive assistant JSONL lines sharing message.id merge into one assistant tuple tagged with the first chunk's uuid — matching the indexer's rule (ADR-003, indexer.parse_byte_range).
  • tool_use widgets and tool_result widgets inherit the enclosing turn's canonical uuid instead of their JSONL line's own uuid. toolUseResult user lines no longer flush the pending assistant turn.
  • bookmark_toggle_selection pre-checks the FK target with SELECT 1 FROM messages WHERE uuid = ?, dedups duplicate uuids within a selection, and shows a "skipped (not indexed yet)" toast instead of letting IntegrityError bubble through on_key.

Deliberately not landed:

  • Visual unification — tool calls and tool results still render as their own stacked widgets between assistant prose. In selection mode each fragment is still a separate navigation stop.
  • Turn-shaped indexer output for tool results — _extract_user_text in indexer.py still skips toolUseResult lines entirely, so tool result summaries aren't in the FTS row for the turn.
  • Live-turn re-composition during the 5 s refresh — not a concern today because each event is its own widget; becomes a concern once widgets span multiple events.

So today selecting a tool widget correctly toggles the turn's bookmark (same uuid as the prose), but the user still sees N separate blocks per turn and has to remember they're one thing.

2. Why turn-as-unit is the right unit

The unit of meaning in a Claude conversation is the turn, not the JSONL event. A turn = everything between two genuine human messages (assistant prose, tool_use calls the assistant made, tool results returned to it, more prose, repeat until control hands back to the human).

Observed downstream consequences of today's per-event model:

  • Selection-mode bloat. A reply that did six tool calls is seven stops instead of one. Range selection for copy / export / bookmark is noisier than the content warrants.
  • Subsystems already disagreed about the unit. The indexer merges assistant chunks into one row. The observer and reflector reason about decisions and todos at the turn level (see prompts/observer.md). Only the renderer treated each event as its own thing — which is precisely how the bookmark-FK crash happened, and a later feature in the same seam would rediscover the same class of bug.
  • Export / handoff payoff. The handoff skill (in progress, see docs/DESIGN-DECISIONS.md phase roadmap) wants turn-shaped payloads. Rendering at the turn level makes "select 3 turns, export" trivial; doing it over per-event widgets requires reassembly at export time.

The interim id-layer fix already proved the plumbing works: every widget in a turn resolves to the same row today. The remaining work is to make the visual model match the already-correct identity model.

3. Direction and open design questions

Shape

Replace per-line widget emission in TranscriptView._parse_messages / transcript-build path with a turn composer that buffers events until the next genuine user message, then emits one block. The block is a composite — it still shows internal structure — but selection, scroll, bookmark, copy, export all treat it as one unit anchored on the turn's canonical uuid (the first assistant event's uuid, which is what messages.uuid already stores).

Questions to resolve before implementation

  1. Turn boundary. Strictly the next genuine human message? Or also break on sidechain spawn, session resume, or long idle gap? Current bias: only genuine human input ends a turn. Sidechains are the interesting edge case — they're the only in-file event marking "main turn paused for something on the side" and they interact with pattern #10 in docs/UI-IMPROVEMENTS.md (subagent split panel). Keep inside parent turn? Break and reassemble for export?

  2. Tool result inclusion. Keep the current filter (surface Found N files, +X/-Y lines, errors; drop bare success) and fold survivors into the turn block? Errors probably always visible.

  3. Visual structure. Flat flowing section (minimal change, matches current aesthetic) vs subtly-bordered card with collapsible tool details (buys a "hide tool calls" density toggle, more work). Ties into pattern #6 in UI-IMPROVEMENTS.md (density toggle).

  4. Search jump target. When an FTS hit lands inside a tool-call snippet, jump to the enclosing turn block and highlight within — same mechanism as jumping to a long prose message, widened to cover the tool lines.

  5. Indexer text shape. The indexer already merges assistant text + tool-call abbreviations into the turn row. Should it also fold _format_tool_result-style summaries so FTS hits on "Found 12 files" land on the right turn? Probably yes, but adds a small change to _extract_user_text.

  6. Live-turn re-composition. The 5 s refresh can catch a turn mid-flight. The composer must be idempotent across refreshes — same turn on disk must build the same block — and must not flicker or lose scroll position when trailing events arrive.

What stays the same

  • Row identity in messages (first-assistant-event uuid) — unchanged.
  • Bookmarks table and FK — unchanged.
  • Observer / reflector pipelines — unchanged; they already think in turns.
  • Search FTS schema — unchanged; possibly gains a little more matched text if the indexer folds tool results.

4. Action items

  • Pick turn-boundary rule for sidechain spawns / session resume / idle gap (see Q1)
  • Decide flat vs card visual structure (see Q3); wire to density-toggle if card
  • Replace per-event widget emission in TranscriptView._parse_messages + transcript-build with a turn composer
  • Unify the three widget classes (UserMessage / AssistantMessage / ToolMessage) or introduce a TurnBlock composite
  • Extend indexer._extract_user_text (or parallel helper) to fold surviving toolUseResult summaries into the turn row, so FTS hits on tool output land correctly
  • Update selection-mode navigation (j/k, range v, copy y, export e, bookmark space, label L) to operate on turn blocks; remove the dedup workaround in bookmark_toggle_selection once per-widget duplicates can't happen
  • Update search jump-to-source (_jump_to_search_result, _scroll_to_uuid) to highlight within a turn block rather than targeting an event-level widget
  • Handle live-turn re-composition on the 5 s refresh without flicker or scroll loss (see Q6)
  • Add integration tests: streamed assistant reply with interleaved tool calls renders as one turn block; bookmark any sub-element resolves to the same row; export of a range yields turn-shaped markdown; FTS hit inside a tool abbreviation jumps to the right turn

References

  • docs/UI-IMPROVEMENTS.md — "Turn-as-unit transcript rendering" section (landed alongside the interim fix; contains the same design questions in slightly different framing)
  • docs/DESIGN-DECISIONS.md — ADR-003 (assistant streaming-chunk merge), phase roadmap for observer / reflector / handoff
  • threadhop._parse_messages — the renderer function the interim fix modified and the turn composer will replace
  • threadhop.bookmark_toggle_selection — contains the dedup + FK pre-check workaround that becomes unnecessary once one widget = one turn
  • indexer.parse_byte_range, indexer._extract_assistant_blocks, indexer._extract_user_text — the canonical merge rule the renderer now mirrors at the id layer
  • Issue #42 (bookmark tags editor) — lands on top of the bookmark system and will benefit from turn-level bookmarks not requiring per-widget reasoning
  • prompts/observer.md — observer already operates in turn-shaped chunks; aligning the renderer closes the last subsystem seam

Activity

0

No activity yet.