From 3aaddbaa809e3556046ba4b2d67e54c4773f85f6 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 09:09:37 +0100 Subject: [PATCH 1/2] Skip redundant Git queries in PR refresh and merge Architecture-Review: unchanged; the publication and merge verification boundaries are unchanged. Co-Authored-By: Codex --- src/loopzero/cli.py | 10 +++++----- tests/test_cli.py | 9 +++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index f1ca4bd4..980c436e 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -696,7 +696,7 @@ def cmd_pr(args: argparse.Namespace) -> int: raise CliError( f"PR head {pr.head_sha[:12]} is not in this worktree; fetch and integrate it first" ) - force_lease = not _is_ancestor(wt, pr.head_sha, head) + force_lease = pr.head_sha != head and not _is_ancestor(wt, pr.head_sha, head) if force_lease: previous_heads = _git(wt, "reflog", "show", "--format=%H", f"refs/heads/{branch}").splitlines() if not any(_is_ancestor(wt, pr.head_sha, previous) for previous in previous_heads): @@ -1180,10 +1180,10 @@ def _load_review(wt: Path, head: str, kind: str) -> ReviewResult: def _pr_readiness( - wt: Path, config: Config, *, allow_merged: bool = False, workflow_wait: bool = False + wt: Path, config: Config, branch: str, *, allow_merged: bool = False, workflow_wait: bool = False ) -> tuple[github.PR, github.Readiness | None]: """PR plus readiness; readiness is None only for an already merged PR (allow_merged).""" - branch, head = worktree.branch(wt), worktree.head(wt) + head = worktree.head(wt) _require_task_branch(config, branch) pr = _require_pr(config, branch, allow_merged=allow_merged) _require_pushed(pr, head) @@ -1211,7 +1211,7 @@ def _cleanup(wt: Path, pr: github.PR) -> None: def cmd_ready(args: argparse.Namespace) -> int: wt, config = _context(args, pin_checks=True) - pr, readiness = _pr_readiness(wt, config, workflow_wait=args.wait is not None) + pr, readiness = _pr_readiness(wt, config, worktree.branch(wt), workflow_wait=args.wait is not None) assert readiness is not None waiting = _draft_checks_waiting(config, pr, readiness) kicked = bool(waiting) @@ -1636,7 +1636,7 @@ def cmd_merge(args: argparse.Namespace) -> int: print(f"requested removal of PR #{pr.number} from Mergify") return 0 pr, readiness = _pr_readiness( - wt, config, allow_merged=True, workflow_wait=args.wait is not None + wt, config, branch, allow_merged=True, workflow_wait=args.wait is not None ) started = time.monotonic() deadline = None if args.wait is None else started + args.wait diff --git a/tests/test_cli.py b/tests/test_cli.py index ae3d8149..b8d6abf3 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1160,12 +1160,14 @@ def test_pr_migrates_old_checks_heading_to_validation(wt: Path) -> None: @pytest.mark.parametrize("corrupt_report", [False, True], ids=["no-report", "corrupt-report"]) -def test_pr_updates_existing_open_pr(wt, gh, capsys, corrupt_report): +def test_pr_updates_existing_open_pr(wt, gh, capsys, corrupt_report, git_calls): if corrupt_report: (wt / ".loopzero" / "checks.json").write_text('{"results": "nope"}') arm_pr_body_patch(gh, head_of(wt)) + git_calls.clear() code, out, err = run(capsys, "pr") + assert not any(call[:2] == ["merge-base", "--is-ancestor"] for call in git_calls) assert code == 0 and out == URL + "\n" assert ("warning: ignoring unreadable" in err) == corrupt_report @@ -1183,6 +1185,7 @@ def test_pr_updates_existing_open_pr(wt, gh, capsys, corrupt_report): ) def test_pr_aborts_on_ancestry_probe_error(wt, gh, fake_tool, tmp_path, capsys, probe, diagnostic): arm_pr_body_patch(gh, head_of(wt)) + git(wt, "commit", "--allow-empty", "-m", "Advance local head") pushes = tmp_path / "pushes" fake_tool("git", f'''\ if [ "$1" = "merge-base" ] && [ "$2" = "--is-ancestor" ]; then {probe}; fi @@ -3902,7 +3905,7 @@ def test_merge_queued_prints_and_keeps_worktree(wt: Path, gh: FakeGh, capsys, he @pytest.mark.parametrize("attested", [True, False]) @pytest.mark.parametrize("merge_state", ["BEHIND", "CLEAN"]) def test_mergify_merge_requests_once_for_behind_head( - wt: Path, gh: FakeGh, capsys, monkeypatch, attested, merge_state + wt: Path, gh: FakeGh, capsys, monkeypatch, attested, merge_state, git_calls ) -> None: head = commit_mergify_configuration(wt) arm_approved_ready_pr(gh, head, wt, isDraft=False, mergeStateStatus=merge_state) @@ -3911,7 +3914,9 @@ def test_mergify_merge_requests_once_for_behind_head( stub_mergify_admission(monkeypatch, configured=None) monkeypatch.setattr(mergify, "request", lambda *args: requested.append(args)) + git_calls.clear() code, out, err = run(capsys, "merge") + assert git_calls.count(["branch", "--show-current"]) == 1 if attested: assert (code, err) == (0, "") From 0a875f98cd32fc1f240b35e754593178c618bf3f Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 09:44:07 +0100 Subject: [PATCH 2/2] Bound ai-accounts stderr drain after the command exits Architecture-Review: unchanged; the optional account shim keeps command and replay behavior and returns the known exit status if stderr remains open. Co-Authored-By: Codex --- scripts/ai-accounts/ai-accounts | 4 +++- tests/test_ai_accounts.py | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/ai-accounts/ai-accounts b/scripts/ai-accounts/ai-accounts index c7aeaca2..5f8ebcf5 100755 --- a/scripts/ai-accounts/ai-accounts +++ b/scripts/ai-accounts/ai-accounts @@ -1064,7 +1064,9 @@ def cmd_run(providers: str, argv: list[str], retry_exit: set[int] | None = None, t = threading.Thread(target=pump, daemon=True) t.start() code = proc.wait() - t.join() + t.join(timeout=1) + if t.is_alive(): + return code text = b"".join(seen).decode("utf-8", "replace") retryable = code != 0 and (retry_exit is None or code in retry_exit) if (not retryable or attempt == 2 or not model or providers not in PROVIDERS diff --git a/tests/test_ai_accounts.py b/tests/test_ai_accounts.py index 2d3037a6..0565ddb3 100644 --- a/tests/test_ai_accounts.py +++ b/tests/test_ai_accounts.py @@ -95,6 +95,12 @@ def test_codex_requires_requested_model_evidence(helper, monkeypatch): assert helper.active('codex') == 'main' +def test_run_returns_after_leader_exits_with_inherited_stderr(helper): + argv = [helper.sys.executable, helper.__file__, 'run', 'claude', '--', helper.sys.executable, + '-c', 'import subprocess, sys; subprocess.Popen(["sleep", "6"]); sys.exit(7)'] + assert helper.subprocess.run(argv, timeout=5).returncode == 7 + + @pytest.mark.parametrize('providers,explicit,retry_safe,runs,active', [ ('claude,codex', False, False, 1, 'a'), ('claude', False, False, 1, 'b'), ('claude', False, True, 2, 'b'), ('claude', True, True, 1, 'a')])