Skip to content

fix: doctor loops forever on legacy OAuth profiles with missing sidecars - #123093

Merged
steipete merged 2 commits into
mainfrom
fix/team-doctor-authloop-0813
Aug 13, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/team-doctor-authloop-0813

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an operator dead-end loop: a legacy auth-profiles.json containing an OAuth profile whose sidecar state is missing made the gateway refuse startup with "run openclaw doctor --fix" — while doctor completed successfully, deliberately left that profile in the legacy file, and told the operator to rerun doctor. The instruction loop never terminated; the gateway never started. Hit in practice when restoring partial backups or copying an agent directory between installs.

Also fixes boot-to-boot inconsistency where the same startup-migration warning was non-fatal on one boot and blocked readiness on the next (fatality depended on whether the startup checkpoint needed renewal).

Why This Change Was Made

Doctor pruned unresolved OAuth profiles before SQLite import and retained the legacy JSON, so the gateway's migration preflight kept demanding doctor forever. Doctor now migrates ref-only OAuth profiles into SQLite as configured-unavailable rows carrying no credential material (they can never authorize anything; re-authentication is the terminating action, and the warning says so), then archives the legacy JSON so the preflight stops firing. The whole pre-import pruning machinery became dead and was deleted. Migration warnings now deterministically block readiness whenever gateway startup migrations run, instead of depending on checkpoint state.

User Impact

openclaw doctor --fix always converges: after one run the gateway starts, cold profiles are visible as needing re-authentication, and no instruction loop remains. Startup behavior is the same on every boot given the same state.

Evidence

  • Regression-first: pre-fix, the auth test failed because the legacy JSON survived doctor, and the checkpoint test failed because readiness resolved inconsistently; both pass post-fix.
  • Auth migration suite 50 passed; startup migration suite 30 passed; lifecycle preflight suite 6 passed.
  • Synthetic end-to-end state: source file removed, one archive created, no credential material stored, migrated profile ineligible to authorize, startup preflight clear.
  • Production LOC net −82 (tests +51).

Persist missing-sidecar OAuth profiles as cold SQLite rows and make startup migration warnings deterministic.
@clawsweeper

clawsweeper Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 13, 2026 09:11
@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: M maintainer Maintainer-authored PR labels Aug 13, 2026
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 13, 2026
@clawsweeper

clawsweeper Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 13, 2026, 5:16 AM ET / 09:16 UTC.

ClawSweeper review

What this changes

The PR migrates legacy OAuth profiles with missing sidecars into unavailable SQLite rows and makes Gateway startup migration warnings consistently block readiness.

Merge readiness

⛔ Blocked by patch quality or review findings - 5 items remain

Keep open: the new archive path can discard a usable shared OAuth credential while retaining an ineligible legacy reference for the same profile, leaving the operator unable to authenticate after Doctor completes.

Priority: P1
Reviewed head: dcc3e4373f71aaac17cf6ba66c18e343fbe63774

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is coherent and net-negative, but it has a high-impact OAuth collision that breaks its claimed convergent outcome.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; its stated test evidence remains supplemental to the source-confirmed correctness finding.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; its stated test evidence remains supplemental to the source-confirmed correctness finding.
Evidence reviewed 5 items Cold profile is archived before the shared OAuth collision is resolved: The changed archive path now archives every legacy auth source after importing the missing-sidecar ref, which allows the later shared OAuth import to proceed despite the existing cold record.
Shared OAuth import retains the existing cold record: The shared OAuth importer calls the merge helper without replacement enabled; the helper only replaces an existing profile when explicitly requested and when the existing credential is unusable.
Retained ref is not eligible: OAuth credentials with neither access nor refresh material and an oauthRef resolve as unresolved_ref, so the profile retained by the collision cannot authorize requests.
Findings 1 actionable finding [P1] Preserve usable shared OAuth when replacing a cold legacy ref
Security None None.

How this fits together

Doctor migrates legacy auth JSON and OAuth files into OpenClaw’s canonical SQLite auth-profile store. Gateway startup preflight then consumes migration warnings and the stored profile eligibility to decide whether startup can proceed.

flowchart LR
A[Legacy auth profile JSON] --> B[Doctor migration]
C[Shared OAuth file] --> B
B --> D[SQLite auth profile store]
D --> E[Profile eligibility]
E --> F[Gateway startup and provider access]
Loading

