Skip to content

fix(doctor): agents lose inherited logins after doctor when the auth inheritance owner is not main - #178684

Closed
sukhdeepjohar wants to merge 4 commits into
openclaw:mainfrom
sukhdeepjohar:fix/auth-inheritance-owner-cutover
Closed

sukhdeepjohar wants to merge 4 commits into
openclaw:mainfrom
sukhdeepjohar:fix/auth-inheritance-owner-cutover

Conversation

@sukhdeepjohar

@sukhdeepjohar sukhdeepjohar commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Related: #178421

Fixes the Doctor path, which is how the reporter's install was switched over (its ledger names main's store as the Doctor source). The fresh-install switch-over has the same mismatch and remains open under #178421; it needs a separate change because that code cannot see the config.

What Problem This Solves

Fixes: agents lose an inherited login after openclaw doctor --fix when agents.defaults.authInheritance.agentId names an agent other than main. Doctor moved main's login store into shared state and turned inheritance off, so the owner kept its login and every other agent had none.

User Impact

  • Doctor moves the configured owner's store when that owner holds the logins and main holds none. Other agents can then use the owner's logins, which is what authInheritance documents.
  • Behavior change to review: agent turns before relocation never actually read the owner's store (on 2026.7.1 and 2026.10.5 peers used main's store; see Details). So for these installs, other agents get the owner's logins for the first time after this Doctor run. Agents' own private logins are not copied.
  • If both main and the owner hold logins, Doctor skips this one move with a recoverable warning naming both stores, and the install keeps its current layout and behavior.
  • Unchanged: installs whose owner is main, OPENCLAW_AGENT_DIR relocation, installs whose owner holds no logins (main still moves), and the existing refusal to delete the configured owner.
  • Not covered: installs already switched over by an earlier Doctor keep their current state.

Why This Change Was Made

Until the move, the configured owner is the documented inheritance source, so the move carries the owner's store. Doctor picks the source from its own selected config, refuses to choose when both stores hold logins, and re-checks the source right before copying. The copied-update planner checks the owner's store against its snapshot boundary too.

Example of the fresh-install path left open (shared-store-bootstrap*.ts): on 2026.10.5, openclaw models auth paste-api-key --agent main on such an install switches the store over and leaves the owner's logins behind.

Details
  • The source comes from sourceConfigBeforeMigrations ?? cfg via resolveLegacyInheritedAuthAgentId/resolveLegacyInheritedAuthAgentDir; there is no process-wide config fallback.
  • Same store: an owner whose agentDir is main's directory, directly or through a symlink, is treated as main (isSameOpenClawAgentDatabasePath). This check runs only in the repair path; outside Doctor repair, detection still returns before touching any source file.
  • At the point of effect, under the migration lock: a source agent deleted with its database retained after detection is skipped as held, and the source database is opened under the resolved agent id, so a database recorded for another agent is refused before any copy or cleanup.
  • Both stores holding logins: on 2026.7.1, peers sent main's key, while the upgraded config names the owner. Moving either store alone would change which credential peers use, so Doctor leaves it to the operator. An unreadable store payload counts as holding logins.
  • Why peers never read the owner before: run/auth-plan.ts loads an agent's store without the inherited directory, so turns fall back to main's store. That is a separate runtime issue, not changed here.
  • OPENCLAW_AGENT_DIR still relocates only main's store, which matches how the owner's agentDir is resolved.

Evidence

Isolated containers, network off, and a fake OpenAI-compatible model server that records the key it receives and returns 401 unless it gets the owner's key. Each run first checked that the built output contains this branch's code.

Upgrade from stable 2026.10.5 (login only on ops, authInheritance.agentId: "ops", agents ops and dev), then two openclaw agent --agent dev turns through a real Gateway:

Doctor Shared store after dev turns Key the model server received
2026.10.5 empty; ledger source agents/main/agent/openclaw-agent.sqlite (does not exist); ops keeps mock:ops 401, 401 auth=<none>
this branch [mock:ops]; owner's local copy cleaned; ledger source agents/ops/agent/openclaw-agent.sqlite AUTH_OK, AUTH_OK Bearer <owner key>

Real Gateway proof: direct upgrade from 2026.7.1

Direct upgrade from 2026.7.1 (default agent ops; logins added with 2026.7.1's own CLI). On 2026.7.1 itself, dev sent no key when only ops had one, and sent main's key when main also had one.

Install 2026.10.5 Doctor → dev sends This branch's Doctor → result, dev sends
login on ops only no key (401) owner moved; Bearer <owner key>, AUTH_OK
logins on ops and main main's key skipped with the warning below, nothing moved; main's key (as on 2026.7.1)
- Shared auth migration skipped: agents.defaults.authInheritance names agent ops, whose credentials other agents inherit from <state>/agents/ops/agent/openclaw-agent.sqlite, but <state>/agents/main/agent/openclaw-agent.sqlite also stores credentials. Keep the credentials agents should share in one of these stores, then run openclaw doctor --fix.
ownership: <none> (legacy-main); ops local: [ 'mock:ops' ]; main local: [ 'mock:main' ]  (unchanged)

Real CLI proof: authority checks (2026.10.5-built state)

### peer dev has its own login (mock:dev), then this branch's doctor --fix
before: ops local [ 'mock:ops' ]   dev local [ 'mock:dev' ]   shared: none
after:  shared [ 'mock:ops' ]      ops local: null            dev local [ 'mock:dev' ]  (not copied)
### openclaw agents delete ops --force (before relocation)
"Agent "ops" owns inherited credentials through agents.defaults.authInheritance.agentId and cannot be deleted. Relocate those credentials, then re-point or remove that binding before retrying."
ops local after the attempt: [ 'mock:ops' ]

Real Doctor proof: rejection after detection

Fresh install on this branch's build, login on ops only (old layout). Doctor's shared-auth detect and migrate functions, with the owner retired or reassigned in between:

##### owner retired between detection and copy
1. detected: {"ownerId":"ops","sourcePath":"<state>/agents/ops/agent/openclaw-agent.sqlite","hasLegacy":true}
   owner store: {"profiles":["mock:ops"],"agentId":"ops"} sha256: ec59c8376b0262b3 shared keys: []
2. after detection: agent ops deleted with its database retained (deletion journal completed)
3. migrate: {"changes":[],"outcome":"skipped","warnings":["Shared auth migration skipped: store held for agent ops at <state>/agents/ops/agent/openclaw-agent.sqlite; run openclaw doctor --fix after restoring the agent."]}
4. owner store: {"profiles":["mock:ops"],"agentId":"ops"} sha256: ec59c8376b0262b3 (unchanged) shared keys: []
##### owner reassigned between detection and copy
1. detected: {"ownerId":"ops","sourcePath":"<state>/agents/ops/agent/openclaw-agent.sqlite","hasLegacy":true}
2. after detection: the owner directory's database reassigned to agent 'other'
3. migrate: {"changes":[],"warnings":["Failed relocating the shared auth store: SharedAuthStoreSourceInspectionError: Cannot read legacy shared auth database <state>/agents/ops/agent/openclaw-agent.sqlite: OpenClaw agent database ... belongs to agent other ..."]}
4. owner store: {"profiles":["mock:ops"],"agentId":"other"} unchanged by the migration; shared keys: []

Regression tests. These fail on main (or on an earlier commit of this PR, for the review fixes) and pass here:

  • the owner's logins move for its peers, with a standard and a custom agentDir (peer's own store stays private)
  • both stores hold logins → skipped, nothing moved
  • the planner refuses an owner store outside the copied snapshot
  • with OPENCLAW_AGENT_DIR set, the configured owner's store still moves
  • an owner agentDir symlinked to main's directory is treated as main
  • an owner deleted after detection is never relocated or cleaned (state-migrations.retained-deleted-agent.test.ts)
  • outside Doctor repair, detection returns before touching an unreadable owner agentDir (no EACCES)

Guards for unchanged behavior: an owner with no logins → main moves as before; an owner database recorded for another agent → refused, untouched.

Checks: pnpm tsgo:core and pnpm tsgo:core:test pass. oxlint on the changed files: 0 warnings, 0 errors. A wider run of 112 related test files fails only in suites that fail identically on unmodified main in the same container: terminal-UI PTY timeouts, .clawdbot → .openclaw rename tests, and a few timing-sensitive suites. pnpm check:changed passes typecheck-all, import cycles, plugin boundaries and the database-first guard. Its remaining failures are outside this change: max-lines in untouched files, the existing core test-shard root budget, and two steps that need network.

While shared auth is legacy-main, peers inherit the store of
agents.defaults.authInheritance.agentId, not main's. Doctor always relocated
main's store and then disabled inheritance, so an owner's credentials stayed
local and peers lost them.

Relocate the configured owner's store when main holds no credentials, keep
relocating main when the owner holds none, and skip with a recoverable
warning when both hold credentials, since a single-source move would drop one
side. Copied-update planning now checks both candidate sources.
@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M labels Oct 20, 2026
@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 20, 2026
@sukhdeepjohar
sukhdeepjohar marked this pull request as ready for review October 20, 2026 19:12
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Maintainer security review required

This external contributor PR changes sensitive security components. A maintainer must review these changes before merging.

Current SHA: 7c72f7b4f3934edbf2e54c395a0960e79f566a3d

These sensitive security changes were made:

  • src/infra/state-migrations.shared-auth-store.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/infra/state-migrations.shared-auth-store.types.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

After reviewing the changes, post a new PR comment containing only approval commands, each on its own line:

/allow-security-sensitive-change

A later push requires a fresh approval comment.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 20, 2026
@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

Doctor selects the configured non-main auth inheritance owner's credentials for relocation and skips ambiguous two-store layouts.

Example: authInheritance.agentId is ops, only ops has mock:ops, and dev has no login.

  • Before: Doctor relocates empty main storage; dev's model requests receive 401.
  • After: Doctor relocates mock:ops into shared state; dev's model requests return AUTH_OK.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch and supplied behavior proof are credible; the credential-sharing decision and deliberately partial issue coverage cap overall readiness.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Supplied terminal output exercises built Doctor and real Gateway agent turns after upgrades from 2026.10.5 and 2026.7.1, showing successful owner-backed peer authentication and preserved private peer credentials; production migration-owner traces additionally show retired and reassigned sources rejected without shared publication or source cleanup.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial
User problem: Doctor can leave peer agents without the login designated by the existing inheritance configuration.
Reason: The focused repair has clear value, but changes actual credential access and leaves bootstrap and already-completed cutovers outside its scope.

Merge readiness

⛔ Blocked before merge - 1 item remains

This PR contains useful Doctor repair work and resolves the previous finding; accepting its change to which credentials peers receive needs an explicit owner decision.

Priority: P1
Reviewed head: 8708b7ff12989cfa7bf261dbe0efffddc5244539
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should Doctor make the configured non-main owner's credentials available to peers when released agent turns previously used main's credentials or no credential?
  • Recommendation: Accept configured-owner inheritance: Accept the documented owner as the shared credential source when main is empty, retaining the existing skip when both stores contain credentials.
  • Why: The configured inheritance contract supports this correction, but the original relocation promised unchanged effective credentials and the supplied upgrade traces establish newly granted peer access; no maintainer approval of that tradeoff is recorded.

Before merge

  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

None.

Agent review details

How this fits together

Doctor reads the selected installation's configuration and legacy agent databases, then copies shared credentials, commits shared ownership, cleans source rows, and records migration receipts.

flowchart TD
  A[Selected installation configuration] --> B[Doctor source selection]
  C[Main and configured owner stores] --> B
  B --> D[Conflict and source authority checks]
  D --> E[Existing staged relocation]
  E --> F[Shared state credentials and receipts]
  F --> G[Peer agent authentication]
Loading

Technical review

Best possible solution:

Use the existing staged Doctor relocation with an explicitly accepted configured-owner credential policy, while retaining separate tracking for bootstrap and previously switched installations.

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

Current-main source deterministically selects main regardless of the configured inheritance owner, and the contributor supplies matching stable-upgrade Gateway traces; this review executed no target code.

Is this the best way to solve the issue?

The implementation repairs source selection in the existing migration owner, preserves private peer stores and canonical ownership, and adds distinct snapshot, alias, and retired-source protections without a parallel fallback.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0f46faecf63c.

Provenance checked

  • Doctor shared-auth source selection and relocation changes intended behavior with a stated reason (d2dad76: Separate fleet-wide credentials from main's lifecycle using a staged, recoverable relocation that preserves effective credentials.)
  • Retained deleted-agent source handling keeps the original intent (b068eab: Preserve intentionally retained stores and let unrelated update and Doctor work continue.)
  • Selected installation and copied-plan authority keeps the original intent (6277d6d: Keep migration execution with its existing owner and prevent copied-state planning from inspecting sources outside its authorized snapshot.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +109, Tests +262, Docs 0. Total +371 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 129 20 +109
Tests 3 264 2 +262
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 394 23 +371

Root-cause cluster

Relationship: partial_overlap
Canonical: #178421
Summary: The canonical report covers the shared-source selection mismatch across Doctor and bootstrap; this PR repairs only the Doctor path.

Members:

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status no longer selects a status label.

Label justifications:

  • P1: The targeted cutover leaves peer agents unable to authenticate while the configured credential owner continues working.
  • merge-risk: 🚨 security-boundary: Relocation makes the non-main owner's credentials usable by peers that did not receive them through released agent turns.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-20T19:30:21.843Z sha 487b0d1 :: needs real behavior proof before merge. :: [P2] Compare physical directory identity before declaring separate stores
  • reviewed 2026-10-20T20:20:03.501Z sha a08f303 :: needs real behavior proof before merge. :: [P2] Return before resolving physical sources outside Doctor repair

Reviewed October 20, 2026, 4:37 PM ET / 20:37 UTC (Revision 3).

…before relocation

Compare the configured owner's store with main's by physical database
identity, so an owner agentDir that links to main's directory is not
reported as a second credential store. Recheck the retained-agent matcher
under the migration lock before copying, so a source agent deleted after
detection is never relocated or cleaned.
@sukhdeepjohar

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 20, 2026
The physical identity check for the configured owner's store ran before the
non-repair early return, so an unreadable owner agentDir made ordinary
detection throw. Resolve only path names up front and compare physical
identity in the repair-only source selection.
@sukhdeepjohar

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed 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. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 20, 2026
@clawsweeper clawsweeper Bot added the rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. label Oct 20, 2026
…cation

The point-of-effect recheck treated an unreadable deletion journal as a held
source, so a relocation without a preceding detection pass in that state was
skipped. Detection already refuses an unreadable journal; under the lock only
a deletion recorded since detection blocks the copy.
@sukhdeepjohar

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 21, 2026
steipete added a commit that referenced this pull request Oct 21, 2026
… not main (#179726)

Doctor relocated main's credential store regardless of the configured auth inheritance owner, so agents lost inherited logins. The existing migration now selects the configured owner, preserves conflicting stores with a warning, and protects private credentials and deleted-agent state. Supersedes #178684, thanks @sukhdeepjohar.

Co-authored-by: Sukhdeep Johar <[email protected]>
@steipete

Copy link
Copy Markdown
Contributor

Thank you @sukhdeepjohar! You were right that Doctor ignored a non-main auth inheritance owner and agents lost inherited logins. We re-implemented the fix in #179726, which landed with you credited as co-author. Closing this one as superseded.

@steipete steipete closed this Oct 21, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 22, 2026
… not main (openclaw#179726)

Doctor relocated main's credential store regardless of the configured auth inheritance owner, so agents lost inherited logins. The existing migration now selects the configured owner, preserves conflicting stores with a warning, and protects private credentials and deleted-agent state. Supersedes openclaw#178684, thanks @sukhdeepjohar.

Co-authored-by: Sukhdeep Johar <[email protected]>
@sukhdeepjohar

Copy link
Copy Markdown
Contributor Author

Thanks @steipete for getting this fixed and landed !

RomneyDa pushed a commit that referenced this pull request Oct 26, 2026
… not main (#179726)

Doctor relocated main's credential store regardless of the configured auth inheritance owner, so agents lost inherited logins. The existing migration now selects the configured owner, preserves conflicting stores with a warning, and protects private credentials and deleted-agent state. Supersedes #178684, thanks @sukhdeepjohar.

Release adaptation: stable lacks the integrityCheck option on the shared auth source reader/cleanup, so ownerId is threaded without it. The main test-file refactor (top-level helpers) does not exist on stable; the new owner/conflict/alias cases live in state-migrations.shared-auth-store.inheritance-owner.test.ts, and the deleted-owner case uses stable fixtures (createLegacyDatabaseFixture + deletion journal).

Co-authored-by: Sukhdeep Johar <[email protected]>
(cherry picked from commit 3d51d00)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. docs Improvements or additions to documentation merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. security-review-required security-sensitive-changed size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants