* fix(close): restore idempotent re-close by ordering, not by clearing the pin
`bd close --force` on a boolean-pinned bead leaves `{pinned: true, status:
closed}` — closeIssueInTx writes only status/closed_at/updated_at/close_reason/
closed_by_session/row_lock, never the pinned column. Since #5212 taught
validation.NotPinned to refuse on `issue.Pinned || status == pinned`, the plain
retry hit that guard before ever reaching the `!res.Changed` already-closed
branch, so an idempotent re-close started exiting nonzero. That branch is the
only thing that re-drives a stranded molecule auto-close, so a crashed
auto-close of a pinned final step stayed stranded forever.
An earlier ruling proposed clearing the pin on close. It was WITHDRAWN on
evidence: Pinned is the deletion-protection flag at six destructive call sites
(bd gc, bd purge, bd cleanup), and in filterClosedDeletionCandidates the pinned
check sits immediately before the closed check, so there it protects closed rows
exclusively. Clearing it would make a pinned closed bead impossible and turn all
six branches into dead code. The current ruling is to fix the ordering instead:
short-circuit the already-closed no-op before validateIssueClosable in both close
paths. Ruling 10 is not narrowed and NotPinned is not exempted — it simply is
never reached on a row that is already closed, because closing an already-closed
issue is a no-op with nothing to protect.
Both close paths skip only validateIssueClosable, and only when the resolve-time
snapshot they already hold reports literal StatusClosed:
- The engine still runs. Its in-transaction `WHERE status != 'closed'` guard
remains the authority on whether the close is a no-op, so two actors closing
concurrently still converge, the coordination-cell touch still happens, and
the closed-target open-children refusal is preserved.
- No extra read: close.go reuses result.Issue from resolveCloseTargets and
closeProxiedOne reuses `current`.
- Only literal StatusClosed qualifies, mirroring issueops.isClosedInTx —
reaching a configured done status is a real close and still validates.
A re-close was verified to be a pure no-op for user-visible close state, so the
reorder drops no writes: the guarded UPDATE means --reason and --session are
already discarded on an already-closed row today (issueops/close.go), and the
CLI never sets ExpectedVersion.
The direct and proxied paths change identically; diverging here is the defect
class #5217 just closed, and both now carry command-level twins asserting the
force-close → plain-retry exit 0, the surviving pin, and (direct) that the row
is still excluded by filterClosedDeletionCandidates with PinnedSkipped == 1.
Agent-Signature: claude-opus-5
Co-authored-by: CI Bot <ci@beads.test>
* test(close): pin the owner-accepted collateral of the re-close reorder
Skipping validateIssueClosable on an already-closed row skips the whole
chain, not only the pinned guard, so a foreign actor's re-close now exits
0 where it used to refuse with the be-035 authority error. The owner
accepted that on 2026-08-01: a re-close writes nothing, because the close
UPDATE is guarded `WHERE id = ? AND status != 'closed'`, so the authority
check has no state change left to protect.
The alternative — scoping the skip to NotPinned alone — was rejected by
the review council and by the ruling, because a per-validator carve-out
is the guard-narrowing shape the ruling exists to avoid.
This pins the new semantics so a future change to them fails loudly
rather than sliding through. It also asserts the assignee is unchanged,
which is the evidence that nothing was written. The refusal itself is
untouched: close_assignee_mismatch_refuses_without_force still pins it on
an open bead, which is the case be-035 was filed for.
NotTemplate needs no equivalent case: a closed template is unreachable
from the CLI, since validateIssueClosable and validateIssueUpdatable both
refuse templates, so neither `bd close` nor `bd update --status closed`
can produce one.
Agent-Signature: claude-opus-5
Co-authored-by: CI Bot <ci@beads.test>
---------
Co-authored-by: CI Bot <ci@beads.test>