Skip to content

fix(agents): stored auth profile order is ignored when resolving CLI runtime aliases - #129165

Merged
steipete merged 2 commits into
openclaw:mainfrom
masatohoshino:runtime-alias-auth-order-store
Aug 26, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
masatohoshino:runtime-alias-auth-order-store

Conversation

@masatohoshino

@masatohoshino masatohoshino commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Related: #119946

What Problem This Solves

Fixes an issue where operators using openclaw models auth order set would still get the configured/default execution backend instead of the CLI backend they selected. Stored credentials could also be ignored when login had not created matching auth.profiles config metadata.

Why This Change Was Made

Credential selection and CLI runtime routing now share one stored-over-config order lookup. Runtime routing consumes the lifecycle-published auth snapshot, including the requested agent's inherited auth owner, without reopening SQLite on request paths. Selected profile metadata comes from config or the actual stored credential; explicit model-runtime policy and explicit auth pins retain precedence.

The rewrite preserves the existing repair for orders containing only deleted profiles, honors explicit empty configured orders, and keeps the first existing direct-API profile authoritative. It also removes unreachable OpenAI order-alias merging: both provider constants already identify openai, so the alias path could never win. Credential eligibility, cooldowns, and OpenAI API-key versus OAuth handling remain owned by the existing credential selector.

User Impact

Stored auth order now controls the intended runtime, even when it conflicts with config or the selected credential exists only in the auth store. Clearing the stored order returns selection to configured/automatic behavior. Merely discovering a sole CLI credential does not implicitly select it. No new config option, dependency, database schema, or protocol change.

Documentation now describes stored-order precedence and the SQLite auth store. Production delta: +67 / −97 (net −30); tests: +176 / −5; docs: +4 / −1. Thanks @masatohoshino for the original fix and production reproduction; contributor credit is retained.

Evidence

Reviewed candidate: 410a8e8c1be3f9a0bbe7fe3f9bc8b08652e13a56.

  • Before/after regressions: baseline ignored stored-only and conflicting stored order and routed despite an empty configured order. Additional failing-before cases caught stale-profile repair, a first store-only API profile, and stored-only CLI order/pins without config metadata.

  • 77 tests passed across runtime aliases, credential ordering, snapshot lifecycle, external CLI selection, and CLI auth-order commands:

    OPENCLAW_VITEST_MAX_WORKERS=2 node scripts/run-vitest.mjs \
      src/agents/model-runtime-aliases.test.ts \
      src/agents/auth-profiles/order.test.ts \
      src/agents/auth-profiles/runtime-snapshots.test.ts \
      src/agents/auth-profiles/external-cli-auth-selection.test.ts \
      src/commands/models/auth-order.test.ts
  • Eight real production-module scenarios passed on macOS / Node v24.19.0 with isolated synthetic state: actual setAuthProfileOrder → SQLite reload → runtime snapshot publication → actual Anthropic plugin discovery → runtime resolution. No mocks or provider requests:

    Scenario Observed runtime
    Stored order, no config order CLI
    Stored order conflicts with config CLI
    Clear stored order with direct-API config Direct provider
    Config-only CLI order CLI
    Clear order with multiple profiles Direct provider
    Stored CLI order without config profile metadata CLI
    Stored CLI pin without matching config metadata CLI
    Sole stored CLI with no explicit selection Direct provider
  • Local and complete-branch structured autoreview passed with no actionable findings; separate independent owner-boundary review passed.

  • Direct Codex contract inspection: codex-rs/protocol/src/auth.rs:5-65, codex-rs/model-provider/src/auth.rs:197-220, and codex-rs/model-provider/src/provider.rs:389-429 at upstream d47e5cc0e2bb. These preserve the separate API-key/OAuth shapes; this change does not alter Codex auth.

Proof boundary: the production harness verifies persisted selection and resolver output, not an authenticated turn or Gateway snapshot-refresh lifecycle. The latter remains covered by the unchanged snapshot/auth-order tests and the preceding merged #119946. Callers that do not publish a runtime snapshot retain config-only behavior.

ClawSweeper rank-up: focused resolver tests are complete; required CI must be green on the pushed candidate before landing. The earlier CLI-help probe timed out during a cold build and was not a runtime-routing failure. The prior +59 production-line concern is eliminated by the net-negative owner refactor.

…untime aliases

`resolveCliRuntimeFromAuthProfile` built its ordered profile list from
`cfg.auth.order` alone, and `RuntimeAuthAliasParams` carried no auth store at
all, so the order an operator sets through `models auth order set` never
reached CLI runtime alias resolution. The canonical sibling resolver,
`resolveAuthProfileOrderWithMetadata`, already reads the stored order first and
falls back to config, so the two disagreed about the same question.

With no config `auth.order` and two profiles sharing a provider auth key, the
ordered list came out empty and the resolver fell through to its "exactly one
compatible profile" branch, returning undefined. The gateway then reported
model availability and picked the turn's execution backend as if the reorder
had not happened, and no restart cleared it because the store was never read on
this path.

Rather than re-deriving the precedence at the call site, extract it: the
stored-first explicit-order resolution moves out of
`resolveAuthProfileOrderWithMetadata` into `resolveExplicitAuthOrderSelection`,
and alias routing becomes its second consumer. Both now resolve the order
through one implementation, across normalized provider keys, so they cannot
drift apart again. The store is read from the lifecycle-published runtime
snapshot for the requested agent and its declared inherited owner, matching how
prepared model catalog and registry resolve the same pair; no new snapshot API
and no SQLite reopen on request paths.

An authored stored order also owns selection, so it suppresses the
unique-compatible-profile fallback the way the canonical resolver does.

Tests cover stored-order-only selection, stored-over-config precedence,
non-normalized stored keys, inheritance from the main agent, authoritative
empty orders with a control for the fallback that must survive, and the
unchanged config-only path.
@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Aug 25, 2026
@masatohoshino
masatohoshino marked this pull request as ready for review August 25, 2026 08:30
@masatohoshino
masatohoshino requested a review from a team as a code owner August 25, 2026 08:30
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 25, 2026
@clawsweeper

clawsweeper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 26, 2026, 4:26 PM ET / 20:26 UTC.

ClawSweeper review

What this changes

The PR makes CLI runtime alias selection use the persisted per-agent auth-profile order before configured order, including credentials present only in the SQLite auth store.

Merge readiness

⚠️ Needs maintainer review before merge - 3 items remain

Keep this PR open: it fixes a real current-main gap, but its revised stale-order path still disagrees with the canonical credential selector and can route a CLI-selected execution back to direct provider execution.

Priority: P2
Reviewed head: 410a8e8c1be3f9a0bbe7fe3f9bc8b08652e13a56

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The proof is meaningful, but the canonical stale-order behavior is not preserved by the revised alias resolver.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body records eight after-fix production-module SQLite, snapshot-publication, plugin-discovery, and resolver scenarios with observed routing outcomes; the remaining blocker is the uncovered mixed stale-order case.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body records eight after-fix production-module SQLite, snapshot-publication, plugin-discovery, and resolver scenarios with observed routing outcomes; the remaining blocker is the uncovered mixed stale-order case.
Evidence reviewed 7 items Current-main gap: Current main exits runtime-alias resolution without config profile metadata and otherwise reads only configured order, so it does not consume persisted auth order.
Canonical stale-order repair: The PR's canonical selector repairs an all-missing explicit order by falling back to eligible stored profiles, then applies normal ordering.
Alias-routing divergence: The alias resolver treats an all-missing order as stale but then considers only configured profiles and returns no CLI runtime unless exactly one is compatible, rather than using the repaired stored-profile selection.
Findings 1 actionable finding [P2] Align stale-order repair with canonical profile selection
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/agents/model-runtime-aliases.test.ts

Result: FAIL (partial) — step 2 expect_output stored auth order: expected terminal output was not visible within 30 seconds: "stored auth order"

[test] starting test/vitest/vitest.agents-core.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-129165-x9IQg9/target

 ✓  agents-core  src/agents/model-runtime-aliases.test.ts (25 tests) 45ms

 Test Files  1 passed (1)
      Tests  25 passed (25)
   Start at  20:27:06
   Duration  9.16s (transform 7.07s, setup 952ms, import 7.80s, tests 45ms, environment 0ms)

[test] passed 1 Vitest shard in 15.32s
[test] starting test/vitest/vitest.agents-core.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-129165-x9IQg9/target

 ✓  agents-core  src/agents/model-runtime-aliases.test.ts (25 tests) 39ms

 Test Files  1 passed (1)
      Tests  25 passed (25)
   Start at  20:27:22
   Duration  4.25s (transform 2.29s, setup 431ms, import 3.55s, tests 39ms, environment 0ms)

[test] passed 1 Vitest shard in 10.30s

Assertions:

  • FAIL expect_output: stored auth order

How this fits together

Auth-order commands persist per-agent credential preferences and publish a runtime snapshot. Runtime alias selection consumes that state to choose whether an agent executes through a direct provider or a compatible local CLI runtime.

flowchart LR
  Command[Auth order command] --> Store[Per-agent SQLite auth store]
  Store --> Snapshot[Published runtime snapshot]
  Config[Configured auth order] --> Selection[Profile-order selection]
  Snapshot --> Selection
  Selection --> Runtime[CLI runtime alias selection]
  Runtime --> Execution[Direct provider or CLI execution]
Loading

Before merge

  • Align stale-order repair with canonical profile selection (P2) - When every explicit-order profile is deleted, this falls through to configured profiles and only selects a CLI runtime when exactly one is compatible. The canonical selector instead repairs to eligible stored profiles and orders them, so a mixed stored direct-API and CLI setup can execute a CLI-selected credential through the direct route. The added stale-order test uses only a CLI profile and misses that state.
  • Resolve merge risk (P1) - Existing stored orders intentionally alter CLI-versus-direct routing after upgrade; the corrected head needs exact-head CI and the mixed stale-order case before merge.
  • Complete next step (P2) - A focused mechanical repair can align stale-order routing with the canonical selector and add the missing regression.

Findings

  • [P2] Align stale-order repair with canonical profile selection — src/agents/model-runtime-aliases.ts:264-290
Agent review details

Security

None.

PR surface

Source -30, Tests +171, Docs +3. Total +144 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 67 97 -30
Tests 1 176 5 +171
Docs 2 4 1 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 247 103 +144

Review metrics

Metric Value Why it matters
Production versus test delta production −30, tests +171, docs +3 The revised owner refactor is net-negative in production while adding focused coverage and documentation.
Runtime routing precedence 1 persisted-order precedence change Stored auth order now overrides configured order when selecting a CLI runtime, which can change execution routing for existing installations.

Merge-risk options

Maintainer options:

  1. Unify stale-order selection before merge (recommended)
    Route aliases through the canonical repaired stored-profile selection and add a mixed direct-API plus CLI regression before rerunning exact-head checks.
  2. Pause the behavior change
    Do not merge until the stale-order fallback has one authoritative outcome for both credential and runtime selection.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Use the canonical stale-order repair result for runtime alias routing, add a mixed stored direct-API and CLI regression, and rerun the focused auth-order and runtime-alias suite.

Technical review

Best possible solution:

Make runtime alias routing consume the same repaired profile-selection outcome as credential execution, then prove mixed stored direct-API and CLI profiles remain aligned after stale-order repair.

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

Yes in source: an all-deleted stored order plus stored direct-API and CLI credentials takes different paths in canonical selection and alias routing. It was not executed here because this is a read-only review.

Is this the best way to solve the issue?

No: shared precedence alone is insufficient because stale-order repair still has two outcomes; the alias resolver should consume the canonical repaired selection.

Full review comments:

  • [P2] Align stale-order repair with canonical profile selection — src/agents/model-runtime-aliases.ts:264-290
    When every explicit-order profile is deleted, this falls through to configured profiles and only selects a CLI runtime when exactly one is compatible. The canonical selector instead repairs to eligible stored profiles and orders them, so a mixed stored direct-API and CLI setup can execute a CLI-selected credential through the direct route. The added stale-order test uses only a CLI profile and misses that state.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a27f7fe56c28.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body records eight after-fix production-module SQLite, snapshot-publication, plugin-discovery, and resolver scenarios with observed routing outcomes; the remaining blocker is the uncovered mixed stale-order case.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P2: A bounded but user-visible routing mismatch remains when stale order entries coexist with multiple stored credentials.
  • merge-risk: 🚨 compatibility: Stored per-agent auth preferences can change an existing installation from direct-provider execution to CLI execution after upgrade.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body records eight after-fix production-module SQLite, snapshot-publication, plugin-discovery, and resolver scenarios with observed routing outcomes; the remaining blocker is the uncovered mixed stale-order case.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body records eight after-fix production-module SQLite, snapshot-publication, plugin-discovery, and resolver scenarios with observed routing outcomes; the remaining blocker is the uncovered mixed stale-order case.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/agents/model-runtime-aliases.test.ts src/agents/auth-profiles/order.test.ts src/agents/auth-profiles/runtime-snapshots.test.ts src/agents/auth-profiles/external-cli-auth-selection.test.ts src/commands/models/auth-order.test.ts.

What I checked:

  • Current-main gap: Current main exits runtime-alias resolution without config profile metadata and otherwise reads only configured order, so it does not consume persisted auth order. (src/agents/model-runtime-aliases.ts:225, a27f7fe56c28)
  • Canonical stale-order repair: The PR's canonical selector repairs an all-missing explicit order by falling back to eligible stored profiles, then applies normal ordering. (src/agents/auth-profiles/order.ts:373, 410a8e8c1be3)
  • Alias-routing divergence: The alias resolver treats an all-missing order as stale but then considers only configured profiles and returns no CLI runtime unless exactly one is compatible, rather than using the repaired stored-profile selection. (src/agents/model-runtime-aliases.ts:264, 410a8e8c1be3)
  • Affected automatic caller: The unpinned automatic route used by BTW invokes the alias resolver, so the mismatch can affect actual execution choice. (src/agents/btw.ts:1140, 410a8e8c1be3)
  • Insufficient regression coverage: The new deleted-order test supplies only a configured CLI profile, so it cannot expose the normal mixed direct-API plus CLI stored-profile case. (src/agents/model-runtime-aliases.test.ts:171, 410a8e8c1be3)
  • Related merged predecessor: The earlier Gateway-refresh repair is merged, but it refreshes auth state rather than making runtime aliases consume persisted order; this PR remains distinct work. (src/commands/models/auth-order.ts, 20fe56116d3d)

Likely related people:

  • steipete: Introduced the current-main runtime-alias resolver and authored the revised PR head. (role: recent area contributor and current implementation author; confidence: high; commits: 3601020fb4c2, 410a8e8c1be3; files: src/agents/model-runtime-aliases.ts, src/agents/auth-profiles/order.ts)
  • wangmiao0668000666: Authored the merged Gateway-refresh predecessor for auth-order writes, which is adjacent but does not cover alias resolution. (role: adjacent auth-order lifecycle contributor; confidence: medium; commits: 20fe56116d3d; files: src/commands/models/auth-order.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Make the mixed stored direct-API plus CLI stale-order case select the same runtime as canonical credential selection.
  • Rerun the focused alias/auth-order suite and let required exact-head CI complete after the repair.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-25T08:36:25.680Z sha b8279e5 :: needs maintainer review before merge. :: none

Share stored-over-config precedence, preserve stale-profile repair, and route explicitly selected stored credentials without config metadata. Remove unreachable OpenAI order-alias merging.

Co-authored-by: masatohoshino <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Aug 26, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

Updated the original contributor branch at 410a8e8. The owner refactor now removes 30 production lines, preserves stale-profile repair, and covers stored-only credentials and explicit pins without config metadata. All 77 focused tests, eight real SQLite/snapshot/plugin-discovery scenarios, and complete-branch structured autoreview pass. The PR body records proof and its limits. Required CI on this candidate remains the landing gate.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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 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. labels Aug 26, 2026
@steipete
steipete merged commit df559c3 into openclaw:main Aug 26, 2026
264 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
…runtime aliases (openclaw#129165)

* fix(agents): honor the stored auth profile order when resolving CLI runtime aliases

`resolveCliRuntimeFromAuthProfile` built its ordered profile list from
`cfg.auth.order` alone, and `RuntimeAuthAliasParams` carried no auth store at
all, so the order an operator sets through `models auth order set` never
reached CLI runtime alias resolution. The canonical sibling resolver,
`resolveAuthProfileOrderWithMetadata`, already reads the stored order first and
falls back to config, so the two disagreed about the same question.

With no config `auth.order` and two profiles sharing a provider auth key, the
ordered list came out empty and the resolver fell through to its "exactly one
compatible profile" branch, returning undefined. The gateway then reported
model availability and picked the turn's execution backend as if the reorder
had not happened, and no restart cleared it because the store was never read on
this path.

Rather than re-deriving the precedence at the call site, extract it: the
stored-first explicit-order resolution moves out of
`resolveAuthProfileOrderWithMetadata` into `resolveExplicitAuthOrderSelection`,
and alias routing becomes its second consumer. Both now resolve the order
through one implementation, across normalized provider keys, so they cannot
drift apart again. The store is read from the lifecycle-published runtime
snapshot for the requested agent and its declared inherited owner, matching how
prepared model catalog and registry resolve the same pair; no new snapshot API
and no SQLite reopen on request paths.

An authored stored order also owns selection, so it suppresses the
unique-compatible-profile fallback the way the canonical resolver does.

Tests cover stored-order-only selection, stored-over-config precedence,
non-normalized stored keys, inheritance from the main agent, authoritative
empty orders with a control for the fallback that must survive, and the
unchanged config-only path.

* fix(agents): align runtime routing with stored auth selection

Share stored-over-config precedence, preserve stale-profile repair, and route explicitly selected stored credentials without config metadata. Remove unreachable OpenAI order-alias merging.

Co-authored-by: masatohoshino <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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.

2 participants