Skip to content

fix(codex): stop rebuilding shared Codex state from a read that failed (STA-4823) - #15417

Merged
brennanb2025 merged 10 commits into
mainfrom
brennanb2025/sta-4823-shared-observation-batch
Aug 23, 2026
Merged

brennanb2025 merged 10 commits into
mainfrom
brennanb2025/sta-4823-shared-observation-batch

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​737 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​736
Prod 14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​494 $\color{#cf222e}{\Huge{\mathbf{−}}}$​142 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​352

ELI5

Orca now treats a failed read as “unknown,” not “missing.” A transient filesystem or transport failure can no longer authorize a rebuild, destructive write, cached erasure, or healthy sync result; genuine absence and malformed state still recover as intended.

What Changed

Defect Host trigger after measurement Fix
D15 — sync status Live: a content read fails after metadata succeeds, but status reported synced Observe the bounded content read and report the existing managed-home-unavailable state
D26 — settings baseline Live: promotion/mirror loses an unreadable baseline, returns an empty plan, and can overwrite a pending runtime edit Preserve indeterminate baselines across snapshot and promotion; rebuild only absent or known-invalid state
D30 — trust-grant ledger Live: an unreadable ledger becomes empty and the next write drops other homes’ grants Refuse the write until the existing ledger can be read
D31 — pane attribution Live: an unreadable registry becomes a cached/persisted empty registry Do not cache or persist stand-in state; retain one-shot mutations and retry bounded persistence after recovery
D29 — config.toml trust upsert Host-lane insurance: requires an indeterminate existence observation to be folded into absence Seed only after definitive ENOENT/ENOTDIR; propagate every other read failure
D33 — hooks.json observation Host-lane insurance: likewise requires the existence probe to hide a present file Use one classified content read and return unknown for indeterminate failures

Permission-denial correction

An ordinary permission denial cannot reach D29’s rebuild-from-empty branch. On macOS, chmod 000 leaves existsSync true and stat/lstat successful before readFileSync fails with EACCES (-13); on Windows, icacls /deny USER:(R) produces the same metadata shape before the content read fails with EPERM (-4048). Pre-fix D29 therefore took the read branch, threw, and the hook-service caller reported that trust entries could not be written—no trust-only stub was produced.

D29 and D33 remain conservative insurance for indeterminate existence/transport states. The host defects that survive the measurement are D15, D26, D30, and D31. D26’s live failure is the promotion/mirror path; its snapshot path was already fail-safe for the measured permission-denial shape.

Pane-attribution durability

One-shot pane attribution updates are now retained while the registry is unreadable and merged after recovery. Automatic retries are bounded to 2,000 pending mutations and delays of 100 ms, 1 s, 5 s, and 30 s; the timer is unreferenced, and failed reconciliation-only writes also retry rather than silently canceling themselves.

Sync-health parity

The final review found that an unreadable D26 baseline safely stopped promotion/mirroring but could still report synced. Health now observes that baseline too, reuses the existing managed-home-unavailable reason, and includes an optional managed-state path so diagnostics name the file that actually failed; the optional field preserves compatibility with existing status consumers.

Linked Issue

Fixes STA-4823. The transport-specific follow-up remains in STA-4606.

Visual Proof

Final-head (02990b36f1) isolated Electron startup via Playwright CDP: correct branch/worktree identity, zero console errors, and no secrets or unrelated workspace state. The filesystem-denial path has no bespoke rendered control, so this proves clean startup rather than the main-process failure path itself.

startup-full-window.png

Testing

The focused STA regression file has 20 cases, with four additional pane-registry retry cases and two baseline-health status/IPC cases. The mutation matrix was rerun against each guard rather than inferred from the happy-path suite:

Reverted behavior Mutation result
D15 content observation unreadable managed config incorrectly reports healthy
D26 tri-state baseline/promotion pending runtime edit is lost or baseline is replaced
D30 ledger guard unrelated homes’ grants are dropped
D31 registry guards attribution is cached/persisted as erased
D29 definitive-absence guard denyExistence rebuilds from trust entries alone; ordinary content denial remains fail-safe pre-fix
D33 definitive-absence guard denyExistence reports a present file as valid empty config; ordinary content denial remains unknown pre-fix
Reconciliation persistence gate failed reconciliation writes only once instead of retrying
Baseline health observation mirror refusal remains safe but status/IPC incorrectly report synced
  • Requested main suites after the final fix: 175 files passed, 1 skipped; 1,787 tests passed, 12 skipped across src/main/codex, src/main/codex-accounts, and src/main/agent-hooks.

  • Including the sync-status IPC suite: 176 files passed, 1 skipped; 1,792 tests passed, 12 skipped.

  • Codex-focused readiness run: 106 files passed, 1 skipped; 1,117 tests passed, 6 skipped.

  • Renderer stale-pane coverage: 4 files / 71 tests passed.

  • Node 24 typecheck, changed-code quality, max-lines ratchet, oxfmt, and diff checks passed.

  • CI passed, including all Node 24/26 test shards and Windows packaging.

  • macOS and Windows permission behavior was measured directly as described above.

  • Automated tests added

  • Manual final-head Electron startup validation

AI Disclosure

N/A — internal.

@coderabbitai

coderabbitai Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7d01855a-0212-4094-9bad-f47a4389f397

📥 Commits

Reviewing files that changed from the base of the PR and between e3327c2 and 572b2fa.

📒 Files selected for processing (14)
  • src/main/agent-hooks/hooks-json-read.ts
  • src/main/codex/codex-config-mirror.ts
  • src/main/codex/codex-pane-account-registry.ts
  • src/main/codex/codex-real-home-hook-install.test.ts
  • src/main/codex/codex-real-home-hook-install.ts
  • src/main/codex/codex-trust-grant-ledger.ts
  • src/main/codex/config-settings-baseline.ts
  • src/main/codex/config-settings-promotion.ts
  • src/main/codex/config-sync-stall.test.ts
  • src/main/codex/config-sync-stall.ts
  • src/main/codex/config-toml-trust.ts
  • src/main/codex/hook-service-user-hook-mirroring.test.ts
  • src/main/codex/hook-service.ts
  • src/main/codex/sta-4823-shared-state-survives-a-failed-read.test.ts
🚧 Files skipped from review as they are similar to previous changes (13)
  • src/main/codex/codex-real-home-hook-install.ts
  • src/main/codex/config-toml-trust.ts
  • src/main/agent-hooks/hooks-json-read.ts
  • src/main/codex/config-sync-stall.test.ts
  • src/main/codex/codex-real-home-hook-install.test.ts
  • src/main/codex/hook-service-user-hook-mirroring.test.ts
  • src/main/codex/codex-pane-account-registry.ts
  • src/main/codex/hook-service.ts
  • src/main/codex/config-settings-promotion.ts
  • src/main/codex/config-sync-stall.ts
  • src/main/codex/codex-trust-grant-ledger.ts
  • src/main/codex/sta-4823-shared-state-survives-a-failed-read.test.ts
  • src/main/codex/config-settings-baseline.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Codex shared-state readers now distinguish absent, malformed, and unreadable files. Write and reconciliation paths stop when existing state cannot be read. Settings baseline observation now has present, absent, and indeterminate states. Configuration sync reports unavailable or unreadable paths. Hook cleanup and mirroring preserve existing runtime state when source reads fail. Regression tests cover failed reads and recovery across hooks, ledgers, baselines, configuration, and pane registries.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the Codex fix and the failure mode addressed, matching the PR's main goal of preventing rebuilds after failed reads.
Description check ✅ Passed The description is detailed and covers the change, rationale, linked issue, visual proof, testing, and AI disclosure, although some template sections are omitted.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/main/codex/config-settings-promotion.ts (1)

246-251: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Preserve the original baseline read error.

The runtime-config arm at Line 242 throws runtimeTomlObservation.error, so the errno reaches the log. This arm throws a new Error and discards the underlying filesystem error. An operator cannot then tell EPERM from EBUSY for the baseline path.

CodexSettingsBaselineObservation does not carry the error today. Add it to the indeterminate variant in src/main/codex/config-settings-baseline.ts, then rethrow it here.

♻️ Proposed change

In src/main/codex/config-settings-baseline.ts:

   | { kind: 'absent' }
-  | { kind: 'indeterminate' }
+  | { kind: 'indeterminate'; error: unknown }

Return the caught error from readParsedCodexSettingsBaseline instead of the 'unreadable' sentinel, then here:

   if (baselineObservation.kind === 'indeterminate') {
     // Why: an empty plan here lets the mirror proceed and write the system value
     // back over an in-Codex edit this baseline would have identified. The caller
     // turns a throw into the existing stall-and-retry null.
-    throw new Error('Codex settings baseline could not be read')
+    throw baselineObservation.error
   }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f5883728-2239-47bb-a2a5-a543d1c0fc28

📥 Commits

Reviewing files that changed from the base of the PR and between 200d8a5 and 80aba44.

📒 Files selected for processing (8)
  • src/main/agent-hooks/hooks-json-read.ts
  • src/main/codex/codex-pane-account-registry.ts
  • src/main/codex/codex-trust-grant-ledger.ts
  • src/main/codex/config-settings-baseline.ts
  • src/main/codex/config-settings-promotion.ts
  • src/main/codex/config-sync-stall.ts
  • src/main/codex/config-toml-trust.ts
  • src/main/codex/sta-4823-shared-state-survives-a-failed-read.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Comment thread src/main/codex/config-sync-stall.ts Resolved
@brennanb2025
brennanb2025 force-pushed the brennanb2025/sta-4823-shared-observation-batch branch from 80aba44 to 6e3aaf5 Compare August 19, 2026 05:28
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review verdict: PASS

I completed a source, call-site, test-rig, mutation, compatibility, and performance review and pushed the scoped fixes found during review. The final branch is clean: an indeterminate filesystem observation cannot authorize a rebuild, destructive write, cached erasure, or healthy sync status; genuine absence and known-invalid baseline state still recover.

Issues found and fixed

  • src/main/codex/config-toml-trust.ts:337 — hook-trust upsert treated existsSync() === false as an empty config, so a read denial could replace the user's model/provider/MCP/comments with a trust-only stub. It now uses one classified content read, seeds only after definitive absence, and propagates indeterminate errors. src/main/codex/config-toml-trust.ts:381 had the identical problem in the sibling project-trust upsert and now uses the same fail-closed rule.
  • src/main/codex/codex-trust-grant-ledger.ts:50 and :107 — a failed ledger read degraded to an empty ledger, allowing the next home write to discard every other home's grants. Reads now distinguish indeterminate from absent/corrupt, and the whole-ledger writer skips on indeterminate state.
  • src/main/agent-hooks/hooks-json-read.ts:29 — the pre-read existence probe reported an unreadable hooks.json as a valid empty config, authorizing regeneration. A single read now returns empty only for ENOENT/ENOTDIR, null for other read failures, and preserves malformed-content behavior.
  • src/main/codex/config-settings-baseline.ts:39, :56, and src/main/codex/config-settings-promotion.ts:162/:245 — unreadable baselines collapsed into absence, so snapshot/promotion could overwrite the comparison point and strand an in-Codex edit. The tri-state observation and writer guard now refuse only indeterminate reads. Syntax-invalid, structure-capacity-invalid, and known-present over-4 MiB baselines remain rebuildable (config-settings-baseline.ts:87); the writer's own bounded comparison read at :96 rethrows permission/I/O/unknown failures, closing the second-read race. Both mirror callers, including the bootstrap at src/main/codex/codex-config-mirror.ts:89, funnel through the guarded snapshot writer.
  • src/main/codex/config-sync-stall.ts:20 — status used existence/metadata evidence while promotion requires a content read, so metadata-success/content-denial could still report synced. Status now uses the same bounded content observation and returns the existing managed-home-unavailable stall reason for managed-side failures.
  • src/main/codex/codex-pane-account-registry.ts:62, :190, and :313 — an unreadable registry could be cached as empty and later persisted, erasing pane attribution even after access recovered. Indeterminate reads are no longer cached, and record/reconcile writers refuse rather than persist a stand-in.
  • src/main/codex/sta-4823-shared-state-survives-a-failed-read.test.ts:190 — the D29 fixture used hookIndex behind as never; it now satisfies the real CodexTrustEntry shape (handlerIndex plus command).

Sweeps that were clean

  • The denial rig models and exercises all three load-bearing shapes: deny, denyReads, and denyExistence. D29 uniquely uses denyExistence, keeping statSync and atomic replace healthy so the test cannot pass merely because the write failed. No other case had that false-positive shape: D30/D26/D31 keep their destructive write/rename path healthy, while D33/D15 are observation-only.
  • openSync interception is limited to r* read intent at sta-4823-shared-state-survives-a-failed-read.test.ts:92; the bounded config/baseline reader uses openSync(path, 'r'), while write/atomic-replace opens remain healthy.
  • Genuine-absence, first-launch seeding, readable updates, malformed baseline recovery, structure-limit recovery, and oversized self-produced baseline recovery all have positive anchors. The oversized case keeps the 4 MiB read cap and rejects at fstat before payload allocation.
  • Sibling reads/removals and all callers in src/main/codex, src/main/codex-accounts, and src/main/agent-hooks were swept. No second errno allowlist was added; the shared absence/observation primitives remain authoritative.
  • No renderer, IPC/RPC schema, stream opcode, mobile-facing contract, or new stall reason changed. There is no Electron/UI QA leg. Cross-platform, SSH/remote, and folder-workspace behavior stays on Node path/fs APIs with conservative error classification. No polling, subprocess, listener/timer, unbounded collection, or provider-specific behavior was added.

Verification

  • pnpm install
  • Full src/main/codex, src/main/codex-accounts, and src/main/agent-hooks suites: 173 files passed, 1 skipped; 1,768 tests passed, 12 skipped
  • pnpm typecheck: node, CLI, and web projects passed
  • node config/scripts/check-changed-code-quality.mjs: 0 findings
  • oxfmt --check and git diff --check: passed

Per-test mutation results (source restored immediately after each run):

  • Reverted src/main/codex/config-toml-trust.ts to origin/main → D29 “refuses the write rather than rebuilding the file from the trust entries alone” went red.
  • Reverted src/main/codex/config-toml-trust.ts to the pre-review PR head → “also refuses a project-trust write when the existing config cannot be read” went red.
  • Reverted src/main/codex/codex-trust-grant-ledger.ts to origin/main → D30 “skips the write instead of dropping every other home” went red.
  • Reverted src/main/agent-hooks/hooks-json-read.ts to origin/main → D33 “reports a failed read as unknown rather than as no hooks configured” went red.
  • Reverted src/main/codex/config-settings-promotion.ts to origin/main → D26 “leaves the record alone so the pending edit can still be promoted” went red.
  • Reverted src/main/codex/config-settings-baseline.ts to the pre-review PR head → “still replaces a fully-read baseline rejected by the JSON structure limit” went red.
  • Reverted src/main/codex/config-settings-baseline.ts to the prior review commit → “rebuilds an oversized baseline previously produced from a bounded runtime config” went red.
  • Reverted src/main/codex/config-sync-stall.ts to origin/main → D15 “reports the managed home as unavailable when its config cannot be read” went red.
  • Reverted src/main/codex/config-sync-stall.ts to the pre-review PR head → “reports the managed home as unavailable when only its content read is denied” went red.
  • Reverted src/main/codex/codex-pane-account-registry.ts to origin/main → D31 “does not persist an empty registry over the real one” and “does not cache the erasure, so attribution returns when the file does” each went red in isolated runs.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 128caa49-a0bf-440b-a0ff-84ea0d56c759

📥 Commits

Reviewing files that changed from the base of the PR and between 80aba44 and 6e3aaf5.

📒 Files selected for processing (4)
  • src/main/codex/config-settings-baseline.ts
  • src/main/codex/config-sync-stall.ts
  • src/main/codex/config-toml-trust.ts
  • src/main/codex/sta-4823-shared-state-survives-a-failed-read.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment on lines +382 to +417
describe('STA-4823 D15 — the sync status must not report synced while the mirror refuses', () => {
it('reports the managed home as unavailable when its config cannot be read', () => {
const runtimeConfigPath = join(runtimeHomePath, 'config.toml')
realFs.writeFileSync(runtimeConfigPath, 'model = "m"\n', 'utf-8')
realFs.writeFileSync(join(systemHome(), 'config.toml'), 'model = "s"\n', 'utf-8')
denials.deny(runtimeConfigPath)

const status = getCodexConfigSyncStatus({ runtimeHomePath, systemHomePath: systemHome() })

// Before the fix existsSync reported the locked runtime config as absent
// and this returned `synced` — telling the user their edits had been
// applied while nothing had run.
expect(status).toMatchObject({ state: 'stalled', reason: 'managed-home-unavailable' })
})

it('reports the managed home as unavailable when only its content read is denied', () => {
const runtimeConfigPath = join(runtimeHomePath, 'config.toml')
realFs.writeFileSync(runtimeConfigPath, 'model = "m"\n', 'utf-8')
realFs.writeFileSync(join(systemHome(), 'config.toml'), 'model = "s"\n', 'utf-8')
denials.denyReads(runtimeConfigPath)

expect(
getCodexConfigSyncStatus({ runtimeHomePath, systemHomePath: systemHome() })
).toMatchObject({ state: 'stalled', reason: 'managed-home-unavailable' })
})

it('still reports synced when no runtime config exists yet', () => {
realFs.writeFileSync(join(systemHome(), 'config.toml'), 'model = "s"\n', 'utf-8')

// Why: with no managed config the mirror seeds one; there is nothing to
// have fallen behind, and warning here would fire on every fresh install.
expect(
getCodexConfigSyncStatus({ runtimeHomePath, systemHomePath: systemHome() })
).toMatchObject({ state: 'synced', reason: null })
})
})

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add a case for the unreadable-source reason.

getCodexConfigSyncStatus gained a new branch at config-sync-stall.ts Line 46 that returns unreadable-source when the system config read is indeterminate. This suite covers managed-home-unavailable and synced, but no test reaches the new source-side branch. A revert of that branch would not fail any test.

Add a case that keeps the runtime config readable and denies the system config.

💚 Proposed test
+  it('reports an unreadable source config rather than claiming a sync', () => {
+    const systemConfigPath = join(systemHome(), 'config.toml')
+    realFs.writeFileSync(join(runtimeHomePath, 'config.toml'), 'model = "m"\n', 'utf-8')
+    realFs.writeFileSync(systemConfigPath, 'model = "s"\n', 'utf-8')
+    denials.denyReads(systemConfigPath)
+
+    expect(
+      getCodexConfigSyncStatus({ runtimeHomePath, systemHomePath: systemHome() })
+    ).toMatchObject({ state: 'stalled', reason: 'unreadable-source' })
+  })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
describe('STA-4823 D15 — the sync status must not report synced while the mirror refuses', () => {
it('reports the managed home as unavailable when its config cannot be read', () => {
const runtimeConfigPath = join(runtimeHomePath, 'config.toml')
realFs.writeFileSync(runtimeConfigPath, 'model = "m"\n', 'utf-8')
realFs.writeFileSync(join(systemHome(), 'config.toml'), 'model = "s"\n', 'utf-8')
denials.deny(runtimeConfigPath)
const status = getCodexConfigSyncStatus({ runtimeHomePath, systemHomePath: systemHome() })
// Before the fix existsSync reported the locked runtime config as absent
// and this returned `synced` — telling the user their edits had been
// applied while nothing had run.
expect(status).toMatchObject({ state: 'stalled', reason: 'managed-home-unavailable' })
})
it('reports the managed home as unavailable when only its content read is denied', () => {
const runtimeConfigPath = join(runtimeHomePath, 'config.toml')
realFs.writeFileSync(runtimeConfigPath, 'model = "m"\n', 'utf-8')
realFs.writeFileSync(join(systemHome(), 'config.toml'), 'model = "s"\n', 'utf-8')
denials.denyReads(runtimeConfigPath)
expect(
getCodexConfigSyncStatus({ runtimeHomePath, systemHomePath: systemHome() })
).toMatchObject({ state: 'stalled', reason: 'managed-home-unavailable' })
})
it('still reports synced when no runtime config exists yet', () => {
realFs.writeFileSync(join(systemHome(), 'config.toml'), 'model = "s"\n', 'utf-8')
// Why: with no managed config the mirror seeds one; there is nothing to
// have fallen behind, and warning here would fire on every fresh install.
expect(
getCodexConfigSyncStatus({ runtimeHomePath, systemHomePath: systemHome() })
).toMatchObject({ state: 'synced', reason: null })
})
})
describe('STA-4823 D15 — the sync status must not report synced while the mirror refuses', () => {
it('reports the managed home as unavailable when its config cannot be read', () => {
const runtimeConfigPath = join(runtimeHomePath, 'config.toml')
realFs.writeFileSync(runtimeConfigPath, 'model = "m"\n', 'utf-8')
realFs.writeFileSync(join(systemHome(), 'config.toml'), 'model = "s"\n', 'utf-8')
denials.deny(runtimeConfigPath)
// Before the fix existsSync reported the locked runtime config as absent
// and this returned `synced` — telling the user their edits had been
// applied while nothing had run.
const status = getCodexConfigSyncStatus({ runtimeHomePath, systemHomePath: systemHome() })
expect(status).toMatchObject({ state: 'stalled', reason: 'managed-home-unavailable' })
})
it('reports the managed home as unavailable when only its content read is denied', () => {
const runtimeConfigPath = join(runtimeHomePath, 'config.toml')
realFs.writeFileSync(runtimeConfigPath, 'model = "m"\n', 'utf-8')
realFs.writeFileSync(join(systemHome(), 'config.toml'), 'model = "s"\n', 'utf-8')
denials.denyReads(runtimeConfigPath)
expect(
getCodexConfigSyncStatus({ runtimeHomePath, systemHomePath: systemHome() })
).toMatchObject({ state: 'stalled', reason: 'managed-home-unavailable' })
})
it('reports an unreadable source config rather than claiming a sync', () => {
const systemConfigPath = join(systemHome(), 'config.toml')
realFs.writeFileSync(join(runtimeHomePath, 'config.toml'), 'model = "m"\n', 'utf-8')
realFs.writeFileSync(systemConfigPath, 'model = "s"\n', 'utf-8')
denials.denyReads(systemConfigPath)
expect(
getCodexConfigSyncStatus({ runtimeHomePath, systemHomePath: systemHome() })
).toMatchObject({ state: 'stalled', reason: 'unreadable-source' })
})
it('still reports synced when no runtime config exists yet', () => {
realFs.writeFileSync(join(systemHome(), 'config.toml'), 'model = "s"\n', 'utf-8')
// Why: with no managed config the mirror seeds one; there is nothing to
// have fallen behind, and warning here would fire on every fresh install.
expect(
getCodexConfigSyncStatus({ runtimeHomePath, systemHomePath: systemHome() })
).toMatchObject({ state: 'synced', reason: null })
})
})

@brennanb2025
brennanb2025 force-pushed the brennanb2025/sta-4823-shared-observation-batch branch 3 times, most recently from 7f51841 to 7d90e51 Compare August 19, 2026 23:54
@OrcaWin

OrcaWin commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Main validation evidence — origin/main on Windows high spec (not PR validation)

Isolated origin/main worktree OrcaWin/main-validation-fs-errors-20260819 @ fcdbcf85d0, launched with ORCA_DEV_USER_DATA_PATH + CDP 9333. Playwright CDP attached to Orca: OrcaWin/main-validation-fs-errors-20260819. No product code edited. Screenshots not committed.

gh image --repo stablyai/orca upload is blocked on this host (no GH_SESSION_TOKEN; browser cookie extract failed / Edge Local State locked). Local uncropped windows are under main-validation-evidence/ in that worktree. Full write-up: main-validation-evidence/REPORT.md.

Host measurement (before any app flow)

icacls /deny USER:(R) on marker / auth.json / sessions tree: existsSync stays true, stat/lstat succeed, content readFileSync/opendir throw EPERM errno -4048. Restore (/remove:d + /reset) verified after every step.

FileShare.None on files: metadata stat/lstat/opendir succeed; content read throws EBUSY errno -4082. Directories cannot be locked (File.Open → MethodInvocationException). App scenarios used icacls deny-R, not FileShare.None and not existsSync===false.

Results

Ticket Verdict Denial shape Observation
#15046 PASS icacls deny-R on selected .orca-managed-home Quota poll ran; persisted activeCodexManagedAccountId stayed aaaaaaaa-…; UI still showed [email protected] Active. Log: Managed account home is temporarily unreadable; keeping selection (EPERM open marker).
#15279 NOT VALIDATED n/a — login path unavailable codexAccounts.add() fails immediately: ~/.codex/config.toml pins custom provider "codex-lb". No successful Codex login on this host. Reauth/import/add-from-home substitutes not counted.
#15093 PASS icacls deny-R on selected sessions tree (stat ok, opendir EPERM/-4048) Bridged rollout id cccccccc-… into two homes. pty.spawn resume by session id refused: Codex account files are temporarily locked. Retry in a moment. Cause: EPERM opendir in findTrustedCodexSessionResume listing. Did not start under bravo.
#15289 PASS icacls deny-R on runtime auth.json after writing rotated token After quota poll + restore, SHA256 still A6F64A08… (rotated), not stale 81BE0D38…. LastWriteTime unchanged. Alpha remained Active.

Screenshots (local; upload blocked)

  • main-validation-evidence/01-15046-before-quota-poll.png
  • main-validation-evidence/02-15046-during-marker-deny.png
  • main-validation-evidence/03-15046-after-acl-restore.png
  • main-validation-evidence/04-15279-add-blocked-custom-provider.png (gap)
  • main-validation-evidence/05-15279-add-error-toast.png (gap: toast names codex-lb)
  • main-validation-evidence/07-15093-resume-refused-locked-sessions.png
  • main-validation-evidence/08-15289-after-runtime-auth-deny-poll.png

Cleanup

All ACL denials restored (inherited (F) only). Isolated userdata left untracked under main-validation-evidence/.

@OrcaWin

OrcaWin commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator

Main validation evidence — origin/main on Windows high spec (not PR validation)

Isolated origin/main worktree OrcaWin/main-validation-fs-errors-20260819 @ fcdbcf85d0, CDP 9333. No product code edited. Screenshots not committed.

Prior comment without images: #15417 (comment)

Host measurement (before any app flow)

icacls /deny USER:(R): existsSync stays true; stat/lstat succeed; content readFileSync/opendir throw EPERM errno -4048. FileShare.None on files: metadata ok; content EBUSY errno -4082. Directories cannot be locked. App scenarios used icacls deny-R.

Results

Ticket Verdict Notes
#15046 PASS Marker deny-R + quota poll; [email protected] stayed Active
#15279 NOT VALIDATED Add blocked by host ~/.codex/config.toml pinning "codex-lb"; no successful-login path
#15093 PASS Sessions-tree deny-R (opendir EPERM); resume refused files temporarily locked; did not start under the other home
#15289 PASS Rotated runtime auth.json SHA256 unchanged after deny + poll

Screenshots

#15046 before quota poll

01-15046-before-quota-poll.png

#15046 during marker deny + poll (alpha still Active)

02-15046-during-marker-deny.png

#15046 after ACL restore

03-15046-after-acl-restore.png

#15279 gap: Add Account blocked (custom provider)

04-15279-add-blocked-custom-provider.png

#15279 gap: toast names codex-lb

05-15279-add-error-toast.png

#15093 isolated app after refused resume

07-15093-resume-refused-locked-sessions.png

#15289 after denied runtime auth poll (alpha still Active)

08-15289-after-runtime-auth-deny-poll.png

@OrcaWin

OrcaWin commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator

Windows high-spec validation of PR 15417 at 7d90e51. Isolated Orca Accounts pane after icacls deny (R) on the managed runtime config.toml. Visible text: Orca could not read this account's Codex files just now, so settings may not be syncing. Uncropped renderer screenshot. No API keys, tokens, cookies, or emails in the image. accounts-managed-home-unavailable.png

@brennanb2025
brennanb2025 force-pushed the brennanb2025/sta-4823-shared-observation-batch branch from 7d90e51 to b58b788 Compare August 20, 2026 03:32
@OrcaWin

OrcaWin commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Windows HIGH SPEC (STA-4823 / PR 15417): Accounts pane shows managed-home-unavailable after icacls deny of the isolated managed config.toml.

@OrcaWin

OrcaWin commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator

Windows HIGH SPEC STA-4823 screenshot

accounts-managed-home-unavailable.png

…d (STA-4823)

Six shared files were rebuilt, erased or reported healthy after a read that had
only failed. Batch A of the STA-4606 split: every one of these is reachable and
testable on the host lane, so none of them wait on the WSL work.

- `config-toml-trust.ts` upsertHookTrustEntries: `existsSync` reported a locked
  config.toml as absent, so the base content became '' and the upsert rewrote
  the file from the trust entries alone — a trust-only stub, with the user's
  model, provider, MCP servers, approvals and comments gone. It refuses now;
  every hook-service caller already turns that into "trust entries could not be
  written. Run /hooks in Codex to approve."
- `codex-trust-grant-ledger.ts`: an unreadable ledger degraded to empty and the
  next write persisted a file holding only the home being written, dropping
  every other home's grants. The write paths refuse; the read path still
  degrades, and a corrupt ledger is still rebuilt.
- `codex-pane-account-registry.ts`: an unreadable registry erased every pane's
  attribution AND cached that erasure, so it survived the file recovering. The
  failure is no longer cached, and both write sites refuse rather than persist a
  registry derived from an empty stand-in.
- `hooks-json-read.ts`: the read arm already separated "no hooks" from "could
  not read", but the `existsSync` arm in front of it returned a valid empty
  config for a file that could not be opened. One read now classifies both.
- `config-settings-baseline.ts`: absent, unparseable and unreadable all collapsed
  into `null`, so the snapshot rebuilt a baseline it could not read — recording
  an in-Codex edit as Orca's own write, after which promotion skips it forever.
- `config-sync-stall.ts`: an unreadable runtime config read as absent and the
  status reported `synced` while the mirror was refusing. It reports
  `managed-home-unavailable`, the existing reason for exactly this, rather than
  borrowing a source-side one and blaming the wrong path.

Absent and malformed still rebuild throughout — resetting corrupt state is the
intent, and conflating it with unreadable would wedge a user on a broken file.
MEASURED on both platforms: a file-permission denial leaves existsSync TRUE
and fails only the content read — chmod 000 gives EACCES on macOS, icacls
/deny (R) gives EPERM errno -4048 on Windows, with stat/lstat succeeding in
both. The rig's docblock claimed this mode modelled that denial. It does not.

What it models is the UNC / \\wsl$ transport, where an unreachable distro
reports errno UNKNOWN at every level and existsSync folds it to false.

The distinction decides what the D29 guard is worth: under a permission denial
the pre-fix code already failed safe, because existsSync was true so it took
the read branch and threw. Only a transport that lies about existence reaches
the rebuild-from-empty path. No behaviour change; the comment was wrong, not
the code.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/sta-4823-shared-observation-batch branch from 8b7964b to 572b2fa Compare August 23, 2026 19:01
@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review verdict: PASS — ready to land

Second-loop review is complete at 02990b36f1. The branch is clean and the final same-model review loop plus the opening and closing readiness audits found no remaining scoped correctness, regression, or performance issue.

Honest trigger map

  • Live host content-read triggers: D15, D26, D30, and D31.
  • Host-lane insurance: D29 and D33.
  • D26 clarification: the live defect is promotion/mirror losing the comparison baseline and overwriting a pending runtime edit; snapshot was already fail-safe for the measured permission-denial shape.

An ordinary permission denial cannot reach D29’s rebuild-from-empty path. On macOS, chmod 000 leaves existsSync true and stat/lstat successful before content read fails with EACCES (-13); Windows icacls /deny USER:(R) has the same metadata shape before content read fails with EPERM (-4048). Pre-fix D29 therefore took the read branch, threw, and the hook-service caller reported that trust entries could not be written—no trust-only stub was produced. denyExistence instead exercises an indeterminate existence/transport shape, so D29/D33 are valuable conservative guards but not live host permission defects.

Mutation and review results

I reran the mutation matrix rather than relying on the prior PR table. Reverting the D15/D26/D30/D31 guards makes their live content-denial cases red; reverting D29/D33 makes their denyExistence insurance cases red, while ordinary content denial remains fail-safe/unknown pre-fix. The focused STA file now has 20 cases, including positive anchors for genuine absence and malformed/known-invalid baseline recovery.

The review also found and fixed two scoped gaps. Pending pane-attribution mutations are retained and merged after registry recovery with bounded capacity/retry timing, and a final mutation check caught the reconciliation-only write path canceling its own retry. The closing readiness audit then found that an unreadable D26 baseline safely stopped mirroring but could still report synced; health now observes the baseline, reports the existing wire-compatible managed-home-unavailable state, and includes an optional managed path so diagnostics name the actual file.

Validation

  • Requested src/main/codex, src/main/codex-accounts, and src/main/agent-hooks suites after the final fix: 175 files passed, 1 skipped; 1,787 tests passed, 12 skipped.
  • Including the sync-status IPC suite: 176 files passed, 1 skipped; 1,792 tests passed, 12 skipped.
  • Focused failure-path readiness run: 6 files / 105 tests passed.
  • Codex-focused readiness run: 106 files passed, 1 skipped; 1,117 tests passed, 6 skipped.
  • Renderer stale-pane coverage: 4 files / 71 tests passed.
  • Node 24 typecheck, changed-code quality, max-lines ratchet, oxfmt, and diff checks passed.
  • CI passed at the final head, including all Node 24/26 test shards and Windows packaging.

Final-head Electron startup was validated at 02990b36f1 in an isolated profile via Playwright CDP. Identity matched review2-15417-pr and this worktree, the renderer had zero console errors, and the screenshot contains no secrets or unrelated workspace state; the denial path itself has no bespoke rendered control.

startup-full-window.png

No additional WSL or SSH runtime leg was needed: this PR does not change SSH execution, wire contracts, or remote publishing, and the indeterminate transport case modeled by D29 remains part of the WSL-lane follow-up. The final Windows CI packaging job passed, alongside the direct macOS/Windows permission measurements above.

@brennanb2025
brennanb2025 merged commit 677718c into main Aug 23, 2026
47 checks passed
brennanb2025 added a commit that referenced this pull request Aug 23, 2026
…d trust

`cleanupLegacySystemManagedHooks` reads `~/.codex/hooks.json` and, when it finds
no hooks, removes Orca's managed trust entries from the system config.toml and
deletes that home's grant-ledger record.

Since the STA-4823 read classification landed, `readHooksJsonWithRaw` reports a
genuine absence as `{ raw: null, config: {} }` and a failed read as
`{ raw: null, config: null }`. Both still fell into the same branch, so a read
that merely failed discarded hook approvals the user had already given — and the
ledger record that would have let a later pass notice.

Only the definitive-absence answer may reach the removal now.

Found while reviewing #15417 and not covered by it: that PR fixed the classifier
and this is a consumer of it that still collapsed the two answers.

The sibling `assertHooksJsonGeneration` guard in codex-real-home-hook-install.ts
has the same `existsSync ? read : null` shape and is deliberately NOT changed
here. Measured, a permission denial leaves existsSync true and throws from the
read, so that path already fails closed; a guard there could not be made to fail
in a test and would be unprovable code.
brennanb2025 added a commit that referenced this pull request Aug 24, 2026
…d trust (#16147)

`cleanupLegacySystemManagedHooks` reads `~/.codex/hooks.json` and, when it finds
no hooks, removes Orca's managed trust entries from the system config.toml and
deletes that home's grant-ledger record.

Since the STA-4823 read classification landed, `readHooksJsonWithRaw` reports a
genuine absence as `{ raw: null, config: {} }` and a failed read as
`{ raw: null, config: null }`. Both still fell into the same branch, so a read
that merely failed discarded hook approvals the user had already given — and the
ledger record that would have let a later pass notice.

Only the definitive-absence answer may reach the removal now.

Found while reviewing #15417 and not covered by it: that PR fixed the classifier
and this is a consumer of it that still collapsed the two answers.

The sibling `assertHooksJsonGeneration` guard in codex-real-home-hook-install.ts
has the same `existsSync ? read : null` shape and is deliberately NOT changed
here. Measured, a permission denial leaves existsSync true and throws from the
read, so that path already fails closed; a guard there could not be made to fail
in a test and would be unprovable code.
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 25, 2026
…d (STA-4823) (stablyai#15417)

* fix(codex): stop rebuilding shared Codex state from a read that failed (STA-4823)

Six shared files were rebuilt, erased or reported healthy after a read that had
only failed. Batch A of the STA-4606 split: every one of these is reachable and
testable on the host lane, so none of them wait on the WSL work.

- `config-toml-trust.ts` upsertHookTrustEntries: `existsSync` reported a locked
  config.toml as absent, so the base content became '' and the upsert rewrote
  the file from the trust entries alone — a trust-only stub, with the user's
  model, provider, MCP servers, approvals and comments gone. It refuses now;
  every hook-service caller already turns that into "trust entries could not be
  written. Run /hooks in Codex to approve."
- `codex-trust-grant-ledger.ts`: an unreadable ledger degraded to empty and the
  next write persisted a file holding only the home being written, dropping
  every other home's grants. The write paths refuse; the read path still
  degrades, and a corrupt ledger is still rebuilt.
- `codex-pane-account-registry.ts`: an unreadable registry erased every pane's
  attribution AND cached that erasure, so it survived the file recovering. The
  failure is no longer cached, and both write sites refuse rather than persist a
  registry derived from an empty stand-in.
- `hooks-json-read.ts`: the read arm already separated "no hooks" from "could
  not read", but the `existsSync` arm in front of it returned a valid empty
  config for a file that could not be opened. One read now classifies both.
- `config-settings-baseline.ts`: absent, unparseable and unreadable all collapsed
  into `null`, so the snapshot rebuilt a baseline it could not read — recording
  an in-Codex edit as Orca's own write, after which promotion skips it forever.
- `config-sync-stall.ts`: an unreadable runtime config read as absent and the
  status reported `synced` while the mirror was refusing. It reports
  `managed-home-unavailable`, the existing reason for exactly this, rather than
  borrowing a source-side one and blaming the wrong path.

Absent and malformed still rebuild throughout — resetting corrupt state is the
intent, and conflating it with unreadable would wedge a user on a broken file.

* fix(codex): close shared state read-denial gaps

* fix(codex): recover oversized settings baselines

* fix(codex): name the stalled managed config

* fix(codex): preserve hooks after failed source reads

* test(codex): correct what the denyExistence rig actually models

MEASURED on both platforms: a file-permission denial leaves existsSync TRUE
and fails only the content read — chmod 000 gives EACCES on macOS, icacls
/deny (R) gives EPERM errno -4048 on Windows, with stat/lstat succeeding in
both. The rig's docblock claimed this mode modelled that denial. It does not.

What it models is the UNC / \\wsl$ transport, where an unreachable distro
reports errno UNKNOWN at every level and existsSync folds it to false.

The distinction decides what the D29 guard is worth: under a permission denial
the pre-fix code already failed safe, because existsSync was true so it took
the read branch and threw. Only a transport that lies about existence reaches
the rebuild-from-empty path. No behaviour change; the comment was wrong, not
the code.

* test(codex): exercise live baseline read denial

* fix(codex): retry pane attribution writes

* fix(codex): retry reconciliation registry writes

* fix(codex): report unreadable sync baselines

(cherry picked from commit 677718c)
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 25, 2026
…d trust (stablyai#16147)

`cleanupLegacySystemManagedHooks` reads `~/.codex/hooks.json` and, when it finds
no hooks, removes Orca's managed trust entries from the system config.toml and
deletes that home's grant-ledger record.

Since the STA-4823 read classification landed, `readHooksJsonWithRaw` reports a
genuine absence as `{ raw: null, config: {} }` and a failed read as
`{ raw: null, config: null }`. Both still fell into the same branch, so a read
that merely failed discarded hook approvals the user had already given — and the
ledger record that would have let a later pass notice.

Only the definitive-absence answer may reach the removal now.

Found while reviewing stablyai#15417 and not covered by it: that PR fixed the classifier
and this is a consumer of it that still collapsed the two answers.

The sibling `assertHooksJsonGeneration` guard in codex-real-home-hook-install.ts
has the same `existsSync ? read : null` shape and is deliberately NOT changed
here. Measured, a permission denial leaves existsSync true and throws from the
read, so that path already fails closed; a guard there could not be made to fail
in a test and would be unprovable code.

(cherry picked from commit 8d08d00)
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…d (STA-4823) (stablyai#15417)

* fix(codex): stop rebuilding shared Codex state from a read that failed (STA-4823)

Six shared files were rebuilt, erased or reported healthy after a read that had
only failed. Batch A of the STA-4606 split: every one of these is reachable and
testable on the host lane, so none of them wait on the WSL work.

- `config-toml-trust.ts` upsertHookTrustEntries: `existsSync` reported a locked
  config.toml as absent, so the base content became '' and the upsert rewrote
  the file from the trust entries alone — a trust-only stub, with the user's
  model, provider, MCP servers, approvals and comments gone. It refuses now;
  every hook-service caller already turns that into "trust entries could not be
  written. Run /hooks in Codex to approve."
- `codex-trust-grant-ledger.ts`: an unreadable ledger degraded to empty and the
  next write persisted a file holding only the home being written, dropping
  every other home's grants. The write paths refuse; the read path still
  degrades, and a corrupt ledger is still rebuilt.
- `codex-pane-account-registry.ts`: an unreadable registry erased every pane's
  attribution AND cached that erasure, so it survived the file recovering. The
  failure is no longer cached, and both write sites refuse rather than persist a
  registry derived from an empty stand-in.
- `hooks-json-read.ts`: the read arm already separated "no hooks" from "could
  not read", but the `existsSync` arm in front of it returned a valid empty
  config for a file that could not be opened. One read now classifies both.
- `config-settings-baseline.ts`: absent, unparseable and unreadable all collapsed
  into `null`, so the snapshot rebuilt a baseline it could not read — recording
  an in-Codex edit as Orca's own write, after which promotion skips it forever.
- `config-sync-stall.ts`: an unreadable runtime config read as absent and the
  status reported `synced` while the mirror was refusing. It reports
  `managed-home-unavailable`, the existing reason for exactly this, rather than
  borrowing a source-side one and blaming the wrong path.

Absent and malformed still rebuild throughout — resetting corrupt state is the
intent, and conflating it with unreadable would wedge a user on a broken file.

* fix(codex): close shared state read-denial gaps

* fix(codex): recover oversized settings baselines

* fix(codex): name the stalled managed config

* fix(codex): preserve hooks after failed source reads

* test(codex): correct what the denyExistence rig actually models

MEASURED on both platforms: a file-permission denial leaves existsSync TRUE
and fails only the content read — chmod 000 gives EACCES on macOS, icacls
/deny (R) gives EPERM errno -4048 on Windows, with stat/lstat succeeding in
both. The rig's docblock claimed this mode modelled that denial. It does not.

What it models is the UNC / \\wsl$ transport, where an unreachable distro
reports errno UNKNOWN at every level and existsSync folds it to false.

The distinction decides what the D29 guard is worth: under a permission denial
the pre-fix code already failed safe, because existsSync was true so it took
the read branch and threw. Only a transport that lies about existence reaches
the rebuild-from-empty path. No behaviour change; the comment was wrong, not
the code.

* test(codex): exercise live baseline read denial

* fix(codex): retry pane attribution writes

* fix(codex): retry reconciliation registry writes

* fix(codex): report unreadable sync baselines
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…d trust (stablyai#16147)

`cleanupLegacySystemManagedHooks` reads `~/.codex/hooks.json` and, when it finds
no hooks, removes Orca's managed trust entries from the system config.toml and
deletes that home's grant-ledger record.

Since the STA-4823 read classification landed, `readHooksJsonWithRaw` reports a
genuine absence as `{ raw: null, config: {} }` and a failed read as
`{ raw: null, config: null }`. Both still fell into the same branch, so a read
that merely failed discarded hook approvals the user had already given — and the
ledger record that would have let a later pass notice.

Only the definitive-absence answer may reach the removal now.

Found while reviewing stablyai#15417 and not covered by it: that PR fixed the classifier
and this is a consumer of it that still collapsed the two answers.

The sibling `assertHooksJsonGeneration` guard in codex-real-home-hook-install.ts
has the same `existsSync ? read : null` shape and is deliberately NOT changed
here. Measured, a permission denial leaves existsSync true and throws from the
read, so that path already fails closed; a guard there could not be made to fail
in a test and would be unprovable code.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…d (STA-4823) (stablyai#15417)

* fix(codex): stop rebuilding shared Codex state from a read that failed (STA-4823)

Six shared files were rebuilt, erased or reported healthy after a read that had
only failed. Batch A of the STA-4606 split: every one of these is reachable and
testable on the host lane, so none of them wait on the WSL work.

- `config-toml-trust.ts` upsertHookTrustEntries: `existsSync` reported a locked
  config.toml as absent, so the base content became '' and the upsert rewrote
  the file from the trust entries alone — a trust-only stub, with the user's
  model, provider, MCP servers, approvals and comments gone. It refuses now;
  every hook-service caller already turns that into "trust entries could not be
  written. Run /hooks in Codex to approve."
- `codex-trust-grant-ledger.ts`: an unreadable ledger degraded to empty and the
  next write persisted a file holding only the home being written, dropping
  every other home's grants. The write paths refuse; the read path still
  degrades, and a corrupt ledger is still rebuilt.
- `codex-pane-account-registry.ts`: an unreadable registry erased every pane's
  attribution AND cached that erasure, so it survived the file recovering. The
  failure is no longer cached, and both write sites refuse rather than persist a
  registry derived from an empty stand-in.
- `hooks-json-read.ts`: the read arm already separated "no hooks" from "could
  not read", but the `existsSync` arm in front of it returned a valid empty
  config for a file that could not be opened. One read now classifies both.
- `config-settings-baseline.ts`: absent, unparseable and unreadable all collapsed
  into `null`, so the snapshot rebuilt a baseline it could not read — recording
  an in-Codex edit as Orca's own write, after which promotion skips it forever.
- `config-sync-stall.ts`: an unreadable runtime config read as absent and the
  status reported `synced` while the mirror was refusing. It reports
  `managed-home-unavailable`, the existing reason for exactly this, rather than
  borrowing a source-side one and blaming the wrong path.

Absent and malformed still rebuild throughout — resetting corrupt state is the
intent, and conflating it with unreadable would wedge a user on a broken file.

* fix(codex): close shared state read-denial gaps

* fix(codex): recover oversized settings baselines

* fix(codex): name the stalled managed config

* fix(codex): preserve hooks after failed source reads

* test(codex): correct what the denyExistence rig actually models

MEASURED on both platforms: a file-permission denial leaves existsSync TRUE
and fails only the content read — chmod 000 gives EACCES on macOS, icacls
/deny (R) gives EPERM errno -4048 on Windows, with stat/lstat succeeding in
both. The rig's docblock claimed this mode modelled that denial. It does not.

What it models is the UNC / \\wsl$ transport, where an unreachable distro
reports errno UNKNOWN at every level and existsSync folds it to false.

The distinction decides what the D29 guard is worth: under a permission denial
the pre-fix code already failed safe, because existsSync was true so it took
the read branch and threw. Only a transport that lies about existence reaches
the rebuild-from-empty path. No behaviour change; the comment was wrong, not
the code.

* test(codex): exercise live baseline read denial

* fix(codex): retry pane attribution writes

* fix(codex): retry reconciliation registry writes

* fix(codex): report unreadable sync baselines
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…d trust (stablyai#16147)

`cleanupLegacySystemManagedHooks` reads `~/.codex/hooks.json` and, when it finds
no hooks, removes Orca's managed trust entries from the system config.toml and
deletes that home's grant-ledger record.

Since the STA-4823 read classification landed, `readHooksJsonWithRaw` reports a
genuine absence as `{ raw: null, config: {} }` and a failed read as
`{ raw: null, config: null }`. Both still fell into the same branch, so a read
that merely failed discarded hook approvals the user had already given — and the
ledger record that would have let a later pass notice.

Only the definitive-absence answer may reach the removal now.

Found while reviewing stablyai#15417 and not covered by it: that PR fixed the classifier
and this is a consumer of it that still collapsed the two answers.

The sibling `assertHooksJsonGeneration` guard in codex-real-home-hook-install.ts
has the same `existsSync ? read : null` shape and is deliberately NOT changed
here. Measured, a permission denial leaves existsSync true and throws from the
read, so that path already fails closed; a guard there could not be made to fail
in a test and would be unprovable code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants