beads/cmd/bd/protocol
Vishnu J c296fc9205 Beads #6648: report partial batch-close failure (#6740)
* fix(close): fail partial batch closes

Fixes #6648

* review: exit nonzero on proxied partial close, update tests and changelog

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* review: print close failure summary only for multi-id batches

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* review: machine-readable close failures, and adjudicate --claim-next

Maintainer fixup for the two major findings on #6740 (Beads #6648).

1. --claim-next x partial failure (major). --claim-next rides inside the
   batch transaction and fires whenever something LANDED, so a mixed batch
   claimed a fresh issue and then exited 1, with nothing in the diff, the
   CHANGELOG or the tests saying so.

   Adjudicated as "the claim stands and the report names it", not "the claim
   is suppressed". Suppressing it at cmd/bd -- the site the review named --
   cannot un-claim anything: ExecuteCloseBatch (and the uow provider's twin)
   commit the claim alongside the survivors before the CLI ever sees a
   refusal, so gating the report would only leave an issue assigned to the
   actor with nothing on stdout or stderr saying so. Strictly worse than
   announcing it. The claim is now named in the text summary and in the JSON
   failure payload, so a caller that exits on the nonzero status can still
   see what it owns.

   The review's "unbounded claim leak -- another ready issue on every
   attempt" does not hold, and the new test pins why: on a retry the survivor
   is already closed, so `landed` is 0 and an empty batch earns no claim
   (close_batch.go:146, uow/batch_closer.go:71). The leak is bounded at the
   one claim the first run earned. The defect that remains -- a durable claim
   the caller is never told about -- is what this fixes.

2. --json partial failure carried no machine-readable signal (major). The new
   exit 1 left stdout as the success-shaped array of CLOSED issues and put
   only human refusal prose on stderr, so a JSON consumer could not learn
   WHICH ids failed without scraping it -- the exact fragility #6648 was filed
   about, left in place for the callers most likely to batch. Both routes now
   report through one reportCloseFailures helper modelled on bd update's
   reportUpdateFailures: a compact {"error","failed":[{"id","error"}]} line on
   stderr, stdout keeping the closed-issues array. That also removes the
   summary hand-rolled twice with two denominators (the architectural nit).

Also taken, all non-gating and adjacent to the above:
- CHANGELOG narrowed to the refusals it actually covers, noting that an
  UNRESOLVABLE id still aborts the direct route before any close runs while
  the proxied route refuses it per-argument (the route-parity overclaim).
- Tests for the three deliberately-chosen behaviours that had no pin: the
  --json partial failure (proxied), the --claim-next interaction above
  (embedded, both failure channels), and the single-id summary suppression
  that commit 97151ab8e exists solely to add -- asserted in
  TestParityCloseNothingSettledExits1, which checked stdout but not stderr.

Contributor commits preserved; behaviour of the original fix is unchanged on
every route it already covered. Single-id stderr stays byte-identical.

Validated: go build ./..., go vet ./cmd/bd/..., TestParityClose family,
cmd/bd/protocol, TestEmbeddedClose close/claim-next subtests
(BEADS_TEST_EMBEDDED_DOLT=1), TestProxiedServerClose partial-failure subtests
(BEADS_TEST_PROXIED_SERVER=1), TestMultiIDUpdatePartialFailure.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
(cherry picked from commit 730fb9867e)

Hand-resolved for hotfix/1.3.1: CHANGELOG.md conflicted only because main's
Unreleased/Fixed list does not exist on the release line. The release
CHANGELOG is kept and this entry is added verbatim under Unreleased
"### Fixed". No code hunk needed changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 03:49:22 +00:00
..
testdata/corpus fix(contracts): JSON contract fixes before 1.3.0 freezes them — string revision tokens, --set-metadata scalar typing, create --json nano timestamps (#6053) 2026-08-29 05:20:27 +00:00
assignee_test.go test(protocol): pin data-model + ready-front production-scar clauses (wy-nzybu) 2026-07-13 09:46:16 -07:00
blocked_status_test.go feat(test): parallelize protocol tests for 3x speedup (bd-dgp) 2026-02-27 20:04:00 -08:00
blocked_test.go feat(test): parallelize protocol tests for 3x speedup (bd-dgp) 2026-02-27 20:04:00 -08:00
blocking_semantics_test.go feat(test): parallelize protocol tests for 3x speedup (bd-dgp) 2026-02-27 20:04:00 -08:00
canonicalize_test.go test(protocol): make corpus determinism pure (bd-qq1qn) (#5281) 2026-08-02 07:14:30 -07:00
CATALOG.md Merge remote-tracking branch 'upstream/main' into pr-4232-fix 2026-07-13 20:43:10 -07:00
child_id_test.go test(protocol): pin data-model + ready-front production-scar clauses (wy-nzybu) 2026-07-13 09:46:16 -07:00
children_test.go fix(cli): implement children pretty and defer reason 2026-06-13 21:22:38 -07:00
close_guard_test.go feat(test): parallelize protocol tests for 3x speedup (bd-dgp) 2026-02-27 20:04:00 -08:00
comments_test.go feat(test): parallelize protocol tests for 3x speedup (bd-dgp) 2026-02-27 20:04:00 -08:00
corpus.go fix(contracts): JSON contract fixes before 1.3.0 freezes them — string revision tokens, --set-metadata scalar typing, create --json nano timestamps (#6053) 2026-08-29 05:20:27 +00:00
corpus_test.go test(protocol): make corpus determinism pure (bd-qq1qn) (#5281) 2026-08-02 07:14:30 -07:00
defer_test.go fix(cli): implement children pretty and defer reason 2026-06-13 21:22:38 -07:00
dep_identity_test.go test(protocol): pin data-model + ready-front production-scar clauses (wy-nzybu) 2026-07-13 09:46:16 -07:00
errors_contract_test.go test(protocol): pin §E/§M/§V conformance clauses at the CLI level (wy-ge2h8) 2026-07-13 10:30:24 -07:00
exit_codes_init_test.go test(protocol): pin §E/§M/§V conformance clauses at the CLI level (wy-ge2h8) 2026-07-13 10:30:24 -07:00
exit_codes_test.go Beads #6648: report partial batch-close failure (#6740) 2026-09-29 03:49:22 +00:00
helpers_test.go feat(storage): refuse test DBs on production dolt servers (AD-01) (#3632) 2026-07-24 01:28:51 -07:00
input_validation_test.go feat(test): parallelize protocol tests for 3x speedup (bd-dgp) 2026-02-27 20:04:00 -08:00
interchange_test.go test(protocol): pin the §J interchange clauses; fix the bd import header gap (wy-ltox1) 2026-07-13 11:20:06 -07:00
json_contract_test.go fix(show): flag comment_count as omitted when comments are not streamed (#4865) 2026-07-25 16:16:41 -07:00
lease_claim_test.go test: fix red main — init-cancel E2E deadline + reclaim JSON assertion (#5039) 2026-07-25 10:10:18 -07:00
lifecycle_test.go feat(test): parallelize protocol tests for 3x speedup (bd-dgp) 2026-02-27 20:04:00 -08:00
memory_contract_test.go test(protocol): pin §E/§M/§V conformance clauses at the CLI level (wy-ge2h8) 2026-07-13 10:30:24 -07:00
preservation_test.go test(protocol): realign show --json contract tests with count-only payload (wy-017ry) 2026-07-13 10:08:34 -07:00
ready_front_test.go test: make ready ordering setup deterministic (bd-y9cjq) (#5238) 2026-08-01 09:55:11 -07:00
roundtrip_test.go test(protocol): realign show --json contract tests with count-only payload (wy-017ry) 2026-07-13 10:08:34 -07:00
stale_test.go feat(test): parallelize protocol tests for 3x speedup (bd-dgp) 2026-02-27 20:04:00 -08:00
status_validation_test.go feat(test): parallelize protocol tests for 3x speedup (bd-dgp) 2026-02-27 20:04:00 -08:00
versioning_contract_test.go test(protocol): pin §E/§M/§V conformance clauses at the CLI level (wy-ge2h8) 2026-07-13 10:30:24 -07:00
wp4_helpers_test.go test(protocol): pin §E/§M/§V conformance clauses at the CLI level (wy-ge2h8) 2026-07-13 10:30:24 -07:00