Skip to content

fix(state): repair private state stores after K8s fsGroup remount - #196706

Open
shuisadev wants to merge 1 commit into
openclaw:mainfrom
shuisadev:fix/private-store-repair-minted-stores
Open

shuisadev wants to merge 1 commit into
openclaw:mainfrom
shuisadev:fix/private-store-repair-minted-stores

Conversation

@shuisadev

@shuisadev shuisadev commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: after a Kubernetes PVC remount with fsGroup, openclaw gateway run repairs the SQLite credential store but managed GitHub identities still fail git push ("Reconnect or change GitHub Identity") and Codex workers report Worker Codex configuration directory is unsafe — their private stores stay group-writable (2770 dirs / 0660 files) because the startup repair only enumerated .update-captures, client/credentials.sqlite, and control/services.sqlite, missing credentials/github/<scope>/<profileId> and codex-runtime.

User Impact

Users running openclaw on Kubernetes or Podman who have enrolled managed GitHub identities or Codex workers keep them after a PVC remount — no reconnect, no re-enroll. Unaffected installations see no change.

Why This Change Was Made

Extend restorePrivateStateStoreModes to enumerate two minted-store families through their owners' naming contracts:

  • GitHub: credentials/github/system, credentials/github/personal, and every 64-hex hashed agent key under credentials/github/agents/<key>, then every child matching isManagedGitHubProfileId (ghp_[a-f0-9]{32})
  • Codex: <stateDir>/codex-runtime (direct child of state root)

Each minted store is restored as a whole: directory first (descriptor-bound, O_NOFOLLOW, uid-match), then every regular file directly inside. namesPlainDirectoryChainSync refuses symlinked ancestors above the store so an alias at credentials or credentials/github cannot lend the repair to another tree.

Review follow-up: repair owned stores without requiring unrelated ones

The previous revision bailed out entirely when the state directory contained neither <stateDir>/.update-captures nor an existing SQLite store, as a workaround for test fixtures that stub OPENCLAW_STATE_DIR at synthetic roots. That pre-check was wrong twice over:

  • it probed <stateDir>/.update-captures, while the capture root is the sibling <stateDir>.update-captures;
  • it skipped real stores whenever an unrelated one was absent, including the capture-only layout main already repaired.

The pre-check is gone. Every store admits itself through its own descriptor, so a state directory that holds only some stores is repaired for what it holds, and the repair makes no decision about stores it cannot see. Two regressions pin that, both with no SQLite store present: a capture root mounted alone, and minted GitHub/Codex stores mounted alone.

Evidence

All repair paths run through openclaw doctor --non-interactive --repair, which invokes ensureOpenClawStatePermissions via doctor-config-preflight.ts:100 and gateway-lock.ts:531 (gateway startup path).

Red/green on the reviewed defect

Same filesystem layouts, same code path, only src/state/openclaw-state-db-permissions.ts differs:

Layout Before (reviewed head 5cebd16) After (this head)
capture root only (no SQLite) 2770, not repaired 0700, repaired
GitHub profile + codex-runtime only (no SQLite) 2770 / 0660, not repaired 0700 / 0600, repaired

Driver-lane GHA upgrade proof (external repo)

Public repo github.com/SunnyShu0925/oc-privatestore-upgrade-proof, run 42953923900, checked out at 42653076a7b7b3ad36e1fcc64ce1a1b138288785. Recipe: install latest stable [email protected] → fixtures widened to 2770/0660 → driver doctor confirms what it can and cannot repair → tarball built from this PR head (stamped 2026.11.4, see note) → openclaw update installs it over the stable driver → candidate doctor --repair repairs every private store → data retained.

The candidate carries the version stamp 2026.11.4 because this branch still declares 2026.11.2 in package.json; without a stamp above the driver's 2026.11.3, openclaw update would treat the candidate as a downgrade. The stamp is the only change CI makes to the packaged tree — dist/ and every source file come from this head.

Fixture Driver widens Driver repairs Candidate repairs Data retained
SQLite .update-captures/ 2770 dir ✅ ✅ ✅
client/credentials.sqlite 0660 ✅ ✅ ✅
GitHub credentials/github/system/ghp_* 2770 / 0660 ❌ (not enumerated) ✅ ✅
GitHub credentials/github/personal/ghp_* 2770 / 0660 ❌ (not enumerated) ✅ ✅
GitHub credentials/github/agents/<64hex>/ghp_* 2770 / 0660 ❌ (not enumerated) ✅ ✅
Codex codex-runtime/ 2770 / 0660 ❌ (not enumerated) ✅ ✅
Capture root only, no SQLite (new) 2770 dir —¹ ✅ ✅
Minted stores only, no SQLite (new) 2770 / 0660 —¹ ✅ ✅

¹ The two minimal layouts run against the candidate binary, after the upgrade step has replaced the driver. Both contain only the capture root / the minted stores when doctor starts; doctor then creates its own state database inside them, which is why the log later lists client/credentials.sqlite beside the repaired stores. The reviewed-head red check for both layouts is in the table above.

Raw proof log (trimmed to the permission checks)
42653076a7b7b3ad36e1fcc64ce1a1b138288785 fix(state): repair minted private stores after an fsGroup remount
driver: OpenClaw 2026.11.3 (847611d)   candidate tarball: 2026.11.4

=== step 6b: permissions after driver doctor (still widened) ===
2770 .../proof-state/credentials/github/system/ghp_0123456789abcdef0123456789abcdef
660  .../proof-state/credentials/github/system/ghp_0123456789abcdef0123456789abcdef/hosts.yml
2770 .../proof-state/credentials/github/agents/aaaaaaaa...aaaa/ghp_0123456789abcdef0123456789abcdef
660  .../proof-state/credentials/github/agents/aaaaaaaa...aaaa/ghp_0123456789abcdef0123456789abcdef/hosts.yml
2770 .../proof-state/codex-runtime
660  .../proof-state/codex-runtime/config.json
  MINTED-STILL-WIDENED (expected): codex-runtime → 2770
    FILE-STILL-WIDENED (expected): config.json → 660
driver controls_repaired=true minted_still_broken=true

=== step 7: upgrade driver → candidate tarball ===
✅ OpenClaw updated to 2026.11.4 (from 2026.11.3); 22 warnings need attention.
Update target: 2026.11.4
update exit=0

=== step 8b: permissions after candidate doctor --repair ===
700 .../proof-state/credentials/github/system/ghp_0123456789abcdef0123456789abcdef
600 .../proof-state/credentials/github/system/ghp_0123456789abcdef0123456789abcdef/hosts.yml
700 .../proof-state/credentials/github/agents/aaaaaaaa...aaaa/ghp_0123456789abcdef0123456789abcdef
600 .../proof-state/credentials/github/agents/aaaaaaaa...aaaa/ghp_0123456789abcdef0123456789abcdef/hosts.yml
700 .../proof-state/codex-runtime
600 .../proof-state/codex-runtime/config.json
  MINTED REPAIRED (expected): codex-runtime → 700
    FILE REPAIRED (expected): config.json → 600

=== step 10: candidate repairs a capture-only state directory (no SQLite store) ===
before: 2770 .../proof-capture-only.update-captures
capture-only doctor exit=0
  [capture-only] capture root → 700 (want 700), repaired=true
  [capture-only] captured bytes retained=YES

=== step 11: candidate repairs minted stores without an installation database ===
minted-only doctor exit=0
  [minted-only] ghp_0123456789abcdef0123456789abcdef dir → 700 (want 700)
  [minted-only] hosts.yml → 600 (want 600)
  [minted-only] codex-runtime dir → 700 (want 700)
  [minted-only] config.json → 600 (want 600)
  [minted-only] repaired=true

=== FINAL VERDICT ===
  VERDICT=PASS

Checklist:
  [driver] controls_repaired       = YES
  [driver] minted_still_broken      = YES
  [candidate] all_stores_repaired   = YES
  [candidate] data_retention        = YES
  [candidate] capture_only_repaired = YES
  [candidate] minted_only_repaired  = YES
  [upgrade]  exit_code              = 0

Regression tests

15 test declarations (16 cases) in src/state/openclaw-state-db-permissions.test.ts covering minted-store enumeration, descriptor admission (O_NOFOLLOW + uid-match), ancestor alias refusal, Codex bundle repair, and the two minimal layouts above. No new test file; the added lines are covered by config/test-lines-allocations/fsgroup-remount-minted-stores.txt (181 lines, the ceiling growth the ratchet grants this diff).

CI note

After rebasing onto current main, the previously-red sessions-rewind.storage.test.ts and telegram-model-picker-prepared-gateway.e2e.test.ts shards are green: main fixed the former in #196702, and the latter was an intermittent e2e flake. This head still fails four shards on tests this diff does not touch:

  • src/cli/gateway-cli/run-loop.direct-stop-active-work.process.test.ts — timing assertion on the shared runner's systemd shutdown budget;
  • test/loopback-ask-user-telegram-channel.test.ts — Telegram loopback flake;
  • src/gateway/server-close.session-rewind.test.ts — session-rewind race;
  • ui/src/e2e/screen-requester-routing.e2e.test.ts — UI e2e flake (this file differs from main only because main advanced past the rebase point via fix(ui): restore settings browser fixture capabilities #197001; the PR does not touch it).

All four are byte-identical to the rebase base (or, for the UI file, untouched by this diff), none appear in git diff --name-only, and the changed code only narrows modes on paths the process already owns. The prior sessions-rewind.storage failure was independently reproducible on #192552 (agentic-gateway-methods-hosted-4, job 129605811557).

@clawsweeper

clawsweeper Bot commented Nov 10, 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 triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Nov 10, 2026
@shuisadev shuisadev changed the title fix: repair private state stores after K8s fsGroup remount fix(state): repair private state stores after K8s fsGroup remount Nov 10, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Nov 10, 2026
@shuisadev
shuisadev marked this pull request as ready for review November 10, 2026 14:42
@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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head 42653076a7b7b3ad36e1fcc64ce1a1b138288785, but the PR head is now 62dd8949b5248f2af09ca9850cfee524fb093991. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (5 earlier review cycles)
  • reviewed 2026-11-10T15:10:39.991Z sha 5cebd16c014f3f1ae239f592548c360f2e0d9b9d :: needs real behavior proof before merge. :: [P2] [P2] Repair owned stores without requiring unrelated SQLite files
  • reviewed 2026-11-11T01:43:14.944Z sha 68c9b84f31e0afaab52206112fa5d041ea48e8e1 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-11T02:17:11.384Z sha 68c9b84f31e0afaab52206112fa5d041ea48e8e1 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-11T02:56:13.104Z sha 68c9b84f31e0afaab52206112fa5d041ea48e8e1 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-11T04:16:55.796Z sha 42653076a7b7b3ad36e1fcc64ce1a1b138288785 :: needs maintainer review before merge. :: none

@shuisadev
shuisadev force-pushed the fix/private-store-repair-minted-stores branch 2 times, most recently from cd3e18d to 68c9b84 Compare November 11, 2026 01:09
@shuisadev

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Head 68c9b84, body and proof are current:

  • Removed the installation-wide pre-check that made the repair wait for an unrelated store. Every store now admits itself, so a capture-only volume and a minted-store-only directory are repaired for what they hold. Two regressions in openclaw-state-db-permissions.test.ts cover both layouts with no SQLite store present.
  • Red/green on the reviewed defect: the same two layouts stay at 2770/0660 on the reviewed head and return to 0700/0600 on this head.
  • Fresh driver-lane upgrade proof at this head: run 42937923754 — VERDICT=PASS, including capture_only_repaired=YES and minted_only_repaired=YES; the raw log is inline in the body.
  • The two red shards (sessions-rewind.storage.test.ts, run-loop.direct-stop-active-work.process.test.ts) are recurring timing assertions in files byte-identical to main; the body states that and the changed code only narrows modes on paths the process already owns.

@clawsweeper

clawsweeper Bot commented Nov 11, 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 Nov 11, 2026
@clawsweeper

clawsweeper Bot commented Nov 11, 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed 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. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 11, 2026
@shuisadev
shuisadev force-pushed the fix/private-store-repair-minted-stores branch from 68c9b84 to 4265307 Compare November 11, 2026 03:36
@shuisadev

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 11, 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 11, 2026
@shuisadev
shuisadev force-pushed the fix/private-store-repair-minted-stores branch 2 times, most recently from 95a8b99 to c7ef18f Compare November 12, 2026 01:44
@shuisadev
shuisadev force-pushed the fix/private-store-repair-minted-stores branch from c7ef18f to 052e603 Compare November 12, 2026 02:19
An fsGroup volume remount re-applies group permissions across the state
volume, and the private stores refuse to open state they own at a widened
mode. restorePrivateStateStoreModes repaired an enumerated list that held
only the SQLite stores and the capture root, so a remounted installation
still refused the two stores whose names are minted at runtime: the
managed GitHub identity profiles, and the enrolled Codex worker's
codex-runtime bundle. git push then failed with a reconnect hint that
could not help, and codex.app-server stayed unavailable.

Enumerate both families through the owners that mint them -
isManagedGitHubProfileId per scope generation below credentials/github,
the hashed agent key for agent-scoped identities, and the regular files
directly inside codex-runtime - and admit the scope root that holds them
before reading it, so a symlinked scope stops the search instead of
lending the repair to another tree. The repair stays an enumerated list,
keeps every downstream admission check strict, and still skips symlinks,
foreign-owned paths and world bits.

Every store admits itself, so a state directory that holds only some of
them is repaired for what it holds: a capture-only volume, or stores
whose databases live under a custom path, no longer waits for an
unrelated store to exist.
@shuisadev
shuisadev force-pushed the fix/private-store-repair-minted-stores branch from 052e603 to 62dd894 Compare November 12, 2026 02:31
@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Nov 19, 2026

This branch has not been deployed

No deployments
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 P1 High-priority user-facing bug, regression, or broken workflow. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants