Skip to content

fix(doctor): keep inherited logins with a non-main owner - #179726

Merged
steipete merged 2 commits into
mainfrom
upd/upd-l1772
Oct 21, 2026
Merged

steipete merged 2 commits into
mainfrom
upd/upd-l1772

Conversation

@steipete

@steipete steipete commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes lost inherited logins after openclaw doctor --fix when agents.defaults.authInheritance.agentId names an agent other than main.

Supersedes #178684, thanks @sukhdeepjohar. Related: #178421.

User Impact

Doctor relocates the configured owner's credentials when that owner has credentials and main has none. Peers can then use the configured shared login; their private credentials stay local. If both stores contain credentials, Doctor preserves both and reports a recoverable warning explaining how to retry.

This corrects the documented inheritance contract: affected peers can gain access to their configured owner's credentials after relocation, where released runtimes previously used main or had no credential. Fresh-store bootstrap and installations that already completed the shared-state cutover remain outside this repair.

Why This Change Was Made

The existing staged migration always selected main's database. The repair supplies Doctor's selected configuration to that same migration owner, checks both possible sources against copied-state boundaries, and carries the selected agent identity through source reads and cleanup. Retained deleted stores remain protected, including deletion after detection. Physical directory aliases are compared without registering a different runtime owner.

The copy, ownership publication, cleanup, conflict checks, and receipts retain their existing owners. No config option, dependency, database schema, or runtime auth fallback is added. Production: +132/-35 (net +97); tests: +159/-2 (net +157); docs: +2. The necessary growth is source selection and preservation checks within the existing migration.

Evidence

  • CI typing follow-up: reproduced TS2322 in test/tsconfig/tsconfig.core.test.state-logging.json, then typed the shared-auth fixture environment as NodeJS.ProcessEnv (no cast or suppression). node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.state-logging.json --noEmit now passes. OPENCLAW_VITEST_RUNTIME=node and OPENCLAW_VITEST_RUNTIME=bun, each with node scripts/run-vitest.mjs src/infra/state-migrations.shared-auth-store.test.ts --maxWorkers=1, both pass: 32 passed / 1 existing Linux-only skip. Runner times: 47.00 s Node / 33.28 s Bun. All used isolated HOME/state under the worktree. Targeted type-aware lint, formatting, diff checks, and Codex autoreview pass. Follow-up delta: production +0/-0; test +5/-1.

  • Regressions on main c5471a5ffd8d failed for standard/custom owner directories, the main-directory override, two populated stores, and the copied snapshot boundary. The alias regression also caught and now protects against reverse-owner registration during source selection.

  • Bun: OPENCLAW_VITEST_RUNTIME=bun node scripts/run-vitest.mjs src/infra/state-migrations.shared-auth-store.test.ts src/infra/state-migrations.caller-mode.refusal.test.ts src/infra/state-migrations.retained-deleted-agent.test.ts --maxWorkers=1 — 65 passed, one existing Linux-only POSIX-lock case skipped on macOS; 87.84 seconds total.

  • Core and infra-test typechecks, targeted type-aware oxlint/oxfmt, git diff --check, and the import-cycle check pass. Codex autoreview found no actionable P0/P1 findings. The full SQLite inventory in check:changed was not run locally because of its known 20–40+ minute host stall; PR CI remains the broad gate.

  • Live upgrade: installed published [email protected] in an isolated prefix and saved fixture:owner using its models auth paste-api-key --provider fixture --profile-id fixture:owner --agent ops command. The candidate's pnpm openclaw doctor --fix --non-interactive --no-workspace-suggestions upgraded that stopped synthetic state from shared/agent schemas 20/25 to 30/31, moved the owner profile, recorded the ops source path, and cleaned the local auth row.

  • Started pnpm openclaw gateway run --port 62382 --bind loopback on the upgraded state. Two pnpm openclaw agent --agent dev --message <request> --json turns (requests: Reply AUTH_OK only. and Reply AUTH_OK again.) returned status: ok and AUTH_OK; the local OpenAI-compatible model server observed the expected owner credential on both requests. Agent-reported durations: 929 ms and 141 ms. The Gateway and model server were stopped after proof.

  • All live commands used isolated HOME, config, and state directories under this worktree. A stopped pre-upgrade copy was retained before mutation. Doctor's automatic original-state capture warned about this host volume's writable ancestor; that host limitation did not prevent migration, and no operator state was used.

  • Node: all 40 directly importing test files passed, with 481 passed / 4 existing skips, across six Vitest shards in 1135.74 seconds. The skips are three opt-in PostgreSQL integration cases and the Linux-only POSIX-lock case. The caller list was collected and run in its original order:

    rg -l 'state-migrations\.(doctor|shared-auth-store)' --glob '*.test.ts' src extensions packages test > .artifacts/consumer-tests.txt
    lane_tests=("${(@f)$(cat .artifacts/consumer-tests.txt)}")
    OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs "${lane_tests[@]}" --maxWorkers=1
  • Reported test time for the touched files (Node / Bun, excluding shared preparation): shared-auth store 34.81 / 22.37 s, copied-plan refusals 31.69 / 15.29 s, retained deleted agents 71.52 / 38.35 s. These exercise real SQLite migration and custody; the new retired-owner case takes about one second. No individual test exceeded 30 seconds, and no test file exceeded 120 seconds of test time. No flaky failure was observed. Initial PR CI caught the fixture typing error corrected above.

Relocate the configured inheritance owner's credentials through Doctor's
existing staged migration, while preserving populated main/owner stores
with a recoverable warning. Keep copied-state boundaries and source custody,
and resolve path aliases without changing runtime ownership registration.

Related: #178421
Supersedes: #178684
Co-authored-by: Sukhdeep Johar <[email protected]>
@clawsweeper

clawsweeper Bot commented Oct 21, 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.

@steipete
steipete marked this pull request as ready for review October 21, 2026 17:04
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T17:20:50.329264Z 6e4796b Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M labels Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 39d2fe159525c23261817eee54c6cc8638b561bb
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive 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.

Carefully review these changes before merging.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e4796b39a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +547 to +548
(hasPendingSharedAuthCleanup(env, owner.sourcePath, params) ||
(ownership.location === "legacy-main" && hasCredentials(owner.sourcePath, params)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check retained ownership before reading the configured store

When the configured non-main owner was already deleted and retained before detection, this condition calls hasCredentials() before retainedSource() checks the deletion journal. If that held database is unreadable or corrupt, detection throws SharedAuthStoreSourceInspectionError, blocking Doctor/update instead of returning the recoverable held-store warning used for main; check retention before inspecting the owner's rows.

AGENTS.md reference: AGENTS.md:L75-L76

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 21, 2026
@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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 21, 2026
@clawsweeper

clawsweeper Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Doctor relocates credentials from the configured non-main inheritance owner while preserving private credentials and ambiguous populated stores.

Example: The inheritance owner is ops, ops holds fixture:owner, main is empty, and dev has no local login.

  • Before: Doctor relocates empty main state, leaving dev without the intended shared credential.
  • After: Doctor relocates fixture:owner from ops, allowing dev to authenticate through shared state.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused repair with stable-upgrade evidence, one verified P2 defect, and incomplete candidate authority-boundary proof.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Peers can lose access to the intended shared login after Doctor relocates an empty main store instead of the configured owner's credentials.
Reason: The maintainer-authored direction restores the documented ownership contract and explicitly leaves bootstrap and completed-cutover recovery to separate work.

Merge readiness

⛔ Blocked before merge - 5 items remain

Keep this PR open: it repairs a current credential-migration bug, but retained-store detection still has an actionable P2 defect.

Priority: P1
Reviewed head: 39d2fe159525c23261817eee54c6cc8638b561bb

Before merge

  • Add real behavior proof - Authority-chain proof required: the supplied isolated 2026.10.5 upgrade and real Gateway turns demonstrate allowed ops-to-shared publication and peer authentication, but candidate-specific final-effect rejection for a retired or reassigned ops source is absent; the credited predecessor's traces exercise its own source-resolution path. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Check retained ownership before inspecting candidate credentials (P2) - With legacy-main ownership and a configured ops owner already deleted with its database retained, hasCredentials opens ops before retainedSource checks the deletion journal. An unreadable or corrupt held database therefore throws SharedAuthStoreSourceInspectionError and halts Doctor/update instead of producing the established recoverable held-store skip. The same ordering can inspect a retained main store during the conflict check. Classify retention before credential reads for either candidate and cover a held unreadable store.
  • Resolve security concern: Verify stale source authority at credential publication - The candidate carries ownerId into database admission and rechecks the deletion journal after its awaited source read, but supplied candidate evidence exercises allowed publication only; retirement and reassignment rejection traces belong to the predecessor implementation.
  • Resolve merge risk - Publishing a non-main owner's credentials fleet-wide requires candidate-specific final-effect rejection evidence for a retained or reassigned source owner; the linked predecessor exercised a different source-resolution implementation.
  • Explain or restore the original intent of Retained deleted agent stores - b068eab: Preserve retained databases and continue updates with recoverable warnings rather than treating them as active migration sources.

Findings

  • [P2] Check retained ownership before inspecting candidate credentials — src/infra/state-migrations.shared-auth-store.ts:547-551
  • [medium] Verify stale source authority at credential publication — src/infra/state-migrations.shared-auth-store.ts:616

Provenance

  • Retained deleted agent stores changes intended behavior without addressing why it exists (b068eab: Preserve retained databases and continue updates with recoverable warnings rather than treating them as active migration sources.)

Tests

  • Missing end-to-end proof: Add candidate production-path evidence that retirement or database reassignment after detection prevents shared credential publication and source cleanup; redact credentials and private endpoints.
Agent review details

How this fits together

Doctor consumes the selected installation configuration and legacy agent databases, then copies credentials into shared SQLite state, publishes shared ownership, and cleans the recorded source.

flowchart TD
  A[Selected installation config] --> B[Doctor source detection]
  C[Legacy agent stores] --> B
  B --> D[Retention and ownership checks]
  D --> E[Staged shared state migration]
  E --> F[Peer credential resolution]
Loading

Technical review

Best possible solution:

Keep the existing staged migration owner, check retention before inspecting either candidate store, and preserve the explicitly limited Doctor scope.

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

Current main selects main without consulting the configured inheritance owner; the supplied base-red regressions and stable-upgrade Gateway results support this path, but this review executed no target code.

Is this the best way to solve the issue?

Repairing source selection inside Doctor's existing migration is appropriate and avoids restoring a competing runtime fallback; the retention check must precede credential inspection.

Full review comments:

  • [P2] Check retained ownership before inspecting candidate credentials — src/infra/state-migrations.shared-auth-store.ts:547-551
    With legacy-main ownership and a configured ops owner already deleted with its database retained, hasCredentials opens ops before retainedSource checks the deletion journal. An unreadable or corrupt held database therefore throws SharedAuthStoreSourceInspectionError and halts Doctor/update instead of producing the established recoverable held-store skip. The same ordering can inspect a retained main store during the conflict check. Classify retention before credential reads for either candidate and cover a held unreadable store.
    Confidence: 0.99
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Prove rejected source owners cannot publish credentials (recommended)
    Exercise the candidate's production migration with ops retained or its database reassigned after detection, showing shared credentials and source rows remain unchanged.

Provenance checked

  • Staged shared-auth relocation changes intended behavior with a stated reason (d2dad76: Move fleet-wide credentials away from the main agent through a retryable Doctor-owned copy, ownership publication, and cleanup.)
  • Post-cutover local overrides keeps the original intent (7278377: Ownership markers and exact-source receipts authorize relocation; ordinary local rows after cutover must remain untouched.)
  • Selected installation and copied-state boundaries keeps the original intent (6277d6d: Keep migration inspection inside bound source endpoints and preserve required refusal behavior.)

Testing

Proof path: shipped entry point.

Security

Needs attention: Candidate-specific rejection proof remains necessary before non-main credentials become fleet-wide.

Evidence

Security concerns:

  • [medium] Verify stale source authority at credential publication — src/infra/state-migrations.shared-auth-store.ts:616
    The candidate carries ownerId into database admission and rechecks the deletion journal after its awaited source read, but supplied candidate evidence exercises allowed publication only; retirement and reassignment rejection traces belong to the predecessor implementation.
    Confidence: 0.9

What I checked:

PR surface

Source +97, Tests +161, Docs +2. Total +260 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 132 35 +97
Tests 3 164 3 +161
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 298 38 +260

Labels

Label changes:

  • add P1: The central bug breaks peer agent authentication during Doctor relocation for installations with a configured non-main credential owner.
  • add merge-risk: 🚨 security-boundary: The migration makes previously local owner credentials available through the fleet-wide shared store, so stale or reassigned source authority must be rejected before publication.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P1: The central bug breaks peer agent authentication during Doctor relocation for installations with a configured non-main credential owner.
  • merge-risk: 🚨 security-boundary: The migration makes previously local owner credentials available through the fleet-wide shared store, so stale or reassigned source authority must be rejected before publication.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

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

  • Show the candidate rejecting a retained or reassigned source owner before shared credential writes or source cleanup.

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.

Reviewed October 21, 2026, 4:03 PM ET / 20:03 UTC.

@steipete
steipete merged commit 3d51d00 into main Oct 21, 2026
142 of 143 checks passed
@steipete
steipete deleted the upd/upd-l1772 branch October 21, 2026 20:09
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]>
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)
tideclaw-bot added a commit that referenced this pull request Nov 4, 2026
Adapt 21 audited fixes to release-native ownership and recovery.
Retain strict temporary environment isolation and provider-only cooldowns.

Original-source provenance and contributor credit:
#179144 5a97c90 — Peter Steinberger <[email protected]>
#180280 442c2f7 — Jason (Json) <[email protected]>
#178596 63f386b — Braden Guliano <[email protected]>
#181804 d75915e — Peter Steinberger <[email protected]>
#181140 b4031b2 — Peter Steinberger <[email protected]>
#182207 b8fae65 — Peter Steinberger <[email protected]>
#180792 d2c70dd — Peter Steinberger <[email protected]>
#179205 c08aa6d — Peter Steinberger <[email protected]>
#179997 f178dd9 — mali <[email protected]>
#181270 e204484 — Peter Steinberger <[email protected]>
#179031 855b0aa — Peter Steinberger <[email protected]>
#179726 3d51d00 — Peter Steinberger <[email protected]>
#179249 b617d97 — Josh Avant <[email protected]>
#182385 bb13bcd — Peter Steinberger <[email protected]>
#182615 411bac2 — Peter Steinberger <[email protected]>
#181300 765c2f1 — Peter Steinberger <[email protected]>
#179549 09ba994 — Peter Steinberger <[email protected]>
#179445 ac5587b — Peter Steinberger <[email protected]>
#181127 25dde25 — Josh Lehman <[email protected]>
#173209 ebccf57 — Peter Steinberger <[email protected]>
#175289 e579f09 — Peter Steinberger <[email protected]>

Proof: targeted owner/regression tests; Qwen15 and catalog pool13 pass.
Final integrated lint/type/format pass remains pending under user direction.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. security-sensitive-changed size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant