Janitor: prune PR-less agent/issue-<N> placeholders at an ancestor of main (#269) #270

Closed
matou-build-agent wants to merge 1 commit from agent/issue-269 into main

closes #269

Follow-up to #253. Prunes PR-less agent/issue-<N> remote placeholder branches sitting at an ancestor of main — pure landing clutter (land-pr.sh pushes non-force, so each PR stacks on the stale placeholder).

What changed

  • sweep-lib.sh — new sweep_agent_branches <repo_dir>. Deletes a remote agent/issue-<N> branch ONLY when BOTH hold: its head is an ancestor of origin/main (reachable — the SHA is already in main's history, so the branch is recreatable at that SHA; fully recoverable, a two-way door under ADR 0174) AND it has no open PR (forgejo_open_pr_for returns empty). A branch with an open PR, or whose head is not an ancestor of main (unlanded work), is left untouched — never force-deleted. Each prune is logged to stderr and echoed branch<TAB>sha to stdout so a human can recreate any branch at its SHA. Idempotent; never fails the caller (runs from the EXIT trap). Fail-safe no-op when forgejo_open_pr_for / origin/main / a git repo is absent.
  • report-lib.sh — wired into the post-run report_sweep as quiet housekeeping (job-log line, no Mattermost alert), alongside the container reap and worktree sweep. Runs on the HOST post-landing where origin/main is current and forgejo-lib.sh is in scope (via landing-lib.sh).

Home choice

Triage ruled the home (sweep-lib.sh vs a land-pr.sh pre-step) the implementer's call. sweep-lib.sh wins — the global post-run sweep prunes the whole placeholder backlog (agent/issue-230, -237, -239, -176 observed), not just the current issue's branch.

Acceptance

  • Deletes a PR-less agent/issue-<N> branch whose head is an ancestor of origin/main.
  • Does not delete a branch with an open PR, nor a non-ancestor (unlanded) branch.
  • Each deletion logged with branch name + head SHA.
  • Running twice is a no-op the second time (idempotent).
  • New offline test covers delete-eligible / open-PR skip / non-ancestor skip (+ non-agent branch untouched, idempotency, fail-safe no-ops); lib + test in the same commit.

Tests

  • tests/sweep-lib-test.sh — new block using a real local bare remote as origin and a stubbed forgejo_open_pr_for; placed before the git-fence worktree skip (no worktree op, runs in-sandbox). Passes.
  • tests/report-lib-test.sh — report_sweep logs the pruned names quietly; a failing janitor never fails the run. 8 groups pass.

Root-only — INERT in the running .sandcastle/ self-copy and every consumer until a human re-vendors + bumps FACTORY_REF (GOTCHAS 4). No GOTCHAS entry (closes no operational hazard).

Screenshots: none — shell-library change (a post-run git/branch janitor) with no visible UI surface; behaviour is proven by the offline sweep-lib/report-lib suites.

closes #269 Follow-up to #253. Prunes PR-less `agent/issue-<N>` remote placeholder branches sitting at an ancestor of `main` — pure landing clutter (`land-pr.sh` pushes non-force, so each PR stacks on the stale placeholder). ## What changed - **`sweep-lib.sh` — new `sweep_agent_branches <repo_dir>`.** Deletes a remote `agent/issue-<N>` branch ONLY when BOTH hold: its head is an ancestor of `origin/main` (reachable — the SHA is already in `main`'s history, so the branch is recreatable at that SHA; fully recoverable, a two-way door under ADR 0174) AND it has no open PR (`forgejo_open_pr_for` returns empty). A branch with an open PR, or whose head is **not** an ancestor of `main` (unlanded work), is left untouched — never force-deleted. Each prune is logged to stderr and echoed `branch<TAB>sha` to stdout so a human can recreate any branch at its SHA. Idempotent; never fails the caller (runs from the EXIT trap). Fail-safe no-op when `forgejo_open_pr_for` / `origin/main` / a git repo is absent. - **`report-lib.sh` — wired into the post-run `report_sweep`** as quiet housekeeping (job-log line, no Mattermost alert), alongside the container reap and worktree sweep. Runs on the HOST post-landing where `origin/main` is current and `forgejo-lib.sh` is in scope (via `landing-lib.sh`). ## Home choice Triage ruled the home (`sweep-lib.sh` vs a `land-pr.sh` pre-step) the implementer's call. `sweep-lib.sh` wins — the global post-run sweep prunes the whole placeholder backlog (`agent/issue-230`, `-237`, `-239`, `-176` observed), not just the current issue's branch. ## Acceptance - [x] Deletes a PR-less `agent/issue-<N>` branch whose head is an ancestor of `origin/main`. - [x] Does **not** delete a branch with an open PR, nor a non-ancestor (unlanded) branch. - [x] Each deletion logged with branch name + head SHA. - [x] Running twice is a no-op the second time (idempotent). - [x] New offline test covers delete-eligible / open-PR skip / non-ancestor skip (+ non-agent branch untouched, idempotency, fail-safe no-ops); lib + test in the same commit. ## Tests - `tests/sweep-lib-test.sh` — new block using a real local bare remote as `origin` and a stubbed `forgejo_open_pr_for`; placed before the git-fence worktree skip (no worktree op, runs in-sandbox). Passes. - `tests/report-lib-test.sh` — `report_sweep` logs the pruned names quietly; a failing janitor never fails the run. 8 groups pass. Root-only — INERT in the running `.sandcastle/` self-copy and every consumer until a human re-vendors + bumps `FACTORY_REF` (GOTCHAS 4). No GOTCHAS entry (closes no operational hazard). **Screenshots:** none — shell-library change (a post-run git/branch janitor) with no visible UI surface; behaviour is proven by the offline `sweep-lib`/`report-lib` suites.
sandcastle: #269 — janitor prunes PR-less agent/issue-<N> placeholders at an ancestor of main
All checks were successful
ci / test (pull_request) Successful in 5m17s
ci / static (pull_request) Successful in 2m18s
68fab2f3ef
New `sweep_agent_branches` (sweep-lib.sh) deletes a remote `agent/issue-<N>`
branch ONLY when its head is an ancestor of `origin/main` (SHA already in
main's history — recoverable, two-way door) AND it has no open PR
(`forgejo_open_pr_for` empty). A branch with an open PR, or whose head is NOT
an ancestor of main (unlanded work), is left untouched — never force-deleted.
Logs `branch<TAB>sha` per prune, idempotent, never fails the caller.

Wired into the post-run `report_sweep` (report-lib.sh) as quiet housekeeping
(job-log line, no alert) alongside the container reap / worktree sweep — runs
on the HOST post-landing where origin/main is current and forgejo-lib is in
scope (via landing-lib). Fail-safe no-op when forgejo_open_pr_for / origin/main
/ a git repo is absent.

Home choice (sweep-lib vs a land-pr pre-step) ruled implementer's call by
triage; sweep-lib wins — the global sweep prunes the whole placeholder backlog,
not just the current issue's branch. Follow-up to #253 (placeholders are now
harmless to the pre-push gate; this is pure hygiene).

Red-first offline tests same commit:
- tests/sweep-lib-test.sh: real local bare remote as origin, stubbed
  forgejo_open_pr_for; covers delete-eligible, open-PR skip, non-ancestor skip,
  non-agent branch untouched, idempotent re-run, three fail-safe no-ops. Placed
  before the git-fence worktree skip (no worktree op; runs in-sandbox).
- tests/report-lib-test.sh: report_sweep logs the pruned names quietly; a
  failing janitor never fails the run.

STATUS.md header + docs/journal/2026-10-16-269.md updated. Root-only — INERT in
the running .sandcastle self-copy and consumers until a human re-vendors
(GOTCHAS 4). No GOTCHAS entry (closes no operational hazard).

Note: tests/rehearsal-heal-lib-test.sh reds in-sandbox only (CLAUDE_ACCOUNT_FP
is set here, so its "no trailer without fp" case trips) — pre-existing,
unrelated to this slice, green in CI where the var is unset.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Factory-Account: d631bd58e1e9
Author
Member
close-report gates passed for #269 — every claim verified; this PR is cleared for merge.
<!-- close-report: gates-passed --> close-report gates passed for #269 — every claim verified; this PR is cleared for merge.
Owner

Superseded, closed unmerged (Ben, 2026-10-17). #269 landed on main as 5e246f6 through the push-mode host-land after LANDING=push returned (#276); its close-report verified against main and the ticket is closed. This PR's 68fab2f is the same work on a pre-#276 base — nothing left to merge.

Superseded, closed unmerged (Ben, 2026-10-17). #269 landed on `main` as `5e246f6` through the push-mode host-land after `LANDING=push` returned (#276); its close-report verified against main and the ticket is closed. This PR's `68fab2f` is the same work on a pre-#276 base — nothing left to merge.
ben closed this pull request 2026-10-17 19:37:41 +00:00
All checks were successful
ci / test (pull_request) Successful in 5m17s
ci / static (pull_request) Successful in 2m18s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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!270
No description provided.