Skip to content

fix(auto-reply): match throttling transient errors in fallback-state regex - #112702

Merged
altaywtf merged 1 commit into
openclaw:mainfrom
yangxiansheng:fix/throttl-regex
Jul 26, 2026
Merged

altaywtf merged 1 commit into
openclaw:mainfrom
yangxiansheng:fix/throttl-regex

Conversation

@yangxiansheng

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where error messages containing "throttle", "throttled", "throttling", or "ThrottlingException" are silently collapsed to the generic label "rate limit" in model fallback notices, losing diagnostic detail.

When a provider returns a throttling error (e.g., AWS Bedrock ThrottlingException: Too many concurrent requests), the upstream classifier correctly classifies it as reason = "rate_limit", but the fallback-state safety gate regex fails to detect the throttling signal. The error detail is hidden and the user sees only the generic "rate limit" reason.

Why This Change Was Made

TRANSIENT_ERROR_DETAIL_HINT_RE in src/auto-reply/fallback-state.ts uses a \b(?:...)\b pattern to whitelist transient-looking error texts for detail exposure. One alternative, throttl\b, was intended to match all throttling variants (throttle, throttled, throttling, ThrottlingException) as a prefix, but the trailing \b word boundary breaks the match: in every real English inflection, l is followed by a word character (e, i, e), so \b never holds. The branch is dead code.

The fix changes throttl\b to throttl\w*, matching all word continuations of the "throttl" prefix. This follows the same prefix + optional suffix pattern already established in the same regex (seconds?, minutes?, hours?) and in a parallel safety gate elsewhere in the codebase (rate[-\s]?limit(?:ed|ing)? in manager.backend-failover.ts).

No changes to upstream classification, failover routing, or persisted session schema. The fix only affects the display path: matching errors now show their text instead of being collapsed to the generic reason label.

User Impact

Users of providers that return throttling errors without additional transient keywords (e.g., "ThrottlingException: Too many concurrent requests" from AWS Bedrock) now see the specific error text in fallback notices instead of the generic "rate limit" label.

Evidence

Before fix (bug reproduction)

Unit tests — 2 newly added tests fail as expected:

FAIL  src/auto-reply/fallback-state.test.ts
  ✓ 17 passed
  ✗ preserves throttle-flavored transient details … ("ThrottlingException: … account quotas for Amazon Bedrock.")
  ✗ preserves throttle-flavored transient details … ("ThrottlingException: Too many concurrent requests")

  AssertionError: expected 'rate limit' to contain 'ThrottlingException'

Real-behavior proof (MJS harness invoking real production code) — full chain via classifyProviderSpecificError → resolveFallbackTransition → TRANSIENT_ERROR_DETAIL_HINT_RE + formatRawAssistantErrorForUi:

=== Real-behavior proof: fallback-state throttl regex (full chain) ===

[throttle msg1 (failover-error.test.ts:54)]
  error          = ThrottlingException: Your request was denied due to exceeding the account quotas for Amazon Bedrock.
  classify→reason = rate_limit  (upstream OK ✓ (bug not upstream))
  reasonSummary   = rate limit
  detail kept    = NO ✗ (collapsed to 'rate limit')

[throttle msg2 (failover-error.test.ts:688)]
  error          = ThrottlingException: Too many concurrent requests
  classify→reason = rate_limit  (upstream OK ✓ (bug not upstream))
  reasonSummary   = rate limit
  detail kept    = NO ✗ (collapsed to 'rate limit')

=== Verdict ===
BUG PRESENT: throttle classified rate_limit upstream, but fallback-state regex (throttl\b) dropped the detail → 'rate limit'

The MJS harness (proof-fallback-throttle.mjs, 5 files mirroring the established proof architecture in scripts/proof-retry-session.mjs) runs real production code paths:

  • classifyProviderSpecificError from src/agents/embedded-agent-helpers/provider-error-patterns.ts
  • resolveFallbackTransition from src/auto-reply/fallback-state.ts
  • formatRawAssistantErrorForUi from src/shared/assistant-error-format.ts
  • The only stubs are off-bug-path modules: the barrel's eager re-exports (replaced by thin re-export from the same source) and areRuntimeModelRefsEquivalent (used only for fallbackActive, not reasonSummary).

After fix (verification)

Unit tests — 19/19 pass, including 3 new tests (2 positive, 1 negative):

✓ 19 passed (no regressions)
  ✓ preserves throttle-flavored transient details … (both Bedrock fixtures)
  ✓ still collapses to the reason label when a transient reason lacks any transient-detail hint

Real-behavior proof (exact terminal output):

=== Real-behavior proof: fallback-state throttl regex (full chain) ===

[throttle msg1 (failover-error.test.ts:54)]
  error          = ThrottlingException: Your request was denied due to exceeding the account quotas for Amazon Bedrock.
  classify→reason = rate_limit  (upstream OK ✓ (bug not upstream))
  reasonSummary   = ThrottlingException: Your request was denied due to exceeding the account quota…
  detail kept    = YES ✓

[throttle msg2 (failover-error.test.ts:688)]
  error          = ThrottlingException: Too many concurrent requests
  classify→reason = rate_limit  (upstream OK ✓ (bug not upstream))
  reasonSummary   = ThrottlingException: Too many concurrent requests
  detail kept    = YES ✓

=== Verdict ===
FIXED: throttle detail preserved through full real chain (throttl\w* matches)

Checks:

  • oxfmt format check: ✅ All matched files use the correct format
  • oxlint (212 rules): ✅ 0 warnings, 0 errors
  • tsgo:core typecheck: ✅ EXIT 0
  • tsgo:core:test typecheck: ✅ EXIT 0
  • tsgo:extensions:test typecheck: ✅ EXIT 0
  • tsgo:test:root typecheck: ✅ EXIT 0
  • No existing tests regressed (all other test files use error messages without throttling keywords, or already matched via other regex alternatives)

Fixture provenance

The test error messages are real AWS Bedrock ThrottlingException fixtures from the codebase's own test suite:

  • src/agents/failover-error.test.ts:54 — "ThrottlingException: Your request was denied due to exceeding the account quotas for Amazon Bedrock." (from AWS troubleshooting docs)
  • src/agents/failover-error.test.ts:688 — "ThrottlingException: Too many concurrent requests"

Messages of this form are produced by the Bedrock runtime at extensions/amazon-bedrock/stream.runtime.ts:322-323 and flow through model-fallback.ts → RuntimeFallbackAttempt → formatFallbackAttemptErrorPreview in production.


This PR is AI-assisted. Analysis, implementation, and testing were performed using AI tools (opencode) with review by the author.

…regex

`TRANSIENT_ERROR_DETAIL_HINT_RE` used `throttl\b` which never matches
real throttling error messages (throttle, throttled, throttling) because
`\b` requires a non-word character after `l`, but `l` is always
followed by a word character in all English inflections.

Fix: `throttl\b` → `throttl\w*` to match all throttling variants.
Add regression tests using real AWS Bedrock ThrottlingException fixtures.
@yangxiansheng

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 24, 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 repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@altaywtf
altaywtf merged commit 89cc2cc into openclaw:main Jul 26, 2026
126 of 128 checks passed
@altaywtf

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 26, 2026
…regex (openclaw#112702)

`TRANSIENT_ERROR_DETAIL_HINT_RE` used `throttl\b` which never matches
real throttling error messages (throttle, throttled, throttling) because
`\b` requires a non-word character after `l`, but `l` is always
followed by a word character in all English inflections.

Fix: `throttl\b` → `throttl\w*` to match all throttling variants.
Add regression tests using real AWS Bedrock ThrottlingException fixtures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants