Skip to content

fix(auth-profiles): break self-reinforcing session auth override loop (#85126)#85311

Closed
mlaihk wants to merge 1 commit into
openclaw:mainfrom
mlaihk:fix/85126-session-auth-override-loop
Closed

fix(auth-profiles): break self-reinforcing session auth override loop (#85126)#85311
mlaihk wants to merge 1 commit into
openclaw:mainfrom
mlaihk:fix/85126-session-auth-override-loop

Conversation

@mlaihk

@mlaihk mlaihk commented May 22, 2026

Copy link
Copy Markdown

Description

Fixes a self-reinforcing loop in resolveSessionAuthProfileOverride that permanently pins a session to the wrong auth profile after a fallback occurs.

Root Cause

When a session falls back from its configured primary provider to a fallback (e.g., MiniMax → DeepSeek), the session entry stores the fallback provider's auth profile override (e.g., deepseek:default) with source: "auto". On every subsequent turn, resolveSessionAuthProfileOverride builds the auth profile order exclusively from the current run's provider (the fallback, e.g., deepseek), never from the agent's configured default model provider (e.g., minimax). Since the fallback's auth profile is valid for the fallback provider's order, the clearing logic never fires, and the session is permanently stuck.

Fix

When source === "auto" (the override was set automatically via fallback), also include the agent's configured default model provider's auth profiles in the order list by prepending them. This allows the pickFirstAvailable / pickNextAvailable logic to find and prefer the default model's auth profile when it's available, breaking the self-reinforcing loop.

Testing

  • For an agent configured with minimax/MiniMax-M2.7 as primary and deepseek/deepseek-v4-flash as fallback:
    • Before: After the first fallback to DeepSeek, the session permanently pins to deepseek:default. Auth order is ["deepseek:default"] → no alternative to pick.
    • After: Auth order becomes ["minimax:global", "deepseek:default"]. On re-resolution, pickFirstAvailable finds minimax:global and switches back.

Related

Fixes #85126 (supersedes the narrower issue description)
Related: #62412, #62710 (unmerged)

When a session falls back to a different provider (e.g. minimax → deepseek),
the session entry stores the fallback provider's auth profile override
(e.g. deepseek:default) with source 'auto'. On subsequent turns,
resolveSessionAuthProfileOverride builds the auth profile order from the
current run's provider (deepseek), not the agent's configured default
model provider (minimax). Since deepseek:default is valid for deepseek's
auth order, it's never re-evaluated against the agent's actual default
model, creating a self-reinforcing loop.

Fix: when source === 'auto', also include the agent's configured default
model provider's auth profiles in the order list. This ensures the
resolver can find and prefer the default model's auth profile when it's
available, breaking the loop.

Fixes openclaw#85126
@mlaihk
mlaihk requested a review from a team as a code owner May 22, 2026 10:41
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 22, 2026
@clawsweeper

clawsweeper Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 24, 2026, 6:18 AM ET / 10:18 UTC.

Summary
The PR prepends the agent primary provider's auth-profile order when automatic session auth override resolution handles a fallback provider.

PR surface: Source +29. Total +29 across 1 file.

Reproducibility: yes. source-reproducible. Current main passes the already-selected provider into the auth-profile resolver, and the resolver returns only an auth profile id, so adding another provider's profile order can create a provider/auth mismatch.

Review metrics: 1 noteworthy metric.

  • Persisted Session Auth Selection: 1 resolver write path changed. The PR changes logic that can write authProfileOverride back to session state, so upgrade/runtime behavior needs explicit proof before merge.

Stored data model
Persistent data-model change detected: serialized state: src/agents/auth-profiles/session-override.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🧂 unranked krab
Result: blocked until real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Move the recovery to a path that updates or clears provider, model, and auth profile together.
  • [P2] Add focused regression coverage for cross-provider auto fallback recovery without selecting an incompatible auth profile.
  • [P1] Add redacted real behavior proof from the affected setup, with keys, phone numbers, IP addresses, non-public endpoints, and other private details removed; updating the PR body should trigger re-review, or a maintainer can comment @clawsweeper re-review.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body has a hypothetical before/after scenario but no redacted after-fix terminal output, logs, recording, linked artifact, or live runtime proof from the affected setup. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] Merging this can return a MiniMax auth profile while the active run provider remains DeepSeek, causing auth failure or cross-provider credential routing.
  • [P1] The diff mutates persisted session auth selection without after-fix proof from the affected WebChat/TUI, gateway, or comparable real setup.
  • [P1] The linked canonical bug and broader resolver tracker are still open, so this auth-only patch is not proven to be the complete owner-boundary fix.

Maintainer options:

  1. Move Recovery To Model/Session Selection (recommended)
    Repair stale auto fallback state where provider, model, and auth profile can be selected or cleared as one coherent state, then leave auth-profile resolution provider-scoped.
  2. Require Real Runtime Proof
    Ask for redacted terminal output, logs, or a recording from the affected session flow before any merge decision.
  3. Fold Into The Resolver Tracker
    If maintainers prefer the broader shared resolver first, preserve this reproduction context on Refactor session model/auth state resolution #87957 and pause or close this branch.

Next step before merge

  • [P1] Human review is needed because the blocker is the auth/session owner-boundary decision plus missing contributor real behavior proof, not a narrow automated repair on this branch.

Security
Needs attention: The diff has no supply-chain change, but it introduces a concrete auth-boundary risk by allowing cross-provider profile selection.

Review findings

  • [P1] Keep auth profiles tied to the active provider — src/agents/auth-profiles/session-override.ts:184
  • [P2] Add stale-fallback regression coverage — src/agents/auth-profiles/session-override.ts:167
Review details

Best possible solution:

Recover stale fallback provider, model, display, and auth state together in session/model selection, while keeping the auth-profile resolver scoped to the active provider.

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

Yes, source-reproducible. Current main passes the already-selected provider into the auth-profile resolver, and the resolver returns only an auth profile id, so adding another provider's profile order can create a provider/auth mismatch.

Is this the best way to solve the issue?

No. The PR is a plausible symptom fix, but provider, model, display, and auth need to recover together in session/model selection instead of broadening a provider-scoped auth helper.

Full review comments:

  • [P1] Keep auth profiles tied to the active provider — src/agents/auth-profiles/session-override.ts:184
    resolveSessionAuthProfileOverride returns only an auth profile id; it does not switch the run provider/model. Prepending the agent-primary provider's order here can return minimax:global while the caller still executes DeepSeek, causing auth failure or cross-provider credential routing. Move this recovery to the model/session selection path so provider, model, and auth profile change together.
    Confidence: 0.9
  • [P2] Add stale-fallback regression coverage — src/agents/auth-profiles/session-override.ts:167
    This changes auto session auth recovery but adds no regression for the MiniMax-primary/DeepSeek-fallback shape from the linked bug. Without coverage proving selected provider/model and auth profile recover together, the PR can pass while preserving the stale runtime mismatch.
    Confidence: 0.82

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P1: The PR targets and currently risks a real auth/session routing bug that can pin active agent sessions to the wrong provider/profile.
  • merge-risk: 🚨 auth-provider: The diff can select an auth profile for the agent default provider while the active run still uses the fallback provider.
  • merge-risk: 🚨 session-state: The changed resolver persists authProfileOverride back into session state and can make automatic selection incoherent across turns.
  • merge-risk: 🚨 security-boundary: Cross-provider auth profile selection can route provider-specific credentials outside their intended provider boundary.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body has a hypothetical before/after scenario but no redacted after-fix terminal output, logs, recording, linked artifact, or live runtime proof from the affected setup. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +29. Total +29 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 29 0 +29
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 29 0 +29

Security concerns:

  • [medium] Cross-provider credential selection — src/agents/auth-profiles/session-override.ts:184
    Prepending the agent default provider's auth order can return a MiniMax profile for a DeepSeek run, risking credential use outside the intended provider boundary or an auth failure.
    Confidence: 0.78

What I checked:

Likely related people:

  • steipete: History shows Peter Steinberger introduced sticky auth profile rotation and later moved model override auth handling into session-override.ts. (role: introduced auth-profile resolver behavior; confidence: high; commits: 8c3cdba21c57, 1e05925e47b2; files: src/agents/auth-profiles/session-override.ts, src/auto-reply/reply/get-reply-run.ts)
  • vincentkoc: Current main and latest release commits touch the same auth/session/model-selection surfaces, and earlier history includes per-agent defaults and fallback work. (role: recent area contributor; confidence: medium; commits: 2ad2e4f2dc6c, aa69b12d0086, c96a12aeb9e8; files: src/agents/auth-profiles/session-override.ts, src/auto-reply/reply/model-selection.ts, src/gateway/server-methods/sessions.ts)
  • jalehman: History shows Josh Lehman working on session lifecycle hooks and related auth/session behavior in the same decision surface. (role: adjacent auth/session contributor; confidence: medium; commits: 2b28e758222c, 1c83e2eec727; files: src/gateway/server-methods/sessions.ts, src/agents/auth-profiles/session-override.ts)
  • osolmaz: Onur authored the broader closed repair branch and the open shared resolver tracker connected to this bug class. (role: likely follow-up owner; confidence: high; commits: b0d73d733352; files: src/auto-reply/reply/model-selection.ts, src/gateway/server-methods/sessions.ts, src/gateway/session-utils.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels May 22, 2026
@clawsweeper

clawsweeper Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@RomneyDa

Copy link
Copy Markdown
Member

Heads up: this PR needs to be updated against current main before the new required Dependency Guard check can pass.

@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jun 19, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

@openclaw-barnacle openclaw-barnacle Bot closed this Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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: XS stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Control UI (TUI/WebChat) sessions auto-select wrong authProfileOverride (deepseek instead of minimax) at creation

3 participants