fix(cli): evaluate reopen's --if-revision guard before the already-open short-circuit

bd reopen's direct route checked issue.Status == StatusOpen before ever
calling ops.Reopen, so a stale --if-revision guard against an
already-open issue silently returned the "already open" no-op (exit 0)
instead of the precondition_failed refusal (exit 13) every other guarded
verb gives for a stale token. ops.Reopen itself already evaluates
ExpectedVersion first (ExecuteReopen -> CheckVersionInTx) on both the
dolt and embeddeddolt backends, and the proxied-server route already
called through unconditionally -- only the direct route's pre-check
bypassed it.

Fix: skip the already-open pre-check when --if-revision is set, letting
ops.Reopen evaluate the revision guard first. Without --if-revision,
today's behavior for already-open issues is unchanged.

Tests:
- if_revision_reopen_embedded_test.go (new): direct route, all four
  combinations (already-open/closed x stale/matching revision). Verified
  live that already_open_mismatch_refuses fails against the pre-fix
  ordering and passes against the fix.
- if_revision_proxied_integration_test.go: added the same already-open
  coverage to TestIfRevisionGuardProxiedReopen to confirm the
  proxied-server route already behaved correctly and keeps doing so.

Also documents in CHANGELOG.md that a `bd create --graph` plan over
issueops.MaxApplyBatchItems (1000) is refused outright with
GraphApplyTooLargeError (non-blocking review item).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Julian Knutsen 2026-10-06 01:18:44 +00:00 • committed by Eddie the Engineer
commit 266cacfca1
5 changed files with 141 additions and 2 deletions

View file

@ -22,7 +22,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
scenarios this path's local gates cover (blocking through existing or
planned hierarchy, transitive external-parent paths, cycles hidden in an
inline dep, combined scheduling cycles) are exercised against a real Dolt
store, not just skipped placeholders.
store, not just skipped placeholders. A graph plan whose translated
BatchApplier items (nodes, edges and deferred assignments combined) exceed
`issueops.MaxApplyBatchItems` (1000) is now refused outright with
`GraphApplyTooLargeError` rather than silently chunked across several
transactions — `bd create --graph` promises one atomic request, so a plan
over the cap must be split by the caller into multiple `bd create --graph`
calls instead.
- `--if-revision` (gastownhall/beads#4682) is extended to `bd reopen`, the
one lifecycle verb #7203 did not add it to, reusing the same
`issueops.ReopenRequest.ExpectedVersion` field the library already

View file

@ -820,6 +820,7 @@ go_test(
"if_revision_proxied_integration_test.go",
"if_revision_reassign_fence_embedded_test.go",
"if_revision_reassign_fence_proxied_test.go",
"if_revision_reopen_embedded_test.go",
"if_revision_test.go",
"import_chunking_embedded_test.go",
"import_chunking_test.go",

View file

@ -153,12 +153,48 @@ func TestIfRevisionGuardProxiedClose(t *testing.T) {
// unlike the other four verbs there is no embedded-leg sibling to mirror
// here -- this is reopen's only --if-revision coverage on either route
// beyond TestGCConditionalMatcherDecode's embedded smoke case.
//
// The already_open_* subtests pin the bee-ghosttrack maintainer-review
// blocker: a stale --if-revision guard on an already-open issue must still
// report exit 13 with a precondition_failed body, not the silent
// already-open no-op. See if_revision_reopen_embedded_test.go for the
// direct-route twin of this same gap.
func TestIfRevisionGuardProxiedReopen(t *testing.T) {
requireProxiedServerEnv(t)
bd := buildEmbeddedBD(t)
proj := newSharedProxiedProject(t, bd, "pir")
env := crossModeEnv{mode: "proxied", bd: bd, dir: proj.dir, env: bdProxiedEnv(proj.dir)}
alreadyOpen := bdProxiedCreate(t, bd, proj.dir, "Guarded proxied reopen (already open)", "--type", "task")
openRev := currentRevisionOfProxied(t, bd, proj.dir, alreadyOpen.ID)
t.Run("already_open_mismatch_refuses", func(t *testing.T) {
stale := staleRevisionFor(openRev)
stdout, stderr, code := env.run(t, "reopen", alreadyOpen.ID, "--if-revision", strconv.FormatInt(stale, 10), "--json")
if code != ExitGuardMismatch {
t.Fatalf("exit = %d, want %d\nstdout:\n%s\nstderr:\n%s", code, ExitGuardMismatch, stdout, stderr)
}
assertProxiedPreconditionBody(t, stderr, stale)
got := bdProxiedShow(t, bd, proj.dir, alreadyOpen.ID)
if got.Status != types.StatusOpen {
t.Errorf("stale --if-revision reopen of an already-open issue changed status: %s", got.Status)
}
if gotRev := currentRevisionOfProxied(t, bd, proj.dir, alreadyOpen.ID); gotRev != openRev {
t.Errorf("stale --if-revision reopen of an already-open issue advanced the revision: %d, want unchanged %d", gotRev, openRev)
}
})
t.Run("already_open_match_is_noop", func(t *testing.T) {
stdout, _, code := env.run(t, "reopen", alreadyOpen.ID, "--if-revision", strconv.FormatInt(openRev, 10))
if code != 0 {
t.Fatalf("matching --if-revision reopen of an already-open issue should succeed as a no-op, exit = %d\nstdout:\n%s", code, stdout)
}
got := bdProxiedShow(t, bd, proj.dir, alreadyOpen.ID)
if got.Status != types.StatusOpen {
t.Errorf("matching --if-revision reopen of an already-open issue changed status: %s", got.Status)
}
})
issue := bdProxiedCreate(t, bd, proj.dir, "Guarded proxied reopen", "--type", "task")
bdProxiedClose(t, bd, proj.dir, issue.ID)
rev := currentRevisionOfProxied(t, bd, proj.dir, issue.ID)

View file

@ -0,0 +1,90 @@
//go:build cgo
package main
import (
"os"
"testing"
"github.com/steveyegge/beads/internal/types"
)
// if_revision_reopen_embedded_test.go pins the bee-ghosttrack maintainer-review
// blocker on `bd reopen --if-revision`'s direct (non-proxied) route: reopen.go
// used to run its "issue.Status == types.StatusOpen" already-open short-circuit
// unconditionally, BEFORE ops.Reopen ever got a chance to evaluate
// ExpectedVersion (ExecuteReopen -> CheckVersionInTx). That meant a stale
// --if-revision guard against an already-open issue silently returned the
// "already open" no-op (exit 0) instead of the precondition_failed refusal
// (exit 13) every other guarded verb gives for a stale token -- see
// TestGCConditionalMatcherDecode's "reopen's guard only fires on an
// already-closed issue" comment for the same gap pinned from the gc-matcher
// angle.
//
// TestIfRevisionGuardProxiedReopen (if_revision_proxied_integration_test.go)
// is this file's proxied-server-leg twin.
func TestIfRevisionReopenGuardDirect(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}
t.Parallel()
bd := buildEmbeddedBD(t)
dir, _, _ := bdInit(t, bd, "--prefix", "irr")
t.Run("already_open_mismatch_refuses", func(t *testing.T) {
issue := bdCreate(t, bd, dir, "Guarded reopen (already open)", "--type", "task")
rev := bdShowRevision(t, bd, dir, issue.ID)
stale := rev + 1_000_000
out, code := bdRunFailCode(t, bd, dir, "reopen", issue.ID, "--if-revision", revStr(stale), "--json")
if code != ExitGuardMismatch {
t.Fatalf("stale --if-revision reopen of an already-open issue exit = %d, want %d\n%s", code, ExitGuardMismatch, out)
}
if got := bdShow(t, bd, dir, issue.ID); got.Status != types.StatusOpen {
t.Errorf("stale --if-revision reopen of an already-open issue changed status: %s", got.Status)
}
if got := bdShowRevision(t, bd, dir, issue.ID); got != rev {
t.Errorf("stale --if-revision reopen of an already-open issue advanced the revision: %d, want unchanged %d", got, rev)
}
})
t.Run("already_open_match_is_noop", func(t *testing.T) {
issue := bdCreate(t, bd, dir, "Guarded reopen (already open, matching)", "--type", "task")
rev := bdShowRevision(t, bd, dir, issue.ID)
out := bdRunOK(t, bd, dir, "reopen", issue.ID, "--if-revision", revStr(rev))
if got := bdShow(t, bd, dir, issue.ID); got.Status != types.StatusOpen {
t.Errorf("matching --if-revision reopen of an already-open issue changed status: %s\noutput:\n%s", got.Status, out)
}
})
t.Run("closed_mismatch_refuses", func(t *testing.T) {
issue := bdCreate(t, bd, dir, "Guarded reopen (closed, mismatch)", "--type", "task")
bdClose(t, bd, dir, issue.ID)
rev := bdShowRevision(t, bd, dir, issue.ID)
stale := rev + 1_000_000
out, code := bdRunFailCode(t, bd, dir, "reopen", issue.ID, "--if-revision", revStr(stale), "--json")
if code != ExitGuardMismatch {
t.Fatalf("stale --if-revision reopen of a closed issue exit = %d, want %d\n%s", code, ExitGuardMismatch, out)
}
if got := bdShow(t, bd, dir, issue.ID); got.Status != types.StatusClosed {
t.Errorf("stale --if-revision reopen of a closed issue changed status: %s", got.Status)
}
if got := bdShowRevision(t, bd, dir, issue.ID); got != rev {
t.Errorf("stale --if-revision reopen of a closed issue advanced the revision: %d, want unchanged %d", got, rev)
}
})
t.Run("closed_match_reopens", func(t *testing.T) {
issue := bdCreate(t, bd, dir, "Guarded reopen (closed, matching)", "--type", "task")
bdClose(t, bd, dir, issue.ID)
rev := bdShowRevision(t, bd, dir, issue.ID)
bdRunOK(t, bd, dir, "reopen", issue.ID, "--if-revision", revStr(rev))
if got := bdShow(t, bd, dir, issue.ID); got.Status != types.StatusOpen {
t.Fatalf("matching --if-revision reopen of a closed issue did not reopen: status = %s", got.Status)
}
})
}

View file

@ -77,7 +77,13 @@ another actor won the race, so retrying the same guard is pointless).`,
issueStore := result.Store
issue := result.Issue
if issue.Status == types.StatusOpen {
// An active --if-revision guard must be evaluated before this
// already-open short-circuit: ops.Reopen below checks
// ExpectedVersion first (ExecuteReopen -> CheckVersionInTx), so a
// stale revision on an already-open issue still reports exit 13
// instead of silently returning the "already open" no-op here.
// Without --if-revision, today's pre-check stands unchanged.
if ifRevision == nil && issue.Status == types.StatusOpen {
fmt.Fprintln(os.Stderr, reopenNoOpMessage(fullID, types.StatusOpen))
result.Close()
continue