Skip to content

Confine local task state to the worktree - #1356

Closed
eowca wants to merge 2 commits into
mainfrom
lean178/1027-replacement
Closed

eowca wants to merge 2 commits into
mainfrom
lean178/1027-replacement

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confine local task state to the worktree

Context and goal

  • Goal: Local check and review files stay inside their worktree.
  • Problem: Symbolic links can redirect local state reads and writes.
  • Context: The ignored .loopzero directory holds the handoff and receipts used by checks, readiness, and review.

Closes #1027

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.
  • A normal directory remains usable. External sentinel contents and permissions stay unchanged.

Notes

Reject tracked state before using it as evidence. Check the state directory and direct child at the point of use. Use a directory descriptor for reads, writes and chmod so path replacement cannot redirect them.

This replaces #1306. It carries the reviewed local-state change, preserves the receipt diagnostics from #1294, and keeps the state-refusal cases in one regression test.

Validation

Recorded for c4345e2c7ae1

  • 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

The previous full-suite rerun passed, including the earlier intermittent readiness case. The conflict resolution passed the size budget and 16 focused cases.

Base

Base: bafb356


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

Review

  • primary, claude, c4345e2, approve

Co-Authored-By: Codex <noreply@openai.com>

@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 c4345e2c7ae1ccf37ae94f494e84630671310d9a, 57.6s: approve (0 critical, 0 important, 1 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/worktree.py
try:
fd = os.open(path, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
except NotADirectoryError as exc:
raise WorktreeError(f"local state directory is not a directory or is a symbolic link: {path}") from 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: A symlinked state directory never reaches the WorktreeError branch

On Linux, os.open(path, O_DIRECTORY | O_NOFOLLOW) on a symbolic link fails with ELOOP, not ENOTDIR. So the except NotADirectoryError branch only handles a regular file named .loopzero. When .loopzero is a symlink, the user gets a raw OSError: [Errno 40] Too many levels of symbolic links. main still turns this into exit 1, so the behavior is safe. The regression test asserts "symbolic link" in err, and that only passes because the errno text happens to contain those words.

The same gap shows up in read_local_state, where O_NOFOLLOW on a symlinked artifact also raises ELOOP. Callers handle it differently:

  • _load_report lets it propagate as a generic OSError.
  • task_text lets it propagate the same way.
  • _load_review reports it as "not runner-produced".
  • sandbox._previous swallows it silently.

Smallest fix: in _local_state_directory, catch OSError with errno in (ELOOP, ENOTDIR) and raise the existing WorktreeError. In read_local_state, map ELOOP to the 'not regular or is a symbolic link' WorktreeError. Then every caller gets the intended diagnostic, and the test checks the message the code actually produces.

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Parked at approved head c4345e2c. The full local heavy-slot gate and hosted required checks passed on this head. Integration with current main projects 13,529 test lines against its 13,500 cap. Readiness and queue admission are pending PR #1352 landing on main.

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #1408. After merging main, hosted lint found that the PR-body updates added by #1230 still called the removed state lock. The replacement routes those updates and receipt publication through the same guarded directory lock. The integration fix needs a fresh primary review.

@eowca eowca closed this Nov 26, 2026
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