Skip to content

fix(agents): skip profile rotation for missing-model errors - #138943

Closed
teddytennant wants to merge 6 commits into
openclaw:mainfrom
teddytennant:fix/idle-timeout-same-model-retry
Closed

teddytennant wants to merge 6 commits into
openclaw:mainfrom
teddytennant:fix/idle-timeout-same-model-retry

Conversation

@teddytennant

@teddytennant teddytennant commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Assistant model_not_found failures were rotating same-provider auth profiles before model fallback. A model the provider no longer serves cannot be fixed by another credential, so those runs spent a profile rotation and could surface idle-timeout copy for a failure that was never a credential fault.

model_not_found is also used for account-scoped denials and for ambiguous transport text. isModelNotFoundErrorMessage in src/agents/live-model-errors.ts matches a plain missing id, copy such as "The model does not exist or you do not have access", generic 404 page not found, and bare not_found_error. With two authorized profiles where only the second can use the selected model, skipping rotation on every model_not_found would switch models or fail despite a usable credential.

Rotation is now skipped only when isProviderWideModelNotFoundErrorMessage affirmatively matches text that says the selected model does not exist, was retired, or was deprecated (for example, the model named as not found, or no longer available). It is a positive allowlist, not a broad missing-model match with denial phrases removed. Generic 404 page not found, bare not_found_error, empty or unknown messages, and anything with access, permission, or account wording stay on rotate_profile and call advanceAuthProfile. After authorized profiles are exhausted, configured model fallback still runs. TLS certificate failures and replay-safe idle timeouts are unchanged.

Evidence

Rebased onto current openclaw/openclaw main (e2dc6ad93f8aa03dcfde61cf37eb8948e75d27cc). Head 822a45f2f8b8e64215cdc2c8f13740b4ade2f26f.

isProviderWideModelNotFoundErrorMessage returns true only for affirmative model-absence copy: the model named as not found, does not exist, retired, deprecated, or no longer available. Generic 404 page not found, bare not_found_error, empty or unknown messages, and access, permission, or account wording return false and remain on profile rotation.

The vitest and tsgo commands below were run on that same failover patch (previous head cd160579392e1c3b5047dfb99d0554396ac6621d). A later conflict-free rebase onto e2dc6ad93f8aa03dcfde61cf37eb8948e75d27cc did not change the six failover files. That rebase picks up the workboard control-ui asset hash already on main so the bundled-plugin asset check is comparing current main bytes.

node scripts/run-vitest.mjs run --config test/vitest/vitest.config.ts src/agents/live-model-errors.test.ts src/agents/embedded-agent-runner/run/failover-policy.test.ts src/agents/embedded-agent-runner/run/assistant-failure.test.ts

 Test Files  3 passed (3)
      Tests  87 passed (87)
   Start at  14:02:43
   Duration  63.10s (transform 86%, import 7%, worker 4%, tests 4%)

That run covers both paths: a provider-wide 404 model not found goes to model fallback without advanceAuthProfile, and "The model does not exist or you do not have access" rotates to the next authorized profile. A model_not_found reason with no proving message also keeps profile rotation. The same assistant-failure cases now assert that generic 404 page not found and bare not_found_error still call advanceAuthProfile and record rotate_profile.

The cross-provider scenarios live in src/agents/embedded-agent-runner/run.cross-provider-fallback-error-context.test-support.ts, imported by the shared integration entry:

node scripts/run-vitest.mjs run --config test/vitest/vitest.config.ts src/agents/embedded-agent-runner/run.shared-integration.test.ts -t "cross-provider fallback"

 Test Files  1 passed (1)
      Tests  6 passed | 130 skipped (136)
   Start at  14:04:04
   Duration  36.02s (tests 59%, transform 34%, import 6%, setup 1%)

The compaction-removed case still expects two failover classifications. Its message is "current candidate model unavailable", which is not affirmative provider-wide absence, so same-provider rotation remains.

Typecheck: node scripts/run-tsgo.mjs -p tsconfig.core.json passed (exit 0).

Those suites ran on this failover patch. No live vendor client was run for that head. A later local stub run is recorded below.

Local stub run

Follow-up head 60bd04e7281b794248d5a0d0a39bb4bea3d7c587 drops the provider-wide fallback, account-scoped access denial, and ambiguous not-found cases from src/agents/embedded-agent-runner/run/failover-policy.test.ts. The assistant-failure boundary table already covers those routes. The distinct no-fallback and absent-message policy cases stay.

pnpm test -- src/agents/embedded-agent-runner/run/failover-policy.test.ts

 Test Files  1 passed (1)
      Tests  50 passed (50)
   Duration  33.84s

oxlint and oxfmt --check on that file passed.

