Skip to content

Preserve PR body sections across checkouts - #1922

Merged
mergify[bot] merged 2 commits into
mainfrom
lean178/1371-share-pr-body-lock
Nov 26, 2026
Merged

mergify[bot] merged 2 commits into
mainfrom
lean178/1371-share-pr-body-lock

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Preserve PR body sections across checkouts

Context and goal

Closes #1371

Acceptance

  • A separate cloned checkout pauses check immediately before its PATCH while review attempts publication.
  • The final body keeps the recorded Validation, appended Review, and human prose.
  • Independent PR numbers use independent existing locks.

Base

Base: c21528b

Validation

Recorded for 2b4a38b225fc

  • 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, 2b4a38b, approve

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

The regression runs real check and review commands against one fake GitHub PR from separate Git checkouts. It pauses check just before its full-body PATCH. With main’s original source, review publishes and the delayed check erases the Review entry. With this change, review waits for the existing github.pr_lock and preserves both sections plus human prose. All 24 focused cases passed, including check coalescing; source +4, tests +17. The lock in cmd_check around coalescing/receipt publication remains intact.

@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 2b4a38b225fc261e35407702b6d35e3a15fd2164, 54.4s: 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/cli.py
pr = github.pr_for_branch(config.repo, branch, open_only=True)
if pr is None or pr.head_sha != head:
return
with github.pr_lock(config.repo, pr.number):

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: PR body writers can now publish another check's in-progress checkpoint from the same worktree

_refresh_pr_checks and cmd_pr (line 734) used to read checks.json through _validation_section while holding worktree.lock_local_state. That stopped them from seeing the partial reports that sandbox.run_checks writes through checkpoint=partial(_save_report, ...) while a check is running. They now hold only github.pr_lock.

How it fails: in one worktree, check A finishes and releases the worktree lock (line 684). Check B starts and writes a partial checkpoint. A's refresh, or a concurrent loopzero pr, then puts B's incomplete results into the Validation section. Before this change, both would have waited for B's final receipt. B's own refresh normally overwrites it later. But that refresh is best-effort, so if it fails, or B is interrupted, the PR keeps the partial Validation.

Smallest fix: take the worktree lock around the PR lock in both places (with worktree.lock_local_state(wt), github.pr_lock(...)). This can't deadlock, because review takes only pr_lock and no path takes pr_lock before the worktree lock. Alternatively, document that body writers may publish checkpoints. Either way, the docstring of worktree.lock_local_state (worktree.py:131) still says it serializes "PR-body updates for this worktree", which is no longer true and should be updated.

Comment thread tests/test_cli.py
proceed, flock, update = Event(), github.fcntl.flock, github.update_body

def acquire(fd, op):
if current_thread() is not main_thread() and op == github.fcntl.LOCK_EX:

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: Pause hook in the acceptance test patches the process-wide fcntl.flock

github.fcntl is the shared fcntl module, so monkeypatch.setattr(github.fcntl, "flock", acquire) also changes every worktree and state lock taken in the review thread. The test only works because review's first contended LOCK_EX happens to be the PR lock. If review later takes a contended worktree lock first, proceed would be set at the wrong point, and the test could still pass without proving it paused at the PR-lock handoff. Consider scoping the hook to the PR-lock path, for example by checking that fd.name is under github.PR_LOCK_DIR.

@eowca
eowca marked this pull request as ready for review November 26, 2026 14:21
@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 15034eb at 14:28 UTC

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

So far

  • ✅ Entered the queue Thu 26 Nov, 14:23 · rule main · triggered by @eowca with the @mergifyio queue command
  • ✅ Passed · draft #1933
  • ✅ Merged 14:28 · 15034eb · 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 15034eb into main Nov 26, 2026
18 checks passed
@eowca
eowca deleted the lean178/1371-share-pr-body-lock branch November 26, 2026 14:29
@mergify mergify Bot removed the queued label 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.

Preserve PR sections when Loop Zero updates them from separate checkouts

1 participant