Skip to content

fix(agents): keep the provider reset in agent-route failure notices - #206945

Merged
obviyus merged 2 commits into
mainfrom
core/rate-limit
Nov 27, 2026
Merged

obviyus merged 2 commits into
mainfrom
core/rate-limit

Conversation

@obviyus

@obviyus obviyus commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

On a production deployment over 7 days, every user turn that failed on a provider rate limit (36 of 36) showed a wrong failure notice in the session:

  • 26: "Your request couldn't be completed." The run had already rendered "⚠️ is rate-limited. The provider says to retry in 6 days (Nov 30, …)".
  • 10: "⚠️ The AI service needs a short break. Please try again in a few minutes." The models were limited for 4–6 days.

All 36 ran on the Gateway agent route. This route serves openclaw agent and subagent completion announcements. chat.send shows the correct copy.

Retries are not the cause. Long limits already end after one attempt, and later turns are refused locally by the shared rate-limit gate with no network request. Of 3,193 rate-limit attempt rows, 2,087 are per-minute TPM retries, and 99% of those recover on the same model.

Cause

On chat.send, handleAgentExecutionError emits the run's lifecycle error with errorNotice set to the rendered reply (src/auto-reply/reply/agent-runner-error-handler.ts:100-108). The agent route's catch (src/agents/command/run-embedded-attempt.ts) emits only a formatted error string. recordGatewaySessionRunFailure (src/sessions/session-run-error.ts:53-66) then rebuilds copy from that string, and the reset time is lost.

Fix

At the agent route catch, the code now emits errorNotice from resolveReplyFailureSummary. chat.send uses the same function for capacity copy (rate limit, overload, billing). It uses the configured time zone and fallback attempts. Other failure classes keep their current notice. Retry, backoff, the shared gate, copy renderers and the recorder do not change.

User impact

Gateway agent and openclaw agent users, and subagent announcements whose run hits a long rate limit, now see the model and the provider's reset time. The notice matches chat.send.

Evidence

  • Regression test src/agents/agent-command.settled-recovery.test.ts. It covers the gate-refusal shape on one model and an "All models failed" aggregate in a non-host time zone. It fails on main (no errorNotice) and passes with the fix.
  • Real Gateway from dist (dist-nodts), with a fake OpenAI-compatible provider. It returns 429 with retry-after: 518400; the fallback model returns a weekly-limit body without a header.
Shape Route Provider requests Session notice on main Session notice with this PR
single model, 6-day limit agent 1 "Your request couldn't be completed." "⚠️ fake/long-limit is rate-limited. The provider says to retry in 6 days (Dec 4, …)."
single model chat.send 0 (shared gate) reset copy reset copy (unchanged)
both fallbacks limited agent 2 (1 per candidate) "⚠️ The AI service needs a short break. Please try again in a few minutes." same reset copy, naming the first limited model
both fallbacks limited chat.send 1 reset copy reset copy (unchanged)

Attempt counts are the same on main and on this branch.

Not covered

  • A chain that mixes a rate limit with another failure (for example, a timeout) gets no capacity summary. It keeps the recorder's notice on both routes.
  • A 429 after committed tool effects ends through emitResultError, not the catch. This is unproven; none of the production inputs took that path.
  • The aggregate copy names the first attempt with a structured reset. That owner behavior also applies on chat.send and does not change here.

- The Gateway agent route (openclaw agent, subagent announcements) emitted no errorNotice,
  so the session notice re-derived copy from a string and lost the provider's reset time.
- Emit the capacity summary chat.send uses (rate limit, overload, billing) with config and fallback attempts.
@clawsweeper

clawsweeper Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Nov 27, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 27, 2026
@obviyus
obviyus merged commit e7325fb into main Nov 27, 2026
127 of 128 checks passed
@obviyus
obviyus deleted the core/rate-limit branch November 27, 2026 21:10
obviyus added a commit that referenced this pull request Nov 28, 2026
…ext run (#207091)

## Problem

On a production deployment, 126 scheduled-automation runs in 7 days failed with "<model> is rate-limited. The provider says to retry in 5-6 days". Recurring jobs ran again on every slot, or hourly once the error backoff reached its 60-minute maximum, and every run hit the same limit. Two jobs were still looping with 25 consecutive errors. Nothing in the cron scheduler read the provider's reset time; a rate limit counted as a transient error.

## Fix

- The run result now carries the provider's reset time as a transient fact (`rateLimitResetAt`, never stored). It is set only when every failed model attempt was rate-limited with a known reset (candidates skipped for a local cooldown are ignored), and the earliest reset wins. It reuses the existing reset facts on the failover error.
  - Session-target jobs: the settled failure cause already reaches the automation settlement in-process.
  - Isolated jobs: the run's catch, forwarded by the isolated execution adapter.
- `applyJobResult` uses it when scheduling the next run after an error:
  - The next normal slot is the first scheduled slot at or after the reset, so cron expressions stay on their schedule.
  - A reset before the schedule's own next slot moves the quick retry to the reset. A later reset skips quick retries for the first slot after it (an off-slot time there would be moved earlier by schedule maintenance), and the failure alert is not held for a retry that is days away.
- One-shot jobs are unchanged.
- Jobs are not paused; the failure notice already names the reset time (#206945).

## User impact

A recurring automation on a model with a multi-day limit stops hitting the provider, or the local limit gate, every hour. It runs again on its first slot after the stated reset, and the user gets the failure alert once instead of after every slot.

## Evidence

- `src/cron/rate-limit-reset.integration.test.ts`: a loopback provider returns 429 with `retry-after: 518400`. On both the session-target and the isolated path, the run makes one provider request and reports the reset (~6 days). Fails on main (no reset reported), passes here.
- `src/cron/service/timer-outcomes.regression.test.ts`: an hourly `every` job and a weekday cron job land exactly on their first slot after the reset, schedule maintenance keeps that slot, and the failure alert is emitted. A 45-second reset moves the quick retry instead of skipping to the next day. Fails on main, passes here.
- The same file runs both execution adapters through the timer, schedule maintenance and the persisted store, including a 5-minute cron with a 20-minute reset: the stored next run is the first slot after the reset.
- Cron run, outcome, failure-alert and cross-provider fallback suites on both paths pass.

Accepted edge: a provider that states an absurd reset (for example years away) parks the job until then; the failure notice shows that date, and a reset the scheduler cannot represent is ignored.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 28, 2026
…206945)

## Problem

On a production deployment over 7 days, every user turn that failed on a provider rate limit (36 of 36) showed a wrong failure notice in the session:

- 26: "Your request couldn't be completed." The run had already rendered "⚠️ <model> is rate-limited. The provider says to retry in 6 days (Nov 30, …)".
- 10: "⚠️ The AI service needs a short break. Please try again in a few minutes." The models were limited for 4–6 days.

All 36 ran on the Gateway `agent` route. This route serves `openclaw agent` and subagent completion announcements. chat.send shows the correct copy.

Retries are not the cause. Long limits already end after one attempt, and later turns are refused locally by the shared rate-limit gate with no network request. Of 3,193 rate-limit attempt rows, 2,087 are per-minute TPM retries, and 99% of those recover on the same model.

## Cause

On chat.send, `handleAgentExecutionError` emits the run's lifecycle error with `errorNotice` set to the rendered reply (`src/auto-reply/reply/agent-runner-error-handler.ts:100-108`). The `agent` route's catch (`src/agents/command/run-embedded-attempt.ts`) emits only a formatted error string. `recordGatewaySessionRunFailure` (`src/sessions/session-run-error.ts:53-66`) then rebuilds copy from that string, and the reset time is lost.

## Fix

At the `agent` route catch, the code now emits `errorNotice` from `resolveReplyFailureSummary`. chat.send uses the same function for capacity copy (rate limit, overload, billing). It uses the configured time zone and fallback attempts. Other failure classes keep their current notice. Retry, backoff, the shared gate, copy renderers and the recorder do not change.

## User impact

Gateway `agent` and `openclaw agent` users, and subagent announcements whose run hits a long rate limit, now see the model and the provider's reset time. The notice matches chat.send.

## Evidence

- Regression test `src/agents/agent-command.settled-recovery.test.ts`. It covers the gate-refusal shape on one model and an "All models failed" aggregate in a non-host time zone. It fails on main (no `errorNotice`) and passes with the fix.
- Real Gateway from dist (`dist-nodts`), with a fake OpenAI-compatible provider. It returns `429` with `retry-after: 518400`; the fallback model returns a weekly-limit body without a header.

| Shape | Route | Provider requests | Session notice on main | Session notice with this PR |
|---|---|---|---|---|
| single model, 6-day limit | `agent` | 1 | "Your request couldn't be completed." | "⚠️ fake/long-limit is rate-limited. The provider says to retry in 6 days (Dec 4, …)." |
| single model | chat.send | 0 (shared gate) | reset copy | reset copy (unchanged) |
| both fallbacks limited | `agent` | 2 (1 per candidate) | "⚠️ The AI service needs a short break. Please try again in a few minutes." | same reset copy, naming the first limited model |
| both fallbacks limited | chat.send | 1 | reset copy | reset copy (unchanged) |

Attempt counts are the same on main and on this branch.

## Not covered

- A chain that mixes a rate limit with another failure (for example, a timeout) gets no capacity summary. It keeps the recorder's notice on both routes.
- A 429 after committed tool effects ends through `emitResultError`, not the catch. This is unproven; none of the production inputs took that path.
- The aggregate copy names the first attempt with a structured reset. That owner behavior also applies on chat.send and does not change here.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit e7325fb)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
…penclaw#206945)

## Problem

On a production deployment over 7 days, every user turn that failed on a provider rate limit (36 of 36) showed a wrong failure notice in the session:

- 26: "Your request couldn't be completed." The run had already rendered "⚠️ <model> is rate-limited. The provider says to retry in 6 days (Nov 30, …)".
- 10: "⚠️ The AI service needs a short break. Please try again in a few minutes." The models were limited for 4–6 days.

All 36 ran on the Gateway `agent` route. This route serves `openclaw agent` and subagent completion announcements. chat.send shows the correct copy.

Retries are not the cause. Long limits already end after one attempt, and later turns are refused locally by the shared rate-limit gate with no network request. Of 3,193 rate-limit attempt rows, 2,087 are per-minute TPM retries, and 99% of those recover on the same model.

## Cause

On chat.send, `handleAgentExecutionError` emits the run's lifecycle error with `errorNotice` set to the rendered reply (`src/auto-reply/reply/agent-runner-error-handler.ts:100-108`). The `agent` route's catch (`src/agents/command/run-embedded-attempt.ts`) emits only a formatted error string. `recordGatewaySessionRunFailure` (`src/sessions/session-run-error.ts:53-66`) then rebuilds copy from that string, and the reset time is lost.

## Fix

At the `agent` route catch, the code now emits `errorNotice` from `resolveReplyFailureSummary`. chat.send uses the same function for capacity copy (rate limit, overload, billing). It uses the configured time zone and fallback attempts. Other failure classes keep their current notice. Retry, backoff, the shared gate, copy renderers and the recorder do not change.

## User impact

Gateway `agent` and `openclaw agent` users, and subagent announcements whose run hits a long rate limit, now see the model and the provider's reset time. The notice matches chat.send.

## Evidence

- Regression test `src/agents/agent-command.settled-recovery.test.ts`. It covers the gate-refusal shape on one model and an "All models failed" aggregate in a non-host time zone. It fails on main (no `errorNotice`) and passes with the fix.
- Real Gateway from dist (`dist-nodts`), with a fake OpenAI-compatible provider. It returns `429` with `retry-after: 518400`; the fallback model returns a weekly-limit body without a header.

| Shape | Route | Provider requests | Session notice on main | Session notice with this PR |
|---|---|---|---|---|
| single model, 6-day limit | `agent` | 1 | "Your request couldn't be completed." | "⚠️ fake/long-limit is rate-limited. The provider says to retry in 6 days (Dec 4, …)." |
| single model | chat.send | 0 (shared gate) | reset copy | reset copy (unchanged) |
| both fallbacks limited | `agent` | 2 (1 per candidate) | "⚠️ The AI service needs a short break. Please try again in a few minutes." | same reset copy, naming the first limited model |
| both fallbacks limited | chat.send | 1 | reset copy | reset copy (unchanged) |

Attempt counts are the same on main and on this branch.

## Not covered

- A chain that mixes a rate limit with another failure (for example, a timeout) gets no capacity summary. It keeps the recorder's notice on both routes.
- A 429 after committed tool effects ends through `emitResultError`, not the catch. This is unproven; none of the production inputs took that path.
- The aggregate copy names the first attempt with a structured reset. That owner behavior also applies on chat.send and does not change here.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
…ext run (openclaw#207091)

## Problem

On a production deployment, 126 scheduled-automation runs in 7 days failed with "<model> is rate-limited. The provider says to retry in 5-6 days". Recurring jobs ran again on every slot, or hourly once the error backoff reached its 60-minute maximum, and every run hit the same limit. Two jobs were still looping with 25 consecutive errors. Nothing in the cron scheduler read the provider's reset time; a rate limit counted as a transient error.

## Fix

- The run result now carries the provider's reset time as a transient fact (`rateLimitResetAt`, never stored). It is set only when every failed model attempt was rate-limited with a known reset (candidates skipped for a local cooldown are ignored), and the earliest reset wins. It reuses the existing reset facts on the failover error.
  - Session-target jobs: the settled failure cause already reaches the automation settlement in-process.
  - Isolated jobs: the run's catch, forwarded by the isolated execution adapter.
- `applyJobResult` uses it when scheduling the next run after an error:
  - The next normal slot is the first scheduled slot at or after the reset, so cron expressions stay on their schedule.
  - A reset before the schedule's own next slot moves the quick retry to the reset. A later reset skips quick retries for the first slot after it (an off-slot time there would be moved earlier by schedule maintenance), and the failure alert is not held for a retry that is days away.
- One-shot jobs are unchanged.
- Jobs are not paused; the failure notice already names the reset time (openclaw#206945).

## User impact

A recurring automation on a model with a multi-day limit stops hitting the provider, or the local limit gate, every hour. It runs again on its first slot after the stated reset, and the user gets the failure alert once instead of after every slot.

## Evidence

- `src/cron/rate-limit-reset.integration.test.ts`: a loopback provider returns 429 with `retry-after: 518400`. On both the session-target and the isolated path, the run makes one provider request and reports the reset (~6 days). Fails on main (no reset reported), passes here.
- `src/cron/service/timer-outcomes.regression.test.ts`: an hourly `every` job and a weekday cron job land exactly on their first slot after the reset, schedule maintenance keeps that slot, and the failure alert is emitted. A 45-second reset moves the quick retry instead of skipping to the next day. Fails on main, passes here.
- The same file runs both execution adapters through the timer, schedule maintenance and the persisted store, including a 5-minute cron with a 20-minute reset: the stored next run is the first slot after the reset.
- Cron run, outcome, failure-alert and cross-provider fallback suites on both paths pass.

Accepted edge: a provider that states an absurd reset (for example years away) parks the job until then; the failure notice shows that date, and a reset the scheduler cannot represent is ignored.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…206945)

## Problem

On a production deployment over 7 days, every user turn that failed on a provider rate limit (36 of 36) showed a wrong failure notice in the session:

- 26: "Your request couldn't be completed." The run had already rendered "⚠️ <model> is rate-limited. The provider says to retry in 6 days (Nov 30, …)".
- 10: "⚠️ The AI service needs a short break. Please try again in a few minutes." The models were limited for 4–6 days.

All 36 ran on the Gateway `agent` route. This route serves `openclaw agent` and subagent completion announcements. chat.send shows the correct copy.

Retries are not the cause. Long limits already end after one attempt, and later turns are refused locally by the shared rate-limit gate with no network request. Of 3,193 rate-limit attempt rows, 2,087 are per-minute TPM retries, and 99% of those recover on the same model.

## Cause

On chat.send, `handleAgentExecutionError` emits the run's lifecycle error with `errorNotice` set to the rendered reply (`src/auto-reply/reply/agent-runner-error-handler.ts:100-108`). The `agent` route's catch (`src/agents/command/run-embedded-attempt.ts`) emits only a formatted error string. `recordGatewaySessionRunFailure` (`src/sessions/session-run-error.ts:53-66`) then rebuilds copy from that string, and the reset time is lost.

## Fix

At the `agent` route catch, the code now emits `errorNotice` from `resolveReplyFailureSummary`. chat.send uses the same function for capacity copy (rate limit, overload, billing). It uses the configured time zone and fallback attempts. Other failure classes keep their current notice. Retry, backoff, the shared gate, copy renderers and the recorder do not change.

## User impact

Gateway `agent` and `openclaw agent` users, and subagent announcements whose run hits a long rate limit, now see the model and the provider's reset time. The notice matches chat.send.

## Evidence

- Regression test `src/agents/agent-command.settled-recovery.test.ts`. It covers the gate-refusal shape on one model and an "All models failed" aggregate in a non-host time zone. It fails on main (no `errorNotice`) and passes with the fix.
- Real Gateway from dist (`dist-nodts`), with a fake OpenAI-compatible provider. It returns `429` with `retry-after: 518400`; the fallback model returns a weekly-limit body without a header.

| Shape | Route | Provider requests | Session notice on main | Session notice with this PR |
|---|---|---|---|---|
| single model, 6-day limit | `agent` | 1 | "Your request couldn't be completed." | "⚠️ fake/long-limit is rate-limited. The provider says to retry in 6 days (Dec 4, …)." |
| single model | chat.send | 0 (shared gate) | reset copy | reset copy (unchanged) |
| both fallbacks limited | `agent` | 2 (1 per candidate) | "⚠️ The AI service needs a short break. Please try again in a few minutes." | same reset copy, naming the first limited model |
| both fallbacks limited | chat.send | 1 | reset copy | reset copy (unchanged) |

Attempt counts are the same on main and on this branch.

## Not covered

- A chain that mixes a rate limit with another failure (for example, a timeout) gets no capacity summary. It keeps the recorder's notice on both routes.
- A 429 after committed tool effects ends through `emitResultError`, not the catch. This is unproven; none of the production inputs took that path.
- The aggregate copy names the first attempt with a structured reset. That owner behavior also applies on chat.send and does not change here.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit e7325fb)

Companion audit: 17e2ec9 adds a different finished-subagent notice; 1ed6fd2 changes cron scheduling, not user-visible Gateway summary projection.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…ext run (#207091)

## Problem

On a production deployment, 126 scheduled-automation runs in 7 days failed with "<model> is rate-limited. The provider says to retry in 5-6 days". Recurring jobs ran again on every slot, or hourly once the error backoff reached its 60-minute maximum, and every run hit the same limit. Two jobs were still looping with 25 consecutive errors. Nothing in the cron scheduler read the provider's reset time; a rate limit counted as a transient error.

## Fix

- The run result now carries the provider's reset time as a transient fact (`rateLimitResetAt`, never stored). It is set only when every failed model attempt was rate-limited with a known reset (candidates skipped for a local cooldown are ignored), and the earliest reset wins. It reuses the existing reset facts on the failover error.
  - Session-target jobs: the settled failure cause already reaches the automation settlement in-process.
  - Isolated jobs: the run's catch, forwarded by the isolated execution adapter.
- `applyJobResult` uses it when scheduling the next run after an error:
  - The next normal slot is the first scheduled slot at or after the reset, so cron expressions stay on their schedule.
  - A reset before the schedule's own next slot moves the quick retry to the reset. A later reset skips quick retries for the first slot after it (an off-slot time there would be moved earlier by schedule maintenance), and the failure alert is not held for a retry that is days away.
- One-shot jobs are unchanged.
- Jobs are not paused; the failure notice already names the reset time (#206945).

## User impact

A recurring automation on a model with a multi-day limit stops hitting the provider, or the local limit gate, every hour. It runs again on its first slot after the stated reset, and the user gets the failure alert once instead of after every slot.

## Evidence

- `src/cron/rate-limit-reset.integration.test.ts`: a loopback provider returns 429 with `retry-after: 518400`. On both the session-target and the isolated path, the run makes one provider request and reports the reset (~6 days). Fails on main (no reset reported), passes here.
- `src/cron/service/timer-outcomes.regression.test.ts`: an hourly `every` job and a weekday cron job land exactly on their first slot after the reset, schedule maintenance keeps that slot, and the failure alert is emitted. A 45-second reset moves the quick retry instead of skipping to the next day. Fails on main, passes here.
- The same file runs both execution adapters through the timer, schedule maintenance and the persisted store, including a 5-minute cron with a 20-minute reset: the stored next run is the first slot after the reset.
- Cron run, outcome, failure-alert and cross-provider fallback suites on both paths pass.

Accepted edge: a provider that states an absurd reset (for example years away) parks the job until then; the failure notice shows that date, and a reset the scheduler cannot represent is ignored.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 1ed6fd2)

Follow-ups: c27edf0 is required for restart catch-up and is its own later lane row. #207186 (22a3aec) concerns alternate notice delivery when the owner model cannot run; not needed to carry the reset timestamp.

Co-authored-by: RomneyDa <[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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. P2 Normal backlog priority with limited blast radius. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant