buzz icon indicating copy to clipboard operation
buzz copied to clipboard

fix(acp): preserve JSON-RPC error data

Open brainx opened this issue 4 months ago • 4 comments

Problem

buzz-acp currently keeps only a JSON-RPC error's code and message. Adapter diagnostics carried in error.data are lost, turning actionable failures such as an incompatible CLI flag into a generic -32603 Internal error.

Fix

Preserve error.data as a compact, UTF-8-safe, 4 KiB-bounded owner diagnostic. High-level logs and channel failure notices continue to use only the public code and message; the encrypted turn_error observer payload receives the detail in a separate data field.

Errors without a string message retain their bounded full error object for owner diagnosis. The implementation retains immediate handling for non-retryable authentication failures.

Regression guard

Add focused tests for structured data, missing and null messages, UTF-8 truncation, public display behavior, observer propagation, and owner-transcript rendering.

Testing

  • cargo fmt --all -- --check — passed
  • cargo test -p buzz-acp — 621 unit tests and 9 lifecycle tests passed
  • node --import ./test-loader.mjs --experimental-strip-types --test src/features/agents/ui/agentSessionTranscript.test.mjs — 51 passed
  • pnpm exec biome check src/features/agents/lib/friendlyAgentLastError.ts src/features/agents/ui/agentSessionTranscript.ts src/features/agents/ui/agentSessionTranscript.test.mjs — passed
  • git diff --check upstream/main...HEAD — passed

Addresses the diagnostic-loss portion of #2422.

brainx avatar Jul 22 '26 23:07 brainx

Solid root-cause fix — preserving data structurally is clearly right for tooling that wants to parse it. One thing worth flagging on the desktop consumer side, since it affects whether operators actually see the detail you're now preserving: the transcript builds its user-facing text from payload.error / payload.code (agentSessionTranscript.ts:775-776) and never reads payload.data, and friendlyAgentLastError's -32603 branch (written to preserve adapter detail after the standard prefix) never receives any, because buzz-acp strips it upstream. So today the detail lands in the observer payload but not in front of the operator.

Relatedly, the codex reviewer's P2 on the "Unknown agent error" message-missing fallback looks real: for data-only errors that string becomes all a string-based consumer gets, where error.to_string() previously at least carried the raw JSON. If you also appended the bounded data onto the AgentError message itself (in addition to the structured field), the existing Display/to_string() surfaces — harness logs, the channel retry notice, and that -32603 preserve-detail branch — would light up with no new plumbing, and the fallback wouldn't drop detail. Structured field for tooling + message append for humans compose cleanly. Happy to help with the message-side piece if useful.

SeanGearin avatar Jul 23 '26 20:07 SeanGearin

@SeanGearin Addressed in d835077c by consuming the bounded turn_error.data field in the desktop owner transcript. I kept it out of AcpError::Display because that text also feeds general logs and channel retry notices. This keeps the diagnostic human-visible to the operator without broadening its exposure. Regression coverage includes both data-only and -32603 errors.

brainx avatar Jul 23 '26 22:07 brainx

Updated the branch to current main in f7ef14d3. The conflict resolution preserves both the bounded owner-only error.data diagnostics and the newer immediate handling for non-retryable authentication errors. Current-head verification passed: cargo test -p buzz-acp (603 unit + 9 lifecycle tests), the 51 transcript tests, Rust formatting, and targeted Biome checks. DCO is green; the refreshed CI and Docker workflow runs are awaiting maintainer approval.

brainx avatar Jul 26 '26 16:07 brainx

Verified d835077c against the head - friendlyTurnErrorCopy consuming payload.data with the transcript-only scoping is exactly the shape I was hoping for, and pinning both the data-only -32000 and -32603 cases means the visibility can't silently regress. Keeping it out of Display was the right call for the log/notice surfaces. Nothing further from me - this looks ready for a maintainer pass.

SeanGearin avatar Jul 28 '26 16:07 SeanGearin