Repository navigation
fix(auth): stop advising a retry when the auth store needs migration - #127306
Merged
Merged
Conversation
Writing an auth profile on an install whose credentials still live in the retired JSON store printed two contradictory lines: the real migration error, followed by a generic "the auth store lock may be busy. Wait a moment and retry." An operator reading the last line retries forever, because nothing is locked and the write can never succeed until Doctor migrates the store. updateAuthProfileStoreWithLock wrapped its transaction in a blanket catch that logged a warn and returned null, erasing the failure's identity. Callers only saw null, so the sole guess available to them was lock contention. Read paths already let AuthProfileMigrationRequiredError and AuthProfileStoreUnreadableError through; only the write path swallowed them. Rethrow those two credential-boundary errors at the producer and keep null for genuine write failures, which is what the lock hint was always describing. All three sibling call sites (upsertAuthProfileWithLockOrThrow, models auth logout, models auth order set) funnel through that null, so they are fixed by the one change. Onboard now prints only the migration line, and `openclaw doctor --fix` followed by the same onboard command succeeds.
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Contributor
Author
|
Merged via squash.
|
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Aug 22, 2026
…penclaw#127306) Writing an auth profile on an install whose credentials still live in the retired JSON store printed two contradictory lines: the real migration error, followed by a generic "the auth store lock may be busy. Wait a moment and retry." An operator reading the last line retries forever, because nothing is locked and the write can never succeed until Doctor migrates the store. updateAuthProfileStoreWithLock wrapped its transaction in a blanket catch that logged a warn and returned null, erasing the failure's identity. Callers only saw null, so the sole guess available to them was lock contention. Read paths already let AuthProfileMigrationRequiredError and AuthProfileStoreUnreadableError through; only the write path swallowed them. Rethrow those two credential-boundary errors at the producer and keep null for genuine write failures, which is what the lock hint was always describing. All three sibling call sites (upsertAuthProfileWithLockOrThrow, models auth logout, models auth order set) funnel through that null, so they are fixed by the one change. Onboard now prints only the migration line, and `openclaw doctor --fix` followed by the same onboard command succeeds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
Fixes an issue where operators upgrading an install whose credentials still live in the retired
auth-profiles.jsonstore would be told to wait and retry forever when any auth profile write ran (onboarding,models auth login,models auth order set, plugin API-key setup).The command printed two contradictory lines and exited 1:
The first line is correct and actionable. The second is a generic lock-contention fallback that does not apply — nothing is locked, the store needs migration, and retrying can never succeed. An operator who reads the last line (the one closest to the prompt) retries indefinitely.
Verified pre-existing: reproduces identically on a build of
mainfrom before any recent auth-store work, so this is not a regression from the shared-auth-ownership change.Why This Change Was Made
The bug is an asymmetry at the store boundary, not bad message copy.
assertAuthProfileMigrationReadythrowsAuthProfileMigrationRequiredErrordeliberately — it is a fail-closed credential gate, and the error carries both a typed code (AUTH_PROFILE_MIGRATION_REQUIRED) and its own remediation. Every read path lets that error through. The write path did not:updateAuthProfileStoreWithLockwrapped its transaction in a blanketcatchthat logged a warn and returnednull, erasing the error's identity. Callers only ever seenull, so the only thing any of them can say is "the write failed" — and the shipped guess for that was lock contention.The fix rethrows the two errors that name their own remediation (
AuthProfileMigrationRequiredError,AuthProfileStoreUnreadableError) and keepsnullfor genuine write failures, which is what the lock hint was always meant to describe.Because the identity is restored at the producer, all three sibling call sites are fixed by the one change rather than by three message edits:
upsertAuthProfileWithLockOrThrow(src/agents/auth-profiles/upsert-with-lock.ts)models auth logout(src/commands/models/auth-logout.ts)models auth order set/order clear(src/commands/models/auth-order.ts)Blast radius: rethrowing changes behavior for ~20 call sites of a plugin-SDK-exported function, so each was traced. The doctor stale-OAuth-shadow repair already catches and downgrades to a warning; the two importer plugins (
migrate-hermes,codex) and the doctor credential path already threw a vaguer error onnull; and the runtime usage/OAuth paths are only reachable after credentials loaded successfully, which means the boundary already passed. In every case the new behavior is the same or a strictly better message.Also fixed:
src/agents/auth-profiles/source-check.test.tsasserted the same bug's other half as expected behavior — an unreadable store returningnull, which callers were equally mistranslating into "lock busy". Updated to the canonical contract; the test's real intent (updater never runs, corrupt row untouched) is preserved.User Impact
Operators on an unmigrated install now get one correct, actionable line instead of two contradictory ones:
The redundant warn line disappears too, since the rethrow happens before the log. No config surface added; no CLI flags changed.
Evidence
Reproduction (isolated state dir, never touches
~/.openclaw) — against a build of unmodifiedmain, this fails with the two lines quoted above:After the fix, one line, exit 1:
Remediation loop proven end-to-end. Ran the command the message points at, then re-ran onboard on the same state dir:
openclaw doctor --fixexited 0, migrated the JSON into SQLite and archived it (auth-profiles.json.migrated-2026-08-20T23-39-17.222Z-...), and the same onboard command then exited 0. This also confirms the doctor repair paths downstream of the changed producer are unaffected.Sibling call sites verified live on an unmigrated store — both now print the migration remediation instead of their own generic hints:
openclaw models auth order set --provider anthropic anthropic:api-keyopenclaw models auth logout anthropic-api-key --yesRegression test —
src/agents/auth-profiles/upsert-with-lock.sqlite.test.ts, a real store test rather than a mock. Verified it fails on pre-fix production code for the intended reason:Suites (all green):
src/agents/auth-profiles— 28 files, 400 testssrc/commands/doctor— 69 files, 1272 testssrc/commands/models,src/system-agent,src/plugins— 418 files, 6521 testsnode scripts/check-changed.mjs— exit 0 (lint, tsgo shards, native state schema guard, database-first legacy-store guard, runtime sidecar loaders, import cycles, webhook/pairing guards)pnpm build— exit 0Autoreview: Codex
gpt-5.6-sol,xhigh— clean, 0 accepted/actionable findings.LOC delta (
git diff --numstat): productionsrc/agents/auth-profiles/store.ts+9/-1 (net +8); tests +35/-2. The production growth is a credential-boundary ownership fix: the discrimination has to happen where the error identity still exists, and there is no smaller shape that stops the boundary error from being laundered into a retry hint. The absorbing alternative — re-deriving the reason in each caller viaassertAuthProfileMigrationReady— was rejected: it re-runs the file-existence check, only fixes one of three siblings, and is exactly the multi-signal inference the recorded fact at the producer exists to avoid.