lib/issue-priority.sh’s cache-directory ownership record
(ISSUE_PRIORITY_CACHE_DIR_OWNED_PATH, overwritten at line 109 whenever the
source-time else branch creates a fresh directory) holds exactly one path.
A process that makes the library create a second directory in the same
process — by repointing ISSUE_PRIORITY_CACHE_DIR and re-sourcing, or
unsetting it and re-sourcing — orphans the first one permanently:
issue_priority_cache_cleanup only ever knows about the most recent record,
so the earlier directory is never removed.
Found by the Reviewer reviewing PR #618, verified by mutation there and
confirmed independently by the Approver on the same PR. Quoting the
Reviewer’s own verification (PR #618 review thread):
The ownership record holds one path.
ISSUE_PRIORITY_CACHE_DIR_OWNED_PATH is overwritten every time the
source-time else branch runs, so a process that makes the library create
a second directory orphans the first one permanently — cleanup only ever
knows about the most recent.
unsetISSUE_PRIORITY_CACHE_DIR; .lib/...# caller lets go
issue_priority_cache_cleanup
# A exists after cleanup: YES (leaked) <- the first library-created directory
# B exists after cleanup: yes <- correct, the caller owns it
# C exists after cleanup: no <- correct, the record's current path
Requirement 39g (docs/IMPLEMENTATION-PIPELINE-SPEC.md) states that a
directory this file made “is still found and removed even after a caller has
since repointed ISSUE_PRIORITY_CACHE_DIR at its own path” — true for one
repoint (the mirror-case test pins exactly that), and not true once the
library has created a second directory in the same process. The requirement’s
own wording is accurate for the case it names; the gap is in what the
underlying record can represent, not in what the spec claims.
Not a regression and not currently reachable. The same sequence leaked
the same directory before PR #548; PR #618 narrowed the leak rather than
widening it. Both real callers source the library once and never repoint or
unset ISSUE_PRIORITY_CACHE_DIR before cleanup: agent-cycle.sh’s EXIT-trap
cleanup (issue_priority_cache_cleanup call, currently agent-cycle.sh:4701)
and scripts/doctor.sh’s own EXIT trap (currently scripts/doctor.sh:86).
test/doctor.test.sh’s “a clean pass leaves no cache directory under
TMPDIR” is the end-to-end proof for the real consumer.
Suggested fix, per the Reviewer’s own note: replace the single-slot
ISSUE_PRIORITY_CACHE_DIR_OWNED_PATH/_OWNER_PID pair with a record of every
owned path this process has created (an array, or a marker file per
directory), and clean up each one issue_priority_cache_cleanup still finds.
Scope the fix to lib/issue-priority.sh and its own test file
(test/issue-priority.test.sh); this is the register scripts’ own sibling,
not one of the canonical tech-debt tooling files TECH-DEBT.md names, so no
upstream sync applies.
Noticed while working on agent-ops#631, which is when the fix for the gap
this repo’s own filing workflow had (a stage could not land a
tech-debt/<id>.md record in a pull request it was not the sole author of a
new branch for) finally made it possible to file this — the Approver’s own
PR #618 review said as much:
It does warrant a tech-debt file under CLAUDE.md’s ‘do not leave it only in
chat’ rule, but this repo’s filing workflow reserves an ID on its own
td/<id> branch and its own pull request, so it cannot land in #618 — that
is follow-up work, not a defect in this diff.