Skip to content

A failed gh pr create in techdebt_file_debt orphans its td-record/<id> branch and td/<id> reservation, invisible to every sweep

Id: TD-PPagop-26082203 · Status: resolved · Filed: 2026-08-22 · Resolved: 2026-08-23 · Ref: https://github.com/Poetic-Poems/agent-ops/pull/709

lib/tech-debt-file.sh’s techdebt_file_debt reserves a tech-debt id (a td/<id> branch, pushed by scripts/reserve-tech-debt-id.pl), then writes the new td-record/<id> branch and its one tech-debt/<id>.md file purely through the API (POST .../git/refs, then PUT .../contents/<path>), and only then calls gh pr create to open the filing pull request. If that pr create call fails — after the refs POST and the contents PUT have both already succeeded — the function returns 1, but it does not undo the writes that already landed. Two branches are left behind with no pull request carrying them anywhere:

  • td-record/<id>, carrying the record commit tech-debt/<id>.md itself.
  • td/<id>, the reservation lock. .github/workflows/release-td-branch.yml only ever releases a td/<id> reservation in response to a push to main that adds a new tech-debt/<id>.md — since the record never reaches main this way, that trigger never fires, and the reservation is never released by that path.

scripts/sweep-orphan-branches.sh cannot find either one. Its own matching-refs sweep (scripts/sweep-orphan-branches.sh:373) lists exactly two prefixes — td/ and $branch_prefix — and deliberately leaves a bare td/<id> reservation alone by design (issue #545: it cannot tell from the branch alone whether <id> has since been filed elsewhere), so even the td/<id> half of this gap is not swept as orphaned work; it is simply never looked at again. td-record/ is not one of the swept prefixes at all, so the branch actually carrying the lost record is invisible to every pass, regardless of that same-branch exemption.

The same orphaning happens by a second route with no code defect involved: a human (or another automated pass) can close the filing pull request without merging it — e.g. as a duplicate, or because the record turned out to be unwanted — which orphans td-record/<id> and td/<id> exactly the same way, since closing a pull request does not delete either branch and the record still never reaches main.

Suggested fix, per the Reviewer’s own note on PR #686: either add a best-effort cleanup of the branch/reservation on the pr create failure path in techdebt_file_debt (deleting td-record/<id> and td/<id> via the API when the pull request itself could not be opened), or teach scripts/sweep-orphan-branches.sh to also sweep the td-record/ prefix (and, for a td/<id> behind it, to check whether the id was ever filed rather than leaving every td/<id> alone unconditionally) so a branch orphaned either way is found and recovered like any other abandoned claim.

Noticed by the Approver reviewing PR #686 (lib/tech-debt-file.sh:187), which introduced techdebt_file_debt and is the review that first surfaced this gap.