Skip to content

Confine local task state to the worktree - #1306

Closed
eowca wants to merge 6 commits into
mainfrom
lean178/1027-confine-local-state
Closed

eowca wants to merge 6 commits into
mainfrom
lean178/1027-confine-local-state

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.

Local validation

Head f1b3b86 passed 515 CLI cases. A readiness case failed during the full run and passed when rerun in isolation. The local state regression, worktree, and review receipt tests passed.

Base

Base: a4fa169

Validation

Recorded for 6cb497747def

  • 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

eowca and others added 5 commits November 26, 2026 01:11
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; Descriptor-relative access and guarded check publication remain the authority for local state.
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; Local state still uses the same guarded directory and receipt format.
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 6cb497747def833d5fa47325de77770d606b7f8e, 62.2s: approve (0 critical, 0 important, 2 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
return (False,) * len(names)


def read_local_state(wt: Path, name: str) -> str:

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: Symlinked artifacts are reported as a raw ELOOP error, not a WorktreeError

read_local_state opens the file with O_NOFOLLOW but does not catch the error a symlink produces. When an artifact is a symbolic link, os.open raises OSError(ELOOP) and the user sees "[Errno 40] Too many levels of symbolic links". _regular_state raises a clear WorktreeError for the same case, so the two paths disagree. ready and status both reach this path through _current_check_report → _load_report, which has no local_state_files pre-check. _load_review turns the same OSError into "is not runner-produced: invalid saved review", which is misleading. The new tests only pass because "symbolic links" happens to contain "symbolic link". Smallest fix: in read_local_state, catch OSError with errno.ELOOP and re-raise the same WorktreeError(... is a symbolic link ...) that _regular_state uses. That gives one consistent message on every reader path.

Comment thread src/loopzero/worktree.py
@contextmanager
def _local_state_directory(wt: Path, *, create: bool = False):
path = wt / ".loopzero"
if _git(wt, "ls-files", "-z", "--", ".loopzero"):

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: The tracked-state check runs git ls-files on every local-state access

_local_state_directory runs git ls-files each time it is entered. One review invocation enters it several times: local_state_files, the task.md read, the saved-review read, and _save_review. This is why the expected git cost went from 14 to 17 for review, 7 to 8 for ready, and 7 to 8 for status. It is correct, but redundant within one command. A later cleanup could let callers that already validated the directory skip the repeat check, or cache the result per command. Not blocking.

@eowca
eowca marked this pull request as ready for review November 26, 2026 01:42
@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

🚫 Left the queue · pull request manually dequeued

1 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Thu 26 Nov, 01:43 · rule main · triggered by @eowca with the @mergifyio queue command
  • ⏹️ Testing stopped · draft #1333
  • 🚫 Left the queue 01:45 · 6cb4977

Reason

Pull request #1306 has been dequeued by the Mergify API

To get back in the queue

  • Comment @mergifyio queue to queue the pull request again.

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added the queued label Nov 26, 2026
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

No description provided.

Architecture-Review: unchanged; Repost now validates one private receipt snapshot for both review and publication.
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 delta review by claude on 2c8f4408a58f07d58e82609273e7238d6cd5138f, 16.0s: 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/cli.py


def _load_review(wt: Path, head: str, kind: str) -> ReviewResult:
def _load_review(wt: Path, head: str, kind: str) -> tuple[ReviewResult, object]:

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: _load_review's return type tuple[ReviewResult, object] is looser than it needs to be

The publication value is now taken from the same validated read as the result. This removes the second unguarded read_local_state call in cmd_review --repost, which could raise a raw JSONDecodeError or read a different file. That part is an improvement. The new signature types publication as object, but the only caller still checks its shape (isinstance(publication, dict) plus the repo, number and head comparisons). An optional fix is to annotate it as dict | None and validate the shape inside _load_review, so the publication format is checked in one place. This isn't blocking: the behaviour is correct as written. Exception routing is the same as before. CliError is not a ValueError subclass, so the head-mismatch message still reaches the user. FileNotFoundError is caught before OSError. WorktreeError from unsafe local state still propagates unchanged.

@mergify mergify Bot removed the dequeued label Nov 26, 2026
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Delivery is blocked at 2c8f4408. The delta was approved and Loop-zero Eligibility is green. GitHub's checks run counted 13,524 test lines against a 13,500 cap. The earlier full local rerun passed, including the readiness test that failed in the prior run. The current GitHub failure is the size budget.

Main then added the receipt diagnostics from #1294, which conflict with this reviewed head. The local integration at f06ca265 retains those diagnostics, keeps the state-refusal cases in a shared regression test, and passes the size budget and 16 focused cases. This PR has used both review rounds. Publishing the resolved candidate requires authorization for a replacement PR.

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #1356. The replacement carries the reviewed local-state change on current main, preserves the receipt diagnostics from #1294, and consolidates the state-refusal regression cases. Issue #1027 remains open until #1356 lands.

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