Skip to content

Preserve concurrent Git exclude edits during start - #1685

Merged
mergify[bot] merged 3 commits into
mainfrom
lean178/1544-preserve-exclude-edits-v2
Nov 26, 2026
Merged

mergify[bot] merged 3 commits into
mainfrom
lean178/1544-preserve-exclude-edits-v2

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Preserve concurrent Git exclude edits during start

Context and goal

  • Goal: Developers keep exclude entries they add while starting a task.
  • Problem: The previous writer could replace the exclude file with a snapshot taken before a concurrent edit.
  • Context: Start appends missing rules to the current file and repeats the addition if an editor replaced the file during the write.

Closes #1544

Acceptance

  • Exclude edits made at the write boundary survive, whether the editor appends in place or replaces the file.
  • Repeating start keeps one copy of each generated rule.

Base

main @ ef5d13c
Base: ef5d13c

Notes

This draft supersedes #1612 and builds on the landed exclude destination and cleanup guards.

Validation

Recorded for ced390ba0387

  • 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, ced390b, approve

eowca and others added 3 commits November 26, 2026 08:12
Architecture-Review: unchanged; start still installs the same repository-local Git ignore rules before adding a task checkout.
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; start retains the same ignore entries and the landed Git directory guard.
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; this resolves shared imports while retaining the landed cleanup and destination checks.
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 ced390ba03879265aec1dcdcc1e4dabd27f3330d, 38.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
missing = [entry for entry in EXCLUDES if entry not in lines]
if missing:
# An editor can append an unterminated line before this write.
rules = b"\n" + b"\n".join(missing) + b"\n"

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: Separator newline is added even when the file already ends with one

rules always starts with b"\n". Most exclude files end with a newline, including Git's default template, so start inserts an empty line before the generated rules, and does it again on every replace-retry pass. Git ignores blank lines in exclude files, so nothing breaks, but the file gets messier each time. The safe gap is narrow: an editor can only append between stream.read() and os.write, and that window is also why the prefix is unconditional. Smallest fix: keep the bytes from stream.read() as data and add the leading newline only when data is non-empty and does not end with b"\n". This leaves a small chance of a joined line if an unterminated append lands in that window. Or keep the current behaviour and say in the comment that the blank line is intentional.

Comment thread src/loopzero/worktree.py
finally:
temp.unlink(missing_ok=True)
while True:
fd = os.open(exclude, os.O_RDWR | os.O_CREAT | os.O_APPEND | os.O_NOFOLLOW, 0o666)

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: Replacing the exclude path with a symlink or directory during the loop raises a raw OSError

exclude is resolved and checked once, before the loop. If the path becomes a symlink before os.open runs, O_NOFOLLOW raises OSError(ELOOP); if it becomes a directory, os.open raises IsADirectoryError. Either way the caller gets a raw OSError instead of the WorktreeError the start command reports cleanly. Both are unlikely during a write, but wrapping os.open to turn ELOOP/EISDIR into WorktreeError("Git exclude is outside its Git directory") would keep error handling consistent with the containment check just above.

@eowca
eowca marked this pull request as ready for review November 26, 2026 08:25
@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 a6ad74d at 08:35 UTC

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

So far

  • ✅ Entered the queue Thu 26 Nov, 08:26 · rule main · triggered by @eowca with the @mergifyio queue command
  • ✅ Passed · draft #1711
  • ✅ Merged 08:35 · a6ad74d · 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

@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.

@mergify
mergify Bot merged commit a6ad74d into main Nov 26, 2026
18 checks passed
@mergify mergify Bot removed the queued label Nov 26, 2026
@eowca
eowca deleted the lean178/1544-preserve-exclude-edits-v2 branch November 26, 2026 08:37
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.

Preserve concurrent edits to the Git exclude file during start

1 participant