san() and other small utilities are copy-pasted rather than shared between lib/claim.sh, sweep-orphan-branches.sh, agent-cycle.sh and review-cycle.sh
Id: TD-PPagop-26082411 · Status: resolved · Filed: 2026-08-24 · Resolved: 2026-09-10 · Ref: https://github.com/Pullwright/agent-ops/pull/1332 · Review: reviews/project-review-2026-08-23 R-06 F-CODE-02 F-ARCH-03
Severity: Medium
san() (the claim-path sanitizer, san() { local s="$1"; printf '%s' "${s//\//__}"; }) is defined identically in both lib/claim.sh:118 and
scripts/sweep-orphan-branches.sh:122 — the latter sources other lib/*.sh
files but not lib/claim.sh, and reimplements san() instead. Both build
the same claim-registry path shape independently. Separately,
expand_home(), cfg()/cfg_json(), and log_event() are duplicated
with only trivial differences between agent-cycle.sh and
review-cycle.sh, with neither a shared lib/ implementation nor a
pinning test — unlike comparable cases this codebase already handles
correctly (lib/stage-run.sh, test/extract-json-result.test.sh).
Likely arose because scripts/sweep-orphan-branches.sh and
review-cycle.sh were each written as standalone scripts at different
times, each copying whatever it needed from the pattern already
established elsewhere rather than importing it.
Ongoing cost: the san() duplication carries real correctness risk —
if lib/claim.sh’s san() ever changes, sweep-orphan-branches.sh
silently keeps the old encoding, its claim-registry lookups start missing
real claims, and it can delete a branch a peer node still owns. The smaller
utility duplication is lower risk (4-13 line functions unlikely to drift
subtly) but is an inconsistent application of a principle this codebase
otherwise treats as important.
Suggested fix: have scripts/sweep-orphan-branches.sh source
lib/claim.sh and use its san(), deleting the local copy (verify
byte-identical behaviour for every input actually passed before removing
the old copy, given the branch-deletion stakes). For the smaller
utilities, either promote the shared shape into lib/ with the small
difference parameterised, or mark both copies as deliberately duplicated.
Migrated to https://github.com/Poetic-Poems/agent-ops/issues/967.