Skip to content

fix(setup): preserve the current model when activating saved auth - #180832

Closed
xiaopan-xydt wants to merge 5 commits into
openclaw:mainfrom
xiaopan-xydt:fix/saved-auth-model-preservation-167381
Closed

xiaopan-xydt wants to merge 5 commits into
openclaw:mainfrom
xiaopan-xydt:fix/saved-auth-model-preservation-167381

Conversation

@xiaopan-xydt

@xiaopan-xydt xiaopan-xydt commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Related to #167381

What Problem This Solves

Activating a previously saved auth profile failed with The candidate route does not match the selected model when the saved credential's starter model differed from the current agent model. The activation path staged the stored starter model instead of the model the agent was already using, so route verification rejected the candidate. If the models happened to match, activation could also overwrite the user's current model with the starter model. Discovery had the same mismatch: Model Setup forwards the discovered candidate model explicitly, so fixing activation alone was bypassed by the normal UI flow. Provider-qualified aliases such as openai/Fast must also be resolved to their canonical model identity or the same route check rejects a valid current model.

Why This Change Was Made

Saved-auth discovery and stageSavedAuthCandidate now share the same model-selection decision:

  1. An explicitly supplied modelRef.
  2. The canonical current agent route model, when it belongs to the same provider as the saved credential.
  3. The saved credential's stored model, preserving the existing cross-provider fallback.

Both paths call resolveCurrentModelRefForSavedAuth, which uses the existing setup route resolver. Configured aliases therefore resolve to the same concrete model identity used by the model-selection updater, and discovery advertises that canonical current model to Model Setup. The trailing auth-profile suffix is removed before comparing providers. API-key header configuration is applied to the provider of the resolved model rather than always using the saved starter model's provider. Credential and auth-profile binding behavior is unchanged.

The saved-auth route lookup is also scoped to the setup target. Previously it always resolved the primary route and cached by provider alone, so a credential chosen for the utility target could advertise the primary model and ordinary activation could promote a utility-only model to primary. Discovery and stageSavedAuthCandidate now pass modelTarget (primary or utility) into the shared resolver, and the discovery cache is keyed by provider plus target. A utility-only configuration therefore keeps its utility model while saved-auth activation still persists the selected starter model as primary.

User Impact

Users can switch back to a saved sign-in without a spurious route mismatch, and activation no longer resets their current model to the provider's starter model. Cross-provider saved credentials retain the previous fallback behavior.

Evidence

  • Full target suites on the final head: 43 passed across setup-inference-activate.test.ts and setup-inference-saved-model.test.ts, including both openai/gpt-5.4-mini and the configured openai/Fast alias; 19 passed in setup-inference-detect.test.ts.
  • Discovery-to-activation regression: both cases call setup.detect(), assert the saved-auth candidate advertises the canonical current model, activate that candidate as Model Setup does, and verify the persisted model and inference call.
  • Discovery base-red: with the previous discovery selection restored, both cases advertise openai/starter-model and fail before activation.
  • Role-isolation regression: with only agents.defaults.utilityModel configured, detection advertises the saved starter model and activation persists that model as primary while leaving utilityModel unchanged.
  • Type-safety hardening: the API-key header target uses the resolved model provider when a model is present and otherwise falls back to the saved provider, so parseInferenceRef never receives an optional model reference. The final-head model regressions pass (2 passed | 40 skipped).
  • Formatting and lint: oxfmt --check and oxlint passed for all changed files; git diff --check passed.
  • Logs: 180832-final.log (43 + 19 passed) under contributions/pr-evidence-20261025/180832/ in the contributor workspace. Earlier logs remain under contributions/pr-evidence-20261023/, and the upgrade readback files are under 180832-live-proof/upgrade-20261023e/.

Real CLI behavior proof

On 2026-10-23 I exercised the shipped openclaw CLI in an isolated state directory against a local loopback OpenAI Responses provider. The state had an active openai:baseline credential and a saved replacement openai:saved-proof credential whose recorded model was openai/starter-model; the current agent model was openai/gpt-5.4-mini.

  • A baseline openclaw agent --local turn authenticated with the baseline credential and returned LIVE_PROOF_REPLY_1 on gpt-5.4-mini.
  • openclaw models auth activate openai:saved-proof --agent main printed Inference verified: openai/gpt-5.4-mini and Sign-in verified and saved. It authenticated the probe with the saved credential, not the baseline credential.
  • A subsequent openclaw agent --local turn returned LIVE_PROOF_REPLY_3 from gpt-5.4-mini and used the saved credential.
  • Persisted config after activation: agents.defaults.model.primary remained openai/gpt-5.4-mini, while agents.entries.main.model became openai/gpt-5.4-mini@openai:saved-proof.
  • The saved profile remained present in the migrated auth store with its original key; only its consumed setup marker was cleared.

Provider-side request sequence, with keys redacted:

baseline warmup   Bearer <baseline>  gpt-5.4-mini     LIVE_PROOF_REPLY_1
activation probe  Bearer <saved>     gpt-5.4-mini     LIVE_PROOF_REPLY_2
follow-up turn    Bearer <saved>     gpt-5.4-mini     LIVE_PROOF_REPLY_3

The discriminating latest-stable run used the published [email protected] package with the same fixture. It activated the saved credential as openai/starter-model and persisted agents.entries.main.model = openai/starter-model@openai:saved-proof, reproducing the reported drift. The head above instead persisted openai/gpt-5.4-mini@openai:saved-proof.

Existing-state compatibility

The fixture initially used the legacy auth-profiles.json layout. The reviewed head's doctor --fix migrated it to the current state SQLite database, retained both profile IDs and credentials, and the CLI listed and activated both afterwards. This PR adds no persisted-format change.

Latest-stable upgrade readback

The readback was verified on a8b7787e, rebased onto current main (reports 2026.10.6). The branch was then rebased once more to e3d624de solely to pick up upstream 82c46546, a test-fixture typecheck fix; the source diff is unchanged. I seeded an isolated state with the published [email protected] (fe06181) package: its doctor --fix migrated the legacy store and stamped meta.lastTouchedVersion=2026.10.6 with schema v20, and one baseline turn ran against that state (LIVE_PROOF_REPLY_1, baseline credential, gpt-5.4-mini).

The candidate head then opened the same state. Its doctor --fix advanced schema v20 -> v31 and retained pre-migration SQLite backups. models auth activate openai:saved-proof --agent main printed Inference verified: openai/gpt-5.4-mini and Sign-in verified and saved. with no downgrade-guard warning. The follow-up turn returned LIVE_PROOF_REPLY_3 on gpt-5.4-mini using the saved credential. After the upgrade, agents.defaults.model.primary remained openai/gpt-5.4-mini, and only agents.entries.main.model became openai/gpt-5.4-mini@openai:saved-proof.

Machine-checkable result: upgrade-20261023e/upgrade-verification.json (13/13 checks), with logs in upgrade-20261023e/ under contributions/pr-evidence-20261023/.

Command:

OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs run \
  --config test/vitest/vitest.infra.config.ts \
  src/system-agent/setup-inference-activate.test.ts --maxWorkers=1

tsgo could not be run on this host because the available glibc is older than the installed TypeScript native binary requires, so this PR does not claim a local typecheck result.

CI note

check-test-types-core-1 failed only in src/hooks/loader.cache-invalidation.test.ts (managedHooksDir), which this PR does not touch; it is a pre-existing failure on main already fixed by upstream 82c46546. The final rebase includes that fix.

AI Assistance

AI-assisted implementation and test preparation. The contributor reviewed the diff, ran both the focused regression and base-red checks, and verified the final patch.

@clawsweeper

clawsweeper Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@xiaopan-xydt

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Saved-auth discovery and activation preserve the target agent’s current same-provider model, including aliases and primary-versus-utility roles.

Example: Activate openai:saved-proof, saved with openai/starter-model, while the agent uses openai/gpt-5.4-mini.

  • Before: Activation selects openai/starter-model.
  • After: Activation verifies the saved credential and retains openai/gpt-5.4-mini.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful focused repair with shipped-CLI evidence, persisted-state compatibility readback, and the previous finding resolved.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied isolated CLI trace exercises saved-auth activation against a loopback Responses provider, shows the saved credential used for verification and a subsequent agent turn on gpt-5.4-mini, and includes persisted-state readback; the latest role correction preserves that primary-model path and adds discovery-to-activation regression coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Activating a saved sign-in can reset the agent to the provider’s starter model.
Reason: The change repairs the remaining reported model drift without adding configuration, changing storage formats, or weakening activation safeguards.

Merge readiness

