Skip to content

fix(agents): route shared TPM exhaustion to configured fallbacks - #185496

Merged
steipete merged 4 commits into
mainfrom
codex/shared-rate-limit-fallback
Oct 27, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/shared-rate-limit-fallback

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Concurrent sessions can spend minutes retrying a saturated primary without reaching their configured fallback. Remembered new-session defaults also become strict user model overrides, disabling that fallback chain before retry policy can help.

Peter's asks:

openclaw should have a systemwide knowledge of rate limit status, so each session doesn't retry independently. and if stuff's rate limited we have a fallback model, why didn't that work?

oh it's okay to do a few retries before falling back to the fallback model - idk what the best approach is. read more code to come up with sth that feels good for the user and is reliable.

Team evidence from October 26–27: 292 rate-limit errors across 19 of 27 sessions over roughly three hours, with each run logging its own transient same-model retry N/15, waits up to 60 seconds, and no configured model fallback. The primary and fallback used the same OpenAI account, with about 20 concurrent agent runs and 150k–690k input-token requests. The organization TPM bucket remained saturated despite retry hints around 48 ms. One turn exhausted 15 retry events over approximately eight minutes and ended incomplete.

A second blocker affected all 19 sessions created that day: they stored a strict user model override matching the configured primary, although Peter had never selected an override. The remembered new-session.v1:<agent> preference included the displayed model; the new-session flow sent it through sessions.create, whose creation-only forced pin turned it into a strict selection. Gateway logs confirmed configured fallbacks were disabled by that override.

User Impact

Four fixes make the configured fallback reachable:

  1. Scope the existing shared TPM gate by endpoint, account/organization, and model. A primary's TPM exhaustion still coordinates its other runs while another model on the same account has its own gate.
  2. Allow replay-safe embedded turns with an eligible fallback at most two same-model retries within 15 seconds, then advance. Requests without an eligible fallback retain the longer recovery budget and existing provider delay caps.
  3. Route new fallback chains around known saturated candidates. Keep available candidates in configured order; when every eligible candidate is saturated, enter the earliest retry gate. Preserve existing interactive priority, rate-limit fallback provenance, notices, status, and stickiness.
  4. Normalize sessions.create requests matching the effective configured primary instead of forcing an override. Existing saved equal-primary user selections keep the configured fallback chain without a database rewrite or Doctor migration.

Selecting the configured primary retains its configured fallbacks. Different explicit model selections, model-selection locks, and explicit empty fallback lists remain strict. Clear a saved override with sessions.patch model:null; writing the displayed default back as a model is not the cleanup operation.

Why This Change Was Made

The gate already owns shared saturation. Candidate ordering now consumes its read-only account/model snapshot rather than adding another cooldown store. Ordering lives in model-fallback-rate-limit.ts; the fallback runner only calls it and grows by three lines, remaining below its 700-line cap.

Creation's forced-pin history was checked against #169030. Different requested models still preserve explicit selection; same-primary creation now uses the existing default normalization. Existing SDK/session-agent exports are retained after moving unchanged session-agent resolution to its configuration owner to avoid a static import cycle.

Accepted limits: coordination is process-local. Native transports, deferred credentials, and account choices requiring cooldown admission retain ordinary admission when their starting identity cannot be determined read-only. Saturation uses the existing one-minute recovery window, and existing 10-minute idle/30-minute-cap fallback stickiness remains. A saved or remembered model differing from a subsequently changed primary remains a different, strict selection. No UI change, new config, dependency, persisted shape, schema, or migration is introduced.

Evidence

Published head: df7d0bb7ebd6a0f262dcd390997f99abc126dd63. The PR is OPEN, ready and MERGEABLE. Exact-head CI run 40467478171 completed FAILURE. Required openclaw/ci-gate: FAILURE. All six lint jobs, baseline ratchets, and all three PostgreSQL conformance jobs passed. Its only five failed test shards are the coordinator-confirmed CLI and worker failures described below; no unrelated repairs were added. Earlier runs remain prior-head evidence. Stopped for coordinator review; no merge was attempted.

The coordinator-approved file-specific size allowance is committed: agent-command.live-model-switch.test.ts, 3,731→3,736 counted lines, after duplicate fixture wiring cleanup, through the normal per-file lint-limit mechanism. Reason: “expectations updated for equal-primary saved selections keeping configured fallbacks; #185496”. No other ceiling was raised and no baseline entry was added. The current line-cap guard passes for 46 changed source files.

The architecture repair moves fallback availability into the existing model-selection config owner and its type into the leaf fallback contract. All consumers/mocks were cut over. The exact Madge guard passes with zero cycles. One rebase conflict retained both main's added prepared-runtime sharing test and the selection-owner import.

Branch-mode Codex P1 review covered the implementation and selection-owner cutover at 41dd2fd, scoped-clean with confidence 0.84. CI then found two duplicate imports, an unused size suppression, incomplete real-module pass-through in two mocks, and an extra asynchronous suspension-row assertion. The five-file follow-up fixes these; its fresh P1 review is scoped-clean with confidence 0.97, including final source verification. It is now committed and pushed. No fallback production logic changed in that follow-up.

The coordinator approved the deletion-only baseline cleanup made necessary by the repaired mocks. The normal prune command removed exactly two obsolete entries: 6,615→6,613, with no additions. Formatting and line-cap checks pass. Strict-selection tests retain physical selected-model-only requests, terminal failure, exactly one persisted run-error message, and no success text. The extra suspension-row assertion failed once in CI and passed on identical local inputs; it concerns an asynchronous projection outside the direct-agent terminal contract. The command/steering/reply-utils replay passed: 109 command cases and 40 reply cases, two configured shards in 578.33 s. The normal max-lines prune also removed the single obsolete suppression entry (409→408), as required after removing its unused suppression; no baseline entries were added.

The final repair accepts the automated account-identity finding: when bundled catalog metadata exists, normalization needs an explicit provider config to retain configured organization headers and endpoints. Saturation reads now use the same existing config resolver as the real model resolver. The regression failed on e894 (requested primary instead of backup), then all 53 focused fallback cases passed with the two-line production fix. Core and affected agent test types pass; Madge reports zero cycles; line-cap and formatting checks pass. A fresh complete-candidate Codex P1 review is scoped-clean (confidence 0.85), including final source verification. The last commit contains this repair, its single regression, and the stale baseline deletion.

All 16 real Gateway product cases passed locally (790.46 s including imports). An earlier broad replay was stopped before shared-fixture edits; the separate three-file replay above subsequently completed. The requested additional real embedded-runner replay passed in 23,542ms; total wrapper 721.89s, including a 194,967 ms worker build and 496.29 s Vitest duration dominated by imports. It ran alone at host load 52.62, below the earlier peak near 80. The existing 120,000 ms test limit was unchanged. Earlier results remain recorded: timeout at 120,000 ms (reported body 141,627 ms), followed by a 37,869 ms diagnostic pass (wrapper 524.66 s). Passing replay does not prove a fix for that timeout.

The coordinator confirms the CLI and worker failures are not caused by this PR. They are the only five failed test shards on the final head: checks-node-changed-compact-small-6 (CLI), checks-node-changed-compact-large-11 (worker computer launcher), checks-node-changed-compact-large-25-1 (worker detached context), checks-node-changed-compact-large-8-1 (worker context engine), and checks-node-changed-compact-large-26 (worker terminal results/watchdog). CLI #185388 is being fixed forward separately; worker fixtures come from #185424. Source evidence supports both attributions: Main #185424 added preturn workspace quiesce/reconcile/resume; four unchanged worker suites reject/omit that protocol (18 detached-context,27 computer-launcher,2 context-engine,4 terminal-result failures). The last suite also contains a source-demonstrated fixture deadlock consistent with its 300,000 ms no-output watchdog termination; the log does not identify the hung test by stack. Main #185388 changed completion reply-expectation precedence;17 unchanged CLI cases expect different behavior. Explicit child-result precedence needs its policy owner's review rather than blanket fixture relaxation. Relevant production/tests are byte-identical at base 43fbf45 and this head. Exact-base run 40459732984 was cancelled with no jobs, so this is source attribution, not a completed base test verdict. Those files were not edited here. All failed logs were fetched once; no blind CI rerun was requested.

Gate keying, the short retry budget, public sessions.create, and real-runner routing were red with the original owning modules and green with the repair. The original routing owner sent three primary requests for session B instead of going straight to fallback; the original creation owner persisted an equal-default strict override. The scripted provider runs through the real stream gate with isolated SQLite state, synthetic credentials, and rejected network calls. A makes three primary requests then answers on fallback; B sends only fallback; after fake-clock expiry C uses primary; strict[] waits through the gate.

The earlier 14-file touched/consumer batch passed 224 distinct cases plus one existing skip;40 E2E cases also passed under the second configured runtime. After account correction 53 focused cases passed; after ordering correction 52 fallback cases passed. Core/four affected test typechecks, formatting, docs MDX, assertion safety and database-worker checks passed. The local lint wrapper twice hit its unchanged 300,000 ms Plugin SDK declaration prerequisite before lint ran; the coordinator selected PR CI lint as the supported proof. All six lint jobs passed on the final head, with no timeout or guard bypass.

Commands and scope
OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1 node scripts/run-vitest.mjs \
  src/llm/stream.complete-host.test.ts \
  src/agents/embedded-agent-runner/run/failover-retry-controller.test.ts \
  src/agents/agent-scope.test.ts \
  src/agents/agent-tools.prefix-stability.test.ts \
  src/agents/model-fallback.shared-rate-limit.integration.test.ts \
  src/agents/model-fallback.shared-rate-limit.test.ts \
  src/gateway/server.sessions.create.resolved-model.test.ts \
  src/agents/embedded-agent-runner.resolvesessionagentids.test.ts \
  src/agents/model-runtime-policy.test.ts \
  src/cron/isolated-agent/run-fallback-policy.test.ts \
  src/auto-reply/reply/agent-runner-run-params.thinking.test.ts \
  src/gateway/server-methods/chat-send-message-injection.test.ts \
  src/agents/model-fallback.run-embedded.e2e.test.ts \
  src/agents/model-fallback.reply-entry.e2e.test.ts --maxWorkers=1

OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1 node scripts/run-vitest.mjs \
  src/agents/model-fallback.test.ts \
  src/agents/model-fallback.shared-rate-limit.test.ts \
  src/agents/model-fallback.shared-rate-limit.integration.test.ts --maxWorkers=1

pnpm tsgo:core
node scripts/run-tsgo-core-test-shards.mjs --ci-graphs-json '["core-test-agents-root","core-test-agents-other","core-test-gateway-server","core-test-other"]'
pnpm check:line-cap-ratchet --base 9dd9539b04768fe07f190ed6e78eb2e7b77f7db2
pnpm check:max-lines-ratchet --base 9dd9539b04768fe07f190ed6e78eb2e7b77f7db2
pnpm check:assertion-safety --base 9dd9539b04768fe07f190ed6e78eb2e7b77f7db2
pnpm check:test-mock-exports --base 9dd9539b04768fe07f190ed6e78eb2e7b77f7db2
pnpm check:database-worker-ratchet --base 9dd9539b04768fe07f190ed6e78eb2e7b77f7db2
pnpm check:import-cycles
node scripts/check-docs-mdx.mjs docs/concepts/model-failover.md docs/concepts/retry.md
git diff --check

The 14-file batch preceded the final account/ordering refinements; focused reruns cover those changes. lint configuration: +7/-0 (net +7); docs: +30/-12 (net +18); production: +584/-249 (net +335); tests/support including harnesses and mocks: +707/-94 (net +613); obsolete baseline entries: +0/-3. Total: 51 files, +1,328/-358 (net +970). The smallest coherent change includes the gate, chain admission, retry budget, and producer/policy repair: leaving any one of these paths unchanged can still prevent configured fallback.

No live Gateway, Team/stable state, real provider API, deployment, release, new configuration or dependency was used for proof. No worker or completion-policy repair is included here. The coordinator reviewed and accepted the production diff and authorized landing.

Landing update: CLI fix-forward #185667 landed as b3b0f1bb8105cf784f87f47a8f31a9564888f2e3. This branch was rebased onto main 454f79575efd51acaebcfa2e100674f299d96fbb; all four commits are patch-identical by git range-diff, and git diff --check passes. Current head: d371116807e9c310cd789b8d2c130c10b6ebab20. Exact-head CI, attempt 1, is terminal: 60 passed, 25 skipped; four worker shards and their aggregate gate failed. All six lint jobs, security-fast, baseline ratchets, and all three PostgreSQL conformance jobs passed. The CLI failures are gone. The earlier five-shard results above belong to the previous head.

The completed main CI run 40463504008, main commit 9b7db694b593cd2b498d704611414a8659fe7ffb after #185424, has the same detached-context, computer-launcher, and context-engine failures. Its terminal-result log also contains the same four failed assertions followed by the durable-Move timeout. The four affected test files, launch fixtures, launcher/execution owners, and preturn reconciliation owners are byte-identical between that main baseline and the refreshed PR head. Any inherited-failure landing will retain the actual failed run and source evidence; it will not describe failed CI as green.

The coordinator authorized native squash landing with these independently evidenced pre-existing #185424 worker failures. Current failed jobs are checks-node-changed-compact-large-11 (27 computer cases), checks-node-changed-compact-large-24 (18 detached-context cases), checks-node-changed-compact-large-8-1 (two context-engine cases), and checks-node-changed-compact-large-9 (four terminal-result assertions, followed by the unchanged 300,000 ms watchdog); aggregate openclaw/ci-gate is failed. Actual CI checkout 1854829d87feeaff2d63404fd399cf08882fd839 has ordered parents main 06c9568679c378a8e8a4a24468d16300a6c3f378 and this exact PR head; its tree matches their merge. Native evidence retains the logs, the completed failing main run, exact case comparisons, source-object equality, passing scoped proof, and the original investigated local timeout. The watchdog log does not identify its hung test by stack; the same four preceding assertions fail on main, where the durable-Move case also times out. No worker-fixture repair, timeout increase, or successful-CI claim is included here.

@clawsweeper

clawsweeper Bot commented Oct 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 docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: XL labels Oct 27, 2026
@steipete
steipete marked this pull request as ready for review October 27, 2026 05:25
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T08:57:06.598487Z d371116 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR shortens shared TPM recovery, routes around saturated models, and preserves configured fallbacks when a session selects its configured primary.

Example: An agent uses openai/gpt-5.4 with anthropic/claude-sonnet-4-6 as its configured fallback.

  • Before: A saved same-primary user selection disables fallback, or shared TPM exhaustion consumes the long retry budget.
  • After: The same-primary selection permits fallback, and replay-safe TPM recovery advances after at most two retries within 15 seconds.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The product case is strong, but required behavior proof is absent and exact-head CI confirms unupdated consumer tests.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 3 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Concurrent sessions fail to reach configured fallback models, including sessions unintentionally pinned to their displayed default.
Reason: The incident establishes concrete user impact, and the maintainer-authored direction explicitly authorizes both shorter recovery and same-primary normalization.

Merge readiness

⛔ Blocked before merge - 4 items remain

Keep open: this maintainer-authored PR addresses a current fallback failure, but affected consumer tests need repair before it is ready.

Priority: P1
Reviewed head: 8f8a578e814eb0f42147c36902fb1bee6dd0d52d

Before merge

  • Migrate resolver-dependent test fixtures with the moved import (P2) - Importing resolveSessionAgentIds directly from agent-scope-config bypasses existing agent-command test interception through agent-scope.js. Those fixtures return sessionAgentId default alongside agent:main session keys, so the real resolver now throws AGENT_SELECTION_REQUIRED before the behavior under test runs. Exact-head checks-node-changed-compact-small-11 records this failure. Update the affected fixtures or their owning-module interception together with this move, preserving the real resolver's mismatch rejection.
  • Update fallback consumer regressions for same-primary selections (P2) - The same-primary exception changes behavior exercised by agent-runner-fallback-steering.test.ts and server.visible-spawn-fallback.product-proof.test.ts, but their expectations still require strict pins and the previous persisted override fields. Exact-head CI fails at steering line 488 and visible-child lines 534, 537, and 561. Update these consumers to assert the approved same-primary behavior, retaining separate different-model and selection-lock cases that must remain strict.
  • Document the same-primary exception for legacy overrides (P3) - The new equality check also applies when modelOverrideSource is absent and no automatic-fallback provenance exists. A legacy saved override matching the configured primary can therefore use fallbacks, while the retained Legacy session override paragraph still promises that old explicit selections are not converted into fallback behavior. Qualify that paragraph with the same-primary exception so upgrade guidance matches the implementation.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P2] Migrate resolver-dependent test fixtures with the moved import — src/agents/model-runtime-policy.ts:29-30
  • [P2] Update fallback consumer regressions for same-primary selections — src/agents/agent-scope.ts:507-508
  • [P3] Document the same-primary exception for legacy overrides — docs/concepts/model-failover.md:227

Tests

  • Missing end-to-end proof: Supply redacted shipped-entry-point evidence of TPM-to-fallback recovery and same-primary creation, plus an upgrade from v2026.10.7 preserving saved selections and data; the body reports red/green regression results.
Agent review details

How this fits together

Gateway and agent entry points resolve session model policy, the fallback runner orders eligible models, and the shared admission gate paces outgoing provider requests.

flowchart TD
  A[Session or agent request] --> B[Model selection policy]
  B --> C[Fallback candidate runner]
  D[Shared model saturation] --> C
  C --> E[Embedded retry controller]
  E --> F[Provider admission gate]
  F --> G[Provider transport]
  G --> D
Loading

Technical review

Best possible solution:

Retain the existing admission, retry, selection, and persistence owners while making their affected consumers agree on the new fallback contract.

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

Current-main source shows creation forcing a model pin, user pins disabling the fallback ladder, and shared admission spanning models; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The repair addresses both policy and admission blockers through existing owners, but its consumer tests still encode the previous contracts.

Full review comments:

  • [P2] Migrate resolver-dependent test fixtures with the moved import — src/agents/model-runtime-policy.ts:29-30
    Importing resolveSessionAgentIds directly from agent-scope-config bypasses existing agent-command test interception through agent-scope.js. Those fixtures return sessionAgentId default alongside agent:main session keys, so the real resolver now throws AGENT_SELECTION_REQUIRED before the behavior under test runs. Exact-head checks-node-changed-compact-small-11 records this failure. Update the affected fixtures or their owning-module interception together with this move, preserving the real resolver's mismatch rejection.
    Confidence: 0.99
  • [P2] Update fallback consumer regressions for same-primary selections — src/agents/agent-scope.ts:507-508
    The same-primary exception changes behavior exercised by agent-runner-fallback-steering.test.ts and server.visible-spawn-fallback.product-proof.test.ts, but their expectations still require strict pins and the previous persisted override fields. Exact-head CI fails at steering line 488 and visible-child lines 534, 537, and 561. Update these consumers to assert the approved same-primary behavior, retaining separate different-model and selection-lock cases that must remain strict.
    Confidence: 0.99
  • [P3] Document the same-primary exception for legacy overrides — docs/concepts/model-failover.md:227
    The new equality check also applies when modelOverrideSource is absent and no automatic-fallback provenance exists. A legacy saved override matching the configured primary can therefore use fallbacks, while the retained Legacy session override paragraph still promises that old explicit selections are not converted into fallback behavior. Qualify that paragraph with the same-primary exception so upgrade guidance matches the implementation.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against d0916212f458.

Provenance checked

  • Shared admission scope changes intended behavior with a stated reason (68a7e7b: Coordinate organization TPM exhaustion and avoid independent request storms, including same-account fallback siblings.)
  • Fallback availability and strict selections changes intended behavior with a stated reason (5454da8: Use one availability fact so retry escalation cannot target an empty ladder for a pinned model.)
  • Creation-time model pinning changes intended behavior with a stated reason (f442662: The earlier patch normalized default selections while explicitly preserving creation's existing pinning contract; this commit is evidence of retention, not proof that it originally introduced pinning.)
  • Session-agent resolution placement keeps the original intent (0fd838b: Avoid unnecessary roster/default lookup when an owner is already selected; the moved resolver retains its validation and selection behavior.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +343, Tests +536, Docs +18. Total +897 across 28 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 17 474 131 +343
Tests 9 568 32 +536
Docs 2 30 12 +18
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 28 1072 175 +897

Review metrics

Metric Value Why it matters
Production versus test growth Production +474/-131; tests/support +568/-32 Growth covers saturation-aware ordering, bounded admission, selection repair, and distinct regressions without adding another persistent cooldown store.

Labels

Label changes:

  • add P1: The reported incident leaves concurrent agent turns retrying a saturated primary for minutes without reaching configured recovery.
  • add merge-risk: 🚨 compatibility: Existing equal-primary user selections gain fallback behavior and same-primary creation stops storing a strict pin; the maintainer explicitly accepts this behavior change.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P1: The reported incident leaves concurrent agent turns retrying a saturated primary for minutes without reaching configured recovery.
  • merge-risk: 🚨 compatibility: Existing equal-primary user selections gain fallback behavior and same-primary creation stops storing a strict pin; the maintainer explicitly accepts this behavior change.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 27, 2026, 1:42 AM ET / 05:42 UTC.

steipete added a commit that referenced this pull request Oct 27, 2026
Align fallback consumers and their fixtures with the selection owner. Equal-primary selections retain configured fallbacks; different models and explicit empty ladders remain strict.

Approved per-file allowance: 3731 to 3736 counted lines for agent-command.live-model-switch.test.ts; expectations updated for equal-primary saved selections keeping configured fallbacks; #185496.
@steipete
steipete force-pushed the codex/shared-rate-limit-fallback branch from 38f5974 to 41dd2fd Compare October 27, 2026 06:16

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e8945ccc22

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/model-fallback-rate-limit.ts Resolved
Scope shared token-rate-limit admission by account and model, bound replay-safe same-model recovery when a fallback is eligible, and route other sessions around saturated candidates.

Normalize same-primary session creation and keep configured fallbacks for existing equal-primary selections while preserving different strict selections and locks.
Align fallback consumers and their fixtures with the selection owner. Equal-primary selections retain configured fallbacks; different models and explicit empty ladders remain strict.

Approved per-file allowance: 3731 to 3736 counted lines for agent-command.live-model-switch.test.ts; expectations updated for equal-primary saved selections keeping configured fallbacks; #185496.
@steipete
steipete force-pushed the codex/shared-rate-limit-fallback branch from df7d0bb to d371116 Compare October 27, 2026 08:53

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d371116807

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +143 to +144
sessionAuthProfileId: params.userLockedAuthProfileId,
sessionAuthProfileSource: params.userLockedAuthProfileId ? "user" : undefined,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Scope the pinned auth profile to compatible fallback providers

When a user pins a profile for provider A and the fallback chain includes providers B and C, this passes A's profile as a user lock while preparing B's auth. prepareAgentRuntimeAuth rejects the incompatible profile, and the catch below marks B eligible without reading its saturation gate. If A and B are saturated but C is healthy, B is consequently ordered first and the request waits behind its gate instead of using C. The actual candidate loop in model-fallback-runner.ts checks resolveAuthProfileEligibility before applying the pin; apply the same provider compatibility check here so the snapshot observes B's actual starting account.

AGENTS.md reference: AGENTS.md:L70-L70

Useful? React with 👍 / 👎.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The configured-account identity finding is fixed and its thread resolved. The four reviewed patches are unchanged after incorporating #185667. Exact-head CI has only the independently evidenced #185424 worker failures; the PR body records the completed main comparison and authorized native landing exception.

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit 5686263 into main Oct 27, 2026
159 of 165 checks passed
@steipete
steipete deleted the codex/shared-rate-limit-fallback branch October 27, 2026 09:30
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…nclaw#185496)

* fix(agents): route shared TPM exhaustion to configured fallbacks

Scope shared token-rate-limit admission by account and model, bound replay-safe same-model recovery when a fallback is eligible, and route other sessions around saturated candidates.

Normalize same-primary session creation and keep configured fallbacks for existing equal-primary selections while preserving different strict selections and locks.

* refactor(agents): own fallback policy in model selection

Align fallback consumers and their fixtures with the selection owner. Equal-primary selections retain configured fallbacks; different models and explicit empty ladders remain strict.

Approved per-file allowance: 3731 to 3736 counted lines for agent-command.live-model-switch.test.ts; expectations updated for equal-primary saved selections keeping configured fallbacks; openclaw#185496.

* fix(ci): complete fallback mocks and lint cleanup

* fix(agents): honor configured account identity in saturation lookup
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 gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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.

1 participant