The upstream was a local OpenAI-compatible stub on loopback, not a vendor. It served /v1/chat/completions, returned ordinary invalid_request_error / model_not_found JSON for failures, and SSE chat chunks for success. Two fake API keys were saved with openclaw models auth paste-api-key as stubproof:a then stubproof:b, and openclaw models auth order set pinned that order. The fallback model was stubproof/fallback-ok. Keys, the loopback address, and local config paths are redacted. Profile ids in the agent log are already hashed.

The run was openclaw agent exec from this branch's built CLI, which is the embedded agent that owns the failover decision, with an explicit --model, --fallback, --code-mode direct, and --thinking off. It was not a long-lived gateway process. The embedded-run lines below are the same decision logs a gateway turn emits.

Provider-wide missing model (this head)

The stub saw one primary-missing request on profile-a, then fallback-ok on profile-a. Profile-b was not called.

POST /v1/chat/completions profile=profile-a model=primary-missing status=404 outcome=The model `primary-missing` does not exist
POST /v1/chat/completions profile=profile-a model=fallback-ok status=200 outcome=PROOF_FALLBACK_OK

Agent stderr, with the repeated tools-policy warning omitted:

[model-fetch] response provider=stubproof api=openai-completions model=primary-missing status=404 elapsedMs=23 contentType=application/json
embedded run failover decision: stage=assistant decision=fallback_model reason=model_not_found attempt=1 retry=0 rotations=0 from=stubproof/primary-missing profile=sha256:fda42a647467 rawError=404 The model `primary-missing` does not exist
model fallback decision: decision=candidate_failed requested=stubproof/primary-missing candidate=stubproof/primary-missing reason=model_not_found next=stubproof/fallback-ok detail=404 The model `primary-missing` does not exist
model fallback decision: decision=candidate_succeeded requested=stubproof/primary-missing candidate=stubproof/fallback-ok reason=unknown next=none
Model "stubproof/primary-missing" not found. Fell back to "stubproof/fallback-ok".

openclaw agent exec --json ended status=ok, final=PROOF_FALLBACK_OK, model=fallback-ok, provider=stubproof.

Account-scoped access denial (this head)

The same stub returns The model does not exist or you do not have access for profile-a on gated-model, and a normal completion for profile-b. The fallback model was not called.

POST /v1/chat/completions profile=profile-a model=gated-model status=404 outcome=The model does not exist or you do not have access
POST /v1/chat/completions profile=profile-b model=gated-model status=200 outcome=PROOF_PROFILE_B
[model-fetch] response provider=stubproof api=openai-completions model=gated-model status=404 elapsedMs=18 contentType=application/json
embedded run agent end: isError=true model=gated-model provider=stubproof rawError=404 The model does not exist or you do not have access
embedded run failover decision: stage=assistant decision=rotate_profile reason=model_not_found attempt=1 retry=0 rotations=0 from=stubproof/gated-model profile=sha256:fda42a647467 rawError=404 The model does not exist or you do not have access
[agent] run ended with stopReason=stop

openclaw agent exec --json ended status=ok, final=PROOF_PROFILE_B, model=gated-model, provider=stubproof.

Same stub before this patch

failover-policy.ts was restored to e2dc6ad93f8 (the commit this branch was rebased onto, before the rotation skip) and the CLI dist was rebuilt. Source was restored and dist rebuilt from this head afterward. The CLI version line still printed 822a45f because git HEAD did not move during that rebuild. The request trace is the difference.

POST /v1/chat/completions profile=profile-a model=primary-missing status=404 outcome=The model `primary-missing` does not exist
POST /v1/chat/completions profile=profile-b model=primary-missing status=404 outcome=The model `primary-missing` does not exist
POST /v1/chat/completions profile=profile-a model=fallback-ok status=200 outcome=PROOF_FALLBACK_OK
embedded run failover decision: stage=assistant decision=rotate_profile reason=model_not_found attempt=1 retry=0 rotations=0 from=stubproof/primary-missing profile=sha256:fda42a647467 rawError=404 The model `primary-missing` does not exist
[model-fetch] response model=primary-missing status=404 elapsedMs=5 dispatcher=reused
embedded run failover decision: stage=assistant decision=fallback_model reason=model_not_found attempt=2 retry=0 rotations=0 from=stubproof/primary-missing profile=sha256:d5d2a7adcfc5 rawError=404 The model `primary-missing` does not exist
model fallback decision: decision=candidate_succeeded requested=stubproof/primary-missing candidate=stubproof/fallback-ok reason=unknown next=none

On the pre-patch policy that affirmative missing-model error rotated to the second profile before fallback. On this head it does not.

@clawsweeper

clawsweeper Bot commented Sep 5, 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 triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. size: S labels Sep 5, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR skips auth-profile rotation for affirmative provider-wide missing-model errors while retaining rotation for ambiguous and account-scoped failures.