Before merge

  • Preserve usable shared OAuth when replacing a cold legacy ref (P1) - When the legacy profile is an unresolved openai:default ref and oauth.json contains usable credentials for the same profile, this new all-sources archive path lets the shared import run after the cold row is stored. That importer preserves existing rows, so it archives the usable OAuth source while auth selection returns unresolved_ref. Replace the cold record with usable material in this collision and assert eligibility before archiving.
  • Resolve merge risk (P1) - Merging can turn a currently usable shared OAuth credential into an archived source while the canonical profile remains configured-unavailable, causing provider authentication failure immediately after Doctor reports convergence.
  • Complete next step (P2) - The protected maintainer PR has a concrete P1 auth-provider defect that should be corrected and re-reviewed before merge.
  • Improve patch quality - Replace a cold OAuth ref with usable shared OAuth material when profile IDs collide.
  • Improve patch quality - Extend the existing collision fixture to assert that the final selected profile is eligible before its sources are archived.

Findings

  • [P1] Preserve usable shared OAuth when replacing a cold legacy ref — src/commands/doctor-auth-flat-profiles.ts:1278-1279
Agent review details

Security

None.

PR surface

Source -82, Tests +51. Total -31 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 26 108 -82
Tests 2 98 47 +51
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 124 155 -31

Review metrics

Metric Value Why it matters
Production versus test LOC production -82 (26 added, 108 removed); tests +51 (98 added, 47 removed) The net-negative migration simplification is desirable, but the changed collision regression currently misses the resulting provider-eligibility outcome.

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-preflight.state-migration.test.ts, migration/backfill/repair: src/commands/doctor-config-preflight.ts, unknown-data-model-change: src/commands/doctor-auth-flat-profiles.test.ts, unknown-data-model-change: src/commands/doctor-auth-flat-profiles.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Merge-risk options

Maintainer options:

  1. Preserve usable OAuth credentials before archival (recommended)
    Replace the cold legacy reference with usable shared OAuth material for the same profile and add an eligibility regression before merging.
  2. Accept mandatory re-authentication
    Merge only if maintainers intentionally accept that users with this collision must re-authenticate despite an existing usable shared OAuth source.

Technical review

Best possible solution:

Make the shared OAuth import replace an existing unusable OAuth ref with usable OAuth material for the same profile, then prove the final canonical profile is eligible before archiving either source.

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

Yes, from source: use the changed fixture’s unresolved legacy openai:default ref plus its usable shared OAuth entry, then inspect eligibility after Doctor migration. The read-only review did not execute the test.

Is this the best way to solve the issue?

No. Archiving both files is only safe after the canonical profile contains usable OAuth material; the current merge preserves the unusable ref and drops the usable collision candidate.

Full review comments:

  • [P1] Preserve usable shared OAuth when replacing a cold legacy ref — src/commands/doctor-auth-flat-profiles.ts:1278-1279
    When the legacy profile is an unresolved openai:default ref and oauth.json contains usable credentials for the same profile, this new all-sources archive path lets the shared import run after the cold row is stored. That importer preserves existing rows, so it archives the usable OAuth source while auth selection returns unresolved_ref. Replace the cold record with usable material in this collision and assert eligibility before archiving.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: A normal Doctor run can leave a previously usable OpenAI authentication path unavailable.
  • add merge-risk: 🚨 compatibility: The migration changes how existing legacy auth sources are archived during upgrade.
  • add merge-risk: 🚨 auth-provider: The affected collision can leave the selected OpenAI profile unable to authenticate after migration.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; its stated test evidence remains supplemental to the source-confirmed correctness finding.

Label justifications:

  • P1: A normal Doctor run can leave a previously usable OpenAI authentication path unavailable.
  • merge-risk: 🚨 compatibility: The migration changes how existing legacy auth sources are archived during upgrade.
  • merge-risk: 🚨 auth-provider: The affected collision can leave the selected OpenAI profile unable to authenticate after migration.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; its stated test evidence remains supplemental to the source-confirmed correctness finding.

Evidence

What I checked:

Likely related people:

  • Dallin Romney: Blame attributes the surrounding current-base auth migration and startup-preflight code to this contributor; the proposed archive lines sit in that ownership neighborhood. (role: recent area contributor; confidence: medium; commits: eda22ae1d578; files: src/commands/doctor-auth-flat-profiles.ts, src/commands/doctor-config-preflight.ts)

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.

@steipete
steipete merged commit 62ecb31 into main Aug 13, 2026
188 of 190 checks passed
@steipete
steipete deleted the fix/team-doctor-authloop-0813 branch August 13, 2026 10:02
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 14, 2026
…ars (openclaw#123093)

* fix(doctor): converge missing OAuth sidecar migration

Persist missing-sidecar OAuth profiles as cold SQLite rows and make startup migration warnings deterministic.

* test(doctor): restore OAuth sidecar fixture id
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. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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.

1 participant