Skip to content

fix(gateway): surface error-only agent runs in webchat (restore lost fix)#2719

Merged
alexey-pelykh merged 1 commit into
mainfrom
fix/webchat-error-propagation
Jun 15, 2026
Merged

fix(gateway): surface error-only agent runs in webchat (restore lost fix)#2719
alexey-pelykh merged 1 commit into
mainfrom
fix/webchat-error-propagation

Conversation

@alexey-pelykh

Copy link
Copy Markdown

Problem

In the webchat chat handler, when an agent run produced only error payloads (e.g. auth failure, CLI crash) emitted as final-kind dispatcher replies, the error was silently dropped:

  • the deliver collector pushed all final text into finalReplyParts without distinguishing payload.isError;
  • the post-run .then() calls broadcastChatFinal only on the non-agent-run path (if (!agentRunStarted));
  • broadcastChatError fired solely from .catch() (promise rejection), never for in-band error payloads.

So an error-only agent run resolved normally, marked the run ok, and surfaced nothing to the webchat UI.

Fix (src/gateway/server-methods/chat.ts)

  • Collect error text in a dedicated errorReplyParts array (kept out of finalReplyParts), and set hasErrorPayload before the empty-text early return so text-less error payloads still mark the run as errored.
  • In the post-run handler, when an agent run produced only error payloads (finalReplyParts empty, errorReplyParts non-empty), broadcast the combined error to the webchat UI. A mixed run (error + assistant text) is not misclassified — the assistant text still flows via the agent run's own stream.

Provenance / regression context

This fix was previously merged and then silently reverted by a later upstream sync that overwrote chat.ts (upstream never carried it). The accompanying chat.error-propagation.test.ts was left behind and had been passing vacuously — its assertions held trivially against the broken code.

Tests (chat.error-propagation.test.ts)

  • New"broadcasts error when agent run produces only error payloads": asserts exactly one error-state broadcast carrying the error text, and no final broadcast. Verified it fails on the unfixed code (1 failed / 3 passed) and passes with the fix (4/4) — a real regression guard, not vacuous.
  • The 3 pre-existing assertions now hold meaningfully (mixed run → no error broadcast; empty-text error → flag set, no broadcast; non-agent run → final broadcast).

pnpm check (format + tsgo typecheck + lint + fork guards) passes.

Note: like the rest of the gateway suite, this file is gated out of the default test CI job behind REMOTECLAW_TEST_INCLUDE_GATEWAY=1 (orthogonal pre-existing failures — see the test-gateway-preauth comment in ci.yml), so the assertions run in the gateway lane / locally. Because this fix was lost once to a sync overwrite, the hardened test is the regression signal whenever the gateway suite runs.

🤖 Generated with Claude Code

…fix)

When a webchat agent run produced only error payloads (e.g. auth failure, CLI crash) emitted as final-kind replies, the error was silently dropped: the deliver collector pushed all final text into finalReplyParts without distinguishing isError, and the post-run .then() broadcasts a final reply only for the non-agent-run path. broadcastChatError fired solely from .catch() (promise rejection), never for in-band error payloads — so an error-only agent run completed as "ok" with nothing surfaced to the UI.

- Collect error text in a dedicated errorReplyParts array (kept out of finalReplyParts) and set hasErrorPayload before the empty-text early return so text-less error payloads still mark the run as errored.

- In the post-run handler, when the agent run produced only error payloads (finalReplyParts empty, errorReplyParts non-empty), broadcast the combined error to the webchat UI. A mixed run (error + assistant text) is not misclassified as an error.

This fix was previously merged then silently reverted by a later upstream sync that overwrote chat.ts; its error-propagation test was left behind and had been passing vacuously. The test is hardened with an error-only-run case that fails on the unfixed code.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-pelykh
alexey-pelykh enabled auto-merge (squash) June 15, 2026 14:13
@alexey-pelykh
alexey-pelykh merged commit 59ce1b7 into main Jun 15, 2026
17 checks passed
@alexey-pelykh
alexey-pelykh deleted the fix/webchat-error-propagation branch June 15, 2026 14:20
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