buzz icon indicating copy to clipboard operation
buzz copied to clipboard

feat(acp/desktop): classify turn failures and persist them per agent

Open Orland00 opened this issue 4 months ago • 0 comments

Closes #1659.

Problem

Failed turns still burn tokens; when timeouts, transport flakes, auth expiry and panics all collapse into one vanishing "Turn error" badge, that spend is impossible to attribute or reduce. As discussed on the issue, the backend already derives a granular outcome_label — the collapse happens in the desktop store, which handles turn_error/agent_panic in the same fall-through as turn_completed and discards the entire error payload.

Implementation

Two commits (split-able into separate PRs on request):

feat(acp) — additive error_class field on the turn_error and agent_panic payloads: a stable machine discriminant (timeout / transport / agent_error / protocol / exited / cancelled / panic) derived in a pure classify_turn_failure(&PromptOutcome) fn from the same data that drives outcome_label and the existing is_transport_error grouping. Existing payload fields untouched; old frontends unaffected. No central schema doc exists for observer event kinds (grepped docs/, AGENTS.md, NOSTR.md), so the fn's doc comment is the documentation site, matching the existing convention.

feat(desktop) — activeAgentTurnsStore now splits the terminal-event fall-through: turn_completed clears a new per-agent lastFailureByAgent entry; turn_error/agent_panic persist {outcome, error, code, error_class, timestamp}. Both remain inside the pre-existing per-agent watermark gate, so the stale-replay guarantee (replayed turn_error with null turnId must not resurrect state) is preserved — covered by a new regression test. The persisted failure renders in ManagedAgentRow's existing StatusBlock through the existing friendlyTurnErrorCopy, next to the process-exit lastError line — no new UI surface. Clearing happens on the next successful completion, not on turn start: a turn starting proves nothing about health and would make the badge flicker.

Design notes:

  • errorClass is nullable on the frontend so a mixed-version fleet (older harness without the field) degrades gracefully to outcome.
  • Failure map participates in resetActiveAgentTurnsStore and the community-switch save/restore snapshot like the other four maps.

Testing

  • Rust: 9 unit tests covering every classify_turn_failure branch + payload assertions in the existing error_outcome_emission_tests; cargo test -p buzz-acp 580 passed, cargo clippy -p buzz-acp --all-targets -- -D warnings clean, cargo fmt --all -- --check clean, cargo check --workspace clean.
  • Desktop: 8 new store tests (persistence per class, clear-on-complete vs survive-start, per-agent scoping, stale-replay regression, community-switch round-trip); pnpm -C desktop test 3339 passed / 0 failed; typecheck and lint (biome) clean.
  • Ran locally: the commands above. Relying on upstream CI for the web/mobile matrix (mobile untouched).

Manual test: trigger any turn failure (e.g. kill the agent process mid-turn) → the agent row shows "Last turn error (exited): …" persistently; run a successful turn → the line clears.

Deferred

  • No component/e2e test targets ManagedAgentRow's new managed-agent-last-turn-error node (repo has no component-level tests for this row today) — happy to add a Playwright assertion if you want one.

Orland00 avatar Jul 21 '26 17:07 Orland00