Skip to content

fix: Anthropic refusals no longer resend requests - #134980

Merged
obviyus merged 8 commits into
openclaw:mainfrom
Marvinthebored:fix/anthropic-refusal-terminal
Sep 1, 2026
Merged

obviyus merged 8 commits into
openclaw:mainfrom
Marvinthebored:fix/anthropic-refusal-terminal

Conversation

@Marvinthebored

@Marvinthebored Marvinthebored commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #134968

AI-assisted with OpenAI Codex. The original contributor reviewed the initial change. Sanitized session summary.

What Problem This Solves

Anthropic and Amazon Bedrock can return a structured provider_refusal diagnostic with no assistant text. OpenClaw used the provider explanation as ordinary error text, so transient-looking wording retried the same request and then advanced to a configured fallback model.

Root Cause

The shared retry and overflow owners did not read the structured diagnostic before text classification. Transcript projection could also remove the current assistant slice, which let older session evidence control terminal policy. Gateway history then classified the raw refusal explanation again and could show the wrong recovery text after reload.

Fix

  • One terminal-error predicate now covers provider refusals and replay-unsafe provider outcomes.
  • One current-attempt resolver carries the completed assistant through transcript projection without reviving older turns.
  • Retry, overflow, compaction, terminal, and fallback owners use those canonical facts.
  • Terminal and Gateway history output reuse one bounded refusal formatter. It exposes only an allowlisted category and tells the user to revise the request and try again.
  • The mock-only outer proof and its test-only loopback seam were replaced by a real Gateway child and Anthropic Messages server.

Evidence

  • Baseline 4c0588d783c776ed111b8e3e3bf7620a1ab356b4: a structured refusal whose hidden explanation was Service unavailable. Try again. made 10 provider requests across claude-opus-4-8 and claude-sonnet-4-6, then returned no refusal reply.
  • Exact head bfec407de2c12f3e0d1697a472bbb423915134c2: the same Gateway flow made one claude-opus-4-8 request, made no fallback request, ended with error status, and reloaded The provider refused this request (category: reasoning_extraction). Revise the request and try again. from chat.history.
  • The anti-cheat input makes text-only policy choose retry. The exact-head result can pass only when the structured diagnostic reaches the shared owners.

Sibling Coverage

  • AgentSession retry and threshold/overflow compaction, including queued user turns.
  • Anthropic and Amazon Bedrock structured refusal producers.
  • Current-attempt provenance after compaction and transcript projection.
  • Replay-unsafe terminal outcomes, incomplete-turn side-effect warnings, and Gateway history sanitization.
  • Exact changed-scope formatting, Oxlint, dead-code, import-cycle, max-lines, assertion-safety, database, plugin-boundary, and policy checks passed. CI owns type checking on this host.

Codex Contract Check

  • Codex parses policy failures before generic stream errors in responses.rs.
  • Codex classifies those policy failures as non-retryable in error.rs.
  • Codex returns non-retryable failures before retry dispatch in turn.rs.

Diff

  • Production: +132/-76, net +56. Growth adds the shared terminal diagnostic contract, exact-attempt ownership, safe terminal/history projection, and overflow gates; connected stale-session policy is removed.
  • Tests and test support: +896/-90.
  • Docs: +3/-2.

Review Follow-up

  • Applied every latest ClawSweeper rank-up move: terminal refusal copy now includes bounded revise-and-retry guidance, and the real Gateway assertion verifies it after history reload.

@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Sep 1, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 1, 2026
@clawsweeper

clawsweeper Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed September 1, 2026, 12:13 PM ET / 16:13 UTC.

ClawSweeper review

What this changes

The PR makes structured provider refusals terminal across retry, compaction, credential rotation, model fallback, and safe user-facing error delivery.

Regression provenance

Possible regression — probable (reviewed change; known regression link). No predecessor PR is attributed.

Merge readiness

⚠️ Needs maintainer review before merge - 4 items remain

Keep open: the terminality repair is well-covered, but the delivered refusal still gives no recovery action after retries and configured fallback are intentionally disabled.

Priority: P2
Reviewed head: db31c6feb407bd854323a7e2a6555520618cef90

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The central terminality fix and transport-boundary proof are credible, but one user-facing P2 blocker remains.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The exact-head proof is a real local HTTP/SSE transport path: the introduced loopback feeds a refusal through the production Anthropic stream reader and embedded fallback owner, then records one primary request, zero fallback attempts, and the observed terminal error payload. It sufficiently proves terminality, though it does not cure the missing recovery guidance in that payload.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The exact-head proof is a real local HTTP/SSE transport path: the introduced loopback feeds a refusal through the production Anthropic stream reader and embedded fallback owner, then records one primary request, zero fallback attempts, and the observed terminal error payload. It sufficiently proves terminality, though it does not cure the missing recovery guidance in that payload.
Evidence reviewed 7 items Current-main bug path: Current main only treats two error codes as replay-unsafe; it has no structured provider-refusal terminal predicate, while the pre-change silent-error path accepted a zero-output error for retry.
Structured producer and repair boundary: Anthropic’s transport records a provider_refusal diagnostic on a refusal, and the PR centralizes that fact in the terminal-error predicate used by retry and fallback decisions.
Exact-head behavior proof: The introduced loopback test drives the production Anthropic SSE reader through the embedded fallback boundary and asserts one provider request, zero fallback attempts, an error payload, and fallbackSafe false.
Findings 1 actionable finding [P2] Provide a recovery action for terminal refusals
Security None None.

How this fits together

The embedded agent runner receives an assistant response from a provider, determines whether it is terminal, then either retries/recovers or delivers an error. This change prevents a structured provider refusal from being mistaken for an empty transient response.

flowchart LR
A[Provider response] --> B[Refusal diagnostic]
B --> C[Embedded agent runner]
C --> D{Terminal outcome?}
D -->|Yes| E[Safe user error]
D -->|No| F[Retry or context recovery]
F --> G[Configured model fallback]
Loading

Before merge

  • Provide a recovery action for terminal refusals (P2) - The introduced formatter returns only “The provider refused this request…”. Since this PR also disables automatic retry and configured fallback, users are left without guidance on the safe next action. Add bounded revise-and-retry guidance and update the delivered-payload assertion; this is the remaining prior P2 finding.
  • Resolve merge risk (P2) - Existing setups that previously advanced to configured fallback or credential rotation after a provider_refusal will now stop at the refusal; the docs describe this intentional compatibility and provider-routing change.
  • Resolve merge risk (P1) - The bug fix adds 47 net production-source lines; the current-attempt record and shared terminal predicate appear to be the appropriate owner-boundary additions, but they should remain centralized rather than grow parallel retry policy.
  • Complete next step (P2) - One narrow, mechanical P2 remains: add safe recovery guidance to the already-centralized refusal formatter and update its boundary assertion.

Findings

  • [P2] Provide a recovery action for terminal refusals — src/agents/embedded-agent-helpers/error-text.ts:72
Agent review details

Security

None.

PR surface

Source +47, Tests +724, Docs +1. Total +772 across 33 files.

View PR surface stats
Area Files Added Removed Net
Source 16 120 73 +47
Tests 15 798 74 +724
Docs 2 3 2 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 33 921 149 +772

Review metrics

Metric Value Why it matters
Production versus test delta production +120/-73; tests and test support +798/-74; docs +3/-2 The repair has a net +47 production-source delta; the added exact-attempt evidence and centralized predicate need to remain the single terminal-policy path.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #134968
Summary: This PR is the active candidate fix for the linked report’s structured-refusal retry and fallback behavior.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Add safe refusal recovery guidance (recommended)
    Extend the bounded terminal refusal copy to tell users to revise the request and try again, and update the end-to-end payload assertion.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Update terminal provider-refusal copy with bounded revise-and-retry guidance and extend the delivered-payload assertion without exposing raw provider details.

Technical review

Best possible solution:

Keep the shared terminal classification, but add bounded safe guidance to revise the request and try again, then update the delivered-payload assertion without exposing provider explanation text.

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

Yes, at source level: an Anthropic SSE refusal becomes a structured diagnostic, and current main’s zero-output error recovery can retry it. The exact-head loopback test documents the one-request, zero-fallback result, but this read-only review did not execute it.

Is this the best way to solve the issue?

No: centralizing the terminal predicate is the right repair, but its terminal user copy must also state the safe next action rather than leave the user at a dead end.

Full review comments:

  • [P2] Provide a recovery action for terminal refusals — src/agents/embedded-agent-helpers/error-text.ts:72
    The introduced formatter returns only “The provider refused this request…”. Since this PR also disables automatic retry and configured fallback, users are left without guidance on the safe next action. Add bounded revise-and-retry guidance and update the delivered-payload assertion; this is the remaining prior P2 finding.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: A provider refusal is now visible and terminal, but the introduced user-facing error lacks the bounded recovery action needed to make the normal path comprehensible.
  • merge-risk: 🚨 compatibility: The PR intentionally changes existing fallback behavior from trying configured candidates to stopping on every structured provider refusal.
  • merge-risk: 🚨 auth-provider: The terminal classification also suppresses auth-profile rotation for provider refusals, changing provider-routing behavior for existing credentials.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The exact-head proof is a real local HTTP/SSE transport path: the introduced loopback feeds a refusal through the production Anthropic stream reader and embedded fallback owner, then records one primary request, zero fallback attempts, and the observed terminal error payload. It sufficiently proves terminality, though it does not cure the missing recovery guidance in that payload.
  • proof: sufficient: Contributor real behavior proof is sufficient. The exact-head proof is a real local HTTP/SSE transport path: the introduced loopback feeds a refusal through the production Anthropic stream reader and embedded fallback owner, then records one primary request, zero fallback attempts, and the observed terminal error payload. It sufficiently proves terminality, though it does not cure the missing recovery guidance in that payload.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/agents/embedded-agent-helpers.formatassistanterrortext.test.ts.
  • [P2] node scripts/run-vitest.mjs src/agents/model-fallback.run-embedded.e2e.test.ts -t "keeps a structured Anthropic refusal terminal across retry and fallback".
  • [P1] node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/terminal-resolution.test.ts -t "resolves server compaction with a refusal".

What I checked:

Likely related people:

  • steipete: 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.

  • Add bounded revise-and-retry guidance to the refusal copy and update the exact delivered-payload assertion.

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 (6 earlier review cycles)
  • reviewed 2026-09-01T07:50:52.090Z sha 9395293a9ce675dfea48c7e3c2610ec95814d699 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-01T08:38:45.271Z sha 9395293a9ce675dfea48c7e3c2610ec95814d699 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-01T09:27:31.958Z sha 9dfea93 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-01T13:43:43.818Z sha 7403ee6 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-01T14:28:55.931Z sha cd23d150b7f13a507b2a1b0392a4838efaeab184 :: needs changes before merge. :: [P2] Tell users how to recover from a final refusal
  • reviewed 2026-09-01T16:00:08.436Z sha cd23d150b7f13a507b2a1b0392a4838efaeab184 :: needs changes before merge. :: [P2] Tell users how to recover from a final refusal

@openclaw-barnacle openclaw-barnacle Bot closed this Sep 1, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Sep 1, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Sep 1, 2026
@Marvinthebored
Marvinthebored force-pushed the fix/anthropic-refusal-terminal branch from 9395293 to 9dfea93 Compare September 1, 2026 09:19
@Marvinthebored

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete steipete self-assigned this Sep 1, 2026
Select assistant evidence from the current transcript response or captured completed event, never prior session history. Preserve final structured refusals across retry, compaction, overflow and terminal projection while retaining genuine retry and explicit new-turn behavior.

Use one diagnostic predicate and bounded visible refusal copy; remove repeated history fallbacks, obsolete model matching and duplicated test setup. Prove the public SDK and agent exec paths through actual HTTP/SSE and full owner checks.

Co-authored-by: Marvinthebored <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: anthropic size: XL and removed size: M labels Sep 1, 2026
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

Maintainer update at 7403ee6d3e27 addresses the latest proof request and repairs the current-attempt evidence ownership, completed-response bridge, and refusal-versus-overflow collision found during review. The PR body now includes the observed public CLI result: one POST to /v1/messages, exit 1, and the same bounded refusal copy in the delivered payload and error metadata. The successful fallback and transient-503 controls remain successful with one and two requests respectively.

All 30 reviewed source hashes match the published tree. The owner/sibling batch passed 850 tests, the five-case real SDK HTTP fixture passed, and all 32 final gates plus the full build passed. Both final managed review passes have no actionable findings. Hosted CI for this published head is the remaining landing check. The scripted HTTP proof and controlled Bedrock events do not claim an authenticated provider call.

@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper

clawsweeper Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 1, 2026
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 1, 2026
@obviyus obviyus closed this Sep 1, 2026
@obviyus obviyus reopened this Sep 1, 2026
@obviyus
obviyus force-pushed the fix/anthropic-refusal-terminal branch from cd23d15 to db31c6f Compare September 1, 2026 16:04
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 1, 2026
@obviyus

obviyus commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

landpr-approve-unrelated-red
pr: 134980
head: bfec407
breaking: 4c0588d
check: openclaw/ci-gate

@obviyus
obviyus merged commit ead8ce0 into openclaw:main Sep 1, 2026
305 of 309 checks passed
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Independent maintainer validation is in progress on the latest head. The structured-refusal regression fails on current main (83e75f5e310123a393e91d66f86f95be4117e4b2: transient-looking refusal was retryable) and passes on the candidate.

I have a bounded cleanup ready locally: consolidate repeated incomplete-turn visibility classification and remove the now-private replay-error wrapper. This removes 71 production lines, bringing the combined candidate to production +146/-161 (net -15), while preserving the exact-attempt provenance, refusal display, compaction guards, and normal transient retry owner. Independent autoreview is clear at its configured P0 threshold; focused tests and isolated gateway verification are underway. I also corrected the nearby stale documentation for the overload replay loop removed by #134281.

The local full build hits the existing TS7056 declaration failure tracked by #135360; I am not duplicating that repair. I am preserving the active maintainer commits and will recheck the live head before publishing any update.

@obviyus

obviyus commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Thanks @Marvinthebored!

Proof: A real Gateway child received a structured Anthropic refusal whose hidden explanation looked transient. Exact main made 10 requests across the primary and configured fallback. The merged head made one primary request, no fallback request, and kept the bounded refusal guidance after chat.history reload.

  • Bug: Structured provider refusals could enter retry, overflow, compaction, or fallback policy as ordinary error text.
  • Fix: Shared owners now use the structured terminal diagnostic and exact current-attempt assistant. Gateway history reuses the same safe refusal formatter.
Before After
10 requests across primary and fallback; no refusal reply 1 primary request; no fallback; safe revise-and-retry guidance

steipete added a commit that referenced this pull request Sep 1, 2026
Follow up on #134980 by computing attempt visibility and silent-reply eligibility once, removing duplicated empty-turn predicates and a one-call terminal-error wrapper. Align the failover docs with the consolidated transient retry owner from #134281. Production delta: -71 lines; no behavior or configuration change.
steipete added a commit that referenced this pull request Sep 1, 2026
…35374)

Follow up on #134980 by computing attempt visibility and silent-reply eligibility once, removing duplicated empty-turn predicates and a one-call terminal-error wrapper. Align the failover docs with the consolidated transient retry owner from #134281. Production delta: -71 lines; no behavior or configuration change.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 2, 2026
…enclaw#135374)

Follow up on openclaw#134980 by computing attempt visibility and silent-reply eligibility once, removing duplicated empty-turn predicates and a one-call terminal-error wrapper. Align the failover docs with the consolidated transient retry owner from openclaw#134281. Production delta: -71 lines; no behavior or configuration change.
@VACInc

VACInc commented Sep 13, 2026

Copy link
Copy Markdown
Member

Related follow-up: #145291 (#145291) is now merged. It adds a narrow OpenAI-cyber-to-Daybreak recovery decision in the outer embedded entry path; it does not remove the shared terminal-refusal guard introduced here or make Anthropic refusals transient empty errors. The no-resend and sanitized-refusal handling from #134980 remains in place. This PR is not superseded by #145291.

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: anthropic gateway Gateway runtime merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL 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.

Anthropic provider refusals retry the same request

5 participants