Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
d49867e
feat(install): report a rejected state root at install and doctor tim…
screenleon Nov 12, 2026
0c1002e
feat(install): check the state root before changing anything, and let…
screenleon Nov 12, 2026
0a6ccf8
fix(install): protect icacls from MSYS conversion, create the private…
screenleon Nov 12, 2026
eadb21a
test(doctor): run the unsafe state root case on native Windows with a…
screenleon Nov 12, 2026
5503421
test(install): give each state-root repair stage its own path so no s…
screenleon Nov 12, 2026
4c6675b
fix(install): grant the private state root to the SID of the running …
screenleon Nov 12, 2026
bede8f0
test(doctor): give the detached-run cases a private state root so Doc…
screenleon Nov 14, 2026
1df34db
test(install): assert a pre-existing state root keeps its ACL on nati…
screenleon Nov 14, 2026
efd476a
fix(install): create the Windows private state root with its protecte…
screenleon Nov 14, 2026
dc8a20c
fix(state): judge a state root that does not exist yet by what it wou…
screenleon Nov 14, 2026
59ea179
feat(install): say that a state root repair moves nothing, and where …
screenleon Nov 15, 2026
e585991
test(state): make the state-store suite's temp root owner-only on nat…
screenleon Nov 15, 2026
8862cb5
fix(install): read a rejected state root from the exit-3 status repor…
screenleon Nov 15, 2026
4a3df09
fix(state): probe an absent state root's ACL only on a real Windows s…
screenleon Nov 17, 2026
e6b4d7c
docs(architecture): register pmctl-state.sh as an OSTYPE consumer
screenleon Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Versions follow [Semantic Versioning](https://semver.org/).

### Fixed

- **A rejected state root is reported at install and doctor time, and install can fix it.** The state writer refuses a state root another account can write to, which on a native Windows host with a Codex sandbox account is the default location, so every `pmctl task`, `dispatch` and `gate` call stopped after an install that had looked fine. `doctor` now fails with the reason (the first offending principal) and the fix, and `install.sh` ends with the same warning. `install.sh --fix-state-root`, or a yes at the prompt when a person is at the terminal, creates `~/.pm-dispatch-state` (owner-only; an existing directory is checked, never re-permissioned), confirms the guard accepts it, and on native Windows records it as the user's `PM_DISPATCH_STATE_ROOT`.. It moves nothing: when the previous root holds records, the fix names it and says they stay there and are not visible under the new root. The check itself is not relaxed.
- **Gate: an exhausted executor quota is named as such on a real run.** The quota check read the files an adapter banner names, but a gate run through `pmctl dispatch run` has no banner in the reviewer's log; it has `run: <run-id>` and a `<run-id>.footer` beside the log that names the executor's own stderr and event stream. On a real run that hit the Codex usage limit the failure was reported as an unexplained "transport failure" and retried once. The check now follows the footer (and still reads a banner in a directly dispatched log), so the report carries the executor's reset time and no retry is spent.
- **Memory on native Windows.** Claude Code on Windows names a project's memory directory after the drive-letter path with every character that is not a letter or digit turned into `-` (`C--Users-Jo-Doe-repo`); `find_memory_dir` now also tries that name, so a repository on a native Windows host finds its memory. A native `sqlite3` ends rows with CR LF; the usage reader now strips it, so the last-access day is no longer read as 0 and cards are no longer all ranked oldest. Other platforms are unchanged.

Expand Down
6 changes: 6 additions & 0 deletions docs/architecture/script-variable-consumers.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ HOME HOME runtime/lib/memory.sh production
HOME HOME runtime/lib/pmctl-config.sh production
HOME HOME runtime/lib/pmctl-memory-config.sh production
HOME HOME runtime/lib/portable.sh production
HOME HOME runtime/lib/state-root-fix.sh production
HOME HOME runtime/lib/state-paths.sh production
HOME HOME tools/lint/bootstrap-shellcheck.sh production
HOME HOME tools/lint/lint-pmctl-commands.sh production
Expand All @@ -161,6 +162,7 @@ MSYS2_ARG_CONV_EXCL MSYS2_ARG_CONV_EXCL runtime/lib/gate-result-verify.sh produc
MSYS2_ARG_CONV_EXCL MSYS2_ARG_CONV_EXCL runtime/lib/gate-reviewer-contract.sh production
MSYS2_ARG_CONV_EXCL MSYS2_ARG_CONV_EXCL runtime/lib/jq-lf.sh production
MSYS2_ARG_CONV_EXCL MSYS2_ARG_CONV_EXCL runtime/lib/pmctl-gate.sh production
MSYS2_ARG_CONV_EXCL MSYS2_ARG_CONV_EXCL runtime/lib/state-root-fix.sh production
MSYS2_ARG_CONV_EXCL MSYS2_ARG_CONV_EXCL ops/diagnostics/run-ci-lints.sh production
MSYS2_ARG_CONV_EXCL MSYS2_ARG_CONV_EXCL ops/diagnostics/run-tests-in-wsl.sh production
MSYS_NO_PATHCONV MSYS_NO_PATHCONV hosts/claude/bin/install-guards.sh production
Expand Down Expand Up @@ -210,7 +212,9 @@ OSTYPE OSTYPE runtime/hooks/guard-reviewer-write.sh production
OSTYPE OSTYPE runtime/lib/jq-lf.sh production
OSTYPE OSTYPE runtime/lib/memory.sh production
OSTYPE OSTYPE runtime/lib/pmctl-context.sh production
OSTYPE OSTYPE runtime/lib/pmctl-state.sh production
OSTYPE OSTYPE runtime/lib/portable.sh production
OSTYPE OSTYPE runtime/lib/state-root-fix.sh production
OSTYPE OSTYPE tests/bin/run-tests.sh production
OSTYPE OSTYPE tools/eval/gate-test-gap-live-eval.sh production
OSTYPE OSTYPE tools/generate/gate-structural-validator.sh production
Expand Down Expand Up @@ -371,6 +375,7 @@ PM_DISPATCH_REPOS_ROOT PM_DISPATCH_REPOS_ROOT runtime/lib/repo-layout.sh product
PM_DISPATCH_REPOS_ROOT PM_DISPATCH_REPOS_ROOT tools/lint/lint-portable-repo-paths.sh production
PM_DISPATCH_ROTATE_MAX_BYTES PM_DISPATCH_ROTATE_MAX_BYTES runtime/lib/state-writer.sh production
PM_DISPATCH_STATE_ROOT PM_DISPATCH_STATE_ROOT hosts/claude/lib/doctor.sh production
PM_DISPATCH_STATE_ROOT PM_DISPATCH_STATE_ROOT install.sh production
PM_DISPATCH_STATE_ROOT PM_DISPATCH_STATE_ROOT ops/release/clean-install-smoke.sh production
PM_DISPATCH_STATE_ROOT PM_DISPATCH_STATE_ROOT ops/release/release-verify.sh production
PM_DISPATCH_STATE_ROOT PM_DISPATCH_STATE_ROOT ops/release/upgrade-smoke-v0.10-v0.11.sh production
Expand All @@ -380,6 +385,7 @@ PM_DISPATCH_STATE_ROOT PM_DISPATCH_STATE_ROOT runtime/lib/pmctl-context.sh produ
PM_DISPATCH_STATE_ROOT PM_DISPATCH_STATE_ROOT runtime/lib/pmctl-gate.sh production
PM_DISPATCH_STATE_ROOT PM_DISPATCH_STATE_ROOT runtime/lib/pmctl-worktree.sh production
PM_DISPATCH_STATE_ROOT PM_DISPATCH_STATE_ROOT runtime/lib/state-paths.sh production
PM_DISPATCH_STATE_ROOT PM_DISPATCH_STATE_ROOT runtime/lib/state-root-fix.sh production
PM_DISPATCH_STATE_ROOT PM_DISPATCH_STATE_ROOT runtime/lib/state-writer.sh production
PM_DISPATCH_TEST_COMMAND_IDENTITY PM_DISPATCH_TEST_COMMAND_IDENTITY runtime/bin/pr-gate.sh production
PM_DISPATCH_TEST_FORCE_JQ_LF PM_DISPATCH_TEST_FORCE_JQ_LF tests/lib/test-harness.sh test
Expand Down
9 changes: 9 additions & 0 deletions docs/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,15 @@ things to know:
```

`PM_DISPATCH_ALLOW_UNSAFE_STATE_ROOT=1` turns the check off; do not use it to get past this.

`bash runtime/bin/doctor.sh` reports this at setup time (`[FAIL] state root ... is rejected`), and `install.sh` ends with the same
warning. `bash install.sh --fix-state-root` does the steps above for you: it creates `~/.pm-dispatch-state` with an
owner-only ACL (an existing directory is only checked), confirms the guard accepts it, and on native Windows sets the
user environment variable `PM_DISPATCH_STATE_ROOT`; restart open terminals, Claude Code and Codex afterwards.
Switching the state root moves nothing: task history, operation records and worktree registrations stay under the previous
root, so from the new one they look gone. The fix prints the previous root when it holds anything. To keep using those
records, point `PM_DISPATCH_STATE_ROOT` back at that directory once only you can write it, or copy what you need across.
Without the flag, an interactive install asks before changing anything (use it, install unchanged, or cancel) and a scripted install only warns.
- **`PM_DISPATCH_STATE_ROOT` (and `XDG_DATA_HOME`) must be written as a POSIX path, `/c/Users/...`,
not `C:/Users/...`.** The gate's run directory is derived from the state root and its supervisor
refuses a drive-letter run directory. `pmctl gate run` checks the state root before it starts anything
Expand Down
17 changes: 16 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Per-file symlinks: ~/.claude/agents/ may contain agents from other sources alongside.
#
# Usage:
# ./install.sh [--dry-run] [--profile minimal|full] [--verify]
# ./install.sh [--dry-run] [--profile minimal|full] [--verify] [--fix-state-root]
#
# --profile is forwarded to install-guards.sh and selects whether to wire adapter
# bash guards (adapters/<name>/bash-guard.sh, manifest-driven via needs_bash_guard).
Expand All @@ -15,6 +15,11 @@
# minimal skip adapter bash guards
# (omit) auto-detect: codex on PATH → full, else minimal
#
# --fix-state-root: when the pmctl state root is one the safety check rejects (another account can write it), create
# ~/.pm-dispatch-state (owner-only) and use it as PM_DISPATCH_STATE_ROOT. Without the flag install only reports the
# problem and goes on; a person at the terminal is asked first (y use it, n install unchanged, c cancel), before
# anything is changed. Never changes an existing directory.
#
# --verify runs all preflight test suites before installing.
# Skipped by default; recommended when contributing or after updating.
#
Expand Down Expand Up @@ -55,6 +60,7 @@ unset _jq_lf_dir

DRY_RUN=0
VERIFY=0
FIX_STATE_ROOT=0
PROFILE=""
ENABLED_HOSTS=()
SELECTED_HOSTS=(claude)
Expand All @@ -63,6 +69,7 @@ while [[ $# -gt 0 ]]; do
case "$1" in
--dry-run) DRY_RUN=1; shift ;;
--verify) VERIFY=1; shift ;;
--fix-state-root) FIX_STATE_ROOT=1; shift ;;
--enable-codex-command-guard) ENABLED_HOSTS+=(codex); shift ;;
--enable-host)
[[ $# -ge 2 ]] || { echo "install: --enable-host requires a value" >&2; exit 2; }
Expand Down Expand Up @@ -132,6 +139,8 @@ fi
# shellcheck disable=SC1091
. "$REPO_ROOT/runtime/lib/install-receipt.sh"
# shellcheck disable=SC1091
. "$REPO_ROOT/runtime/lib/state-root-fix.sh"
# shellcheck disable=SC1091
. "$REPO_ROOT/runtime/lib/allowlist.sh"
# shellcheck disable=SC1091
. "$REPO_ROOT/runtime/lib/dispatch-common.sh"
Expand Down Expand Up @@ -723,6 +732,12 @@ if [[ "$VERIFY" -eq 1 ]] && [[ "$_SKIP_PREFLIGHT" != "1" ]]; then
echo
fi

# Before anything is changed: tell the person if the state root the tools will use is one the safety check
# rejects, and let them fix it or stop, rather than finishing an install whose pmctl cannot write its state.
if [[ "$DRY_RUN" -eq 0 ]]; then
state_root_install_preflight "$REPO_ROOT" "$FIX_STATE_ROOT" || { echo "install: cancelled; nothing was changed" >&2; exit 1; }
fi

# Validate every selected host before the Claude product install mutates
# anything. Host installers define --dry-run as a read-only ownership and
# conflict check, so a user-owned policy fails the whole multi-host operation
Expand Down
17 changes: 17 additions & 0 deletions runtime/bin/doctor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,22 @@ check_detached_runs() {
fi
}

# The state root is where runs, tasks, decisions and gate results are written, and the canonical writer refuses a root
# another principal can write to (issue #592). Say so here, at setup time, rather than leaving the first `pmctl task`,
# `pmctl dispatch` or `pmctl gate` call to be refused. Read-only: `state status` only inspects the root.
check_state_root() {
local pmctl="$REPO_ROOT/cli/pmctl" status store reasons
[[ -x "$pmctl" ]] || return 0
# Exit 3 is the documented "incompatible or unreadable layout" status and still carries the JSON report (safe_root
# included), so it is read like exit 0; any other failure leaves this check out.
status="$("$pmctl" state status --json --cd "$REPO_ROOT" 2>/dev/null)" || [[ $? -eq 3 ]] || return 0
[[ "$(jq -r 'if .safe_root == false then "false" else "true" end' <<<"$status" 2>/dev/null)" == "false" ]] || { emit_check state-root ok "state root is safe to write"; return; }
store="$(jq -r '.store_root // ""' <<<"$status" 2>/dev/null)"
reasons="$(jq -r '(.safe_root_reasons // []) | join("; ")' <<<"$status" 2>/dev/null)"
emit_check state-root fail "state root ${store:-?} is rejected (${reasons:-unsafe}): pmctl task, dispatch, gate and other state-writing commands will refuse to run" \
"bash '${REPO_ROOT}/install.sh' --fix-state-root # makes ~/.pm-dispatch-state (only you can write) the state root; see docs/platform-support.md"
}

# Read-only parent-operation diagnostics. The operation projection is owned by
# the canonical writer; doctor only uses state status to find its partition and
# then reports non-terminal records with their producer-specific reconcile path.
Expand Down Expand Up @@ -924,6 +940,7 @@ main() {
check_memory_dir
check_frontmatter_lint
check_detached_runs
check_state_root
check_parent_operations
check_usage_tracker_path

Expand Down
16 changes: 16 additions & 0 deletions runtime/lib/pmctl-state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ _pmctl_state_root_safety() {
# there would just repeat the writer's former false "safe" reading. Fail
# closed on an unverifiable ACL (gate round 2), same as the writer: rc=2
# (cannot verify) is reported unsafe, not safe.
# The ACL probe needs a real Windows shell: PM_DISPATCH_PLATFORM=windows (used to pick a profile) on another OS has no
# PowerShell to ask, so it must not turn "cannot verify" into a rejected root there.
if [[ ! -e "$store_root" && ! -L "$store_root" && "$(detect_platform)" == windows ]] && [[ "${OSTYPE:-}" == msys* || "${OSTYPE:-}" == cygwin* ]] && declare -F _sw_windows_absent_root_inherits_write >/dev/null 2>&1; then
# A root that does not exist yet is not safe just because nothing is there: the first writer creates it, and on
# Windows it inherits whatever its parent grants. Report that now (install and doctor read this), not at the
# first state-writing command.
local _abs_rc=0
_sw_windows_absent_root_inherits_write "$store_root" || _abs_rc=$?
if [[ "$_abs_rc" -eq 0 ]]; then
_PMCTL_STATE_SAFE=0
_PMCTL_STATE_SAFE_REASONS+=("$(_sw_acl_unsafe_reason) (the directory does not exist yet and would inherit this from its parent)")
elif [[ "$_abs_rc" -eq 2 ]]; then
_PMCTL_STATE_SAFE=0
_PMCTL_STATE_SAFE_REASONS+=("cannot verify what a new state root would inherit (PowerShell/cygpath unavailable, Get-Acl failed, or the parent chain is not a plain directory)")
fi
fi
if [[ -d "$store_root" ]]; then
if [[ "$(detect_platform)" == windows ]] && declare -F _sw_windows_store_root_allows_write >/dev/null 2>&1; then
local _win_acl_rc=0
Expand Down
Loading
Loading