Janitor: prune PR-less agent/issue-<N> placeholder branches sitting at an ancestor of main #269

Closed
opened 2026-10-16 17:16:21 +00:00 by matou-build-agent · 6 comments

Follow-up to #253 (gate-scoping fix, landed in ce26ea7).

Context

#253 fixed the pre-push language gate so a stale PR-less agent/issue-<N> branch parked at an old ancestor of main no longer skews the gate base (gate_files_from_prepush now falls back to merge-base(lsha, origin/main) for such a placeholder instead of taking base=rsha). That makes the placeholders harmless to the gate.

They are still clutter, though: dev-factory carries several agent/issue-<N> branches sitting at ancestors of main with no open PR (e.g. agent/issue-230, -237, -239, -176 observed 2026-10-16). land-pr.sh pushes agent/issue-<N> non-force, so each lands on top of whatever placeholder is already there.

Proposed

A small janitor that prunes PR-less agent/issue-<N> remote branches whose head is an ancestor of origin/main (fully recoverable — those SHAs are already in main's history). Candidate homes: sweep-lib.sh, or a land-pr.sh pre-step that deletes a stale placeholder before pushing a fresh branch.

Low priority: pure hygiene now that #253 removed the correctness impact. Two-way door (deleting a branch at an ancestor of main is reversible).

Filed by agent under ADR 0174 — veto anytime.

Follow-up to #253 (gate-scoping fix, landed in `ce26ea7`). ## Context #253 fixed the pre-push language gate so a stale PR-less `agent/issue-<N>` branch parked at an old ancestor of `main` no longer skews the gate base (`gate_files_from_prepush` now falls back to `merge-base(lsha, origin/main)` for such a placeholder instead of taking `base=rsha`). That makes the placeholders **harmless** to the gate. They are still **clutter**, though: `dev-factory` carries several `agent/issue-<N>` branches sitting at ancestors of `main` with no open PR (e.g. `agent/issue-230`, `-237`, `-239`, `-176` observed 2026-10-16). `land-pr.sh` pushes `agent/issue-<N>` non-force, so each lands on top of whatever placeholder is already there. ## Proposed A small janitor that prunes PR-less `agent/issue-<N>` remote branches whose head is an ancestor of `origin/main` (fully recoverable — those SHAs are already in `main`'s history). Candidate homes: `sweep-lib.sh`, or a `land-pr.sh` pre-step that deletes a stale placeholder before pushing a fresh branch. Low priority: pure hygiene now that #253 removed the correctness impact. Two-way door (deleting a branch at an ancestor of `main` is reversible). _Filed by agent under ADR 0174 — veto anytime._
Author
Member

This was generated by AI during triage.

Ruled by agent under ADR 0174 — veto anytime.

Ruling: ready-for-agent. Two-way door on two counts: (1) the janitor only deletes agent/issue-<N> remote branches whose head is an ancestor of origin/main, so every deleted SHA is already in main's history and the branch is recreatable at that SHA — fully recoverable; (2) the code change itself is revertible by a later commit and provable by an offline test (shimmed git, no network). It is not on the one-way-door list. The one open design choice — where the janitor lives (sweep-lib.sh vs a land-pr.sh pre-step) — is itself a two-way door the implementing agent may settle; I am not pinning it here.

Context check: confirmed #253 landed in ce26ea7 (pre-push gate now scopes to merge-base(lsha, origin/main) for a placeholder branch), so the correctness impact is gone and this is pure hygiene — low priority, no priority label.


Agent Brief

Category: enhancement
Summary: Prune PR-less agent/issue-<N> remote branches whose head is an ancestor of origin/main.

Current behavior:
land-pr.sh pushes agent/issue-<N> non-force, so each landing stacks on top of whatever placeholder branch is already at that name. Several agent/issue-<N> branches accumulate at ancestors of main with no open PR (e.g. agent/issue-230, -237, -239, -176 observed 2026-10-16). Since #253 they are harmless to the pre-push gate, but they are clutter.

Desired behavior:
A janitor prunes a remote agent/issue-<N> branch only when both hold: its head is an ancestor of origin/main (reachable from origin/main), and it has no open PR. Branches with an open PR, or whose head is not yet an ancestor of main (unlanded work), are left untouched. The prune is idempotent and safe to run repeatedly. Deletions are logged (branch name + head SHA) so a human can recreate any branch at its SHA if needed.

Key interfaces:

  • The pruning predicate: agent/issue-<N> branch AND git merge-base --is-ancestor <branch-head> origin/main AND no open PR for that branch (reuse the existing open-PR lookup helper, e.g. forgejo_open_pr_for).
  • Candidate home: a function in sweep-lib.sh, or a land-pr.sh pre-step that clears a stale placeholder before pushing the fresh branch — implementer's call under the ruling above.
  • A test seam that drives the janitor offline (shimmed git/forgejo_*), matching how the existing lib tests stub the remote.

Acceptance criteria:

  • The janitor deletes a PR-less agent/issue-<N> remote branch whose head is an ancestor of origin/main.
  • It does not delete a branch with an open PR, nor one whose head is not an ancestor of origin/main.
  • Each deletion is logged with the branch name and the head SHA it stood at.
  • Running it twice is a no-op the second time (idempotent).
  • A new/extended offline test covers: delete-eligible branch, open-PR skip, non-ancestor skip. Lib change + test in the same commit; the offline suite is green.

Out of scope:

  • Any branch namespace other than agent/issue-<N> (e.g. sandcastle/worker/*).
  • Force-deleting branches whose head is not an ancestor of main — that would discard unlanded work and is explicitly excluded.
  • The #253 gate-scoping fix (already landed) — do not revisit it.
> *This was generated by AI during triage.* **Ruled by agent under ADR 0174 — veto anytime.** **Ruling:** `ready-for-agent`. Two-way door on two counts: (1) the janitor only deletes `agent/issue-<N>` remote branches whose head is an ancestor of `origin/main`, so every deleted SHA is already in `main`'s history and the branch is recreatable at that SHA — fully recoverable; (2) the code change itself is revertible by a later commit and provable by an offline test (shimmed git, no network). It is not on the one-way-door list. The one open design choice — where the janitor lives (`sweep-lib.sh` vs a `land-pr.sh` pre-step) — is itself a two-way door the implementing agent may settle; I am not pinning it here. **Context check:** confirmed #253 landed in `ce26ea7` (pre-push gate now scopes to `merge-base(lsha, origin/main)` for a placeholder branch), so the correctness impact is gone and this is pure hygiene — low priority, no `priority` label. --- ## Agent Brief **Category:** enhancement **Summary:** Prune PR-less `agent/issue-<N>` remote branches whose head is an ancestor of `origin/main`. **Current behavior:** `land-pr.sh` pushes `agent/issue-<N>` non-force, so each landing stacks on top of whatever placeholder branch is already at that name. Several `agent/issue-<N>` branches accumulate at ancestors of `main` with no open PR (e.g. `agent/issue-230`, `-237`, `-239`, `-176` observed 2026-10-16). Since #253 they are harmless to the pre-push gate, but they are clutter. **Desired behavior:** A janitor prunes a remote `agent/issue-<N>` branch only when **both** hold: its head is an ancestor of `origin/main` (reachable from `origin/main`), and it has no open PR. Branches with an open PR, or whose head is not yet an ancestor of `main` (unlanded work), are left untouched. The prune is idempotent and safe to run repeatedly. Deletions are logged (branch name + head SHA) so a human can recreate any branch at its SHA if needed. **Key interfaces:** - The pruning predicate: `agent/issue-<N>` branch AND `git merge-base --is-ancestor <branch-head> origin/main` AND no open PR for that branch (reuse the existing open-PR lookup helper, e.g. `forgejo_open_pr_for`). - Candidate home: a function in `sweep-lib.sh`, or a `land-pr.sh` pre-step that clears a stale placeholder before pushing the fresh branch — implementer's call under the ruling above. - A test seam that drives the janitor offline (shimmed git/`forgejo_*`), matching how the existing lib tests stub the remote. **Acceptance criteria:** - [ ] The janitor deletes a PR-less `agent/issue-<N>` remote branch whose head is an ancestor of `origin/main`. - [ ] It does **not** delete a branch with an open PR, nor one whose head is not an ancestor of `origin/main`. - [ ] Each deletion is logged with the branch name and the head SHA it stood at. - [ ] Running it twice is a no-op the second time (idempotent). - [ ] A new/extended offline test covers: delete-eligible branch, open-PR skip, non-ancestor skip. Lib change + test in the same commit; the offline suite is green. **Out of scope:** - Any branch namespace other than `agent/issue-<N>` (e.g. `sandcastle/worker/*`). - Force-deleting branches whose head is **not** an ancestor of `main` — that would discard unlanded work and is explicitly excluded. - The #253 gate-scoping fix (already landed) — do not revisit it.
Author
Member

⏩ independent reviewer for #269 — verdict unauthenticated

review JSON
{
  "verdict": "unauthenticated",
  "findings": []
}
:fast_forward: **independent reviewer** for #269 — verdict `unauthenticated` <details><summary>review JSON</summary> ```json { "verdict": "unauthenticated", "findings": [] } ``` </details>
Author
Member

close-report for #269 — status success

✅ close-report gates passed — every claim verified against the PR head. PR #270 (#270) is open and green; a human merges it and the merge closes this issue via closes #269 (MERGE_AUTHORITY=human).

envelope
{
  "issue": 269,
  "status": "success",
  "commits": [
    "68fab2f3ef62d3dcc156c626b1ad3e7b198ed79b"
  ],
  "changed_files": [
    "STATUS.md",
    "docs/journal/2026-10-16-269.md",
    "report-lib.sh",
    "sweep-lib.sh",
    "tests/report-lib-test.sh",
    "tests/sweep-lib-test.sh"
  ],
  "tests": [
    {
      "command": "bash tests/sweep-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/report-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/docs-budget-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash onboarding/tests/vendor-manifest-coverage-test.sh",
      "exit_code": 0
    }
  ],
  "criteria": {
    "Deletes a PR-less agent/issue-<N> remote branch whose head is an ancestor of origin/main": "sweep_agent_branches in sweep-lib.sh (merge-base --is-ancestor + empty forgejo_open_pr_for, then push origin --delete); proven by the delete-eligible case in tests/sweep-lib-test.sh",
    "Does not delete a branch with an open PR, nor one whose head is not an ancestor of origin/main": "open-PR skip (forgejo_open_pr_for non-empty -> continue) and non-ancestor skip (merge-base --is-ancestor false -> continue) in sweep-lib.sh; both asserted in tests/sweep-lib-test.sh",
    "Each deletion is logged with the branch name and the head SHA": "printf '%s\\t%s\\n' branch sha to stdout + stderr log line in sweep_agent_branches; asserted via grep -F 'agent/issue-100<TAB>sha' in tests/sweep-lib-test.sh",
    "Running it twice is a no-op the second time (idempotent)": "second run finds the pruned branch gone (empty output); asserted in tests/sweep-lib-test.sh idempotency block",
    "New/extended offline test covers delete-eligible, open-PR skip, non-ancestor skip; lib change + test in same commit; offline suite green": "tests/sweep-lib-test.sh + tests/report-lib-test.sh extended in commit 68fab2f alongside sweep-lib.sh/report-lib.sh; both suites pass offline (sweep-lib in-sandbox block + report-lib 8 groups)"
  },
  "summary": "Added sweep_agent_branches janitor (sweep-lib.sh) wired into report_sweep to prune PR-less agent/issue-<N> remote placeholders at an ancestor of origin/main, with red-first offline tests.",
  "reason": "",
  "blockers": [],
  "no_code_change": ""
}
**close-report** for #269 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against the PR head. PR #270 (https://git.matou.nz/Matou/dev-factory/pulls/270) is open and green; a human merges it and the merge closes this issue via `closes #269` (MERGE_AUTHORITY=human). <details><summary>envelope</summary> ```json { "issue": 269, "status": "success", "commits": [ "68fab2f3ef62d3dcc156c626b1ad3e7b198ed79b" ], "changed_files": [ "STATUS.md", "docs/journal/2026-10-16-269.md", "report-lib.sh", "sweep-lib.sh", "tests/report-lib-test.sh", "tests/sweep-lib-test.sh" ], "tests": [ { "command": "bash tests/sweep-lib-test.sh", "exit_code": 0 }, { "command": "bash tests/report-lib-test.sh", "exit_code": 0 }, { "command": "bash tests/docs-budget-test.sh", "exit_code": 0 }, { "command": "bash onboarding/tests/vendor-manifest-coverage-test.sh", "exit_code": 0 } ], "criteria": { "Deletes a PR-less agent/issue-<N> remote branch whose head is an ancestor of origin/main": "sweep_agent_branches in sweep-lib.sh (merge-base --is-ancestor + empty forgejo_open_pr_for, then push origin --delete); proven by the delete-eligible case in tests/sweep-lib-test.sh", "Does not delete a branch with an open PR, nor one whose head is not an ancestor of origin/main": "open-PR skip (forgejo_open_pr_for non-empty -> continue) and non-ancestor skip (merge-base --is-ancestor false -> continue) in sweep-lib.sh; both asserted in tests/sweep-lib-test.sh", "Each deletion is logged with the branch name and the head SHA": "printf '%s\\t%s\\n' branch sha to stdout + stderr log line in sweep_agent_branches; asserted via grep -F 'agent/issue-100<TAB>sha' in tests/sweep-lib-test.sh", "Running it twice is a no-op the second time (idempotent)": "second run finds the pruned branch gone (empty output); asserted in tests/sweep-lib-test.sh idempotency block", "New/extended offline test covers delete-eligible, open-PR skip, non-ancestor skip; lib change + test in same commit; offline suite green": "tests/sweep-lib-test.sh + tests/report-lib-test.sh extended in commit 68fab2f alongside sweep-lib.sh/report-lib.sh; both suites pass offline (sweep-lib in-sandbox block + report-lib 8 groups)" }, "summary": "Added sweep_agent_branches janitor (sweep-lib.sh) wired into report_sweep to prune PR-less agent/issue-<N> remote placeholders at an ancestor of origin/main, with red-first offline tests.", "reason": "", "blockers": [], "no_code_change": "" } ``` </details>
Author
Member

swarm-claim host=matou-dev-server-01 run=22811
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=matou-dev-server-01 run=22811 (automated multi-host claim — lowest live claim id works this ticket)
Author
Member

⏩ independent reviewer for #269 — verdict unauthenticated

review JSON
{
  "verdict": "unauthenticated",
  "findings": []
}
:fast_forward: **independent reviewer** for #269 — verdict `unauthenticated` <details><summary>review JSON</summary> ```json { "verdict": "unauthenticated", "findings": [] } ``` </details>
Author
Member

close-report for #269 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 269,
  "status": "success",
  "commits": [
    "5e246f62b8cca75629319d518aa7dfee349ca9c5"
  ],
  "changed_files": [
    "STATUS.md",
    "docs/journal/2026-10-17-269.md",
    "report-lib.sh",
    "sweep-lib.sh",
    "tests/report-lib-test.sh",
    "tests/sweep-lib-test.sh"
  ],
  "tests": [
    {
      "command": "bash tests/sweep-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/report-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/docs-budget-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash onboarding/tests/vendor-manifest-coverage-test.sh",
      "exit_code": 0
    }
  ],
  "criteria": {
    "Deletes a PR-less agent/issue-<N> remote branch whose head is an ancestor of origin/main": "sweep_agent_branches in sweep-lib.sh (merge-base --is-ancestor origin/main + empty forgejo_open_pr_for, then git push origin --delete); proven by the delete-eligible case (agent/issue-100) in tests/sweep-lib-test.sh",
    "Does not delete a branch with an open PR, nor one whose head is not an ancestor of origin/main": "open-PR skip (forgejo_open_pr_for non-empty -> continue, agent/issue-200) and non-ancestor skip (merge-base --is-ancestor false -> continue, agent/issue-300) in sweep-lib.sh; both asserted survive in tests/sweep-lib-test.sh",
    "Each deletion is logged with the branch name and the head SHA": "printf '%s\\t%s\\n' branch sha to stdout + stderr note in sweep_agent_branches; asserted via grep -F 'agent/issue-100<TAB>sha' in tests/sweep-lib-test.sh",
    "Running it twice is a no-op the second time (idempotent)": "second run (after fetch --prune) finds the pruned branch gone -> empty output; asserted in the idempotency block of tests/sweep-lib-test.sh",
    "New/extended offline test covers delete-eligible, open-PR skip, non-ancestor skip; lib change + test in same commit; offline suite green": "tests/sweep-lib-test.sh + tests/report-lib-test.sh extended in commit 5e246f6 alongside sweep-lib.sh/report-lib.sh; both suites pass offline (sweep-lib in-sandbox block + report-lib 8 groups); full suite green except the pre-existing unrelated tests/rehearsal-heal-lib-test.sh red on clean main"
  },
  "summary": "Added sweep_agent_branches janitor (sweep-lib.sh) wired into report_sweep to prune PR-less agent/issue-<N> remote placeholders at an ancestor of origin/main, with red-first offline tests.",
  "reason": "",
  "blockers": [],
  "no_code_change": ""
}
**close-report** for #269 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 269, "status": "success", "commits": [ "5e246f62b8cca75629319d518aa7dfee349ca9c5" ], "changed_files": [ "STATUS.md", "docs/journal/2026-10-17-269.md", "report-lib.sh", "sweep-lib.sh", "tests/report-lib-test.sh", "tests/sweep-lib-test.sh" ], "tests": [ { "command": "bash tests/sweep-lib-test.sh", "exit_code": 0 }, { "command": "bash tests/report-lib-test.sh", "exit_code": 0 }, { "command": "bash tests/docs-budget-test.sh", "exit_code": 0 }, { "command": "bash onboarding/tests/vendor-manifest-coverage-test.sh", "exit_code": 0 } ], "criteria": { "Deletes a PR-less agent/issue-<N> remote branch whose head is an ancestor of origin/main": "sweep_agent_branches in sweep-lib.sh (merge-base --is-ancestor origin/main + empty forgejo_open_pr_for, then git push origin --delete); proven by the delete-eligible case (agent/issue-100) in tests/sweep-lib-test.sh", "Does not delete a branch with an open PR, nor one whose head is not an ancestor of origin/main": "open-PR skip (forgejo_open_pr_for non-empty -> continue, agent/issue-200) and non-ancestor skip (merge-base --is-ancestor false -> continue, agent/issue-300) in sweep-lib.sh; both asserted survive in tests/sweep-lib-test.sh", "Each deletion is logged with the branch name and the head SHA": "printf '%s\\t%s\\n' branch sha to stdout + stderr note in sweep_agent_branches; asserted via grep -F 'agent/issue-100<TAB>sha' in tests/sweep-lib-test.sh", "Running it twice is a no-op the second time (idempotent)": "second run (after fetch --prune) finds the pruned branch gone -> empty output; asserted in the idempotency block of tests/sweep-lib-test.sh", "New/extended offline test covers delete-eligible, open-PR skip, non-ancestor skip; lib change + test in same commit; offline suite green": "tests/sweep-lib-test.sh + tests/report-lib-test.sh extended in commit 5e246f6 alongside sweep-lib.sh/report-lib.sh; both suites pass offline (sweep-lib in-sandbox block + report-lib 8 groups); full suite green except the pre-existing unrelated tests/rehearsal-heal-lib-test.sh red on clean main" }, "summary": "Added sweep_agent_branches janitor (sweep-lib.sh) wired into report_sweep to prune PR-less agent/issue-<N> remote placeholders at an ancestor of origin/main, with red-first offline tests.", "reason": "", "blockers": [], "no_code_change": "" } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/dev-factory#269
No description provided.