* fix(unclaim): enforce claim ownership and rewrite row_lock/lease on release
bd unclaim accepted an actor argument but never compared it to the current
assignee, so any process could release another agent's claim. It also wrote
only status/assignee, leaving lease_expires_at/heartbeat_at/started_at set and
row_lock unchanged, violating the row_lock invariant (lease.go): a concurrent
heartbeat or reclaim on the released row would silently cell-merge instead of
conflicting.
UnclaimIssueInTx now:
- rejects a non-owner with storage.ErrNotOwner (typed, not a silent no-op);
- accepts force to bypass the ownership check (admin/reaper), threaded from a
new `bd unclaim --force` flag;
- clears lease_expires_at/heartbeat_at/started_at and rewrites row_lock so a
racing heartbeat/reclaim conflicts.
DoltStore.UnclaimIssue is now wrapped in withRetryTx like the other
claim-family writes, so a lost optimistic merge (1213/1205) is retried rather
than surfaced as a hard failure.
Tests (dolt/lease_test.go): non-owner unclaim is rejected and leaves the claim
intact; owner unclaim clears the lease columns and rewrites row_lock; --force
overrides the ownership check.
* fix(claim): stamp lease and row_lock on the proxied-server (uow) claim path
The uow claim path (internal/storage/domain/db Claim, used in proxied-server
mode) ran the compare-and-swap but omitted lease_expires_at, heartbeat_at, and
the row_lock rewrite that issueops.ClaimIssueInTx writes. A claim made through
this path left the lease columns NULL, so it was invisible to bd reclaim (dead
workers never recovered) and reintroduced the cell-merge class the row_lock
invariant guards against.
Both claim branches now append the shared lease SET-clause and rewrite
row_lock, reusing the same fragment as claim.go via new exported
issueops.LeaseSetClause/LeaseTTL wrappers so the two paths stay in lockstep.
Existing claim behavior (started_at handling, idempotency, conflict surfacing
via ClaimRowResult) is unchanged.
Test (domain/db/issue_test.go): a proxied-mode claim stamps lease_expires_at,
heartbeat_at, and a non-zero row_lock, and is subsequently reclaimable.
* fix(update): exit non-zero when a --claim in a batch is lost
`bd update <a> <b> --claim` set firstUpdatedID from any winner, so a mixed
batch where one claim won and another was lost to a different owner exited 0 —
hiding the lost claim from exit-code automation (beads audit finding #10). Track
a requested-but-lost claim separately and return a non-zero exit while still
committing the winners.
Scoped to the exit-code half of the defect. The `--json` lost-claim surface
(a conflict currently emits nothing on stdout, only stderr) is left as a
follow-up: emitting a structured error object there would change the stdout
contract from a plain issue array and needs its own design.
Test (gated cmd/bd embedded suite): a partial-loss batch exits non-zero, the
winning claim still lands in_progress, and the lost issue is untouched.
* fix(update): exit non-zero when a proxied-server --claim in a batch is lost
The batch exit-code fix (bd4dee4a4) only covered the non-proxied path in
update.go. On the proxied-server runtime, runUpdateProxiedServer set anyUpdated
from any winner, so a mixed batch where one --claim won and another lost to a
different owner still exited 0 — masking the lost claim from exit-code
automation, the same defect as beads audit finding #10 but on the other runtime.
applyUpdateProxiedOne now reports a requested-but-lost claim (already-claimed /
not-claimable while --claim was set) via a new return value; the caller tracks
it in a claimFailed flag and returns SilentExit() at the end, matching the
non-proxied semantics exactly: winners still commit (each ID commits its own
UOW), a lost claim in the batch flips the exit code. No other proxied behavior
changes.
Test (proxied integration suite): a partial-loss batch exits non-zero, the
winning claim lands in_progress under the winning actor, and the pre-claimed
issue is untouched — parity with update_claim_batch_partial_loss_exits_nonzero.
The proxied harness currently can't run because `bd init --proxied-server` is
stubbed upstream (init.go: "not yet implemented"), so this test is wired to the
same contract as its ~20 sibling proxied tests and executes once init lands.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* test(unclaim): cover ownership rejection and --force at the CLI level
The unclaim ownership fix (fe908d40b) enforced ErrNotOwner and added
`bd unclaim --force`, but was only covered by storage-layer tests
(dolt/lease_test.go) — no CLI-level e2e test, unlike the sibling batch-claim
fix. Add gated embedded-dolt CLI tests:
- unclaim_non_owner_rejected: a non-owner release exits non-zero with the
ownership error and leaves the claim (assignee + in_progress) intact.
- unclaim_non_owner_force_succeeds: --force lets a non-owner release the claim.
Also assert the new --force flag is registered (TestUnclaimCommand_Flags).
Fix a pre-existing breakage the ownership enforcement introduced but did not
update: unclaim_from_open_stuck_claim released alice's assignment as the default
actor, which now fails ErrNotOwner. Release as the owner (--actor alice),
preserving the open+assigned "stuck claim" dimension the test exercises.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix(unclaim): route wisp tables in UnclaimIssueInTx (Copilot #4675)
UnclaimIssueInTx hardcoded issues/events while ClaimIssueInTx routes via
WispTableRouting(IsActiveWispInTx). bd unclaim on an active wisp read the wisp
via GetIssueInTx but UPDATE'd the permanent issues table -> 0 rows / no event
for wisps. Mirror the claim path so a wisp release updates the wisp tables.
The nolint(gosec) comment is now accurate: table names do come from
WispTableRouting. Regular-issue unclaim is unchanged (TestEmbeddedUnclaim).
* docs(cli): regenerate CLI reference for bd unclaim --force flag
The new --force flag on bd unclaim was not reflected in the generated CLI
docs, failing the doc-freshness CI gate. Regenerate docs/CLI_REFERENCE.md and
website/docs/cli-reference/unclaim.md.
---------
Co-authored-by: sjarmak <sjarmak@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: matt wilkie <maphew@gmail.com>