Skip to content

Confine local task state to the worktree - #1793

Merged
mergify[bot] merged 3 commits into
mainfrom
lean178/1027-state-v2
Nov 26, 2026
Merged

mergify[bot] merged 3 commits into
mainfrom
lean178/1027-state-v2

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confine local task state to the worktree

Context and goal

  • Context: The ignored .loopzero directory holds the handoff, checks, reviews, and reviewer diagnostics.
  • Problem: Tracked state or symbolic links can redirect local state operations.
  • Goal: Keep local task state inside its worktree and preserve existing receipt and review behavior.

Closes #1027

Replaces #1408. This carries its integrated, delta-reviewed code and updates the readiness test to account for the one Git index read that verifies local state is untracked.

Acceptance

  • Reject tracked local state and symbolic links at the directory and artifact levels.
  • Check, review, repost, and readiness reject unsafe state before reading or changing its target.
  • Preserve external sentinel contents and permissions while retaining normal check, review, and repost behavior.

Validation

Recorded for 730f28b0cdbf

  • uv run --group dev ruff check src tests: exit 0
  • uv run --group dev tach check: exit 0
  • uv run --python 3.14 python scripts/check_architecture_docs.py: exit 0
  • scripts/size_budget.sh: exit 0
  • uv run --group dev pytest -q: exit 0

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Review

Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; the local state and review trust boundaries remain the same.

@loopzero-feder-positronics loopzero-feder-positronics Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

loopzero primary review by claude on 87c9ba01fcb86c5a6001e9d30ceafe6dc92c1ae8, 87.6s: approve (0 critical, 0 important, 3 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Native Claude output is retained in the restricted local review receipt.

Comment thread src/loopzero/cli.py Outdated
with _lock_task_state(wt):
with worktree.lock_local_state(wt):
_refresh_existing_pr_checks(wt, config)
except OSError as exc:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Best-effort PR-body updates no longer catch the lock's refusal errors

_local_state_directory now reports a tracked .loopzero, a symbolic-link or non-directory state directory, and a failed git ls-files as WorktreeError/GitError. Neither of those subclasses OSError. The old _lock_task_state raised OSError(ENOTDIR) in the same situations, so these best-effort handlers used to catch it.

There are two places where the error now escapes:

  • _refresh_pr_checks (cli.py:550-555) only catches OSError. If .loopzero is swapped or the git call times out after the receipt is saved, cmd_check fails instead of printing the 'could not refresh PR checks' note.
  • In cmd_review, the summary append after a successful post (cli.py:879-884) catches (GhError, ProcTimeout, OSError, ValueError). A WorktreeError there turns a review that was already published into a non-verdict error exit.

The earlier pre-checks make this a race or git-failure edge case, not a common path. Smallest fix: add worktree.WorktreeError to both except tuples, as _save_review_failure_output already does.

Comment thread src/loopzero/worktree.py

def read_local_state(wt: Path, name: str) -> str:
with _local_state_directory(wt) as fd, os.fdopen(
os.open(name, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=fd), encoding="utf-8"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: A symbolic link at the file level produces a raw ELOOP error, unlike the directory-level WorktreeError

read_local_state opens the file with O_NOFOLLOW. When the artifact is a symbolic link, Python raises a plain OSError ("Too many levels of symbolic links") instead of a WorktreeError. This has inconsistent effects:

  • ready and status reach it through _load_report, which does not catch it, so the user sees the raw errno text.
  • _load_review turns it into the misleading "not runner-produced: invalid saved review".
  • sandbox._previous silently ignores it.

The new parametrized test for (ready, checks.json) passes only because the errno text happens to contain "symbolic link". Smallest fix: in read_local_state, catch OSError with errno.ELOOP (or call _regular_state before opening) and raise the same WorktreeError that _regular_state uses. Then every reader and writer reports the unsafe artifact the same way.

Comment thread src/loopzero/cli.py
@@ -958,7 +931,7 @@ def _has_recoverable_review(
if not _review_file(wt, head, kind).exists() or _review_file(wt, head, other_kind).exists():

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: _has_recoverable_review still checks for saved reviews with Path.exists()

cmd_review now gets saved_files from worktree.local_state_files, which checks for regular files without following symbolic links. _has_recoverable_review still uses _review_file(...).exists() for both kinds. That check follows symbolic links, and the second implementation can drift from the one in local_state_files.

The current behavior is safe because local_state_files already rejected symbolic links and _load_review reads through read_local_state. Still, a shared helper should be the only source of this check. Smallest fix: pass the saved_files existence flags (or a kind-to-exists dict) into _has_recoverable_review and remove its own .exists() calls.

eowca and others added 2 commits November 26, 2026 12:02
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; local state and hosted evidence retain their existing authority boundaries.

@loopzero-feder-positronics loopzero-feder-positronics Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

loopzero delta review by claude on 730f28b0cdbf2fa1f23d2bfe3de025ce8d3e1fa8, 36.5s: approve (0 critical, 0 important, 0 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Native Claude output is retained in the restricted local review receipt.

@eowca
eowca marked this pull request as ready for review November 26, 2026 11:12
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Merged into main as 2f57989 at 11:18 UTC

5 min in the queue, 5 min of it CI.

So far

  • ✅ Entered the queue Thu 26 Nov, 11:12 · rule main · triggered by @eowca with the @mergifyio queue command
  • ✅ Passed · draft #1830
  • ✅ Merged 11:18 · 2f57989 · squash
3 merge conditions met
  • github-review-approved · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required
  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-success = checks
    • check-neutral = checks
    • check-skipped = checks
  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-success = Loop-zero Eligibility
    • check-neutral = Loop-zero Eligibility
    • check-skipped = Loop-zero Eligibility

Times in UTC · dashboard · how the merge queue works

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

No description provided.

@mergify
mergify Bot merged commit 2f57989 into main Nov 26, 2026
18 checks passed
@mergify mergify Bot removed the queued label Nov 26, 2026
@eowca
eowca deleted the lean178/1027-state-v2 branch November 26, 2026 11:18
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.

security: Keep local receipts inside the managed worktree

1 participant