Repository navigation
fix(agents): keep the provider reset in agent-route failure notices - #206945
Merged
Merged
Conversation
- 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.
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
All 36 ran on the Gateway
agentroute. This route servesopenclaw agentand 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,
handleAgentExecutionErroremits the run's lifecycle error witherrorNoticeset to the rendered reply (src/auto-reply/reply/agent-runner-error-handler.ts:100-108). Theagentroute'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
agentroute catch, the code now emitserrorNoticefromresolveReplyFailureSummary. 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
agentandopenclaw agentusers, 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
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 (noerrorNotice) and passes with the fix.dist-nodts), with a fake OpenAI-compatible provider. It returns429withretry-after: 518400; the fallback model returns a weekly-limit body without a header.agentagentAttempt counts are the same on main and on this branch.
Not covered
emitResultError, not the catch. This is unproven; none of the production inputs took that path.