Skip to content

fix(auth): inherit the shared auth store once it owns credentials - #130264

Merged
steipete merged 2 commits into
mainfrom
steipete/auth-profile-store-routing
Aug 26, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/auth-profile-store-routing

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

On a fresh install (and any install after the doctor shared-store relocation), openclaw models auth paste-api-key prints success — Auth profile: anthropic:manual (anthropic/api_key) — but every turn fails with No API key found for provider ... | missing-provider-auth. models status even displays the shared store with the profile present, so setup looks healthy while the runtime is dead: the worst silent-failure class. Found live during the 50-session cross-machine farm test (#129979), where it zeroed an entire run: 49/50 worker launches completed and every turn failed on missing auth.

Why This Change Was Made

Root cause: resolveLegacyInheritedAuthDir unconditionally selected the legacy main-agent directory as the read-through inheritance base. Per docs/auth-credential-semantics.md, agent auth inheritance is read-through to the shared store (state/openclaw.sqlite, canonical after the doctor relocation — and from birth on fresh installs); the legacy directory is only meaningful while it still owns credentials. With the unconditional selection, a fresh install's empty main-agent DB shadowed the canonical shared store and the runtime never consulted it.

  • The resolver now returns the legacy directory only while resolveSharedAuthStoreOwnership reports legacy-main; otherwise inheritance resolves through the shared store (the existing undefined → resolveSharedAuthPath path). Credential writes and the doctor relocation are unchanged — no dual-write, no new fallback reader.
  • A separate physical-directory resolver (resolveLegacyInheritedAuthAgentDir) preserves doctor migration and secrets discovery, which genuinely address the legacy location.
  • The same empty-legacy-shadow existed in sibling catalog paths (prepared-model-catalog-worker, models list command/rows/scoped-catalog) — fixed with the same predicate.
  • The stale root AGENTS.md security line naming the per-agent DB as the profile home now states the shared-store + read-through contract (that stale line misdirected the initial diagnosis).

User Impact

paste-api-key (and token/OAuth profiles in the shared store) work on the first turn of a fresh gateway, in any setup ordering. Pre-relocation installs keep their legacy-store behavior; agent-local profiles still override the shared base.

Evidence

  • Live pre/post on the cross-machine rig: identical state dir failed with missing-provider-auth on the unfixed build; after deploying this fix (only change), the probe turn replied FIXED-OK, and a full 50-session dispatch+turn wave ran (50/50 dispatched in 29s; 38/50 turns completed end-to-end in 105s — the 12 failures are a separate workspace-reconciliation contention finding tracked in Worker launches die unrecoverably on transient network flap: fixed 120s admission deadline, cause-masking error, 25-min stuck-lane terminalization #129979).
  • Regression tests (verified failing pre-fix): fresh shared-store credential resolves with no agent-local profile; populated legacy store stays authoritative pre-relocation; agent-local profile overrides the shared base. Plus sibling catalog coverage.
  • pnpm check:changed green; 287 tests across 11 focused files green; Codex autoreview clean (0.96).

Production LOC: +38/-13; tests +91/-7.

resolveLegacyInheritedAuthDir unconditionally selected the legacy main-agent
directory as the read-through base, so on fresh installs (and post-relocation
installs) the empty agent DB shadowed the canonical shared auth store:
models auth paste-api-key printed success while every turn failed with
missing-provider-auth. The resolver now returns the legacy directory only
while resolveSharedAuthStoreOwnership reports legacy-main ownership;
otherwise inheritance read-throughs to the shared store per
docs/auth-credential-semantics.md. Sibling shadow sites in the models list
catalog paths fixed with the same predicate; stale AGENTS.md security line
corrected. Regression proves fresh shared credentials resolve with no
agent-local profile, populated legacy stores stay authoritative
pre-relocation, and local profiles still override the shared base.
@clawsweeper

clawsweeper Bot commented Aug 26, 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 26, 2026 17:32
@steipete
steipete requested a review from a team as a code owner August 26, 2026 17:32
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime commands Command implementations agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Aug 26, 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: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 2:42 PM ET / 18:42 UTC.

ClawSweeper review

What this changes

This PR makes agent auth inheritance use the shared SQLite profile store once that store owns credentials, while retaining legacy main-agent reads during migration and fixing equivalent model-catalog paths.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for normal maintainer landing review. The patch aligns runtime inheritance with the documented shared-store ownership contract and preserves the physical legacy directory for doctor/secrets paths; exact-head rebase, CI, and ownership-mode proof remain merge conditions.

Priority: P1
Reviewed head: d9675cc7ad6143528d40ac0e7599cf09ad671999

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused ownership-boundary repair with direct regression coverage; rebase and exact-head validation are the remaining merge checks.
Proof confidence 🌊 off-meta tidepool Not applicable: The author is a repository member, so the external-contributor proof gate does not apply; the PR body nevertheless reports a redacted pre/post real-rig recovery.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The author is a repository member, so the external-contributor proof gate does not apply; the PR body nevertheless reports a redacted pre/post real-rig recovery.
Evidence reviewed 6 items Current-main defect: Current main unconditionally returns the legacy agent directory as the inherited base, while the shared-store resolver independently selects state-db ownership.
Ownership-aligned repair: The PR returns a legacy inherited directory only for legacy-main ownership and otherwise leaves inheritance unset, which makes the existing auth-store loader use the canonical shared store.
Documented contract: The auth semantics document states that inheritance is read-through from the shared store after doctor relocation and that agent-local profiles override that base.
Findings None None.
Security None None.

Live Verification

Command: pnpm test src/agents/model-auth.profiles.test.ts

Result: FAIL (failed) — step 1 run pnpm test src/agents/model-auth.profiles.test.ts: previous terminal command was still running after 30 seconds: "pnpm test src/agents/model-auth.profiles.test.ts"

$ node --import tsx scripts/test-projects.mts src/agents/model-auth.profiles.test.ts
[test] starting test/vitest/vitest.agents-core.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130264-3gX5pb/target

 ✓  agents-core  src/agents/model-auth.profiles.test.ts (86 tests) 1579ms

 Test Files  1 passed (1)
      Tests  86 passed (86)
   Start at  18:43:40
   Duration  11.19s (transform 7.51s, setup 954ms, import 8.30s, tests 1.58s, environment 0ms)

[test] passed 1 Vitest shard in 17.75s

Assertions:

  • FAIL expect_output: shared auth profile read-through

How this fits together

Credential setup persists provider profiles in a legacy main-agent database or the shared state database. Agent runtime, model listing, catalog discovery, and Gateway status read those profiles before selecting credentials for provider calls.

flowchart LR
  A[Credential setup] --> B[Shared-store ownership]
  B --> C{Legacy main store?}
  C -->|yes| D[Legacy agent profile store]
  C -->|no| E[Shared state profile store]
  D --> F[Agent and catalog lookup]
  E --> F
  F --> G[Provider credential resolution]
Loading

Before merge

  • Resolve merge risk (P1) - The PR is behind current main and relevant checks are still queued or in progress; merge only after rebase and exact-head CI complete.
  • Resolve merge risk (P1) - Production source changes are net +12 lines; the separate physical legacy-directory resolver is justified to keep doctor and secrets discovery independent from auth-store ownership, but both ownership modes need exact-head confirmation.
  • Complete next step (P2) - This protected maintainer PR needs ordinary landing review, exact-head CI, and upgrade-mode proof rather than an automated repair lane.
Agent review details

Security

None.

PR surface

Source +12, Tests +101, Docs 0. Total +113 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 10 32 20 +12
Tests 6 103 2 +101
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 17 136 23 +113

Review metrics

Metric Value Why it matters
Production versus test delta production +29/-17; tests +103/-2; test support +3/-3; governance docs +1/-1 The production growth separates legacy physical-directory consumers from ownership-aware runtime inheritance and is covered by focused precedence tests.

Root-cause cluster

Relationship: canonical
Canonical: #130264
Summary: This PR owns the missing-provider-auth condition found during the saturation run; the referenced worker-admission issue remains a separate failure mode.

Members:

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

Merge-risk options

Maintainer options:

  1. Rebase and verify both ownership modes (recommended)
    Rebase onto current main, require exact-head CI, and retain redacted proof that fresh state-db and legacy-main installations both complete a first authenticated turn.

Technical review

Best possible solution:

Land one canonical ownership-aware inherited-store resolver after a rebased exact-head run confirms fresh shared-store auth, legacy-main compatibility, and local-profile override precedence.

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

Yes—current-main source shows the unconditional legacy directory, while the auth loader treats an omitted inherited directory as the shared-store base; the PR adds direct precedence coverage for that state.

Is this the best way to solve the issue?

Yes—the fix changes the owner-boundary selector rather than adding fallback readers, and retains a separate physical-directory helper for migration and secrets discovery.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: Fresh and relocated installations can accept credentials during setup but fail every provider-backed agent turn.
  • merge-risk: 🚨 compatibility: The inherited credential base changes for installations whose canonical auth store has moved to the shared state database.
  • merge-risk: 🚨 auth-provider: The changed resolver determines which persisted provider credentials runtime and catalog paths can use.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The author is a repository member, so the external-contributor proof gate does not apply; the PR body nevertheless reports a redacted pre/post real-rig recovery.

Evidence

What I checked:

  • Current-main defect: Current main unconditionally returns the legacy agent directory as the inherited base, while the shared-store resolver independently selects state-db ownership. (src/agents/legacy-inherited-auth-dir.ts:17, 8e39f583650a)
  • Ownership-aligned repair: The PR returns a legacy inherited directory only for legacy-main ownership and otherwise leaves inheritance unset, which makes the existing auth-store loader use the canonical shared store. (src/agents/legacy-inherited-auth-dir.ts:25, d9675cc7ad61)
  • Documented contract: The auth semantics document states that inheritance is read-through from the shared store after doctor relocation and that agent-local profiles override that base. Public docs: docs/auth-credential-semantics.md. (docs/auth-credential-semantics.md:52, 8e39f583650a)
  • Regression coverage: The new table-driven test covers fresh shared-store resolution, legacy-main authority, and agent-local override precedence. (src/agents/model-auth.profiles.test.ts:423, d9675cc7ad61)
  • Feature provenance: Blame attributes the unconditional legacy resolver and shared-store ownership helper to the same historical commit, tying the conflicting ownership decisions to the current implementation. (src/agents/legacy-inherited-auth-dir.ts:17, a2d54319bc31)
  • Current-main and history limitation: The current-main commit object and changed-file trees are present, but the shallow promisor checkout cannot retrieve historical base blobs because its GitHub remote DNS lookup fails; no release-inclusion claim is made. (8e39f583650a)

Likely related people:

  • steipete: Current-main blame assigns both the legacy inherited-directory resolver and shared-store ownership implementation to Peter Steinberger; this PR continues that ownership repair. (role: shared-auth ownership and resolver author; confidence: high; commits: a2d54319bc31, d9675cc7ad61; files: src/agents/legacy-inherited-auth-dir.ts, src/agents/auth-profiles/path-resolve.ts)

Rank-up moves

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

  • Rebase onto current main and obtain green exact-head CI.
  • Retain a redacted fresh-store and relocated-store setup-to-first-turn trace in the PR evidence.

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 (1 earlier review cycle)
  • reviewed 2026-08-26T17:40:41.384Z sha ed47688 :: needs maintainer review before merge. :: none

The chat.history thinkingDefault regression on CI was a pre-existing
isolate:false leak: a sibling test's agentDiscoveryMock catalog fixture
(reasoning:false) survived on globalThis and clamped the level to off.
The shared fixture-reset owner now clears discovery state for both full
and suite-backed resets, and the test publishes its own catalog fixture.
@steipete
steipete merged commit 3826b52 into main Aug 26, 2026
198 checks passed
@steipete
steipete deleted the steipete/auth-profile-store-routing branch August 26, 2026 19:07
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete

Copy link
Copy Markdown
Contributor Author

Two adjacent gaps surfaced during this fix's ownership audit (out of scope here, recording for follow-up):

  1. agent exec does not preserve the original shared-store root when switching to temporary state — a temporary-state run can lose read-through access to shared credentials.
  2. Gateway agent deletion still protects the implicit legacy owner (agents/main) after the doctor relocation, even though the shared store owns credentials by then — the protection predicate should consult resolveSharedAuthStoreOwnership like inheritance now does.

steipete added a commit that referenced this pull request Aug 26, 2026
…deletion

Two follow-ups from #130264: agent exec temporary state now preserves the
original shared auth root, so temp-state runs read-through portable static
profiles (local precedence and cooldowns preserved, no inherited-secret
copies); and agent deletion safety consults resolveSharedAuthStoreOwnership,
so the implicit legacy main owner is protected only while the legacy store
owns credentials — post-relocation main is deletable and shared credentials
provably survive. Explicitly bound inheritance owners stay protected.
steipete added a commit that referenced this pull request Aug 26, 2026
…deletion (#130437)

Two follow-ups from #130264: agent exec temporary state now preserves the
original shared auth root, so temp-state runs read-through portable static
profiles (local precedence and cooldowns preserved, no inherited-secret
copies); and agent deletion safety consults resolveSharedAuthStoreOwnership,
so the implicit legacy main owner is protected only while the legacy store
owns credentials — post-relocation main is deletable and shared credentials
provably survive. Explicitly bound inheritance owners stay protected.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
…enclaw#130264)

* fix(auth): inherit the shared auth store once it owns credentials

resolveLegacyInheritedAuthDir unconditionally selected the legacy main-agent
directory as the read-through base, so on fresh installs (and post-relocation
installs) the empty agent DB shadowed the canonical shared auth store:
models auth paste-api-key printed success while every turn failed with
missing-provider-auth. The resolver now returns the legacy directory only
while resolveSharedAuthStoreOwnership reports legacy-main ownership;
otherwise inheritance read-throughs to the shared store per
docs/auth-credential-semantics.md. Sibling shadow sites in the models list
catalog paths fixed with the same predicate; stale AGENTS.md security line
corrected. Regression proves fresh shared credentials resolve with no
agent-local profile, populated legacy stores stay authoritative
pre-relocation, and local profiles still override the shared base.

* test(gateway): reset shared discovery state in the fixture-reset owner

The chat.history thinkingDefault regression on CI was a pre-existing
isolate:false leak: a sibling test's agentDiscoveryMock catalog fixture
(reasoning:false) survived on globalThis and clamped the level to off.
The shared fixture-reset owner now clears discovery state for both full
and suite-backed resets, and the test publishes its own catalog fixture.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
…deletion (openclaw#130437)

Two follow-ups from openclaw#130264: agent exec temporary state now preserves the
original shared auth root, so temp-state runs read-through portable static
profiles (local precedence and cooldowns preserved, no inherited-secret
copies); and agent deletion safety consults resolveSharedAuthStoreOwnership,
so the implicit legacy main owner is protected only while the legacy store
owns credentials — post-relocation main is deletable and shared credentials
provably survive. Explicitly bound inheritance owners stay protected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations gateway Gateway runtime 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: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant