Skip to content

The reservation-release retry sweep does not carry _techdebt_unfile's record-branch-before-reservation ordering, and the collation that currently saves it is stated nowhere

Id: TD-PPagop-26082805 · Status: resolved · Filed: 2026-08-28 · Resolved: 2026-09-24 · Ref: https://github.com/Pullwright/agent-ops/pull/1849

_techdebt_unfile (lib/tech-debt-file.sh) deletes td-record/<id> before td/<id> and never the other way round. Both the function’s own header and component 23d of docs/IMPLEMENTATION-PIPELINE-SPEC.md state the reason: releasing the id while td-record/<id> still exists lets a later scripts/reserve-tech-debt-id.pl hand that id out again and then fail its own branch-create against the ref that was left behind.

scripts/release-pending-reservations.sh (added by PR #841 for TD-PPagop-26082427) does not carry that ordering. Where both of _techdebt_unfile’s deletes failed against branches confirmed still present — the shape a GitHub window produces when it fails a filing at the contents-write or pr create stage and then fails both cleanup DELETEs — two markers for a single id sit under reservation-releases/<repo>/ together, and the sweep acts on them in whatever order the contents API listed them in. Handling td__<id>.json first releases td/<id> while td-record/<id> still exists: precisely the state the ordering rule exists to prevent.

It does not fire today. GitHub lists a directory by name, and td-record__<id>.json sorts below td__<id>.json because - (0x2D) precedes _ (0x5F), so the safe order happens by accident of byte collation over two sanitized filenames — asserted by no test and stated in no comment. The exposure window is also short, since both markers clear within the same pass, but reserve-tech-debt-id.pl runs on any node at any moment, so short is not closed.

The obvious fix — sorting the listing explicitly — is correct only for these two particular prefix strings. tech_debt_branch_prefix (#835) has since made the reservation prefix configurable for lib/claim.sh and the four gather-*.sh sources, while lib/tech-debt-file.sh still hard-codes td/ and td-record/; at a configured prefix such as reserve/, a plain LC_ALL=C sort would order the two markers the wrong way round. So the fix is a judgement about #835’s intended reach as much as about this sweep: either partition the markers explicitly on the record-branch prefix rather than relying on sort order, or bring lib/tech-debt-file.sh onto the configured prefix first and then sort. Whichever is chosen, the invariant wants a regression test in test/release-pending-reservations.test.sh — two markers for one id, listed reservation-first, asserted to be acted on record-first.

Noticed while reviewing https://github.com/Poetic-Poems/agent-ops/pull/841.

Migrated to https://github.com/Poetic-Poems/agent-ops/issues/1010.