✅ Ready for maintainer review

This PR fixes remaining saved-sign-in model drift on current main; the previous role-isolation finding is resolved, with no new actionable findings.

Priority: P2
Reviewed head: ca0cc3bb69470968febbdef66864ec50a7716923

Before merge

None.

Findings

None.

Agent review details

How this fits together

Model Setup and CLI saved-auth activation consume agent configuration and saved credentials, resolve a candidate model, verify inference, and persist the selected model and credential binding.

flowchart LR
  A[Model Setup or CLI] --> B[Saved auth discovery and staging]
  C[Agent configuration] --> D[Existing route resolver]
  D --> B
  E[Saved credential] --> B
  B --> F[Inference verification]
  F --> G[Existing activation and persistence owner]
Loading

Technical review

Best possible solution:

Use the shared role-aware route resolver for saved-auth discovery and staging while retaining explicit overrides, provider boundaries, and existing activation safeguards.

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

Current-main discovery and staging visibly select the saved starter model; the contributor’s published-package CLI comparison also records that drift.

Is this the best way to solve the issue?

The patch places the shared selection decision beside the existing route owner and updates both consumers, with distinct alias and role-isolation regressions.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Saved-auth staging changes intended behavior with a stated reason (a305caf: Persist retry details and keep replacement credentials inactive until verification, confirmation, and configuration application; later refactoring carried the stored-model selection forward.)
  • Saved-auth discovery changes intended behavior with a stated reason (c518cbd: Fold private discovery handoffs into their consuming operation while preserving existing behavior; the PR explains why advertising the stored starter model causes model drift.)
  • Activation fixture and cleanup keeps the original intent (496433f: Exercise credential retention and activation through the shared setup owner; extracted helpers retain existing assertions and cleanup while enabling the additional regression suite.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +73, Tests +120. Total +193 across 8 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 3 76 3 +73
Tests 5 150 30 +120
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 226 33 +193

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Saved-sign-in activation can replace a deliberately selected model with a starter model; the repair is focused and explicit model selection remains available.
  • 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 (7 earlier review cycles)
  • reviewed 2026-10-22T17:37:20.837Z sha e597d3b8db83ad93964b4343b9fae06a22220de8 :: needs real behavior proof before merge. :: [P2] Resolve aliases before staging the current model
  • reviewed 2026-10-22T18:09:28.255Z sha c679f4a9ff5ae8ff46d69efb9d47fd07513bd684 :: needs real behavior proof before merge. :: [P2] Resolve a definite model before parsing its provider
  • reviewed 2026-10-22T18:30:03.599Z sha 437c1ce5e57e38eabd4745bcfe18dca55a04f6ac :: needs real behavior proof before merge. :: [P2] Preserve the current model in saved-auth discovery too
  • reviewed 2026-10-22T18:56:45.421Z sha 6aec0cf6a3450bc81e0f434b170920fe2cd16071 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-23T01:38:06.472Z sha 6aec0cf6a3450bc81e0f434b170920fe2cd16071 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-23T02:46:34.471Z sha a8b7787e7b97fc4c3c9507835c008ded714ef26f :: needs maintainer review before merge. :: none
  • reviewed 2026-10-24T21:26:25.948Z sha e3d624d :: needs changes before merge. :: [P2] Preserve the primary-versus-utility role during model lookup

Reviewed October 24, 2026, 7:16 PM ET / 23:16 UTC (Revision 8).

@xiaopan-xydt

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. and removed merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. 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 22, 2026
@xiaopan-xydt

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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. labels Oct 24, 2026
@xiaopan-xydt

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The head now also scopes saved-auth model lookup and its discovery cache by modelTarget, so a utility-only model is not promoted to primary. Latest full run: setup-inference-activate.test.ts + setup-inference-saved-model.test.ts 43 passed, setup-inference-detect.test.ts 19 passed; oxfmt/oxlint/git diff --check pass.

@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 24, 2026
@xiaopan-xydt

Copy link
Copy Markdown
Contributor Author

Closing this PR: the setup-inference module has since been restructured on main and the core file this change builds on (setup-inference-saved-model.ts) no longer exists, so the change no longer applies to the current architecture. Issue #167381 remains open and accurately describes the remaining behavior.

@xiaopan-xydt
xiaopan-xydt deleted the fix/saved-auth-model-preservation-167381 branch November 14, 2026 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

1 participant