openclaw - ✅(Solved) Fix [Bug]: Codex OAuth relogin creates fresh named profile but lastGood keeps selecting stale default on 2026.5.18 [1 pull requests, 2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#84386Fetched 2026-05-20 03:41:00
View on GitHub
Comments
2
Participants
3
Timeline
12
Reactions
1
Author
Timeline (top)
labeled ×7cross-referenced ×3commented ×2

This appears to be the same failure mode as #57286, but that issue is locked so I cannot add the requested current-build reproduction there.

On OpenClaw 2026.5.18, running openclaw models auth login --provider openai-codex successfully created a fresh named OAuth profile, and models auth order set was used to put that fresh profile first. However, auth-state.json still moved/kept lastGood.openai-codex on the older openai-codex:default profile. Since the installed selection path prefers lastGood before the first ordered profile, runtime/status can continue selecting stale default credentials unless the operator manually edits/copies auth profiles.

Root Cause

This appears to be the same failure mode as #57286, but that issue is locked so I cannot add the requested current-build reproduction there.

On OpenClaw 2026.5.18, running openclaw models auth login --provider openai-codex successfully created a fresh named OAuth profile, and models auth order set was used to put that fresh profile first. However, auth-state.json still moved/kept lastGood.openai-codex on the older openai-codex:default profile. Since the installed selection path prefers lastGood before the first ordered profile, runtime/status can continue selecting stale default credentials unless the operator manually edits/copies auth profiles.

Fix Action

Workaround

The robust local workaround was to copy the fresh named OAuth credential material into openai-codex:default as well. After that, both profile ids reported the new expiry:

openai-codex:default        expires 2026-05-30T01:09:04.729Z
openai-codex:<email>        expires 2026-05-30T01:09:04.729Z

Then this verification passed:

openclaw infer model run --model openai/gpt-5.5 --prompt 'Reply with exactly: CODEX_STATUS_OK' --json
# returned CODEX_STATUS_OK

PR fix notes

PR #84403: Fix stale Codex lastGood after explicit auth order relogin

Description (problem / solution / changelog)

Summary

  • Make Codex account overview treat explicit openai-codex auth order as authoritative when choosing the active profile, so a fresh relogin profile no longer yields stale lastGood.
  • Add a regression test covering the relogin case from #84386.

Verification

  • Behavior addressed: stale lastGood no longer overrides explicit Codex order in the /codex account view.
  • Real environment tested: local repo on macOS; no live OAuth round-trip.
  • Exact steps or command run after this patch:
    • pnpm test extensions/codex/src/commands.test.ts -- --reporter=verbose
    • git diff --check
    • pnpm changed:lanes --json
    • pnpm check:changed
  • Evidence after fix: 89 tests passed in extensions/codex/src/commands.test.ts, including the new relogin regression.
  • Observed result after fix: the fresh profile is shown as active and the stale default is no longer selected first.
  • What was not tested: a live Codex OAuth relogin round trip.
  • Known proof gap: pnpm check:changed reached unrelated lint apps work and failed because swiftlint is not installed in this environment.

Changed files

  • extensions/codex/src/app-server/compact.test.ts (modified, +58/-2)
  • extensions/codex/src/app-server/compact.ts (modified, +10/-3)
  • extensions/codex/src/app-server/run-attempt.context-engine.test.ts (modified, +59/-1)
  • extensions/codex/src/app-server/run-attempt.ts (modified, +6/-2)
  • extensions/codex/src/command-account.ts (modified, +31/-8)
  • extensions/codex/src/commands.test.ts (modified, +64/-0)
  • src/agents/harness/context-engine-lifecycle.ts (modified, +10/-7)
  • src/agents/pi-embedded-runner/compact.queued.ts (modified, +3/-3)
  • src/agents/pi-embedded-runner/compact.types.ts (modified, +2/-0)
  • src/agents/pi-embedded-runner/run.overflow-compaction.test.ts (modified, +36/-0)
  • src/agents/pi-embedded-runner/run.ts (modified, +7/-5)
  • src/agents/pi-embedded-runner/run/attempt.spawn-workspace.context-engine.test.ts (modified, +68/-0)
  • src/agents/pi-embedded-runner/run/attempt.ts (modified, +11/-0)
  • src/agents/pi-embedded-runner/run/params.ts (modified, +2/-0)
  • src/agents/pi-embedded-runner/run/types.ts (modified, +2/-0)
  • src/agents/pi-embedded-runner/tool-result-context-guard.test.ts (modified, +35/-0)
  • src/agents/pi-embedded-runner/tool-result-context-guard.ts (modified, +6/-4)
  • src/auto-reply/get-reply-options.types.ts (modified, +6/-0)
  • src/auto-reply/reply/agent-runner-execution.test.ts (modified, +21/-0)
  • src/auto-reply/reply/agent-runner-execution.ts (modified, +1/-0)
  • src/infra/heartbeat-runner.isolated-key-stability.test.ts (modified, +64/-0)
  • src/infra/heartbeat-runner.ts (modified, +13/-0)

Code Example

openclaw models auth login --provider openai-codex

---

openai-codex:<email>

---

openclaw models auth order set --provider openai-codex --agent main openai-codex:<email> openai-codex:default

---

- openai-codex:default (same ChatGPT account) [openai-codex/oauth; expires 2026-05-22T15:07:22.131Z]
- openai-codex:<email> (same ChatGPT account) [openai-codex/oauth; expires 2026-05-30T01:09:04.729Z]

---

{
  "order": {
    "openai-codex": [
      "openai-codex:<email>",
      "openai-codex:default"
    ]
  }
}

---

{
  "lastGood": {
    "openai-codex": "openai-codex:default"
  }
}

---

const lastGood = [
  params.store.lastGood?.[OPENAI_PROVIDER_ID],
  params.store.lastGood?.[OPENAI_CODEX_PROVIDER_ID],
].find((profileId) =>
  !!profileId &&
  params.order.includes(profileId) &&
  isActiveProfileCandidate(params, profileId)
);
if (lastGood) return lastGood;

---

openai-codex:default        expires 2026-05-30T01:09:04.729Z
openai-codex:<email>        expires 2026-05-30T01:09:04.729Z

---

openclaw infer model run --model openai/gpt-5.5 --prompt 'Reply with exactly: CODEX_STATUS_OK' --json
# returned CODEX_STATUS_OK
RAW_BUFFERClick to expand / collapse

Bug type

Authentication / profile selection regression

Summary

This appears to be the same failure mode as #57286, but that issue is locked so I cannot add the requested current-build reproduction there.

On OpenClaw 2026.5.18, running openclaw models auth login --provider openai-codex successfully created a fresh named OAuth profile, and models auth order set was used to put that fresh profile first. However, auth-state.json still moved/kept lastGood.openai-codex on the older openai-codex:default profile. Since the installed selection path prefers lastGood before the first ordered profile, runtime/status can continue selecting stale default credentials unless the operator manually edits/copies auth profiles.

Environment

  • OpenClaw: 2026.5.18 (50a2481)
  • Codex CLI: codex-cli 0.130.0
  • OS: macOS / Apple Silicon
  • Auth flow: openclaw models auth login --provider openai-codex
  • OAuth completion: mobile browser login, then manual localhost callback URL/code entry into the CLI prompt

Steps to reproduce

  1. Start with an existing openai-codex:default OAuth profile near expiry.

  2. Run:

    openclaw models auth login --provider openai-codex
  3. Complete OAuth. In this case the login wrote a fresh named profile:

    openai-codex:<email>
  4. Set provider auth order to prefer the fresh named profile:

    openclaw models auth order set --provider openai-codex --agent main openai-codex:<email> openai-codex:default
  5. Check ~/.openclaw/agents/main/agent/auth-state.json.

Expected behavior

After successful reauth and explicit auth-order selection, OpenClaw should either:

  • update lastGood.openai-codex to the fresh profile,
  • clear stale lastGood for that provider,
  • or make explicit auth order override lastGood when choosing an active profile.

The fresh profile should be the effective profile without manual auth-store edits.

Actual behavior

After successful login, the agent had two profiles:

- openai-codex:default (same ChatGPT account) [openai-codex/oauth; expires 2026-05-22T15:07:22.131Z]
- openai-codex:<email> (same ChatGPT account) [openai-codex/oauth; expires 2026-05-30T01:09:04.729Z]

The order was set correctly:

{
  "order": {
    "openai-codex": [
      "openai-codex:<email>",
      "openai-codex:default"
    ]
  }
}

But lastGood still selected the old default profile:

{
  "lastGood": {
    "openai-codex": "openai-codex:default"
  }
}

The installed 2026.5.18 bundle appears to prefer lastGood ahead of the first ordered profile when the lastGood profile is present in the order and not currently marked unusable/cooldowned:

const lastGood = [
  params.store.lastGood?.[OPENAI_PROVIDER_ID],
  params.store.lastGood?.[OPENAI_CODEX_PROVIDER_ID],
].find((profileId) =>
  !!profileId &&
  params.order.includes(profileId) &&
  isActiveProfileCandidate(params, profileId)
);
if (lastGood) return lastGood;

Workaround

The robust local workaround was to copy the fresh named OAuth credential material into openai-codex:default as well. After that, both profile ids reported the new expiry:

openai-codex:default        expires 2026-05-30T01:09:04.729Z
openai-codex:<email>        expires 2026-05-30T01:09:04.729Z

Then this verification passed:

openclaw infer model run --model openai/gpt-5.5 --prompt 'Reply with exactly: CODEX_STATUS_OK' --json
# returned CODEX_STATUS_OK

Why this is worth tracking

This is not only a UI/status issue. The operator-visible recovery path after OAuth renewal still required manual auth-store surgery, even after:

  • successful models auth login --provider openai-codex,
  • explicit models auth order set,
  • and a passing model-run after manually aligning the stale default profile.

The closest existing issue is #57286, but it is locked and cannot receive the requested current-build reproduction comment.

Redaction

No tokens, auth codes, account ids, hostnames, chat ids, or personal identifiers are included here. The email-bearing profile id is redacted as openai-codex:<email>.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

After successful reauth and explicit auth-order selection, OpenClaw should either:

  • update lastGood.openai-codex to the fresh profile,
  • clear stale lastGood for that provider,
  • or make explicit auth order override lastGood when choosing an active profile.

The fresh profile should be the effective profile without manual auth-store edits.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix [Bug]: Codex OAuth relogin creates fresh named profile but lastGood keeps selecting stale default on 2026.5.18 [1 pull requests, 2 comments, 3 participants]