Skip to content

fix(auth): retain the selected account when migrating Codex sessions - #118205

Merged
steipete merged 2 commits into
mainfrom
codex/fix-58498-codex-session-auth-profile-migration
Aug 2, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/fix-58498-codex-session-auth-profile-migration

Conversation

@steipete

@steipete steipete commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #58498

What Problem This Solves

Fixes an issue where upgrading or repairing an installation with multiple ChatGPT OAuth accounts could silently switch an existing session to the wrong account. Session status and rate-limit usage then belonged to a different person even though the user had explicitly selected another account.

Why This Change Was Made

Doctor now derives one collision-safe account migration plan across configuration, existing SQLite credentials, and legacy credential files, and carries that exact ephemeral plan to the existing late session-repair owner. Already-affected installations are repaired by reconstructing account identity only from authentic archived credentials with verified migration receipts and an unambiguous matching OAuth account. Ambiguous, tampered, unresolved, unrelated-agent, and incomplete migrations fail closed.

The sibling Codex source was directly inspected: codex-rs/app-server-protocol/src/protocol/common.rs confirms account/rateLimits/read has no account selector, and codex-rs/app-server/src/request_processors/account_processor.rs obtains rate limits from its selected AuthManager account. Correct host-side account selection is therefore required rather than attempting to pass an unsupported account argument.

User Impact

Existing and newly upgraded multi-account installations retain the chosen ChatGPT account through doctor repair, including installations already affected by an earlier migration. Session status and quota reporting again reflect the intended user.

Evidence

  • Reproduced the complete account-selection failure RED using actual legacy OAuth credentials, real SQLite session/auth stores, canonical doctor migration, and the actual status rendering path.
  • Fresh migration and already-migrated archived-installation cases both now show the selected Kate account with 75 percent quota instead of the unrelated Peter account with 20 percent quota.
  • Independent xhigh review verified 16 focused regressions across five owner files: existing SQLite profile collisions, config-only credentials, unresolved sidecars, receipt/archive tampering, ambiguous identities, four-agent isolation and inherited credentials, late canonical session migration ordering, read-only malformed-session preview, and idempotence.
  • Mandatory fresh structured xhigh autoreview passed with no accepted or actionable findings.
  • No runtime legacy aliases, raw SQL runtime writes, SQLite schema version change, or persisted temporary migration map.

Final-Head CI and Account Proof

  • Actual doctor migration through real SQLite credentials and session stores renders Week 75% left for the selected account and explicitly rejects the unrelated account output Week 20% left (src/commands/doctor-auth-flat-profiles.test.ts:113, :135-137).
  • Dedicated Blacksmith Testbox remote corepack pnpm check:test-types: PASS across core, plugin, and root test-type projects.
  • Same isolated remote box: corepack pnpm test src/flows/doctor-health-contribution-runners.state.codex.test.ts src/node-host/mcp.test.ts: 2 files, 19 tests PASS.
  • Fresh independent xhigh autoreview including P0, P1, and P2: no actionable findings.
  • Direct sibling Codex upstream contract inspection: codex-rs/app-server-protocol/src/protocol/v2/account.rs:20, :184, :269; codex-rs/app-server-protocol/src/protocol/common.rs:1192; codex-rs/app-server/src/request_processors/account_processor.rs:1010; codex-rs/login/src/auth/manager.rs:520, :2115; and codex-rs/login/src/token_data.rs:11.

Unrelated Mainline CI Repair

The existing MCP pagination ceiling test could exhaust its unrelated 50 ms wall-clock deadline under loaded CI before reaching its required 128-page ceiling. This PR isolates that single test with a 1,000 ms request deadline and retains the separate explicit 50 ms deadline regression unchanged. This repairs the independently reproduced existing-main CI failure without changing production behavior.

Exact-Head Redacted Operator-Visible Transcript

Executed both committed scenarios against actual doctor migration, isolated temporary SQLite credentials/session stores, authenticated account selection, and the actual status renderer. A process-local read-only observer prints only the safe quota substring; no OAuth credentials are exposed.

[actual /status][already-migrated verified archive repair] Week 75% left
[negative assertion][already-migrated verified archive repair] wrong-account Week 20% left: absent (PASS)
PASS repairs an already-migrated selected account from its verified auth archive

[actual /status][fresh auth and SQLite session migration] Week 75% left
[negative assertion][fresh auth and SQLite session migration] wrong-account Week 20% left: absent (PASS)
PASS preserves the selected Codex account across auth migration, SQLite sessions, and status

Test Files  1 passed (1)
Tests       2 passed | 47 skipped (49)

Direct Codex contract reverified: codex-rs/app-server-protocol/src/protocol/common.rs:1058 has no account selector for rate-limit reads; codex-rs/app-server/src/request_processors/account_processor.rs:1033 uses the current authenticated account; codex-rs/login/src/auth/manager.rs:2029 and :2115 enforce account-matched reload.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: XL maintainer Maintainer-authored PR labels Aug 2, 2026
@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 6:37 PM ET / 22:37 UTC.

ClawSweeper review

What this changes

The branch carries Doctor’s collision-safe legacy Codex-to-OpenAI profile mapping into persisted session repair so a migrated session retains the OAuth account selected by the operator.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 5 items remain

Keep this PR open for maintainer review. The local migration and session-owner path is coherent and the PR includes focused coverage plus redacted terminal output, but the repository requires this reviewer to inspect sibling ../codex source before issuing a Codex verdict or accepting the proof as sufficient; that checkout is absent and cannot be cloned in this read-only environment.

Priority: P2
Reviewed head: 5af395e130bd829f97eeb9fb6792a1c93f3c2cc7
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The branch has focused tests and operator-visible terminal output, but the mandatory direct Codex contract check is unavailable, so it is not ready for a final merge verdict.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: The PR body includes a redacted exact-head terminal transcript showing the selected-account quota in two migration scenarios, but this review cannot mark it sufficient without the repository-required direct sibling-Codex contract inspection; redact private identifiers in any follow-up evidence. 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.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The PR body includes a redacted exact-head terminal transcript showing the selected-account quota in two migration scenarios, but this review cannot mark it sufficient without the repository-required direct sibling-Codex contract inspection; redact private identifiers in any follow-up evidence. 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 6 items Shared migration decision: The branch computes one collision-aware profile-id map during Doctor repair, passes it through the config health context, and supplies it to the later persisted-session repair owner.
Fail-closed account selection: The proposed session repair filters profile mappings against local credentials or identity-matched inherited OAuth credentials before changing a persisted override, avoiding a same-named account substitution.
Focused regression coverage: The branch adds selected-account status coverage for fresh and archived migrations, plus cases for tampered or ambiguous archives, unresolved credentials, agent isolation, and preview behavior.
Findings None None.
Security None None.

How this fits together

OpenClaw Doctor migrates retired openai-codex credentials and configuration into canonical OpenAI auth profiles. It then repairs durable session overrides, which determine the account used by status and quota reporting.

flowchart LR
  A[Legacy Codex credentials] --> B[Doctor migration plan]
  B --> C[Canonical OpenAI auth profiles]
  B --> D[Session route repair]
  D --> E[Stored selected account]
  E --> F[Status and quota output]
Loading

Decision needed

Question Recommendation
Can a reviewer with sibling ../codex available verify the account-selection and rate-limit contract against the exact Codex source before accepting this auth/session migration repair? Complete the Codex contract check: Inspect the referenced Codex account and rate-limit source, then resume exact-head merge review if it confirms the host-side selected-account mapping.

Why: The repository policy makes that direct dependency inspection a prerequisite for a Codex verdict and a proof-sufficient determination, and this review environment lacks the required checkout.

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The PR body includes a redacted exact-head terminal transcript showing the selected-account quota in two migration scenarios, but this review cannot mark it sufficient without the repository-required direct sibling-Codex contract inspection; redact private identifiers in any follow-up evidence. 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.
  • Resolve merge risk (P1) - This changes durable auth-profile and session mappings for existing multi-account installations; a wrong mapping could make status and quota resolve against a different account.
  • Resolve merge risk (P1) - The required direct Codex account-selection/rate-limit contract review could not be completed because sibling ../codex is absent in this read-only environment.
  • Complete next step (P2) - The protected maintainer label and unavailable mandatory Codex-source contract check require human review rather than an automated repair lane.
Agent review details

Security

None.

PR surface

Source +320, Tests +931. Total +1251 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 7 360 40 +320
Tests 6 936 5 +931
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 1296 45 +1251

Review metrics

Metric Value Why it matters
Persisted migration surfaces 3 durable owner paths changed The branch coordinates auth-profile import, Doctor flow context, and persisted session overrides, so upgrade behavior must be reviewed as one migration boundary.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-auth-flat-profiles.test.ts, migration/backfill/repair: src/commands/doctor-auth-flat-profiles.ts, migration/backfill/repair: src/commands/doctor-config-flow.test.ts, migration/backfill/repair: src/commands/doctor-config-flow.ts, migration/backfill/repair: src/commands/doctor/repair-sequencing.test.ts, migration/backfill/repair: src/commands/doctor/repair-sequencing.ts, and 15 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #58498
Summary: This PR directly addresses the canonical report’s selected OAuth profile versus displayed quota mismatch.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Verify the upstream account-selection contract (recommended)
    Before merge, inspect sibling Codex source and confirm that host-side session auth-profile selection controls the rate-limit account as this migration assumes.
  2. Accept the dependency-contract risk
    Merge based on local fail-closed migration logic and terminal evidence despite the missing direct upstream verification.
  3. Pause the migration repair
    Keep the PR open until a reviewer can complete the required upstream contract check.

Technical review

Best possible solution:

Complete the required direct Codex source inspection, then merge only if its selected-account and rate-limit behavior confirms that preserving the mapped session override is the canonical way to retain the operator’s selected account.

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

Yes, at source level: the added focused tests construct real SQLite auth/session stores, run Doctor migration and session repair, and assert the selected account’s status output. This read-only review did not execute the tests.

Is this the best way to solve the issue?

Unclear pending mandatory Codex contract inspection; locally the patch uses the appropriate owner boundary by carrying one collision-aware migration decision into later persisted-session repair rather than re-inferring account identity.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded multi-account status and quota correctness regression, not a crash, data-loss event, or security bypass.
  • merge-risk: 🚨 compatibility: Existing installations can have legacy profiles, archived credentials, and stored session overrides that Doctor rewrites during upgrade or repair.
  • merge-risk: 🚨 session-state: The patch changes durable session authProfileOverride values and their repair eligibility.
  • merge-risk: 🚨 auth-provider: The patch maps retired Codex OAuth profile identities to canonical OpenAI OAuth credentials.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body includes a redacted exact-head terminal transcript showing the selected-account quota in two migration scenarios, but this review cannot mark it sufficient without the repository-required direct sibling-Codex contract inspection; redact private identifiers in any follow-up evidence. 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

What I checked:

Likely related people:

  • steipete: Peter Steinberger authored both PR commits, including the central account-preservation commit, and the branch changes the Doctor auth/session migration boundary. (role: introduced the proposed repair; confidence: high; commits: dea0db6338ab, 5af395e130bd; files: src/commands/doctor-auth-flat-profiles.ts, src/commands/doctor/shared/codex-route-session-repair.ts, src/commands/doctor/repair-sequencing.ts)
  • Santiago: Current-main blame attributes the existing session-route repair core to Santiago’s commit a2ffa48, making this an adjacent-history routing contact. (role: recent area contributor; confidence: medium; commits: a2ffa4850d6c; files: src/commands/doctor/shared/codex-route-session-repair.ts)

Rank-up moves

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

  • Complete direct inspection of sibling ../codex account-selection and rate-limit source, then refresh the exact-head review.

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 (2 earlier review cycles)
  • reviewed 2026-08-02T21:04:20.929Z sha dea0db6 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-02T21:55:20.052Z sha 5af395e :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 2, 2026
@steipete
steipete merged commit c574a65 into main Aug 2, 2026
136 of 138 checks passed
@steipete
steipete deleted the codex/fix-58498-codex-session-auth-profile-migration branch August 2, 2026 23:14
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
…penclaw#118205)

* fix(auth): preserve selected OAuth accounts during Codex migrations

* test(auth): complete doctor context and stabilize MCP pagination
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations maintainer Maintainer-authored PR 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. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Status card shows the active OAuth profile, but weekly usage appears to reflect a different Oauth credential

1 participant