Skip to content

bug(tui): SSE/event pipeline defects — assistant text fallback, cancel wedge, Esc cancel, cost accumulation, /init dead code #1301

Description

@dennisonbertram

Found by a live tmux-driven TUI test sweep (fake provider rigs). Evidence: .tmp/tui-test/results/ (core.md, info.md, destructive.md, inputux.md).

Bugs (acceptance criteria — each fixed with a regression test)

  • Assistant replies never render for non-streaming providers: TUI only handles assistant.message.delta (cmd/harnesscli/tui/model.go:4237); the final assistant.message has no handler. Blast radius: /export missing replies, /search can't find reply text, ctrl+s copies empty text. Fix: render final assistant.message content when no deltas accumulated.
  • /cancel wedges the TUI in a permanent (esc to interrupt) spinner: run.cancelled not treated as terminal in SSEDoneMsg (model.go:4445); reconnect loop subscribes to a dead run forever.
  • Esc "interrupt" is cosmetic: closes only the local SSE bridge, never POSTs /v1/runs/{id}/cancel; server run executes to completion (model.go:2829 region).
  • Cost/token displays regress across runs: per-run usage.delta cumulative values are assigned, not accumulated (model.go:4386-4393); status bar cost went DOWN across prompts; /cost and /context show only the latest run.
  • /stats total cost shows $0.00 after spend: upsertTodayDataPoint replaces instead of adds (model.go:5071); $%.2f hides sub-cent amounts.
  • /init is dead code: completeInitAgentsMd() only runs from the RunCompletedMsg handler (model.go:3910), but no production code emits RunCompletedMsg; wire pendingInitAgentsMd into the real SSEDoneMsg completion path (bridge.go:301).
  • /compact transcript block vanishes at run completion; ctrl+o then expands the wrong card.
  • CPR response (43;1R) leaks into the input after undo-triggered transcript rebuild; rebuild stalls ~4-5s.

Test plan

Failing Go regression tests first per bug (pattern-match sse_events_test.go, compact_command_test.go, undo_command_test.go), then minimal fixes; scripts/test-regression.sh green.

Rollout/rollback

TUI-only changes in cmd/harnesscli/tui/; rollback by reverting the branch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions