Skip to content

Keep local receipts in the task worktree - #1589

Merged
mergify[bot] merged 2 commits into
mainfrom
lean178/1538-keep-receipts-in-worktree
Nov 26, 2026
Merged

mergify[bot] merged 2 commits into
mainfrom
lean178/1538-keep-receipts-in-worktree

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Keep local receipts in the task worktree

Context and goal

  • Goal: Check and review receipt writes preserve files outside the task checkout.
  • Problem: A redirected task-state directory could reach an unrelated directory when loop-zero locked it or saved a receipt.
  • Context: Both receipt writers use the opened task-state directory for atomic publication.

Closes #1538

Acceptance

  • Both writers refuse a symlinked task-state directory. The existing receipt survives an interrupted write and review leaves the destination mode alone.

Base

main @ 89788a4
Base: 89788a4

Validation

Recorded for bd247d175d7f

  • 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

  • primary, claude, bd247d1, approve

eowca and others added 2 commits November 26, 2026 08:05
Architecture-Review: unchanged; The guide already assigns local receipts to the task worktree and describes atomic local evidence.
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 bd247d175d7f2a03a91ee7b040ecdf8474c37466, 40.8s: 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
_write_json_atomically(path, data)
with _lock_task_state(wt) as directory:
os.fchmod(directory, 0o700)
if path.is_symlink():

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: Symlink pre-check uses the path, not the locked directory fd

Both receipts are now published with os.replace(..., src_dir_fd=directory, dst_dir_fd=directory). A rename replaces the directory entry itself and does not follow a symlink, so a symlinked receipt can no longer send the write somewhere else. The remaining path.is_symlink() check goes back through wt/.loopzero/... by path instead of using the fd that was opened and locked. That makes it a separate check that can drift from the one actually enforced. If you want to keep refusing a symlinked receipt, use stat.S_ISLNK(os.lstat(path.name, dir_fd=directory).st_mode) and handle FileNotFoundError, so the check uses the same directory handle. Otherwise drop the check, since the dir_fd rename already makes it unnecessary.

Comment thread tests/test_cli.py
path.parent.symlink_to(external, target_is_directory=True)
monkeypatch.setattr(cli.os, "replace", interrupt)
with pytest.raises(OSError, match="publication interrupted"):
with pytest.raises(OSError, match="Not a directory" if redirected else "publication interrupted"):

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: Test expects one platform's error for a refused symlink

In the redirected case, the test matches "Not a directory". That message comes from Linux, which returns ENOTDIR when O_DIRECTORY | O_NOFOLLOW meets a symlink. Other systems such as macOS/BSD return ELOOP, so the test would fail there even though the code is correct. If the project only targets Linux this is fine. Otherwise accept either errno (for example match="Not a directory|Too many levels", or check exc.errno in {ENOTDIR, ELOOP}). The same applies to the _save_review assertion further down.

Comment thread src/loopzero/cli.py
def _lock_task_state(wt: Path) -> Iterator[None]:
def _lock_task_state(wt: Path) -> Iterator[int]:
directory = wt / ".loopzero"
directory.mkdir(parents=True, exist_ok=True)

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: New review-state directory is not private until after creation

Before this change, _save_review created .loopzero with mode=0o700. Now _lock_task_state creates it with the umask default (usually 0o755), and _save_review only fixes it with fchmod(0o700) once the directory is open. Staged files are 0o600, so the exposure is small. Still, _lock_task_state could pass mode=0o700 to mkdir so a newly created directory starts out private for every caller.

@eowca
eowca marked this pull request as ready for review November 26, 2026 07:37
@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 84daaa5 at 07:42 UTC

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

So far

  • ✅ Entered the queue Thu 26 Nov, 07:37 · rule main · triggered by @eowca with the @mergifyio queue command
  • ✅ Passed · draft #1649
  • ✅ Merged 07:42 · 84daaa5 · 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 84daaa5 into main Nov 26, 2026
18 checks passed
@mergify mergify Bot removed the queued label Nov 26, 2026
@eowca
eowca deleted the lean178/1538-keep-receipts-in-worktree branch November 26, 2026 07:43
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.

Keep check and review receipts inside the task worktree

1 participant