Example: Two authorized profiles request primary-missing, which returns 404 The model primary-missing does not exist, with fallback-ok configured.

  • Before: Both profiles request primary-missing before fallback-ok succeeds.
  • After: The first missing-model response advances directly to fallback-ok.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, focused, and supported by shipped CLI transport traces; no actionable correctness or security finding remains.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The built openclaw agent exec CLI exercised the embedded assistant-failure owner through a real OpenAI-compatible transport against a loopback HTTP server: affirmative absence skipped profile-b and completed on fallback-ok, while account denial completed on profile-b without fallback. The pre-patch comparison rotated unnecessarily; inspected later changes retain these demonstrated routes and add conservative plan-denial handling.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An unavailable model causes futile credential attempts before recovery through a configured fallback.
Reason: The narrow distinction removes wasted recovery attempts while retaining successful account-specific recovery and existing fallback settings.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: current main still rotates credentials for affirmative missing-model failures, and this focused patch resolves the prior account, ambiguous-response, and plan-denial findings without introducing a new actionable defect.

Priority: P2
Reviewed head: e30623efec4029b47a65a791c3fc1f36b41587ac

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The CLI before/after trace demonstrates the regression, although the supplied evidence does not show the added tests failing on the base.
Agent review details

How this fits together

The embedded agent's assistant-failure handler sends classified provider errors and terminal state to the shared failover policy, which chooses credential rotation, configured model fallback, or a surfaced error.

flowchart TD
A[Provider response] --> B[Assistant failure handler]
B --> C[Model error classifier]
C --> D[Failover policy]
D --> E[Authorized profile rotation]
D --> F[Configured model fallback]
D --> G[Surfaced error]
Loading

Technical review

Best possible solution:

Land the narrow assistant failover distinction while preserving authorized account rotation and the existing configured fallback owner.

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

Current-main source selects profile rotation for affirmative missing-model assistant failures, and the contributor's pre-patch CLI trace independently demonstrates that route; no target code was executed during this review.

Is this the best way to solve the issue?

The patch changes the existing shared failover owner, uses current failure text, preserves replay and cancellation checks, and conservatively retains credential rotation for the reported ambiguous and account-scoped cases.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Assistant profile rotation and fallback policy changes intended behavior with a stated reason (b406b7d: The extraction established shared failover decisions; subsequent merged recovery work preserved replay safety and configured missing-model fallback.)
  • Account-restricted model classification keeps the original intent (fix(agents): classify account-restricted model 400s as model_not_found #104878: Account/model mismatches intentionally classify as model_not_found to reach actionable failure handling and configured fallback.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +77, Tests +200. Total +277 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 77 0 +77
Tests 3 201 1 +200
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 278 1 +277

Review metrics

Metric Value Why it matters
Production versus test changes Production +77 lines; tests +201/-1 lines Growth implements the error-text distinction and exercises affirmative absence, account restrictions, ambiguous responses, absent text, and no-fallback behavior.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The change avoids unnecessary credential attempts for unavailable models while preserving existing recovery paths.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (18 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-25T12:04:08.601Z sha ec2e878228132109adabfbd06716b244d5a7dc4e :: needs real behavior proof before merge. :: [P1] Preserve profile recovery for account-scoped model failures
  • reviewed 2026-10-04T06:59:38.481Z sha ec2e878228132109adabfbd06716b244d5a7dc4e :: needs real behavior proof before merge. :: [P1] Preserve profile recovery for account-scoped model failures
  • reviewed 2026-10-07T14:10:07.627Z sha 9fd98e1e268a997a64dd23abd232a982e673b762 :: needs real behavior proof before merge. :: [P1] Preserve profile rotation for ambiguous not-found responses
  • reviewed 2026-10-07T14:20:20.040Z sha c97d10a71073162cf2f661d3be80d43ae830fd1c :: needs real behavior proof before merge. :: [P1] Preserve profile rotation for ambiguous not-found responses
  • reviewed 2026-10-08T14:14:36.507Z sha cd160579392e1c3b5047dfb99d0554396ac6621d :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-08T14:23:18.319Z sha 822a45f :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-12T14:40:39.310Z sha 60bd04e :: needs changes before merge. :: [P1] [P1] Preserve profile rotation for plan-scoped model denials
  • reviewed 2026-10-12T15:44:31.666Z sha e30623e :: needs maintainer review before merge. :: none

Reviewed October 12, 2026, 12:20 PM ET / 16:20 UTC (Revision 19).

@openclaw-barnacle openclaw-barnacle Bot closed this Sep 5, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Sep 5, 2026
@openclaw-barnacle openclaw-barnacle Bot closed this Sep 5, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Sep 5, 2026
@teddytennant
teddytennant force-pushed the fix/idle-timeout-same-model-retry branch from 51a2c72 to c12539f Compare September 5, 2026 17:52
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Sep 5, 2026
@teddytennant
teddytennant force-pushed the fix/idle-timeout-same-model-retry branch from c12539f to c0d17bb Compare September 5, 2026 18:23
@VACInc

VACInc commented Sep 13, 2026

Copy link
Copy Markdown
Member

Issue #137910 is now fixed on main by #147203 in commit fc1975991f22403d4a8a723c2a27071bbc16d55f.

This PR's current production change instead concerns model_not_found routing. Please remove or replace Closes #137910 so the PR is reviewed independently for that distinct behavior. Keeping this PR open.

@teddytennant

Copy link
Copy Markdown
Contributor Author

dropped the Closes #137910 line.

@teddytennant
teddytennant force-pushed the fix/idle-timeout-same-model-retry branch from e2dfbba to 451e10b Compare September 13, 2026 20:12
@teddytennant

Copy link
Copy Markdown
Contributor Author

dropped it from the commit too, so merge will not auto-close 137910.

@teddytennant
teddytennant force-pushed the fix/idle-timeout-same-model-retry branch from 451e10b to 895535f Compare September 13, 2026 23:31
@teddytennant

Copy link
Copy Markdown
Contributor Author

rebased onto main. missing-model errors skip profile rotation now; idle timeout still rotates, and I dropped the old same-model retry tests that don't match current failover.

@teddytennant teddytennant changed the title fix(agents): retry idle timeouts on the same model before timeout copy fix(agents): skip profile rotation for missing-model errors Sep 13, 2026
@teddytennant
teddytennant force-pushed the fix/idle-timeout-same-model-retry branch from 895535f to ec2e878 Compare September 14, 2026 00:08
@teddytennant

Copy link
Copy Markdown
Contributor Author

rebased onto main for the reef delivery-scan fixture fix

Copy link
Copy Markdown
Contributor Author

Working the ClawSweeper P1 next: the unconditional model_not_found rotation bypass is too wide because the classifier also matches account-scoped "does not exist or you do not have access" failures.

Plan:

  1. Narrow the bypass to proven provider-wide missing/retired models only.
  2. Keep rotate_profile for ambiguous / account-scoped access denials.
  3. Rebase onto current main and add regression coverage for both paths.
  4. Refresh real-behavior proof after the narrower fix lands.

Leaving this open until that lands (or a clean replacement PR if rebase fights get ugly).

@cursor
cursor Bot force-pushed the fix/idle-timeout-same-model-retry branch 3 times, most recently from c97d10a to cd16057 Compare October 8, 2026 14:06
@clawsweeper clawsweeper Bot removed merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Oct 8, 2026
teddytennant and others added 3 commits October 8, 2026 14:16
Assistant model_not_found failures skip auth-profile rotation only when
the missing-model classifier proves the id is gone for the provider.
Account-scoped copy such as "does not exist or you do not have access"
still rotates to the next authorized profile before model fallback.
Skip profile rotation only when the error text says the model does not
exist, was retired, or was deprecated. Generic 404 pages and bare
not_found_error stay on rotate_profile.

Co-authored-by: Teddy Tennant <[email protected]>
@cursor
cursor Bot force-pushed the fix/idle-timeout-same-model-retry branch from cd16057 to 822a45f Compare October 8, 2026 14:16
@teddytennant

Copy link
Copy Markdown
Contributor Author

dropped the duplicated failover-policy cases. added a local stub-provider run to the pr body: a provider-wide missing model skips rotation and hits the fallback, and the access denial still rotates onto the second profile. the pre-patch policy rotates first on that same stub. head 60bd04e.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 12, 2026
cursoragent and others added 2 commits October 12, 2026 15:32
Keep main's model retirement and deprecation classifier and the run-budget
timeout fallback. Preserve the provider-wide missing-model rotation skip.

Co-authored-by: Teddy Tennant <[email protected]>
Plan, tier, subscription, and similar account-scoped denials such as Z.AI's
"model not found for this plan" stay on profile rotation. Provider-wide
missing models, including Ollama retirement notices, still skip rotation.

Co-authored-by: Teddy Tennant <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 12, 2026
@teddytennant

Copy link
Copy Markdown
Contributor Author

kept rotation for plan-scoped model denials like z.ai's 'model not found for this plan' and added it to the boundary table. merged main and kept its retirement/deprecation and timeout handling. head e30623e.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Thanks @teddytennant for this fix and the careful distinction between missing models and account-access errors. A smaller, credited replacement has landed in #189716 (f4c0984), so I am closing this as superseded.

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

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants