Skip to content

Observability: surface per-turn stop-reason / usage / stream lifecycle (loop is silent by design) #81

Closed

Description

@JAORMX

Summary

When the agent behaves abnormally (e.g. a turn ends empty, or stops early), there is no durable or live signal explaining why. We ran a long session with --perf --perf-mcp and still could not tell whether dead turns were no_progress, error, a truncated stream, or a timeout — because the loop is silent by design and the rich signal is client-only and transient. This issue is to add turn-semantics observability that doesn't violate the loop's 3-line invariant.

Why it's hard today

  • The loop emits exactly THREE lines (compaction-fail, policy-deny, drain-abandon) — by design. Confirmed live: across a whole session of abnormal turns, the diagnostic log emitted nothing.
  • The rich signal is client-only and transient. StopReason, EvNoProgress, EvResult.Usage ride the session.Event stream → shown for a blink in the TUI as done, then gone. Never durable.
  • The resilience wrapper is mute — retries, per-attempt timeouts, idle-timeout fires, breaker trips: all unlogged.
  • perf gives runtime observability (CPU/heap/goroutines/latency) but no turn semantics.

Proposed additions (ranked by leverage)

  1. Stop-reason-labeled turn metrics on the perf surface. mecatl_turns_total{stop,role} + a turn_empty_total{role} counter. stop is a closed enum → safe label, no cardinality leak; role reuses the existing closed roleFamily set. Then perf://metrics/summary instantly shows "N turns ended no_progress/error/empty." Metrics ≠ diagnostics, so the 3-line invariant is untouched.
  2. --debug-events live tail. The relay already sees every session.Event; tee the full taxonomy (incl. EvNoProgress, EvResult.Stop, EvToolCall) to the diag log (DEBUG) or a sidecar file. Gated; loop untouched.
  3. Stream-lifecycle DEBUG in the adapter. Log first-chunk latency, chunk count, text/reasoning bytes, terminal event (response.completed/incomplete/idle-timeout/per-attempt-timeout). The missing piece to separate upstream truncation from model-stops-early from timeout. Log-level gated.
  4. Resilience-wrapper diagnostics. Retries / per-attempt-timeout / idle-timeout / breaker transitions at DEBUG/INFO.
  5. Surface the stop reason in the TUI — done · no progress / stopped: incomplete / stopped: error instead of bare done. Cheap UX win.

Related

  • The durable session store (filed separately) is the post-hoc half of this; these are the live/metrics half.
  • This is the prerequisite for root-causing the empty/truncated-turn bug (filed separately).

Filed from a live debugging session.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions