Skip to content

fix(agents): carry classified provider facts into assistant failure copy - #134103

Merged
obviyus merged 3 commits into
mainfrom
fix/assistant-error-copy
Aug 31, 2026
Merged

obviyus merged 3 commits into
mainfrom
fix/assistant-error-copy

Conversation

@obviyus

@obviyus obviyus commented Aug 31, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

When an LLM provider request fails on a chat channel, users usually see the bare string LLM request failed. — even though provider id, model id, HTTP status, and a classified failure reason are all known at the emit site. Two independent layers erase these facts:

  1. src/agents/embedded-agent-helpers/error-text.ts — any error not matching the rich copy branches is treated as raw passthrough and collapsed to the generic constant, while the provider/model/authMode options passed in by run/payloads.ts go unused on that branch.
  2. src/auto-reply/reply/agent-runner-failure-reply.ts — external replies substitute the generic external failure text unless the session verbose level is on/full.

Real incident: a provider returned service_unavailable twice plus one internal error; the Telegram user saw three bare LLM request failed. posts with zero facts and no next step.

Why This Change Was Made

Invariant established: classified, safe-by-construction facts — provider id, model id, classified failover reason, HTTP status when known — survive to every user surface. Only unclassified raw provider text is redacted. Redact, don't erase.

  • formatUserFacingAssistantErrorText now classifies once (classifyFailoverReason + extractErrorHttpStatus) and passes the facts into the formatter; the passthrough branch composes copy from those facts instead of returning the bare constant. The existing raw-passthrough detection still decides what to redact, no longer whether to erase everything.
  • src/agents/failover/user-copy.ts owns the reason table (satisfies Record<FailoverReason, string>) and the composed renderer, so retry/failover/user copy consume one classification.
  • buildExternalRunFailureReply delivers composed classified copy regardless of verbose level (it is safe by construction); the verbose on/full opt-in still gates forwarded sanitized detail for unclassified errors, and provider-specific userMessage keeps precedence with composed copy as fallback. Group SILENT_REPLY_TOKEN behavior is untouched.
  • The duplicate generic literal in run/assistant-failover.ts now uses the one exported constant.

New copy shapes:

  • ⚠️ openai/gpt-5.6-luna request failed (provider overloaded). This is usually temporary — try again shortly.
  • ⚠️ openai/gpt-5.6-luna request failed (authentication failed, HTTP 401). Re-authenticate the provider and try again.
  • ⚠️ openai/test-model request failed. (no classified reason — parenthetical omitted, facts kept)
  • Generic constant remains the last resort only when provider/model are unknown and classification is empty.

User Impact

Chat users hitting a provider failure now learn which provider/model failed, why (when classified), and what to do next — without enabling verbose mode. No raw provider response bodies, URLs, or tokens ever reach the user.

Evidence

Unit/regression (fail-pre-fix proven): node scripts/run-vitest.mjs across the 5 touched suites — 308 tests green post-fix; pre-fix (source stashed) 4 tests failed with Received: "LLM request failed." and the generic external text, proving the regression tests target the erasure paths.

Live Telegram E2E (Test Server, TDLib userbot, mock provider fault injection): persistent HTTP 503 injected with raw-body canary E2E_RAW_BODY_CANARY_7731.

  • Red on baseline main @ a9303f27e98: bot reply after 3 provider attempts (all 503) was the bare LLM request failed. (Bot API message 3713).
  • Green on ddcb7c2b32e (current head dd027bf7fdf differs only by a mechanical module extraction of the unchanged renderer to satisfy max-lines): bot reply ⚠️ openai/gpt-5.5 request failed. — provider/model named, deterministic across two runs (3 provider requests each, 4× status=503 in gateway.log).
  • Canary check: E2E_RAW_BODY_CANARY_7731 appears only in gateway.log (internal), 0× in any Telegram-visible event or reply — redaction holds.
  • Control run (no fault): OPENCLAW_E2E_OK, 1 provider request.

Named follow-ups (out of scope here):

  1. Classified overload/rate-limit errors short-circuit into the earlier fixed friendly copy that names neither provider nor model; consistent fact-carrying there is a small follow-up.
  2. Found during E2E: a provider failure triggers a secondary session-transcript error (Session transcript keyed user is outside the current turn, thrown at src/agents/sessions/session-manager-entries.ts:79) whose unclassified text supersedes the classified copy for the same run. Failure-path-only (control run: zero occurrences). Deserves its own issue/fix.

Production LOC +107 (facts type, reason table, renderer, delivery wiring — new capability: fact-carrying copy), tests +130.

@clawsweeper

clawsweeper Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@obviyus
obviyus marked this pull request as ready for review August 31, 2026 12:35
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 31, 2026
@clawsweeper

clawsweeper Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 31, 2026, 9:56 AM ET / 13:56 UTC.

ClawSweeper review

What this changes

The PR adds a shared renderer for redacted provider/model/reason/status failure copy and applies it to assistant failover and external reply paths.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

Keep this PR open: current main does not contain its new rendering path, but the branch still loses structured failure classification, leaves a common external-reply fast path generic, and can label an observed 5xx response as a timeout.

Priority: P2
Reviewed head: ab1e67a6d287c7f4ac9893a58f32ad5564416326

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The PR has a coherent goal and redaction-oriented implementation, but three P2 copy-path defects prevent merge readiness.
Proof confidence 🌊 off-meta tidepool Not applicable: Not applicable: repository state identifies this as a member-authored PR. The body describes earlier Telegram Test Server evidence, but it predates the current merge head and was not needed to establish the source-backed blockers.
Patch quality 🦐 gold shrimp (3/6) 3 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable: repository state identifies this as a member-authored PR. The body describes earlier Telegram Test Server evidence, but it predates the current merge head and was not needed to establish the source-backed blockers.
Evidence reviewed 6 items Introduced rendering path: The PR introduces raw-message-only classification before invoking the assistant formatter, so the newly rendered fallback copy depends on that reduced fact set.
Complete classification owner: The existing assistant signal includes error code, error type, and structured error-body details; the PR's new facts omit them. The adjacent test already proves upstream_error should classify as server_error.
External fast path bypasses new copy: Provider request facets always return a userMessage when present, and the error handler directly emits it before the newly changed fallback renderer can run; the added nullish fallback is therefore ineffective for that common path.
Findings 3 actionable findings [P2] Preserve the complete assistant failover signal
[P2] Do not call received 5xx responses request timeouts
[P2] Route provider-request failures through composed copy
Security None None.

How this fits together

Provider failures are classified during agent execution, then formatted for embedded-run payloads, lifecycle events, and channel replies. This change sits between the assistant error record and the user-visible failure text.

flowchart LR
  A[Provider failure] --> B[Assistant error record]
  B --> C[Failure classification]
  C --> D[Safe failure-copy renderer]
  D --> E[Embedded-run payload]
  D --> F[External channel reply]
  E --> G[User-visible message]
  F --> G
Loading

Before merge

  • Preserve the complete assistant failover signal (P2) - The new facts classify only errorMessage, then prevent formatAssistantErrorText from classifying again. An opaque message with errorType: "upstream_error" therefore loses the canonical server_error result already covered by the adjacent classifier test, so users receive provider/model only and no temporary-failure guidance. Build the facts from the complete assistant signal and add the user-facing structured case.
  • Do not call received 5xx responses request timeouts (P2) - For an opaque HTTP 500, the classifier's retry category is timeout; this new renderer exposes that internal category verbatim as “request timed out” despite having received an HTTP response. The introduced test at src/agents/embedded-agent-helpers.formatassistanterrortext.test.ts:188 locks in that misleading copy. Preserve retry behavior if needed, but render opaque 5xx failures as a temporary provider/internal error.
  • Route provider-request failures through composed copy (P2) - resolveProviderRequestFailureCopy returns a non-optional userMessage, so the newly added right side of this nullish fallback never runs. The main error handler also emits that message directly at src/auto-reply/reply/agent-runner-error-handler.ts:442, leaving known provider failures generic and contradicting the stated external-reply behavior. Compose safe facts before that early return and update the boundary test that currently asserts the generic text.
  • Resolve merge risk (P1) - The bug-fix branch adds net 109 production lines and a second 17-case reason-to-copy table beside src/agents/failover/user-copy.ts, creating a concrete future copy-drift risk unless the policy is consolidated.
  • Complete next step (P2) - This maintainer-labelled PR needs normal contributor or maintainer resolution of the concrete review findings; it is not a ClawSweeper repair-dispatch candidate.

Findings

  • [P2] Preserve the complete assistant failover signal — src/agents/embedded-agent-helpers/error-text.ts:323-333
  • [P2] Do not call received 5xx responses request timeouts — src/agents/embedded-agent-helpers/error-text.ts:324-331
  • [P2] Route provider-request failures through composed copy — src/auto-reply/reply/agent-runner-failure-reply.ts:292-297
Agent review details

Security

None.

PR surface

Source +104, Tests +130. Total +234 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 6 127 23 +104
Tests 5 144 14 +130
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 271 37 +234

Review metrics

Metric Value Why it matters
Production versus test delta production +120/-11 (net +109); tests and test support +151/-26 (net +125) The production growth implements a shared user-copy path, but its duplicated reason policy needs consolidation before merge.

Merge-risk options

Maintainer options:

  1. Consolidate the safe copy path (recommended)
    Repair the three failure-copy gaps and place the composed reason policy beside the existing failover user-copy owner before merge.

Technical review

Best possible solution:

Derive display facts from the complete assistant failover signal, separate retry classification from user-facing 5xx wording, and route provider-request replies through the same safe renderer without duplicating reason-copy policy.

Do we have a high-confidence way to reproduce the issue?

No current-main live execution was run in this read-only review; source establishes focused, reproducible branch cases for structured error types, opaque 5xx responses, and provider-request replies.

Is this the best way to solve the issue?

No. The rendering boundary is appropriate, but it must consume the complete existing signal and cover the provider-request fast path while avoiding false timeout wording.

Full review comments:

  • [P2] Preserve the complete assistant failover signal — src/agents/embedded-agent-helpers/error-text.ts:323-333
    The new facts classify only errorMessage, then prevent formatAssistantErrorText from classifying again. An opaque message with errorType: "upstream_error" therefore loses the canonical server_error result already covered by the adjacent classifier test, so users receive provider/model only and no temporary-failure guidance. Build the facts from the complete assistant signal and add the user-facing structured case.
    Confidence: 0.98
  • [P2] Do not call received 5xx responses request timeouts — src/agents/embedded-agent-helpers/error-text.ts:324-331
    For an opaque HTTP 500, the classifier's retry category is timeout; this new renderer exposes that internal category verbatim as “request timed out” despite having received an HTTP response. The introduced test at src/agents/embedded-agent-helpers.formatassistanterrortext.test.ts:188 locks in that misleading copy. Preserve retry behavior if needed, but render opaque 5xx failures as a temporary provider/internal error.
    Confidence: 0.99
  • [P2] Route provider-request failures through composed copy — src/auto-reply/reply/agent-runner-failure-reply.ts:292-297
    resolveProviderRequestFailureCopy returns a non-optional userMessage, so the newly added right side of this nullish fallback never runs. The main error handler also emits that message directly at src/auto-reply/reply/agent-runner-error-handler.ts:442, leaving known provider failures generic and contradicting the stated external-reply behavior. Compose safe facts before that early return and update the boundary test that currently asserts the generic text.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 145d9ffafa55.

Labels

Label changes:

  • add merge-risk: 🚨 other: A second independently maintained failover-reason copy table can make user-visible recovery guidance drift over time.

Label justifications:

  • P2: The PR improves failure messaging but currently leaves multiple common classified-failure cases incomplete.
  • merge-risk: 🚨 other: A second independently maintained failover-reason copy table can make user-visible recovery guidance drift over time.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Not applicable: repository state identifies this as a member-authored PR. The body describes earlier Telegram Test Server evidence, but it predates the current merge head and was not needed to establish the source-backed blockers.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. This changes the failure text that a Telegram user sees after a provider request fails.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Build user-facing facts from buildAssistantFailoverSignal and cover opaque upstream_error.
  • Render opaque received 5xx failures as provider/internal failures rather than timeouts.
  • Route provider-request fast-path replies through the composed safe copy and consolidate the reason policy.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-31T12:42:54.964Z sha ddcb7c2 :: needs changes before merge. :: [P2] Do not describe received 5xx responses as timeouts
  • reviewed 2026-08-31T12:58:51.019Z sha dd027bf :: found issues before merge. :: [P2] Use the complete assistant failover signal | [P2] Do not present received 5xx responses as request timeouts

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Aug 31, 2026
@obviyus
obviyus force-pushed the fix/assistant-error-copy branch from ddcb7c2 to dd027bf Compare August 31, 2026 12:50
@clawsweeper clawsweeper Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Aug 31, 2026
…dary

The thrown fallback error message is now composed by the real
formatUserFacingAssistantErrorText renderer, so the sibling integration
assertions track the classified copy (provider/model named) instead of
the mocked internal formatter output. Current-attempt attribution is
proven directly by the composed message.
# Conflicts:
#	src/agents/embedded-agent-helpers/error-text.ts
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. label Aug 31, 2026
@obviyus
obviyus merged commit ee8657a into main Aug 31, 2026
236 checks passed
@obviyus
obviyus deleted the fix/assistant-error-copy branch August 31, 2026 14:45
@obviyus

obviyus commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks @obviyus!

Proof: live Telegram E2E against a mock provider returning persistent 503 — the user now receives the classified copy naming the failing provider/model and reason; plus the full embedded-runner error suites (101 tests) green on the exact head.

  • Bug: every provider failure reached the user as a bare "LLM request failed." — the classifier knew the provider, model, and failure reason, and the renderer erased all of it.
  • Fix: formatUserFacingAssistantErrorText composes user copy from the classified facts (redact, don't erase); rendering reuses the prepared provider owner and never triggers runtime plugin discovery.
Before After
LLM request failed. ⚠️ openai/gpt-5.5 request failed (provider internal error). This is usually temporary — try again shortly.

obviyus added a commit that referenced this pull request Sep 1, 2026
…er (#134281)

Three uncoordinated retry layers replayed the same provider request on a transient failure: provider SDK client defaults, a per-request retry loop inside the ChatGPT transport, and an outer whole-turn replay in the reply runner. Stacked, one transient 429 could hold a turn silently for minutes, and the failover controller that owns provider/model fallback never saw the attempts it needed to budget.

Transient retry now has one owner: the embedded runner's failover retry controller. `retry.provider.maxRetries` is its attempt budget (default 3), the retry window stays flat at 90s so time-to-failover stays bounded, and window truncation is recorded at the producer. SDK clients run with `maxRetries: 0`, the ChatGPT transport loop is deleted, and the outer overload replay plus `OverloadRetryState` and the obsolete `StreamOptions.maxRetries` knob are removed.

User impact: a transient blip retries quickly and quietly, then succeeds or follows the existing failover chain; a persistent outage surfaces within 90s with curated, actionable copy instead of minutes of silence. An unprepared provider HTTP 500 now reads "provider internal error" instead of "request timed out". Not a breaking change: a saved `retry.provider.maxRetries` keeps a coherent meaning and needs no migration.

Named tradeoffs: the 30s "still retrying" notice is gone, and worst-case transient patience drops from about 217s to 90s.

Production LOC: +463 / -685 across 44 files, net -222.

Follows #134103 and #134111 in the LLM error-UX series.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 2, 2026
…er (openclaw#134281)

Three uncoordinated retry layers replayed the same provider request on a transient failure: provider SDK client defaults, a per-request retry loop inside the ChatGPT transport, and an outer whole-turn replay in the reply runner. Stacked, one transient 429 could hold a turn silently for minutes, and the failover controller that owns provider/model fallback never saw the attempts it needed to budget.

Transient retry now has one owner: the embedded runner's failover retry controller. `retry.provider.maxRetries` is its attempt budget (default 3), the retry window stays flat at 90s so time-to-failover stays bounded, and window truncation is recorded at the producer. SDK clients run with `maxRetries: 0`, the ChatGPT transport loop is deleted, and the outer overload replay plus `OverloadRetryState` and the obsolete `StreamOptions.maxRetries` knob are removed.

User impact: a transient blip retries quickly and quietly, then succeeds or follows the existing failover chain; a persistent outage surfaces within 90s with curated, actionable copy instead of minutes of silence. An unprepared provider HTTP 500 now reads "provider internal error" instead of "request timed out". Not a breaking change: a saved `retry.provider.maxRetries` keeps a coherent meaning and needs no migration.

Named tradeoffs: the 30s "still retrying" notice is gone, and worst-case transient patience drops from about 217s to 90s.

Production LOC: +463 / -685 across 44 files, net -222.

Follows openclaw#134103 and openclaw#134111 in the LLM error-UX series.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant