Skip to content

fix(chat): keep the full agent trace visible in history and never end a turn without a summary#160

Merged
ABB65 merged 1 commit into
mainfrom
fix/chat-trace-visibility
Jul 17, 2026
Merged

fix(chat): keep the full agent trace visible in history and never end a turn without a summary#160
ABB65 merged 1 commit into
mainfrom
fix/chat-trace-visibility

Conversation

@ABB65

@ABB65 ABB65 commented Jul 17, 2026

Copy link
Copy Markdown
Member

Problem

Follow-up to #159 (2/2). Persisted transcripts hid every intermediate iteration: only the final assistant row was `internal=false`, so a turn that burned all 8 iterations on tool calls showed the literal `[tool calls]` placeholder as its entire answer on reload (verified on staging, conversation `8ad2bba3…`). The graceful-close wrap could also return zero content without erroring — no error in Railway logs, no summary in the trace.

Changes

  • buildTraceRows: every assistant iteration row is now visible; `tool_result` payload rows (the big truncated JSON blobs) stay internal. Token/model columns still land only on the final row. No migration needed — RLS policy 009 (`internal = false`) exposes the rows as-is.
  • Graceful close hardening:
    • The tools-disabled wrap now carries an explicit summarize instruction appended after the final `tool_result` blocks. The message is replaced, not mutated — the trace holds the same content array reference, so the instruction is never persisted or replayed on resume.
    • If the wrap still returns no text, a deterministic fallback summary built from the executed tool names streams to the client and lands as the final trace iteration — a transcript can never end tool-only again.
  • Messages endpoint: projection gains `turn_id`; limit 100 → 300 (heavy turns now surface up to ~10 visible rows instead of 2; the oldest-N-under-ascending-order wart is noted in a comment, tracked separately).
  • loadConversation: consecutive same-turn assistant rows fold into one message whose segments concatenate chronologically — reload now mirrors the live stream. Legacy rows (distinct turn ids) keep one message per row.

Documented side effect: the ee Conversation API `/history.get` uses the same default visibility filter, so intermediate assistant rows now appear there too (additive). Existing conversations are not backfilled — old turns keep their previous single-row rendering.

Test

  • `pnpm test` — 130 files / 1078 tests green
  • `pnpm test:contract` — 105 tests green against local `postgres:16` (fixtures updated to mirror the new writer)
  • Engine regression: wrap-instruction shape + trace purity + zero-block fallback covered
  • `pnpm lint` + `pnpm typecheck` clean

🤖 Generated with Claude Code

… a turn without a summary

Persisted transcripts hid every intermediate iteration: only the final
assistant row was visible, so a turn that burned all 8 iterations on
tool calls showed the literal '[tool calls]' placeholder as its entire
answer, and the graceful-close wrap could return zero content without
erroring (observed on staging) leaving no summary at all.

- buildTraceRows: every assistant iteration row is now visible
  (internal=false); tool_result payload rows stay internal. Token and
  model columns still land only on the final row
- graceful close: the tools-disabled wrap now carries an explicit
  summarize instruction appended after the tool_result blocks (message
  replaced, not mutated — the trace keeps only the real tool results);
  if the wrap still returns no text, a deterministic fallback summary
  built from the executed tool names streams to the client and lands as
  the final trace iteration
- messages endpoint: projection gains turn_id; limit 100 → 300 since
  heavy turns now surface up to ~10 visible rows instead of 2
- loadConversation folds consecutive same-turn assistant rows into one
  message whose segments concatenate chronologically; legacy rows with
  distinct turn ids keep one message per row
@ABB65
ABB65 merged commit 4da9d3d into main Jul 17, 2026
2 checks passed
@ABB65
ABB65 deleted the fix/chat-trace-visibility branch July 17, 2026 16:56
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.

1 participant