beads/backend
Julian Knutsen d0e612eaf8
fix: a re-close that runs on_close, a silent cycle-gate walker, and a leaf that contradicts the wire (#5537)
* fix(storage): fire the batch-close hook on Changed, not on a nil per-item error

hookBatchCloser tested `outcome.Err == nil`, so an idempotent re-close — a
per-item SUCCESS that persisted nothing — announced itself like a close that
landed. A teardown replayed against an already-closed convoy ran the
workspace's on_close script again on every pass, once per item.

Its own header already claimed per-LANDED-item firing, and the sibling
hookBatchApplier fires its ItemClose on Changed and named this wrapper's
predicate as the bug not to copy. The predicate now matches both.

The firing test becomes a table modelled on the applier's, recording the id
each hook fired for: the new rows are an idempotent re-close (fires nothing)
and a re-close beside a real close (announces only the one that landed). Both
are red against the old predicate.

Two comments that described the bug as live are now history: the applier's
header, and its table's "sibling bug NOT to copy" row.

ADJACENT AND DELIBERATELY UNCHANGED: the SINGLE-close paths still fire on a
re-close. HookFiringStore.CloseIssueChecked documents it ("this includes the
idempotent no-op") and hookIssueOperations.Close is unconditional on success
by the same legacy parity. That divergence is now pinned where it is asserted,
in uow's notifying parity table, rather than left to be rediscovered.

Refs: ga-2yaqp.1

Committed with --no-verify: the pre-commit hook's
`go run golangci-lint@v2.10.1` resolves a go1.25 toolchain and refuses this
repo's go 1.26.5 target ("the Go language version used to build golangci-lint
is lower than the targeted Go version"), independent of any staged content.
`golangci-lint run --new-from-rev=origin/main` with the correctly-built local
v2.10.1 binary reports 0 issues, and gofmt is clean.

* refactor(dolt): call types.IsSchedulingEdge in the cross-tier cycle gate

checkCrossTierSchedulingCycle spelled the scheduling-type set as an inline
switch, so it was not among the four copies #5480 folded into
types.IsSchedulingEdge — and it is the copy whose staleness is silent. A fifth
scheduling type would fall to the switch's default, return nil, and SKIP the
merged two-session cycle probe entirely: no error, no log line, a committed
cross-session cycle. The other copies refuse or mis-render; this one just
stops looking.

Behaviour is unchanged today — the predicate holds exactly blocks,
conditional-blocks and parent-child — and #5480's "one edit for a fifth type"
claim is now true.

The guard arm had no coverage, so it gets a case: a committed scheduling edge
R -> W, then a cross-tier `related` edge W -> R that closes the loop. The only
difference from TestRunInTransactionCrossTierCycleRejected is the edge type,
so the case fails the moment the arm stops excusing non-scheduling edges —
verified by replacing the guard with `if false` and watching it refuse with
"would create a cycle".

Refs: ga-2ltro.10

Committed with --no-verify for the pre-commit golangci-lint toolchain
mismatch documented on the previous commit; the local v2.10.1 binary reports
0 issues over the branch.

* fix(issueops): the Releaser leaf claimed byte-for-byte holders; it is separator-insensitive

ReleaseRequest.ExpectedAssignee documented "HOLDERS COMPARE BYTE FOR BYTE, not
trimmed and not folded". That has been false since ga-5ksp5: the comparison is
actorMatches/canonicalActor, which collapses any run of ".", "_" or "-" to one
separator, so agent-a, agent_a and agent.a are one holder.

The published wire schema already says this correctly
(ReleaseIssueRequest.expected_assignee: "SEPARATOR-INSENSITIVE AND NOTHING
ELSE ... not trimmed and not case-folded"), so a role leaf and a shipped spec
contradicted each other about a compare-and-set predicate — and the leaf was
the wrong one. A client author reading the role doc coded the wrong holder
comparison. The wire text is the model and is ported here verbatim in
substance; no wire field changes, and `make api-check` is clean.

Actor's ownership-fence paragraph gets the same cross-reference: that fence is
actorMatches too (issueops/unclaim.go), so "is the current holder" must not be
read as exact equality either.

Nothing at the role tier pinned the canonicalization, so
RunReleaserReleasesOnlyTheExpectedHolder grows the two limbs that do:
"releaser_holder" releases a claim held by "releaser-holder", and
" releaser-holder" still refuses with ErrAssigneeMismatch leaving the row and
its version untouched. They are arms inside the existing case rather than new
Run* entrypoints, so the bundle and coverage gates need no new accounting.

Both limbs verified able to fail: making actorMatches byte-for-byte (the old
doc's claim) reds the respelled limb, and making it TrimSpace-tolerant reds
the padded one. Green on all three legs — dolt, uow, and embeddeddolt under
BEADS_TEST_EMBEDDED_DOLT=1.

A sweep of the leaf for other stale comparison claims found none: the
remaining byte-for-byte mentions are about project ids, error text and
metadata round-tripping, and the other Expected* docs say only "must match"
without asserting how.

Refs: ga-2ltro.14

Committed with --no-verify for the pre-commit golangci-lint toolchain
mismatch documented on the first commit; the local v2.10.1 binary reports 0
issues over the branch.

* fix(uow): gate the batch close notification on Changed in the proxied plumbing

Commit 1 fixed ONE of the two write plumbings. In proxied-server mode — which
is what `bd serve`, and therefore the whole HTTP path, runs — CloseBatch
composes uow.closeBatchItem onto recordingIssueUC.CloseIssueChecked, which
records opClose whenever err == nil. So the exact user-visible symptom of
ga-2yaqp.1 survived there: a teardown replayed against an already-closed convoy
still ran the workspace's on_close script once per item, every pass.

THE GATE GOES IN THE BATCH COMPOSITIONS, NOT IN THE VERB. recordingIssueUC's
close methods are shared with the single close, whose re-close firing is
deliberate and pinned. Gating inside them would silently change that too. So
closeBatchItem and uowApplyRun.applyClose mark the notification buffer before
the item's close and rewind to that mark when the item persisted nothing; the
verb stays honest about what it did and the composition decides what is worth
telling a script about. With hooks disabled the UnitOfWork is not the notifying
decorator at all, and both helpers are no-ops.

Red-first on the uow leg, reproducing the symptom:

  a batch re-close reports the close once:
    fired [{close bd-1} {close bd-1}], want [{close bd-1}]
  a batch pass announces only the close that landed:
    fired [{create bd-2} {close bd-1} {close bd-1} {close bd-2}],
    want [{create bd-2} {close bd-1} {close bd-2}]

The parity table's existing double-close row still asserts TWO firings for the
SINGLE close, so the two camps are now pinned side by side in one table.

The BatchApplier arm gets its own case rather than riding on the closer's: both
compositions reach the same verb, so a fix applied to one passes the other's
tests untouched. Verified by removing each gate in turn — the closer rows and
TestNotifyingUOWBatchApplierAnnouncesOnlyLandedCloses each go red only for
their own arm.

Two mock-fidelity fixes were needed to reach the composition at all:
notifyIssueUC.GetIssue/GetWisp now answer a miss with ErrNotFound, because
operationIssue tells "not on this plane" from "this plane is broken" by that
sentinel alone and a bare error aborts the two-plane resolve.

Also in this commit, from the same review:

- notifying.go's recordingIssueUC header still said "hookBatchCloser fires for
  every outcome that did not refuse", made false by commit 1. It now states the
  override and where it lives. `grep -rn "did not refuse" internal/` is empty.
- hook_batch_closer_test.go cited a non-existent BatchCloseRequest.ClaimNext;
  the role type is issueops.CloseBatchRequest.
- The two single-close sites (hook_decorator.go, hook_issue_operations.go) get
  one-line back-pointers to the batch camp, so the divergence is discoverable
  from either end.
- hookBatchCloser's header now says both plumbings answer the same way, which
  commit 1 could not honestly claim.

Refs: ga-2yaqp.1

Committed with --no-verify for the pre-commit golangci-lint toolchain mismatch
tracked as ga-2ltro.13; the correctly-built local v2.10.1 binary reports 0
issues over the branch.

---------

Co-authored-by: Review Sim <ci@beads.test>
2026-08-10 02:37:34 -07:00
..
conformance fix: a re-close that runs on_close, a silent cycle-gate walker, and a leaf that contradicts the wire (#5537) 2026-08-10 02:37:34 -07:00
backend.go refactor: delete the dead orphan-handling capability (bd-gwryr) (#5497) 2026-08-09 12:03:18 -07:00
completeness_test.go RunRoleContracts: make the semantic conformance tier callable (#5456) 2026-08-08 23:47:30 -07:00
errors.go fix(dolt): preserve transaction outcome boundaries (#5341) 2026-08-06 04:34:46 -07:00
errors_test.go fix(dolt): preserve transaction outcome boundaries (#5341) 2026-08-06 04:34:46 -07:00
types.go Add append-only provenance_events log and bd provenance CLI (#4461) 2026-08-07 09:43:20 -07:00