Skip to content

feat(install): report a rejected state root at install and doctor time, and offer to fix it - #794

Merged
screenleon merged 15 commits into
mainfrom
fix/doctor-state-root-preflight
Nov 17, 2026
Merged

screenleon merged 15 commits into
mainfrom
fix/doctor-state-root-preflight

Conversation

@screenleon

Copy link
Copy Markdown
Owner

Summary

Tests

  • test-doctor: case_doctor_unsafe_state_root_fails_with_remedy
  • test-install: test_install_reports_and_fixes_rejected_state_root
  • WSL: test-doctor 98/0; test-install 99 pass/0 fail before the 1700 s limit, new case passes alone. CI lints 19/0.
  • Not covered: the interactive prompt itself (needs a TTY).

Permanent test admissions: case_doctor_unsafe_state_root_fails_with_remedy, test_install_reports_and_fixes_rejected_state_root — contract tests for a user-facing failure and its remedy, added to existing suites.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ESW7P8BvZ5Crn6vi6EA2J7

screenleon and others added 15 commits November 12, 2026 18:52
…e, and offer to fix it

The state writer refuses a state root another account can write to. On a native Windows host with a
Codex sandbox account that is the default location, so every state-writing pmctl command stopped after
an install that looked fine.

- doctor fails with the reason and the fix instead of leaving the first pmctl call to be refused.
- install.sh ends with the same warning; --fix-state-root (or a yes at an interactive prompt) creates
  ~/.pm-dispatch-state owner-only, confirms the guard accepts it, and on native Windows records it as the
  user's PM_DISPATCH_STATE_ROOT. An existing directory is checked, never re-permissioned; the check
  stays on.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ESW7P8BvZ5Crn6vi6EA2J7
… a person cancel

The warning came after the install had finished. It now runs before any change: a person at a terminal
chooses y (use ~/.pm-dispatch-state), n (install unchanged) or c (cancel, nothing changed); a scripted
install still only warns, and --fix-state-root still repairs without asking.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ESW7P8BvZ5Crn6vi6EA2J7
… root exclusively, test repair and consent on every platform

Gate remediation: critic-F001 (icacls options rewritten by MSYS), qa-tester-F001/F002 (native-capable
repair and y/n/c/existing-destination coverage), security-reviewer-F001 (exclusive creation).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ESW7P8BvZ5Crn6vi6EA2J7
… real ACL grant

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ESW7P8BvZ5Crn6vi6EA2J7
…tage needs to delete an owner-only directory

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ESW7P8BvZ5Crn6vi6EA2J7
…account, not the profile name

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ESW7P8BvZ5Crn6vi6EA2J7
…tor's new check accepts them on native Windows

A state root made with mkdir -p under the temp root inherits a write grant for another principal on native Windows
(e.g. the Codex sandbox group), which Doctor now reports as a failure. The stale and indeterminate detached-run cases
create their state root with an owner-only helper instead.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ESW7P9zqMvS4GeAcn3S3Jw
…ve Windows

The repair promises to inspect an existing directory and never change its permissions. The Windows branch of the
existing-directory case checked contents and persistence only, so moving the icacls call outside the creation branch
would still pass. It now compares the directory's real ACL before and after the repair.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ESW7P9zqMvS4GeAcn3S3Jw
…d ACL in one step

mkdir followed by icacls left a window in which the new directory carried whatever its parent grants (a Codex sandbox
group, for example), and another principal could plant files in it that the later ACL change does not remove. The root
is now created with Win32 CreateDirectoryW and a protected owner/SYSTEM/Administrators descriptor supplied at creation,
which also refuses a leaf that already exists as a directory or a junction. Without a working PowerShell nothing is
created.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ESW7P9zqMvS4GeAcn3S3Jw
…ld inherit on Windows

pmctl state status reported a missing state root as safe because there was nothing to inspect. The first writer creates
it, and on native Windows it takes whatever its parent grants, so install's preflight skipped the repair and doctor said
safe on exactly the clean-install path the check exists for. The read-only check now looks at the nearest existing
ancestor and counts only grants a new child directory would inherit (ContainerInherit, and for deeper missing levels
not NoPropagateInherit), for the account that would create it. A dangling link, a non-directory or an unverifiable ACL
is reported unsafe. Nothing is created.

The doctor fixtures put their homes under the temp root, which can carry such a grant, so the test makes that root
owner-only once instead of every case depending on the host's temp ACL.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ESW7P9zqMvS4GeAcn3S3Jw
…the previous records stay

Switching PM_DISPATCH_STATE_ROOT leaves task history, operation records and worktree registrations under the previous
root, so from the new one they look gone. The repair now names the previous root when it holds anything and says how to
keep using it; a missing or empty previous root says nothing. The platform guide and the changelog carry the same note.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ESW7P9zqMvS4GeAcn3S3Jw
…ive Windows

The first state_store_init case created its store under a temp root that inherits a Codex sandbox group grant, which the
canonical writer rejects, so the whole suite aborted before reaching later cases (including the absent-state-root ones).
The temp root is the test's own scratch directory, so it is made owner-only once, as test-doctor does. The suite now
runs to the end natively: 88 PASS, 2 FAIL (non-owned store root cannot be simulated without POSIX owners; Windows path
spelling partition keys), both also failing on main.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ESW7P9zqMvS4GeAcn3S3Jw
…t too

pmctl state status exits 3 with a complete JSON report when the store layout is incompatible or unreadable. Doctor's
state-root check and install's state_root_unsafe_reason both treated any non-zero exit as "cannot inspect", so a rejected
root on such a store was neither warned about nor offered the repair. Both now accept exit 3 and still ignore other
failures. A doctor case covers an unsafe root with an incompatible VERSION, for Doctor and for the install check.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ESW7P9zqMvS4GeAcn3S3Jw
…hell; silence three intended shellcheck infos

PM_DISPATCH_PLATFORM=windows selects a profile on any OS, but the absent-root ACL probe needs PowerShell and cygpath. On
Linux CI the override made the probe fail closed and Doctor reported a rejected state root for a root that was fine
(doctor-windows-auto-profile-codex-on-path). The probe now also requires a real msys/cygwin shell.
SC2016 (literal PowerShell expression) and SC2030/SC2031 (a stub PATH set on purpose in a subshell) are disabled at the
line with the reason.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ESW7P9zqMvS4GeAcn3S3Jw
The absent-root ACL probe now reads OSTYPE in runtime/lib/pmctl-state.sh, so the variable consumer graph that
lint-script-domain-inventory checks needs that row.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ESW7P9zqMvS4GeAcn3S3Jw
@screenleon
screenleon merged commit 4abf05e into main Nov 17, 2026
97 checks passed
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.

1 participant