Commit graph

4,130 commits

Author SHA1 Message Date
Steve Yegge
5a4c68a89c fix(leases): keep node_id off the committed config; tighten the replica guard (wy-jpd3.7)
Second adversarial review of the replica-aware lease work, against the opt-in
rewrite. One blocker, in the operating instruction rather than the code.

node_id was documented as "BEADS_NODE_ID, or node_id in config.yaml", and
`bd config set node_id` wrote the PROJECT .beads/config.yaml — a git-TRACKED
file (nothing in .beads/.gitignore excludes it). Commit "node_id: mini" and
every clone that pulls reads "mini", so every granted_node comparison matches
and the guard is at once fully ARMED and fully INERT: laptop reaps mini's
leases exactly as if they were local. That is the precise hazard the feature
exists to close, now happening while the operator believes they are protected
— strictly worse than the pre-feature state, where nobody thought they were.
node_id is per-machine state, the class .beads/.gitignore already excludes as
sync-state.json / push-state.json / redirect. It now routes to the user-global
~/.config/bd/config.yaml through a new exact-key arm of IsUserGlobalKey (the
prefix list only ever held "metrics."); viper already merges that file, so
config.NodeID() reads it straight back.

The docs also said to set it "on every replica sharing the queue", which on a
shared or remote dolt sql-server means every HOST — rebuilding the same
fail-closed regression this commit's parent removed the hostname fallback to
avoid. The load-bearing rule was never stated: node_id names the STORE, not
the host. Clients of one sql-server are ONE replica and must share a value or
leave it unset. Now said outright in federation.md and `bd reclaim --help`.

Also from the review:
- bd show claimed "reclaim will decline it" for any foreign node, but with an
  unnamed local node the guard is disarmed and reclaim reverts the lease
  happily. The annotation is now gated on config.NodeID() != "".
- TestNodeIDContextOverride's empty-override assertion had gone tautological
  when the hostname fallback went away: config.NodeID() is "" under test, so
  it passed whether or not WithNodeID worked at all. It now sets a non-empty
  fallback, asserts the fallback is what a no-override read returns, and only
  then asserts the empty override still beats it.
- The heartbeat backfill's bare `granted_node = ''` is COALESCE'd, matching
  the reclaim predicates; under NULL the IF took the else branch and the row
  was never backfilled. Unreachable today (0016 is NOT NULL DEFAULT ''), but
  the two sites disagreed about whether NULL was possible.
- The --any-replica audit line is skipped when localNode is "" rather than
  printing `not this node ("")`: nothing was overridden, the guard was never
  armed.
- reclaimReplicaSQL documents WHY granted_node stays unqualified — the DELETE
  splices it into a bare `DELETE FROM leases` with no alias to qualify with —
  and what to do if issues ever grows a column of that name.
- CHANGELOG entry, which this feature owed: a new flag, a new config key, two
  env vars, and two public struct fields shipped without one.
2026-07-25 02:32:31 -07:00
Steve Yegge
c00e4d6a9e fix(leases): make the replica guard opt-in — drop the hostname fallback (wy-jpd3.7)
Adversarial review of the landed replica-aware lease work (966ddac5a) found
that deriving the granting replica from os.Hostname() answers the wrong
question: the hostname names the CLIENT PROCESS's machine, not the store.

That is a fail-CLOSED regression in three topologies with no federation to
defend against. With a shared or remote dolt sql-server (BEADS_DOLT_SERVER_HOST,
ServerModeExternal, Hosted Dolt, a VPS) many hosts are clients of ONE store, so
a supervisor would match no worker's lease and reclaim 0 forever. In a container
the hostname is a per-run container ID, so a replaced worker's successor sees
its own single-machine leases as foreign. On macOS/DHCP the transient hostname
follows the network. Stranding a lease on a single-store deployment is a worse
failure than the cross-replica reclaim the guard exists to prevent.

So the guard is now OPT-IN: config.NodeID() reads BEADS_NODE_ID / BD_NODE_ID /
node_id in config.yaml and nowhere else, and "" (the default) disarms the guard
back to exactly the pre-feature behavior. This also settles the heartbeat
backfill hazard — on an unnamed deployment the backfill writes '' over '' and
cannot silently convert a fail-open row into a fail-closed one.

Also from the review:
- node_id joins recognizedConfigKeys and YamlOnlyKeys, so the documented
  `node_id: mini` mitigation no longer warns and no longer writes to the Dolt
  config table that NodeID() never reads (the GH#536 class YamlOnlyKeys exists
  to prevent).
- reclaimReplicaSQL/warnReplica/reportForeignSkips move above the
  ReclaimExpiredLeasesInTx doc block, which they had orphaned onto a private
  helper.
- The --any-replica audit line moves past both re-checks, so it can no longer
  log a revert that a post-snapshot heartbeat prevented.
- lease_granted_node joins ephemeralExportKeys in the conformance round trip.
- New cmd/bd/protocol coverage for the JSONL path (RestoreLeaseOnImportInTx),
  the sole reason the field is on the wire: a lease claimed under
  BEADS_NODE_ID=mini keeps mini after import on laptop, laptop's reaper
  declines it, and --any-replica reverts that same row.
- The embeddeddolt test stops claiming its surviving-lease assertion exercises
  the DELETE-side guard; inside one transaction that copy is defense in depth.
- A stray U+201D and an inconsistent COALESCE in reportForeignSkips.
2026-07-25 02:32:31 -07:00
Steve Yegge
f7eb8abb44 fix(conflicts): address the adversarial review of the merge-blocker surface (wy-36ilm)
Findings from the fresh-subagent review of 6b7ec5bf7, which confirmed the core
diff (the commitWorkingSet gate reaches only the three conflict-open callers,
dolt's allowEmpty=MergeActive makes the conclusion a genuine merge commit, and
all three system-table reads are correct) and raised these:

F1: the schema-conflict remedy pointed at `dolt conflicts resolve`, which dolt
refuses outright while a schema conflict is live (dolthub/dolt#6616) — the
reviewer drove a real schema conflict and the suggested command errored 100%
of the time. A schema conflict is aborted and re-merged, not resolved in
place; the guidance now says so, and no longer promises --conclude will finish
that state.

F2: --conclude returned outputJSON on a blocked merge, so `bd conflicts
resolve --conclude --json` exited 0 while the merge stayed open — a sync
script would read it as success and push. It goes through
HandleErrorRespectJSON like every other error in the file.

F3: the resolve path dropped GetMergeBlockers' error. Since that call returns
PARTIAL results plus a joined error, an unreadable constraint-violations read
looked exactly like "no blockers". Both resolve and --conclude now warn, and
the resolve JSON carries blockers_error like list's does.

F4: concludeOpenMerge degrades to a no-op on an unreadable dolt_merge_status,
but the caller still printed "Merge committed" — the wy-36ilm symptom again,
silently. commitMergeResolution now re-reads the merge status and fails loudly
when the merge is still open.

F8: --conclude ignored --table, implying a scoped conclude that does not
exist; it is rejected with the other resolution flags.

F9: --conclude's three JSON returns had three shapes. One shape now
(committed/remaining/merging/blockers) via concludeJSON.

Left as follow-ups: coverage for --conclude and the BLOCKING blocker paths
(F5), the Docker gating of the decorator regression guard (F6), and the
negative decorator assertion (F7).
2026-07-25 02:32:04 -07:00
Steve Yegge
6b7ec5bf7d feat(conflicts): dolt-backed conflict tests, --conclude, merge-blocker visibility (wy-36ilm)
The wy-jpd3.5 adversarial review's deferred findings.

F9 (the important one): every wy-jpd3.5 test was a pure unit test over
synthetic column maps — no test drove a REAL dolt conflict through
GetConflictRows/ResolveConflictRows, the session flags, the store decorator
chain, or the commit gate, which is why the review's BLOCKER (the decorator
never satisfied ConflictInspector, so `bd conflicts show` printed "No merge
conflicts" over a wedged merge) was invisible to the suite.
conflicts_integration_test.go wedges a real two-branch modify/modify conflict
and drives list/show, resolve --ours and --theirs, a miskeyed resolve, and the
decorator chain — the last asserting BOTH halves: the naked assertion on the
wrapper still fails, and UnwrapStore still reaches the concrete store.

That test immediately caught a live bug: CommitMergeResolution went through
commitWorkingSet, which returns early when no table is dirty — exactly the
--ours case, where our values already stood and clearing the conflict dirtied
nothing. The merge stayed open (is_merging true) while the CLI printed "Merge
committed", and the next pull re-wedged. commitWorkingSet now concludes an
open merge in the merge-resolution mode only; the other modes keep the old
"nothing to commit" behavior.

F4: `bd conflicts resolve --conclude` commits a merge whose conflicts are
already gone — the state --no-commit leaves, or a partial resolve whose later
ID errored out. Before, that merge could not be concluded through bd at all:
with zero live conflicts --all returns early and a named ID errors "no live
conflict". It refuses while anything is still outstanding, and says so rather
than minting an empty commit when no merge is open.

F12: totalConflicts summed dolt_conflicts only, so a schema conflict or a
constraint violation the auto-repair declined could be outstanding while
remaining==0 — CommitMergeResolution then failed with a raw dolt error and no
guidance. storage.MergeBlockerInspector (GetMergeBlockers over
dolt_merge_status, dolt_schema_conflicts, dolt_constraint_violations) is a new
optional interface on both Dolt-backed stores; `bd conflicts list` and the
resolve path report the blockers with the dolt commands that clear them, and
hold the commit instead of letting it fail rawly. Each source is read
independently and a missing system table is not an error — diagnosis must
never be what fails the command.
2026-07-25 01:54:49 -07:00
Steve Yegge
c2796999d1 fix(reclaim): repair a mojibake em dash in the replica help text (wy-jpd3.7) 2026-07-24 23:55:45 -07:00
Steve Yegge
966ddac5af feat(leases): replica-aware leases — record the granting node, refuse cross-replica reclaim (wy-jpd3.7)
A claim lease is only meaningful on the replica that granted it. Every other
replica's view of the holder's liveness is stale by up to one sync interval,
so a reaper over there can revert a unit that is very much alive here. Until
now the only defense was operator discipline: partition every supervisor's
reclaim by label and hope nobody runs an unscoped sweep.

Leases now record WHICH replica granted them (leases.granted_node, ignored
migration 0016, stamped from config.NodeID(): BEADS_NODE_ID / node_id config,
falling back to the hostname). bd reclaim skips a lease that positively names
another replica — on both the snapshot SELECT and the per-row DELETE
re-check — and names each skip on stderr, since silence there is
indistinguishable from "nothing to recover" while a genuinely dead remote
worker's unit sits in_progress forever. bd reclaim --any-replica is the
operator escape hatch for a replica that is gone for good.

The guard is deliberately fail-open on unknown provenance: granted_node ''
(a row predating the column, or a deployment whose NodeID is empty) is
treated as local, so the upgrade itself can never strand a stale lease the
reaper could previously recover. A heartbeat backfills an unknown row with
the local node and never overwrites a known one.

The one path that can materialize a FOREIGN lease row locally is
RestoreLeaseOnImportInTx — lease fields round-trip the JSONL interchange — so
the granting replica rides types.Issue.LeaseGrantedNode and a restored lease
keeps the replica the snapshot names, never this node. A snapshot from an
older binary carries none, restores as unknown, and behaves exactly as before.

What the guard cannot enforce is documented instead, in both bd reclaim --help
and docs/multi-agent/federation.md: grace window > sync interval, and lease
TTL > sync interval. A TTL shorter than the cadence at which replicas exchange
state is meaningless across the bridge — the remote view is a full interval
old by construction.

doc/beads-upstream-asks.md section 5.
2026-07-24 23:53:34 -07:00
Steve Yegge
eb27caf1d1 fix(vc): reach RecomputeBlockedAfterMerge through the storage decorators (wy-163oy)
bd vc merge --strategy asserted the optional post-merge is_blocked repair
directly on the store from getStore(), which is the wireStorageDecorators
chain (HookFiringStore -> InstrumentedStorage -> concrete store). Both
decorators embed the storage.DoltStorage interface and
RecomputeBlockedAfterMerge is not in that set, so the assertion always
failed and the recompute was silently skipped -- on essentially every rig,
since main.go builds a hook runner whenever dbPath != "". Nothing logged,
nothing failed: the code was `if ok` with no else.

Left stale, `bd ready` stays wrong for every dependency edge the merge
brought in until someone runs bd recompute-blocked: the skip writes no
is_blocked_recompute_pending marker (that is only set when a recompute
errors), and the next pull's recompute is scoped from a commit after the
merge, so it never covers those rows.

storage.UnwrapStore before the assertion, behind a named helper, matching
sync.go's BlockedRecomputer and wy-xtv17's persistedRemoteProber. The else
branch now warns instead of skipping in silence.

Same defect class as wy-xtv17; found by its adversarial pass (O1).
2026-07-24 22:46:23 -07:00
Steve Yegge
4c38df03a9 test(cmd/bd): keep telemetry out of the suite — fixes TempDir cleanup flake (wy-12x1p)
TestPrime_HookJSON_RedirectedPrimeOverride (and its Local sibling) failed
intermittently with

  testing.go:1464: TempDir RemoveAll cleanup: unlinkat
  /var/folders/.../TestPrime_HookJSON_RedirectedPrimeOverride3572961888/005:
  directory not empty

with no assertion failure — the test body passed and only t.TempDir()'s
removal failed, reddening the whole cmd/bd package. Every worker landing in
cmd/bd was therefore unable to get an rc=0 out of `go test ./cmd/bd/`.

ROOT CAUSE: metrics.CloseAndFlush runs at the end of every `bd` invocation
with metrics enabled. It writes an eventkit queue under $HOME/.beads/eventsData
and then metrics.MaybeSpawnFlusher starts a DETACHED `bd send-metrics` child —
cmd.Process.Release(), no Wait — which outlives its parent. The e2e tests in
this package run the bd binary with HOME=t.TempDir(), so those orphans go on
creating/removing .evtq files and holding eventkit.lock inside a directory the
test is about to delete. The failing path /005 is precisely the HOME handed to
the last `bd prime` of that test. Reproduced directly: after a plain
`HOME=$tmp bd prime --hook-json` returns, two `bd send-metrics` processes are
still alive and $HOME/.beads/eventsData holds eventkit.lock plus .evtq files.
The window is load-dependent, which is why it flaked rather than failed.

FIX: set BD_DISABLE_METRICS=1 and BD_DISABLE_EVENT_FLUSH=1 in testMainInner.
Subprocess envs in this package are all built with append(os.Environ(), ...),
so one place covers every test, not just the two observed victims — and a test
suite should not be uploading telemetry in the first place. This matches what
export_auto_test.go's env helper already does per-test, and the metrics
resolution tests already unset-and-restore these vars themselves (their
comments note CI sets BD_DISABLE_METRICS).

Also adds TestPrime_NoTelemetryInIsolatedHome as a deterministic guard:
metrics.Init creates eventsData eagerly in the parent when metrics are on, so
asserting the directory is absent proves the detached flusher was never armed.

Acceptance: go test ./cmd/bd/ -run
'TestPrime_HookJSON_RedirectedPrimeOverride|TestPrime_HookJSON_LocalPrimeOverride|TestPrime_NoTelemetryInIsolatedHome'
-count=5 rc=0 on a busy multi-agent machine.
2026-07-24 22:41:56 -07:00
Steve Yegge
dc7a4300ad fix(sync): retry a dirty-working-set recompute instead of failing the run (wy-mlnz2)
RecomputeAllBlocked refuses to derive is_blocked from a graph it cannot
commit (GuardBlockedRecomputeWorkingSet,
internal/storage/issueops/blocked_consistency.go). On a shared-sql-server
topology — the one `bd sync` targets — another agent's uncommitted write to
issues/dependencies landing between this sync's pull and its repair trips
that guard. runSyncLoop classified it as a hard error, so the run returned
"recompute-blocked: ..." -> exit 1 with the push SKIPPED, and local commits
stayed unpublished until some later tick happened to catch a clean working
set. The condition is transient, foreign to this sync, and self-healing, and
the loop already had a retry budget it was not using for it.

Classify it from the typed sentinel — errors.Is(err,
issueops.ErrBlockedRecomputeDirtyGraph), never a message match, so a
reworded guard cannot silently demote this back to a hard error — and
re-enter the attempt loop exactly like a push race. A durable (non-guard)
recompute failure still halts immediately, and no path pushes after a failed
repair, so an exhausted budget halts before the push rather than publishing
a stale is_blocked. Exhaustion now reports the transient exit 3 instead of 1.

syncOutcome gains LastRecomputeError, mutually exclusive with LastPushError
by construction, so an exit-3 report names what the FINAL attempt failed on.
printSyncOutcome's exit-3 branch is extracted to the pure
syncRetriesExhaustedMessage(), which distinguishes "another replica won the
push race" (a different machine) from "another writer on THIS replica has
uncommitted issues/dependencies" (commit or discard it) — telling an
operator the wrong one sends them to the wrong host. syncConflictMessage
gained a matching branch so a run that merged but could not repair no longer
reports that it touched nothing. Help text, the exit-code block and
--attempts are updated.

Tests: dirty-graph classification (bare sentinel, wrapped, joined, foreign);
retry-then-succeed; budget exhaustion -> exit 3 not 1 and never a push;
--attempts 1; context cancellation between dirty retries; the conflict
message's blocked-repair branch; and an embedded-path pin
(TestEmbeddedRecomputeAllBlockedDirtyGraphIsTyped) asserting errors.Is
survives withConn's errors.Join, matching the server-mode pin already in
internal/storage/dolt.

From the wy-jpd3.4 adversarial review, finding 5.
2026-07-24 21:12:12 -07:00
Steve Yegge
4951412f3a fix(dolt): reach HasPersistedRemote through the storage decorator chain (wy-xtv17)
The GH#2118 cold-start probe was silently skipped on essentially every rig.

hasNoRemoteConfigured type-asserted persistedRemoteProber directly on the
store it was handed. That store is never the concrete *dolt.DoltStore: main.go
wires caller -> HookFiringStore -> InstrumentedStorage -> DoltStore
(wireStorageDecorators), and HasPersistedRemote is on none of the decorators
because it is not part of storage.DoltStorage. The hook layer is present
whenever there is a dbPath — hooks.NewRunner is called unconditionally and
always returns non-nil — so only a no-hooks rig ever reached the probe.

The consequence is the failure bd-578h9.10 added the probe to prevent: a
server-mode rig whose sql-server just cold-started reports an empty
dolt_remotes while the remote IS persisted in .dolt/repo_state.json. Pull
fails "no remote", ListRemotes comes back empty, the on-disk probe that would
have vetoed the skip never runs, and `bd sync` prints "No remote is
configured" and exits 0 on every tick, forever, never syncing — with --json
consumers reading {"status":"no-remote"} as success.

Fixed in hasNoRemoteConfigured rather than at the bd sync call site, so
`bd dolt push` and `bd dolt pull` — which carry the same hole through
isConfirmedNoRemote — are covered too. The new persistedRemoteProberFor peels
storage.Unwrapper chains, the same contract storage.UnwrapStore uses; it is
not UnwrapStore itself because the helper takes the narrow remoteLister, not a
storage.DoltStorage. A store implementing the probe directly is honored before
any peeling, so test doubles and any future forwarding decorator keep working.

Tests drive the gate through the REAL production chain (wireStorageDecorators,
both with and without the telemetry layer) and assert three things: the probe
vetoes the skip when a remote is persisted on disk, a genuinely remote-less rig
still gets its benign exit-0 skip, and configured remotes are still vetoed on
the ListRemotes evidence alone. Reverting the one-line fix fails them.

Found by the wy-jpd3.4 adversarial pass. Follow-ups filed for two same-class
observations the review turned up: wy-163oy (vc.go's unwrapped
RecomputeBlockedAfterMerge assertion) and wy-82hc5 (adoptGitOriginRemoteForPush
trusting an empty ListRemotes in the same cold-start window).
2026-07-24 19:56:01 -07:00
Steve Yegge
144876baab feat(conflicts): bd conflicts list|show|resolve — issue-oriented merge conflicts (wy-jpd3.5)
Federation ask #3. Resolving a halted merge meant dropping into the raw dolt
CLI inside .beads/dolt/<db> — dolt conflicts cat issues, dolt conflicts resolve
--ours|--theirs issues, dolt add -A && dolt commit — dolt arcana whose flag
surface differs from git's just enough to bite. This wraps it in bd, presented
per issue FIELD rather than as raw conflict rows.

  bd conflicts list                     tables + conflicted issue IDs
  bd conflicts show [<id>]              base/ours/theirs per diverged field
  bd conflicts resolve <id> --ours      one issue, leaving the rest conflicted
  bd conflicts resolve --all --theirs   whole tables (dolt's own resolution)

Storage: storage.ConflictInspector is a new optional interface (GetConflictRows
/ ResolveConflictRows) implemented by both Dolt-backed stores over
versioncontrolops/conflicts.go, which folds dolt_conflicts_<table>'s
base_/our_/their_ columns into one row per conflict — generically, from the
result-set column names, so it does not rot on the next migration.

Per-row resolution follows dolt's manual-resolution protocol, the one
resolveIssuesLWWConflicts already proves: --ours deletes the conflict row (the
working set already holds our values), --theirs writes their values first and
then deletes it. It is restricted to modify/modify rows — when one side deleted
the row, "ours"/"theirs" do not describe what the operator wants, so it is
refused by name instead of guessed at.

Safety rails, several from the adversarial review of this diff:
- The CLI reaches the store through storage.UnwrapStore: store is always
  decorated (telemetry + hooks), and a decorator embedding the DoltStorage
  interface promotes only that interface's methods, so asserting on the wrapper
  would silently report "No merge conflicts" over a wedged merge.
- The merge is committed only when this invocation actually resolved something
  AND no conflict remains, via CommitMergeResolution (plain Commit excludes
  config, GH#2455/GH#2474). A partial resolution leaves the merge open.
- Server-mode resolution pins a connection and resets
  @@dolt_allow_commit_conflicts/@@dolt_force_transaction_commit before
  returning it to the pool, discarding the connection if the reset fails.
- A --theirs UPDATE that matches no row (concurrent delete on a shared server)
  aborts instead of clearing the conflict and dropping their side.
- Interpolated identifiers — table AND column — are validated; values are bound.

Follow-ups filed as wy-36ilm: a dolt-backed integration test (every test here
is a pure unit test, which is why the review's blocker was invisible to the
suite), a first-class way to conclude an already-resolved merge, and
schema-conflict/constraint-violation visibility in the commit gate.
2026-07-24 19:47:16 -07:00
Steve Yegge
f94ea5bfe5 feat(sync): bd sync — the federation loop as one verb (wy-jpd3.4)
Every multi-machine beads deployment hand-rolls the same shell loop around
pull/push; this ships it as `bd sync [--remote <name>] [--attempts N]`.

Three properties are the point of the verb, and each is a lesson paid for by
the reference deployment (a two-machine federation on a 60s timer):

- Conflicts are detected POSITIVELY, from the merge's own captured conflict
  rows and from dolt_conflicts — never inferred from the pull's exit status.
  A pull fails for reasons that are not conflicts, and a settled merge that IS
  conflicted aborts and leaves dolt_conflicts empty, so an exit-status guess
  both invents phantom conflicts and misses real ones. A pre-flight check also
  halts on conflicts left live by an earlier halted sync, which Dolt otherwise
  refuses to merge over with an opaque transport error.
- A conflict sync cannot settle is NEVER resolved by picking a side: it halts
  before recomputing or pushing, with no --strategy-style override. A timer
  that silently picks a side loses work on a schedule. The halt message
  reports whether the conflict rows are live or were aborted away, read from
  WHICH detection source fired rather than assumed — the SQL pull route aborts
  and restores the working set, the CLI/git-protocol route deliberately leaves
  the rows live, and an operator told the wrong one looks in the wrong place.
- The is_blocked recompute runs unconditionally, on every attempt. That is
  deliberate and load-bearing: RecomputeAllBlocked is specifically the repair
  that does NOT depend on a merge advancing HEAD (bd-6dnrw.37), so it is what
  recovers a column left stale by a conflicted pull an operator resolved by
  hand — a state this verb manufactures itself by exiting 2. Gating it on "did
  this tick merge anything" re-imposes the condition it exists to escape, and
  from then on no tick merges anything, so the repair would never run again
  while every tick reported success. HEAD is the wrong instrument for that
  question anyway: the pull's own pre-merge auto-commit (GH#2474) moves it for
  purely local dirty state, and an auto-resolved merge can land in the working
  set without moving it at all (bd-6dnrw.39).

Exit codes are the machine contract so a timer can branch without parsing
output: 0 synced, 1 error, 2 merge conflict (halted, nothing pushed), 3
push-race retries exhausted (transient). --json reports the same outcome.

Push-race classification is deliberately narrow — race signatures (behind /
non-fast-forward / a lost --force-with-lease: stale info, fetch first, "contains
work that you do not have"), not the word "rejected". A protected branch or a
declining pre-receive hook also rejects, permanently; treating that as a race
burns the whole attempt budget every tick and reports exit 3 ("retry next tick")
forever instead of surfacing the failure.

Also: hasNoRemoteConfigured split out of isConfirmedNoRemote so sync can reuse
the structural no-remote proof with its own (broader) error hint without
loosening it — a solo rig must not fail every tick, but a typoed or broken
remote must still exit non-zero. The command doc and the doc-flags gate are
updated: `bd sync` is live again, so the stale reference to hunt is docs still
calling it removed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-24 18:15:13 -07:00
Isis Anisoptera
40b7f75c26
fix(query): make slash and mixed-case metadata keys queryable (#4896)
* fix(metadata): allow / in metadata keys

ValidateMetadataKey rejected slashes even though keys are always passed
as bind parameters and JSONMetadataPath quotes non-identifier keys, so
the restriction had no safety purpose. Allow / in the key charset and
quote slash keys in JSON paths (unquoted, / is a path syntax error).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019jrTawz2CRUiJLCt2UTQ2B

* fix(query): make slash metadata keys queryable; always quote JSON paths

Code-review follow-ups to the / metadata-key change:

- Allow / in query-language identifiers so keys like jira/sprint are
  reachable from 'metadata.jira/sprint=42' expressions, not just the
  --metadata-field flag.
- JSONMetadataPath now quotes every key unconditionally (valid for plain
  keys too), removing the separator char list that had to stay in sync
  with validMetadataKeyRe.
- Derive the ValidateMetadataKey error message from the regex itself.
- Collapse the five JSONMetadataPath clone tests into one table-driven
  test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019jrTawz2CRUiJLCt2UTQ2B

* test(query): enforce that all valid metadata keys are queryable

Sweep every printable ASCII character and assert each key accepted by
storage.ValidateMetadataKey parses as metadata.<key>=<value>, so the
lexer's identifier alphabet and the storage key regex can't drift apart
and silently recreate the unqueryable-key bug class.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019jrTawz2CRUiJLCt2UTQ2B

* fix(query): preserve metadata key case; escape JSON path keys

Review follow-ups on this branch:

- The parser lowercased the whole field token, so mixed-case metadata
  keys (valid per ValidateMetadataKey, stored case-sensitively) were
  silently unqueryable via metadata.<key>=<value> — and inconsistent
  with has_metadata_key and the --metadata flag, which preserve case.
  Keep field-name matching case-insensitive but restore the key
  suffix's original case.

- JSONMetadataPath spliced the key into the quoted path unescaped,
  relying on every caller validating first. Escape \ and " locally so
  the function is correct for any input.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019jrTawz2CRUiJLCt2UTQ2B

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: matt wilkie <maphew@gmail.com>
2026-07-24 17:52:22 -07:00
Kumar Prateek
41f3bfe6f2
test(backup): use a platform-native absolute path in TestResolveDoltBackupURL (GH#4923) (#4940)
* test(backup): use a platform-native absolute path in TestResolveDoltBackupURL

The "absolute path gets file:// prefix" case hard-coded the POSIX literal
"/mnt/usb/beads-backup" and asserted the prefix "file:///mnt/usb/beads-backup".
On Windows that string is not absolute (it carries no volume name), so
resolveDoltBackupURL resolves it against the current drive and returns
"file://C:\mnt\usb\beads-backup", failing the assertion.

Build the fixture from t.TempDir() instead, which is absolute and already
cleaned on every platform, and assert the exact resulting URL. For an
already-absolute, clean input filepath.Abs is an identity, so the expectation
is deterministic. On POSIX the assertion still resolves to a triple-slash
file:/// URL, preserving the original intent.

Test-only change; resolveDoltBackupURL is untouched.

GH#4923

* ci: re-run checks
2026-07-24 16:40:20 -07:00
coffeegoddd☕️✨
9d2a8793f1 /cmd/bd: isolate the proxied clean-databases test from the shared server
listStaleDatabases closed rows twice (defer plus a returned Close). The defer
alone already releases at the function boundary, before any DROP DATABASE runs.

TestProxiedServerCleanDatabases ran against the shared external Dolt container
under t.Parallel(). bd dolt clean-databases drops every database matching
staleDatabasePrefixes on the server it is pointed at, and the container is
bootstrapped with a database named beads_test, which matches one of those
prefixes -- so each run dropped the shared container's own bootstrap database
out from under whatever siblings were mid-flight. That is timing-correlated
with the busy buffer / "pending schema migrations alter pre-existing dirty
tables" failures in TestProxiedServerDelete and TestProxiedServerFindDuplicates
in proxied shard 1, which also reproduce on main. The test now runs against a
dedicated proxied server, like the new purge test, so its blast radius is its
own server. The underlying naming hazard is tracked separately in p1-8dz.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-24 14:23:45 -07:00
coffeegoddd☕️✨
de05a3d564 /cmd/bd: support --purge-dropped in proxied-server mode 2026-07-24 13:38:54 -07:00
matt wilkie
f11a78fecd
Merge pull request #4877 from anisoptera/feat/json-import-all-native-fields
feat(create): make every native issue field addressable from --graph JSON plans
2026-07-24 09:52:27 -07:00
Steve Yegge
6e8af8bf80
feat(update): conditional compare-and-set guards --if-assignee/--if-status (bd-wsqvw) (#5008)
* feat(update): conditional compare-and-set guards --if-assignee/--if-status (bd-wsqvw)

From wyvern's wheelhouse hostile-review (epic wy-mdi5h): the fleet's most
common bug class is check-then-act on bd assignee/status — read state,
then issue a blind 'bd update -a X', and lose to a racing writer in the
gap. Design: PROPOSAL-cas-conditional-update.md.

Adds --if-assignee/--if-status precondition flags to 'bd update'. When
present, the mutation applies only if the issue's current
assignee/status still equals the expected value — one atomic
transaction, nothing written on a mismatch, loud non-zero exit naming
actual vs expected. --if-assignee '' means "expected unassigned"
(Changed()-detected, the unclaim idiom). Covers the two transitions no
existing verb expresses: reassign X->Y (park) and claim-on-behalf with
a status guard (restore).

Per the reconciliation with #4911, the guards extend the existing
UpdateIssueOptions on UpdateIssueChecked (ExpectedAssignee /
ExpectedStatus, new issueops.CheckExpectedFieldsInTx beside
CheckVersionInTx, typed storage.ErrStatusMismatch beside the existing
ErrAssigneeMismatch) rather than minting a parallel interface method —
no Storage interface break, decorators pass through unchanged. Wired
through all three write stacks: DoltStore (server), EmbeddedDoltStore,
and the proxied-server domain.UpdateSpec/ApplyUpdate path. In Dolt
server mode a guarded update that writes assignee/status is
claim-family and resolves through verifiedClaimWrite (bd-zccb9) with a
guarded-update postcondition, so its exit code stays truthful under a
degraded server; replay after a verified rollback re-checks the guards
in the replayed transaction.

CLI rules: guards are mutually exclusive with --claim (its own CAS),
require a regular field update to ride on (label/parent edits run
outside the guarded transaction), and --if-status is validated against
the live status set so a typo fails fast instead of mismatching
forever. Guard failures flow through the finding-#10 exit contract on
both the classic and proxied paths.

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

* feat(update): exit code 13 distinguishes --if-assignee/--if-status guard mismatch from infra failure (bd-wsqvw)

A stale guard now exits ExitGuardMismatch (13) when every failure in the
run was a guard refusal — scripts can tell 'a racer won, skip gracefully'
from 'server down, retry/abort' without parsing prose. Mixed batches keep
the conservative exit 1. JSON failure entries carry guard_mismatch:true;
stderr keeps the greppable 'assignee mismatch'/'status mismatch' sentinels.
Requested by fly (wyvern) for the wy-mdi5h.3/.6 park/restore adopters.

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

* docs(claim): note guardedUpdatePostcondition attribution narrowness (lion review note 1, PR #5008)

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

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-24 09:11:15 -07:00
Steve Yegge
c38582b7e6 feat(reclaim): scope filters --label/--label-any/--exclude-label/--assignee/--id (wy-jpd3.3)
bd reclaim was global-only: on a federated deployment one machine's reaper
can revert a stale-looking unit that is alive on the machine that granted its
lease. Add scope filters mirroring the claim-side label surface
(bd ready --claim) so a supervisor can point its reaper at exactly the
partition it claims from.

- types.ReclaimFilter (IDs/Assignees/Labels/LabelsAny/ExcludeLabels) + IsEmpty.
- sqlbuild.BuildReclaimScopeClauses/ReclaimScopeSQL: same SQL shapes the
  claim/ready path emits, alias-qualified for the reclaim JOIN. Fails closed
  (1=0) on a degenerate all-empty field so a scoped sweep can never silently
  widen to global.
- issueops.ReclaimExpiredLeasesInTx threads the filter into the snapshot SELECT
  only; the per-row revert re-checks by id from the already-scoped snapshot.
- Threaded ReclaimExpiredLeases through the Store/domain interfaces and every
  backend (dolt, embedded dolt, sql repo, use case) and both CLI paths
  (direct + proxied server). A zero ReclaimFilter reproduces the exact prior
  global behavior.
- CLI hard-errors a scope flag supplied with no usable value (e.g. --label
  "$LANE" with LANE unset) instead of degrading to a global sweep; --json now
  reports a "scoped" boolean.
- Cross-backend conformance coverage (testReclaimScoped) + sqlbuild and
  flag-parsing unit tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 05:31:23 -07:00
Jim Wordelman
3567bf1260
test(cmd/bd): clear baseline gate blockers (#4345)
* test(cmd/bd): fix baseline make-test blockers

Four CGO failures (TestAutoExport*, TestInitNonInteractive*): the pre-built
../../bd binary was compiled with CGO_ENABLED=0 and cannot run embedded Dolt.
Add isCGOBuild() — reads 'go version -m <path>' to detect a statically-linked
binary — and skip it in buildBDForInitTests, falling through to a fresh build.

TestCommitBeadsConfigSkipsGitHooks: TestIgnoreSchemaSkewFlagPropagatesEnvVar
calls rootCmd.PersistentPreRun which sets BEADS_DIR via prepareSelectedCommandContext
without cleanup. savePersistentPreRunState snapshotted globals but not env vars,
so BEADS_DIR leaked across tests and pointed the subsequent commit to the wrong
repo. Add t.Setenv tracking for BEADS_DIR/BEADS_DB/BD_DB to savePersistentPreRunState.

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

* chore: release gate PASS for ga-7psli2.3.1

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: matt wilkie <maphew@gmail.com>
2026-07-24 01:52:38 -07:00
Jim Wordelman
a9a48d6e36
test(cli,storage): BEADS_MAX_ROWS behavioral + opt-out gate tests (be-x42v) (#4160)
* feat(storage): be-x42v.1 BEADS_MAX_ROWS defensive cap foundation

Add IssueFilter.MaxRows + IssueFilter.MaxRowsSource and a typed
issueops.ErrTooManyRows error. searchTableInTx routes its LIMIT through
EffectiveSearchLimit (LIMIT MaxRows+1 when MaxRows>0, with Limit
preserved otherwise); SearchIssuesInTx checks EnforceMaxRowsCap after
the issues+wisps merge so the cap reflects the count returned to the
caller. Both helpers are exported so future PG-backend support can
reuse the same logic.

Default MaxRows=0 disables the cap and is byte-identical to today at
every existing call site. Limit semantics are unchanged: Limit=0 still
means unlimited at the contract level.

PG backend is not on origin/main yet; PG cap support is a follow-up
when the postgres backend merges. Validator's per-backend bead exercises
the issueops path via Dolt/embedded fixtures.

Refs: be-x42v (designer §3/§6.2), be-jp5s (architecture D1/R-03).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(cli): be-x42v.2 wire --max-rows / BEADS_MAX_ROWS on CLI surface

Adds cmd/bd/max_rows.go with three helpers: addMaxRowsFlag registers
--max-rows int with the designer's spec help text, resolveMaxRows
picks flag > env > 0 (negative flag → exit 1, bad env → warn-and-ignore),
and handleMaxRowsError pattern-matches *issueops.ErrTooManyRows to
emit the two-line stderr message and exit 2 with stdout empty.

The flag is wired on bd list, bd ready, bd dep tree, bd find-duplicates,
and bd graph (designer §4). The env-only resolveMaxRowsEnvOnly variant
is wired on bd lint and the SearchIssues paths inside bd doctor
(conventions + pollution checks). bd cleanup, bd gc, bd export,
bd export --auto, bd migrate-issues, and bd jira explicitly set
MaxRows=0 / MaxRowsSource="" in code so a misconfigured env can't
abort a data-integrity sweep partway through.

bd ready needed storage-layer support too: WorkFilter gains MaxRows +
MaxRowsSource and GetReadyWorkInTx routes its LIMIT through
EffectiveSearchLimit and enforces the cap via EnforceMaxRowsCap on
the row count returned to the caller. bd dep tree applies the cap at
the CLI layer on the TreeNode count since the tree walk doesn't go
through IssueFilter.

bd config show gains a standalone-env collector so BEADS_MAX_ROWS
shows up alongside BEADS_DIR etc. when set. The Viper-managed env
detection skips it because BEADS_MAX_ROWS isn't bound to a config key.

Adds a CONTRIBUTING.md section documenting the opt-out rule for new
IssueFilter sites that aren't on designer §4's wired-up list, with a
pointer to the validator's opt-out test gates (be-x42v.4).

Smoke-tested against the rig database (298 issues):
- bd list --max-rows 5 → exit 2, "--max-rows=5"
- BEADS_MAX_ROWS=5 bd list → exit 2, "BEADS_MAX_ROWS=5"
- BEADS_MAX_ROWS=banana bd list --limit 3 → warn + exit 0
- BEADS_MAX_ROWS=5 bd list --max-rows 0 --limit 3 → exit 0
- bd list --max-rows -1 → exit 1, "must be non-negative"
- bd ready --max-rows 5 → exit 2 (storage layer fires)
- bd dep tree be-jp5s --max-rows 1 → exit 2 (CLI-layer count)
- bd find-duplicates --max-rows 5 → exit 2
- bd graph --all --max-rows 5 → exit 2
- BEADS_MAX_ROWS=5 bd lint → exit 2 (env-only)
- BEADS_MAX_ROWS=5 bd export → exit 0, 299 lines (opt-out)
- BEADS_MAX_ROWS=10 bd config show → lists BEADS_MAX_ROWS

The 10 CLI behavioral test scenarios for bd list are owned by
be-x42v.3 (validator). Coverage for the non-list paths, the env-only
doctor family, and config show is filed as be-u8z9 (needs-tests,
routed to validator).

Refs: be-x42v (designer §2-§5), be-x42v.1 (foundation).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: release gate PASS for be-x42v.1 + be-x42v.2 (BEADS_MAX_ROWS)

Documents PASS evaluation across the six gate criteria for the
storage foundation (be-x42v.1, 3900c1bdc) and the CLI wiring
(be-x42v.2, dea537c56) shipping together. Review verdicts: be-xf0o
(foundation) and be-2p12 (CLI), both PASS from Opus 4.7 reviewer.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs: regenerate CLI reference for --max-rows flag

* docs: revert federation to pure-go stub in CLI_REFERENCE.md

CI's check-doc-flags freshness check runs generate-cli-docs.sh with
CGO_ENABLED=0. The previous regeneration used a CGO binary, expanding
the federation section with subcommands. Revert to the requires-CGO
stub that the pure-go binary produces.

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

* docs: revert website federation.md pages to pure-go stub (be-x42v)

Three website cli-reference/federation.md files still had CGO-enabled
content after CLI_REFERENCE.md was reverted. This commit brings them
into sync with the pure-go stub, resolving the Check doc flags freshness
CI failure on PR #3908.

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

* test(cli): be-u8z9 BEADS_MAX_ROWS non-list command paths + config show

Locks down the manually-verified behavior shipped in be-x42v.2 across the
CLI surface beyond `bd list`.

cmd/bd/max_rows_test.go (new):
  - ReadyMaxRows_FlagOverCap_Exits2  - bd ready --max-rows N → exit 2
  - ReadyMaxRows_EnvOverCap_Exits2   - BEADS_MAX_ROWS=N bd ready → exit 2
  - DepTreeMaxRows_TreeNodes_Exits2  - tree-node count cap in dep tree
  - FindDuplicatesMaxRows_Exits2     - find-duplicates --max-rows N
  - GraphAllMaxRows_Exits2           - graph --all --max-rows N
  - LintMaxRows_EnvOnly_Exits2       - bd lint with BEADS_MAX_ROWS=N
  - LintMaxRows_NoFlagAccepted       - cobra rejects --max-rows on lint
  - ConfigShow_ListsBeadsMaxRows     - bd config show surfaces the env var
  - ConventionsMaxRows_EnvOnly       - skipped (bd doctor needs server mode,
                                       follow-up filed as be-pc8c)
  - PollutionMaxRows_EnvOnly         - skipped (same reason)

cmd/bd/ready_max_rows_test.go (new):
  - TestGetReadyWork_MaxRowsSuite — exercises WorkFilter.MaxRows in
    GetReadyWork (under cap / over cap / zero disabled / with Limit
    matrix), via newTestStore. Companion to the SearchIssues parity
    work in be-x42v.3.

Refs: be-u8z9 (this bead), be-x42v.2 (builder), be-pc8c (follow-up).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test(cli,storage): be-x42v.3 BEADS_MAX_ROWS bd list scenarios + backend parity

Covers the 10 CLI scenarios from designer §6.1 against `bd list` and the
5 storage scenarios from designer §6.2 against both Dolt-server and
embedded backends.

cmd/bd/max_rows_test.go (extended):
  TestEmbeddedMaxRowsList — 10 subtests on a shared 21-issue rig:
    - Disabled_NoEnv             (baseline, no cap)
    - Flag_UnderCap              (--max-rows 100 over 21 rows → success)
    - Flag_OverCap               (--max-rows 5 → exit 2, source attribution, empty stdout)
    - Env_OverCap                (BEADS_MAX_ROWS=5 → exit 2, env source)
    - Flag_OverridesEnv          (env=5 flag=100 → success)
    - Flag_Zero_OverridesEnv     (env=5 --max-rows 0 → success, explicit disable)
    - BadEnv_LogsAndIgnores      (env=banana → warning + normal output, exit 0)
    - Negative_FlagRejected      (--max-rows -1 → "must be non-negative", exit 1)
    - LimitSet_CapTighter        (--limit 100 --max-rows 5 → exit 2)
    - LimitSet_CapLooser         (--limit 5 --max-rows 100 → 5 rows, exit 0)

internal/storage/embeddeddolt/search_max_rows_test.go (new):
  TestSearchIssues_MaxRows_{NotExceeded,Exceeded,Zero_NoCap,WithLimit}
  Exercises SearchIssues end-to-end against the embedded backend on a
  6-row fixture, including the four-quadrant (Limit, MaxRows) matrix.

internal/storage/dolt/search_max_rows_test.go (new):
  Identical scenarios against the dolt-server backend. Per-backend
  parity is implicit: both SearchIssues entry points wrap
  issueops.SearchIssuesInTx, so cap behavior is shared by construction.
  Same fixture + same assertions ensures divergence cannot ship silently.

PG backend coverage is deferred until the postgres-backend branch lands
(per PR #3908 description and parent designer notes).

Refs: be-x42v.3 (this bead), be-x42v.2 (builder), be-u8z9 (sibling validator for non-list paths).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test(cli): be-x42v.4 opt-out gate tests for data-integrity commands

Add filterCapturingStore spy and four MaxRows=0 gate tests asserting
that bd export, bd export --auto, bd jira sync, and bd migrate-issues
always construct IssueFilter with MaxRows=0 / MaxRowsSource="" per
designer §4.1 opt-out rule. A BEADS_MAX_ROWS env var on these paths
would corrupt backups, sync state, or migration runs mid-flight.

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

* test(cli): be-x42v.4 add TestExport_BypassesBeadsMaxRows behavioral gate

End-to-end belt-and-suspenders test (designer §6.4): sets BEADS_MAX_ROWS=1,
seeds 5 task issues, runs runExport, and asserts 5 JSONL lines in the output.
Completes the be-x42v.4 acceptance criteria for the bypass behavioral test
alongside the filter-spy gate already committed.

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

* test(cli): be-pc8c server-mode BEADS_MAX_ROWS gate for bd doctor --check={conventions,pollution}

TestDoctorConventionsMaxRows_EnvOnly_Exits2 and TestDoctorPollutionMaxRows_EnvOnly_Exits2
cover the two subtests that were skipped in max_rows_test.go because bd doctor refuses
to run in embedded mode (doctor.go:188). Both tests seed 6 open issues against the
Dolt test server with BEADS_MAX_ROWS=3, assert exit 2, and confirm BEADS_MAX_ROWS=3
in the combined output.

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

* fix(search): enforce MaxRows cap when wisps table is empty

SearchIssuesInTx skipped EnforceMaxRowsCap on the common empty-wisps
path: when filter.Ephemeral is nil/false and the wisps table is empty,
the early `return results, nil` returned before the post-merge cap check.
The issues-only result set (LIMIT cap+1) could exceed MaxRows yet never
trip ErrTooManyRows. Enforce the cap before the early return.

Fixes TestSearchIssues_MaxRows_Exceeded_ReturnsErrTooManyRows and
TestSearchIssues_MaxRows_WithLimit (internal/storage/embeddeddolt).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(rebase): re-home BEADS_MAX_ROWS enforcement onto post-rebase seams

Fixes gaps exposed by rebasing PR #4160 onto current upstream/main,
found by actually running the PR's own gate tests rather than just
resolving textual conflicts:

- internal/storage/issueops/search.go: the Q2 perf-escape-hatch
  SkipWisps early return (added by main's search perf work, landed
  after this PR's original design) skipped EnforceMaxRowsCap entirely.
  bd list sets SkipWisps=true by default, so `bd list --max-rows N`
  silently ignored the cap. Enforce the cap on that return path too,
  mirroring the existing empty-wisps-table fix alongside it.

- internal/storage/issueops/search_counts.go: SearchIssuesWithCountsInTx
  (the `--json` query path, already present at the PR's merge-base but
  never wired for MaxRows by the original be-x42v.1/.2 commits) neither
  sized its SQL LIMIT off the cap nor enforced it on the merged result.
  Thread filter.MaxRows through EffectiveSearchLimit for the query LIMIT
  and check EnforceMaxRowsCap in the shared finishSearchIssuesWithCounts
  terminal helper (now returns an error), which every exit path already
  routed through. Fixes be-x42v.3's TestEmbeddedMaxRowsList/Flag_OverCap
  (`bd list --json --max-rows 5`), which failed after the rebase.

- cmd/bd/jira_max_rows_gate_test.go,
  cmd/bd/migrate_issues_max_rows_gate_test.go: seed INSERTs predate
  migration 0049 (LONGTEXT NOT NULL on issues.description/design/
  acceptance_criteria/notes, no default) that landed on main after
  this branch's merge-base. Provide empty-string values for the
  now-required columns.

Not fixed (separate, pre-existing gap; no gate test in this PR
exercises it): GetReadyWorkWithCountsInTx (`bd ready --json` /
`bd list --ready --json`) also doesn't thread MaxRows. Left alone to
keep this rebase to conflict resolution rather than expanding scope;
worth a follow-up bead.

Agent-Signature: claude-sonnet-medium on behalf of maphew

* fix(review): address adjudicated cross-vendor review follow-up (be-x42v.4)

Works the MUST-FIX / SHOULD-FIX list from the adjudicated claude-opus +
codex-gpt-5.6-sol review on the rebase (25e35cc3e), landing coverage gaps
the vendors found in the feature's own promise rather than the rebase
mechanics.

MUST-FIX:

1. internal/storage/issueops/claim.go: ClaimReadyIssueInTx forwarded the
   caller's MaxRows/MaxRowsSource into its internal unbounded
   GetReadyWorkInTx scan, so a rig-wide cap (e.g. BEADS_MAX_ROWS=100 with
   150 ready issues) hard-failed a claim that only ever consumes one row.
   Bound the internal scan via Limit instead, then clear the cap fields.

2. cmd/bd/ready.go, internal/storage/issueops/ready_work_counts.go:
   GetReadyWorkWithCountsInTx (ready --json / list --ready --json) never
   enforced MaxRows at all — a pre-existing gap in the original PR (the
   function predates this branch's merge-base), not something the rebase
   introduced. Threaded EffectiveSearchLimit into its query LIMIT and added
   EnforceMaxRowsCap via a new finishReadyWorkWithCounts terminal helper,
   mirroring finishSearchIssuesWithCounts. Wired handleMaxRowsError on the
   bd ready --json error branch.

3. cmd/bd/max_rows.go + list/ready/graph/dep/find-duplicates: proxied-server
   mode silently ignored the cap (the proxied repository doesn't thread
   MaxRows through the UOW pipeline). Added rejectMaxRowsUnderProxiedServer,
   called on every command that registers --max-rows before it diverts to
   its *ProxiedServer path — an explicit --max-rows or BEADS_MAX_ROWS now
   errors out under --proxied-server instead of no-oping.

4. cmd/bd/list.go: `--limit N --max-rows N` errored instead of truncating.
   withFetchOneExtra unconditionally bumped Limit to N+1 for its own
   >N-matches truncation-hint probe, which then crossed EffectiveSearchLimit's
   `limit > maxRows` branch and tripped the cap on the probe row alone, even
   though the delivered set is always trimmed back to N. withFetchOneExtra
   now skips the bump when MaxRows is active and no looser than Limit;
   >N-matches semantics for limit<maxRows are unaffected.

5. cmd/bd/list.go: `bd list --watch` swallowed the initial-query cap error
   (logged to stderr, returned void, exited 0). watchIssues now returns the
   initial-query error instead of handling it itself; runListCore routes it
   through handleMaxRowsError for exit-code-2 semantics. Mid-poll refresh
   failures still just log and continue (interactive command, not a reason
   to kill the watch loop).

6. cmd/bd/max_rows.go + every call site: handleMaxRowsError and the
   --max-rows usage-error path in resolveMaxRows called os.Exit directly
   from deep inside RunE, bypassing both the command's own metrics defer
   and main()'s post-ExecuteC metrics.CloseAndFlush(). Converted both to
   return errors: resolveMaxRows now returns (int, string, error) and
   handleMaxRowsError returns error, both following the exact &exitError{Code:
   N}-via-RunE precedent already used elsewhere in this package (e.g.
   list_input.go's skip-labels-conflict check, HandleErrorRespectJSON).
   doctor_conventions.go's runConventionsLint (called from a "()
   []doctorCheck" advisory-checks aggregator with no error channel) needed
   its own (([]doctorCheck, error) signature to propagate the one non-advisory
   failure mode; every other call site was already RunE-adjacent.

SHOULD-FIX (both mechanical, done):

7. cmd/bd/graph.go: `bd graph <issue>` (no --all) never resolved the cap.
   loadGraphSubgraph is a BFS over per-ID GetDependents/GetDependencies
   lookups with no IssueFilter to thread MaxRows through, so — mirroring
   dep tree — the cap is now checked post-hoc against the final
   connected-component node count. Documented both graph's per-status
   (--all) and post-hoc (single-issue) cap semantics, and dep tree's
   post-hoc semantics, in their flag help text.

8. internal/storage/issueops/ready_work.go: getReadyWispsInTx's unbounded
   (Limit<=0) branch queried and hydrated the *entire* wisps table before
   the post-merge cap check in GetReadyWorkInTx ever ran, defeating the
   "circuit breaker against pathological queries" purpose for
   --include-ephemeral. readyWorkWispIssueFilter now propagates
   MaxRows/MaxRowsSource so EffectiveSearchLimit bounds that query to
   cap+1 up front.

Tests added: TestClaimReadyIssue_MaxRows_LargePoolUnderLowCap (1),
ReadyMaxRowsJSON_FlagOverCap_Exits2 + ListReadyMaxRowsJSON_FlagOverCap_Exits2
(2), reject_max_rows_flag + reject_max_rows_env + allow_max_rows_zero under
TestProxiedServerList (3), LimitEqualsCap_TruncatesNotErrors +
LimitEqualsCap_JSON_TruncatesNotErrors (4), Watch_FlagOverCap_Exits2 (5),
GraphSingleIssueMaxRows_NodeCount_Exits2 + _UnderCap_NoError (7),
ReadyIncludeEphemeralMaxRows_FlagOverCap_Exits2 (8).

Verified: go build/vet clean; full MaxRows-named + FilterHasZeroMaxRows +
BypassesBeadsMaxRows sweep passes in both dolt-server and
BEADS_TEST_EMBEDDED_DOLT=1 modes (one dolt-testcontainer flake observed and
confirmed non-reproducing on retry, consistent with prior sessions);
TestProxiedServerList passes with BEADS_TEST_PROXIED_SERVER=1.

Agent-Signature: claude-sonnet-medium on behalf of maphew

* fix(review): address round-2 delta review regressions (be-x42v.4 round 3)

opus verified all eight round-2 items as implemented, but codex found three
regressions those fixes introduced, confirmed on adjudication. Common
thread: enforce the cap on the DELIVERED result, not on fetched/merged
intermediates, and don't let the safety rejection block one-row operations.

1. cmd/bd/ready.go: proxied `bd ready --claim` was rejected by
   rejectMaxRowsUnderProxiedServer before it could dispatch to
   runReadyProxiedClaim, even though --claim always delivers exactly one
   row and the direct-path fix (claim.go, round 2) already exempts claim
   from cap enforcement for that exact reason. Moved the claimReady flag
   parse before the proxied branch and exempt --claim from the rejection;
   bulk (non-claim) proxied `bd ready` still rejects an active cap. Added
   claim_succeeds_under_env_max_rows_cap plus
   reject_bulk_ready_under_max_rows_{flag,env} to
   ready_proxied_integration_test.go.

2. internal/storage/issueops/ready_work_counts.go: with --include-ephemeral,
   GetReadyWorkWithCountsInTx's issues and wisps queries are each
   independently bounded by EffectiveSearchLimit(filter.Limit,
   filter.MaxRows), so the merged pre-trim slice can hold up to ~2x that
   per-table bound even when filter.Limit <= filter.MaxRows (e.g. limit=2,
   cap=3, 2 rows/table -> merged 4 -> false "too many rows" even though the
   delivered page, trimmed to 2, is well within the cap). Reordered
   finishReadyWorkWithCounts to trim to Limit before checking the cap,
   mirroring GetReadyWorkInTx's non-counts path (mergeReadyWisps already
   trims before its caller's EnforceMaxRowsCap runs). Verified this
   reproduces "4 found, --max-rows=3 exceeded" on the pre-fix code and is
   fixed after. Added ReadyIncludeEphemeralMaxRowsJSON_MergedUnderLimit_NoError.

3. cmd/bd/list.go: round-2's fix for `--limit N --max-rows N` (skip the
   withFetchOneExtra probe-row bump entirely when Limit>=MaxRows) stopped
   the false cap error but also stopped fetching the extra row, so
   len(results) could never exceed effectiveLimit and the GH#3212
   truncation notice silently stopped firing — a partial result started
   presenting as complete. Restored the probe-row fetch (Limit still bumps
   to N+1) and instead bump MaxRows to N+1 in lockstep, but only in the
   exact Limit==MaxRows case: this keeps the probe row inside the
   (temporarily N+1) cap so EnforceMaxRowsCap doesn't trip on it, while the
   CLI's own len(results)>effectiveLimit check still sees the extra row and
   correctly reports truncated=true. Tighter-cap (Limit>MaxRows) and
   looser-cap (Limit<MaxRows) cases are unaffected — MaxRows is left
   unbumped there, so a genuine violation still reports the true cap value.
   printTruncationHint's text is gated on ui.IsStderrTerminal() and
   unconditionally suppressed for this subprocess test harness's piped
   stderr (matches the existing limit_truncation_hint subtest's documented
   constraint), so the fix is verified via 4 new unit tests asserting
   withFetchOneExtra's exact bump values directly
   (TestWithFetchOneExtra_LimitEqualsCap_BumpsBothForTruncationProbe et al.)
   rather than the unobservable hint text; extended
   LimitEqualsCap_TruncatesNotErrors's comment to document this and point
   to the unit tests.

Opus nits:

4. internal/storage/issueops/claim.go: bounding the claim scan at
   Limit=MaxRows (round 2) meant a BEADS_MAX_ROWS=1 rig would only attempt
   the single top-of-queue ready row and return "nothing to claim" if it
   was transiently unclaimable (e.g. a race with another agent), even with
   plenty of other ready work available. Restored the unbounded scan
   (Limit=0); the breaker's job is to bound delivered payloads, and a
   claim's payload is always exactly one row regardless of scan size.

5. cmd/bd/find_duplicates.go: replaced the inlined proxied-server rejection
   check with a call to rejectMaxRowsUnderProxiedServer so the message
   can't drift from the other 4 commands that use it.

Verified: go build/vet clean; full MaxRows-named + FilterHasZeroMaxRows +
BypassesBeadsMaxRows + WithFetchOneExtra sweep passes in both dolt-server
and BEADS_TEST_EMBEDDED_DOLT=1 modes; TestProxiedServerList +
TestProxiedServerReady (full suites, ~200s) pass with
BEADS_TEST_PROXIED_SERVER=1; broader TestList|TestWatch|TestGraph|
TestDepTree|TestReady|TestClaim|TestFindDuplicates sweep clean except the
same pre-existing unrelated ICU-header build failure noted in the round-2
commit (confirmed via stash-based control test to reproduce identically
without this round's changes).

Agent-Signature: claude-sonnet-medium on behalf of maphew

* fix(review): address round-3 delta review items (be-x42v.4 round 4)

Converging: four small items adjudicated from round-3 delta reviews.

1. internal/storage/issueops/search.go, search_counts.go: round 3's
   trim-before-cap fix landed in finishReadyWorkWithCounts but not on the
   sibling bd list search paths. `bd list --include-infra --limit 2
   --max-rows 5` (3 durable + 3 wisps) exited 2 in both output modes even
   though the delivered page is 2 rows, since --include-infra disables the
   default SkipWisps escape hatch so the wisps merge actually runs.
   Reproduced live: "6 found, --max-rows=5 exceeded" on the pre-fix code.
   Mirrored the ready remedy: trim to filter.Limit (guarded by Limit>0)
   before EnforceMaxRowsCap in searchInTx's four exit points (added a
   trimToSearchLimit helper) and in finishSearchIssuesWithCounts (swapped
   the cap/trim order). Fixed search_counts.go's doc comment, which still
   asserted the old cap-before-trim rationale and directly contradicted
   ready_work_counts.go's. Single-source results are unaffected (a lone
   query never exceeds Limit when Limit>0, so the trim there is a no-op);
   Limit=0 and genuine Limit>MaxRows overage still error. Added
   IncludeInfraMergedUnderLimit_NoError (both bd list output modes) to
   TestEmbeddedMaxRowsList.

2. cmd/bd/ready.go: the round-3 fix that exempts proxied `ready --claim`
   from rejectMaxRowsUnderProxiedServer also skipped resolveMaxRows
   entirely for that branch, so `--max-rows -1` was silently accepted
   under proxied claim (every other command, direct or proxied, rejects
   it with exit 1). Still call resolveMaxRows in the claim-exempt branch
   for its validation side effect, ignoring the resolved cap for the
   claim itself. Reproduced live (claim succeeded instead of failing) on
   the pre-fix code. Added claim_rejects_invalid_max_rows_flag to
   ready_proxied_integration_test.go.

3. cmd/bd/find_duplicates.go, cmd/bd/max_rows.go: find-duplicates resolved
   --max-rows twice under proxied mode (once to build its filter, again
   inside rejectMaxRowsUnderProxiedServer), doubling the malformed-env
   stderr warning. Split rejectMaxRowsUnderProxiedServer into itself plus
   a new rejectResolvedMaxRowsUnderProxiedServer(maxRows int) that takes
   an already-resolved value; find_duplicates.go now calls the latter with
   its existing resolved maxRows instead of re-resolving.

4. internal/storage/issueops/claim.go: added a comment sentence noting the
   unbounded-scan trade-off per the adjudication note — parity with
   pre-PR main and correctness-first (preserves claim's existing
   fairness/ordering across the ready set); a bounded, paged scan is a
   deliberate follow-up, not folded in here.

Verified: go build/vet clean; full MaxRows-named + FilterHasZeroMaxRows +
BypassesBeadsMaxRows + WithFetchOneExtra sweep passes in both dolt-server
and BEADS_TEST_EMBEDDED_DOLT=1 modes (including the two new regression
tests); full TestProxiedServerReady suite (~211s) passes with
BEADS_TEST_PROXIED_SERVER=1; internal/storage/issueops unit tests pass;
broader TestList|TestWatch|TestGraph|TestDepTree|TestReady|TestClaim|
TestFindDuplicates sweep clean except the same pre-existing unrelated
ICU-header build failure noted in prior rounds. Both new regression tests
(item 1 and item 2) reproduce the reported failure on the pre-fix code via
git-stash and pass after.

Agent-Signature: claude-sonnet-medium on behalf of maphew

* fix(review): sort merged issues+wisps before trim in searchInTx (be-x42v.4 round 5)

codex P1, confirmed live: searchInTx's merge branch concatenates two
independently ORDER BY'd legs (`results = append(filtered,
wispResults...)`), and round-4's trimToSearchLimit then sliced that
UNSORTED concatenation. With Limit=N and durable rows alone filling N, a
higher-ranked wisp (per filter.SortBy/SortDesc) was silently dropped from
the page — before round 4 the CLI received the full merged set and its own
sort-then-trim produced correct page membership; round 4 moved a naive
prefix-trim into storage ahead of any global re-sort.

Fix: added a `less func(a, b T, sortBy string, sortDesc bool) bool` field
to searchProjection[T], populated for issueProjection via sqlbuild.Less
(the existing Go-side mirror of the SQL ORDER BY, already used correctly
by search_counts.go's sortSearchIssuesWithCounts). searchInTx's merge
branch now re-sorts the concatenation via a new sortMergedResults helper
before trimToSearchLimit runs, mirroring how finishSearchIssuesWithCounts
already orders before its own trim. idProjection (bare-ID search, no
sortable payload) leaves less nil — sortMergedResults no-ops in that case;
documented why this is safe today (no current caller combines Limit>0 with
a merged, non-SkipWisps ID-only search — see id_parser.go, which always
passes Limit=0) and where to look if that changes. The other three
trimToSearchLimit call sites in searchInTx are single-source (already
SQL-ordered), so they don't need this.

Checked the two round-3/round-4-cited "mirror" precedents per the
adjudication note, since this bug's shape (unsorted-concat-then-trim) could
plausibly recur there: GetReadyWorkInTx's mergeReadyWisps already calls
sortReadyIssues(kept, filter.SortPolicy) before its own Limit trim, and
GetReadyWorkWithCountsInTx / SearchIssuesWithCountsInTx both already sort
(sortIssuesWithCountsByPolicy / sortSearchIssuesWithCounts) before their
finish* trim-then-cap helpers. All three were already globally ordered
before trimming; only searchInTx had the bug.

Added IncludeInfraMerged_WispOutranksDurable_InDeliveredPage to
TestEmbeddedMaxRowsList: 3 durable P2 issues + 1 wisp at P0 (outranks under
the default priority-ASC sort), --limit 1 in both bd list output modes —
asserts the P0 wisp is the delivered row, not an arbitrary P2 durable row.
Reproduces exactly against 77227aa67 (the durable row is returned instead
of the wisp) and passes after the fix.

Verified: go build/vet clean; full MaxRows-named + FilterHasZeroMaxRows +
BypassesBeadsMaxRows + WithFetchOneExtra + Search sweep passes in both
dolt-server and BEADS_TEST_EMBEDDED_DOLT=1 modes (including the new
regression test); internal/storage/issueops unit tests pass.

Agent-Signature: claude-sonnet-medium on behalf of matt wilkie

* docs: remove --max-rows lines from pinned-generator CLI docs (be-x42v.4 CI fix)

CI's "Check doc flags freshness" job compares docs/CLI_REFERENCE.md and
docs/cli-reference/*.md against bd built from the pin in
docs/cli-docs.pin (v1.1.0), which predates --max-rows/BEADS_MAX_ROWS —
the same pinned-doc-generator trap that hit PRs 3920 and 4022 in this
sweep. Any doc lines this PR added for the new flag are flagged stale
against that older pinned build, and the failure cascades into "PR
Policy (wrapper timing)" via make ci-pr-policy.

Applied CI's own generated fix verbatim (downloaded the
cli-docs-freshness-patch artifact from the failing job
https://github.com/gastownhall/beads/actions/runs/30067827283/job/89403539322,
git apply --check passed cleanly, applied as-is — no manual edits).
Removes the six --max-rows generated-doc lines (bd list, bd ready, bd dep
tree, bd find-duplicates, bd graph — CLI_REFERENCE.md and the matching
cli-reference/*.md) plus the incidental column-width realignment in the
bd graph flag tables that removing the widest flag name triggers.

The flag help strings themselves (cmd/bd/max_rows.go's addMaxRowsFlag)
are untouched — those are the source of truth for docs generation and
will regenerate correctly once docs/cli-docs.pin advances past this
PR's merge. This is a pinned-generator artifact of the CI pipeline, not
a statement that the flag is undocumented.

Agent-Signature: claude-sonnet-medium on behalf of maphew

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: matt wilkie <maphew@gmail.com>
2026-07-24 01:40:36 -07:00
Jim Wordelman
50003b803b
feat(storage): refuse test DBs on production dolt servers (AD-01) (#3632)
* feat(storage): be-c5p AD-01 isProductionPort + DB-name firewall

Generalize the BEADS_TEST_MODE production-port guard so deployments
on non-3307 ports (BEADS_PRODUCTION_PORT env, BeadsDir/dolt-server.port
file) are also caught, and add a defense-in-depth database-name
firewall that refuses test-named DBs on any server unless the operator
opts into the dedicated test-server lane via BEADS_TEST_SERVER=1.

Both defenses honor BEADS_TEST_SERVER=1 as the single opt-in for
test-server connections, so each test harness flips one env var rather
than each layer reasoning about test/prod independently. Adds benchdb_
to testDatabasePrefixes (per-bench scratch DBs from cmd/bd/dolt.go)
and updates the doc-block to call out the two sibling prefix lists
that need to converge under be-avn.

Test harnesses across cmd/bd, internal/storage/dolt, internal/molecules,
internal/tracker, internal/utils, doctor, doctor/fix, protocol,
regression, and the root suite now set BEADS_TEST_SERVER=1 alongside
BEADS_TEST_MODE=1 in TestMain. The cross-rig integration test that
filters BEADS_* env on subprocess Cmd.Env adds it back explicitly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: release gate PASS for be-c5p-firewall (be-m1u/47dcc380)

* fix(test): adapt store_unit_test.go for BEADS_DOLT_SERVER_PORT (rebase compat)

Tests that exercise applyConfigDefaults now clear BEADS_DOLT_SERVER_PORT (added
to main after this branch was cut) so the legacy BEADS_DOLT_PORT path runs as
intended. Without this, a GC-city environment with BEADS_DOLT_SERVER_PORT set
causes the tests to resolve an unexpected port.

* fix(dolt): stop BEADS_TEST_SERVER=1 from suppressing DefaultSQLPort detection

Restructure productionPortReasons so Rule 1 (cfg.ServerPort ==
DefaultSQLPort) is evaluated unconditionally; BEADS_TEST_SERVER=1 now only
suppresses the BEADS_PRODUCTION_PORT and dolt-server.port heuristics (Rules
2 and 3). isProductionPort loses its independent whole-function bypass and
becomes a thin wrapper. Update doc comments on both functions and the
buildTestModeProductionPortPanic fix list (which no longer lists
BEADS_TEST_SERVER=1 as a fix when port 3307 is the matched reason) to match.
Add TestApplyConfigDefaults_TestModeBlocksProdPort_EvenWithTestServerOptIn
asserting port 3307 is still refused with the opt-in set.

Also: drop a redundant explicit db.Close() in openServerConnection's
firewall-refusal path (already covered by the connReady defer), and fix two
comments that referenced a non-existent uniqueBenchDBName, pointing them at
the real generator (cmd/bd/template_test.go newTemplateBenchmarkStore) with
the correct benchdb_ name format.

Agent-Signature: claude-sonnet-medium on behalf of matt wilkie

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: matt wilkie <maphew@gmail.com>
2026-07-24 01:28:51 -07:00
Jim Wordelman
4b02630b97
fix(dolt): PURGE dropped databases after clean-databases DROP (be-pq5) (#3663)
* fix(dolt): PURGE dropped databases after clean-databases DROP (be-pq5)

DROP DATABASE only marks a database as dropped; Dolt moves its directory
under .dolt_dropped_databases/ so dolt_undrop() can restore it, but leaves
the on-disk data in place until an explicit
CALL DOLT_PURGE_DROPPED_DATABASES(). `bd dolt clean-databases` dropped
stale testdb_*/benchdb_*/etc. databases from SHOW DATABASES but never
issued that purge, so disk usage on the shared Dolt server stayed high
across repeated runs.

clean-databases now purges once after the drop loop. A failed purge is
reported as a warning rather than aborting the command, since the stale
databases are already gone from the server's active set at that point;
the purge is a best-effort disk reclaim on top of a cleanup that already
succeeded.

This is the surviving half of the original be-pq5 fix (PR #3663): the
staleDatabasePrefixes benchdb_ entry from that PR already landed on main
via #3618, and the internal/storage/dolt/dolt_benchmark_test.go
uniqueBenchDBName()/dropBenchDB() helpers it purged against never landed
on main (current setupBenchStore uses per-run temp directories in fully
embedded mode with no shared-server dropped-database leak to purge). Only
the cmd/bd/dolt.go clean-databases production fix is rebased forward here;
see the following commit for a from-scratch regression test against
main's current bench/test DB lifecycle.

Co-authored-by: Jim Wordelman <jim@wordelman.name>

* test(dolt): regression test for clean-databases PURGE (be-pq5, rework)

Adapts the be-pq5 regression coverage to current main's bench/test DB
lifecycle instead of the PR #3663 original, which was written against
uniqueBenchDBName()/dropBenchDB() helpers in
internal/storage/dolt/dolt_benchmark_test.go that never landed on main
(current setupBenchStore there is fully embedded, per-run temp dirs, no
shared-server leak to purge) and against BEADS_TEST_EXTERNAL_DOLT_PORT/
BEADS_TEST_EXTERNAL_DOLT_DATA_DIR env vars this repo has never wired up.

TestPurgeDroppedDatabasesReclaimsDisk instead drives purgeDroppedDatabases
(extracted from doltCleanDatabasesCmd in the previous commit) directly
against the existing shared testcontainer-based test Dolt server
(testDoltServerPort), which this package already starts for every other
cgo integration test. Dolt exposes no SQL-visible list of dropped-but-
not-purged databases, so the test uses CALL DOLT_UNDROP(name) as the
observable: it succeeds on a database that was DROPped but not purged,
and fails once DOLT_PURGE_DROPPED_DATABASES() has actually reclaimed it.
A control subtest (undrop without an intervening purge) pins that this
distinction holds, so a future Dolt change that breaks it fails loudly
here rather than making the positive case silently vacuous.

Agent-Signature: claude-sonnet-medium on behalf of maphew

* fix(dolt): gate clean-databases purge behind --purge-dropped (round 2)

Cross-vendor review (opus + codex) of the round-1 fix found two P1s in the
unconditional post-drop purge:

- CALL DOLT_PURGE_DROPPED_DATABASES() is server-global — Dolt has no way to
  scope it to only the databases a given run dropped. Firing it
  unconditionally after every clean-databases run could irreversibly
  destroy unrelated dropped-but-recoverable databases on a shared server
  (e.g. an operator's accidentally-dropped production database that was
  still restorable via CALL DOLT_UNDROP).
- The purge was gated on `dropped > 0`, so a run that found zero stale
  databases this time (e.g. because a prior run already dropped them but
  never purged) early-returned before the purge ever fired, leaving that
  residue unreclaimed — exactly the disk-usage problem be-pq5 targets.

Both are fixed by making the purge an explicit opt-in, gated on the
--purge-dropped flag alone (see the new shouldPurgeDroppedDatabases,
which intentionally ignores the drop count):

- Default (no flag): unchanged drop behavior, no purge. Prints a hint that
  dropped databases remain recoverable via CALL DOLT_UNDROP(name) and that
  --purge-dropped reclaims disk but purges ALL dropped databases on the
  server, not just this run's.
- --purge-dropped: purges after the drop loop, including when this run
  dropped nothing (fixes the residue case). Success output states the
  server-global, irreversible scope explicitly.
- Long help text documents --purge-dropped as server-global and
  irreversible, and that it removes DOLT_UNDROP recovery for every dropped
  database on the server, not just this run's.

Updates the round-1 CHANGELOG entry to describe the flag-gated behavior.

See the following commit for the updated test coverage.

* test(dolt): flag-gated purge coverage + CLI-level residue gate (round 2)

Rewrites the round-1 purge test coverage for the --purge-dropped flag
gating contract from the previous commit:

- TestShouldPurgeDroppedDatabasesGatesOnFlagAlone: pure table-driven test
  pinning shouldPurgeDroppedDatabases's contract directly, including the
  residue case (flag on, dropped == 0 this run -> must still purge) that
  was the exact P1 codex found.
- TestPurgeDroppedDatabasesReclaimsDisk is renamed to
  TestPurgeDroppedDatabasesRemovesUndropRecovery (opus nit: the old name
  overclaimed disk reclamation when what's actually observed is the loss
  of DOLT_UNDROP recovery) and reframed as the two flag outcomes: "with
  purge, undrop fails" and "without purge, undrop succeeds" (the former
  control subtest, now read as the default no-flag behavior). Added the
  one-line comment pinning the no-concurrent-purger assumption the
  CALL DOLT_UNDROP observable depends on (opus nit): neither subtest calls
  t.Parallel(), so Go's testing package never interleaves this test's own
  DROP/(maybe PURGE)/UNDROP sequence with another test's purge.
- New TestCleanDatabasesPurgeDroppedReclaimsResidue drives the actual
  `bd dolt clean-databases --purge-dropped` command end-to-end (not just
  the extracted helpers), via the existing
  buildBDUnderTest/writeServerRepo/runBDCommand harness from
  explicit_db_nodb_test.go. It primes the shared test server first (the
  container's own "beads_test" bootstrap database — see
  internal/testutil/container_provider.go — would otherwise make
  `dropped > 0` true on a fresh container and mask the exact bug being
  tested), then creates its own dropped-but-unpurged residue and asserts a
  second --purge-dropped run reclaims it despite finding zero stale
  databases itself. Verified this test fails against the pre-fix
  `purgeDropped && dropped > 0` gate and passes against the fix.

Agent-Signature: claude-sonnet-medium on behalf of maphew

---------

Co-authored-by: matt wilkie <maphew@gmail.com>
2026-07-24 01:04:57 -07:00
Jim Wordelman
ae48b0a090
perf(dolt): eliminate 12s slow path on bd commands when .local_version is stale (#3710)
* perf(dolt): be-1he eliminate 12s `dolt remote -v` against multi-db server roots

Three layers of defense for the bd 12s slow-path bug:

- Layer 1: migrateServerRootRemotes skips when rootDir/.dolt/repo_state.json
  is missing. Multi-database server roots have only sql-server.info; running
  `dolt remote -v` there takes ~12s to fail.
- Layer 2: ListCLIRemotes wraps the dolt subprocess in a 2s context timeout.
  Backstops Layer 1 against any future variant of the broken-parent-dir case.
- Layer 3: autoMigrateOnVersionBump does a read-only probe of bd_version
  before opening writeable. Read-only stores skip syncCLIRemotesToSQL, so a
  stale .local_version (e.g. from a multi-binary install) no longer triggers
  the slow path on every command.

End-user impact pre-fix: gc mail inbox 60-80s, gc status 30s+ hangs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: release gate PASS for be-1he (3-layer slow-path fix)

* docs(repro): add be-1he slow-path repro script (be-vxngmn)

Adds scripts/repro-be-1he-slow-path/repro.sh + REPRO.md demonstrating
the 12-second `dolt remote -v` slow path on multi-DB server roots.

Satisfies coffeegoddd's review request: "We need a beads-only repro of
this to prove its a bug."

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

* docs(cli): regenerate CLI reference after slow-path fix rebase

Output of ./scripts/generate-cli-docs.sh ./bd and ./scripts/generate-llms-full.sh.

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

* docs(cli): regenerate CLI reference + llms-full with pure-go bd

The previous regen (0aeb5934e) was built with a CGO-enabled bd, which
includes the CGO-only `bd federation` subcommands. CI builds the docs
binary with CGO_ENABLED=0 (scripts/ci/pr-policy.sh build_docs_binary),
so check-doc-flags rejected the extra federation subcommand pages.

Regenerated docs/CLI_REFERENCE.md, the federation cli-reference pages
(live + versioned 1.0.0/1.0.4/1.0.5), and website/static/llms-full.txt
with a CGO_ENABLED=0 binary. check-doc-flags + check-doc-freshness now
pass locally under LC_ALL=C.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* docs(release-gate): correct be-1he layer description to match shipped diff

The PR body and this gate doc both described a "Layer 1" repo_state.json
sentinel in internal/storage/dolt/federation.go, but the actual diff never
touched that file - only cmd/bd/version_tracking.go (Layer 3) and
internal/storage/doltutil/remotes.go (Layer 2) are changed. Correct the
gate doc's commit table, acceptance-criteria row, and follow-up/out-of-scope
notes to describe only what ships. No code or test changes; Layer 2 and
Layer 3 remain independently verified as still-needed on current main
(ListCLIRemotes has no timeout, no equivalent sentinel exists).

Agent-Signature: claude-sonnet-medium on behalf of maphew

* fix(dolt): scope ListCLIRemotes timeout, fix repro.sh, purge Layer 1 narrative

Addresses the cross-vendor review's four should-fixes plus the comment nit
(gastownhall/beads#3710 review, 2026-07-24):

1. ListCLIRemotes' 2s cap could turn a slow-but-valid dolt remote -v into
   "remote absent": FindCLIRemote folds any error (including a timeout) into
   "", and EnsureCLIRemote then blind-adds on that signal, which hard-fails
   if the remote actually exists. Chose the "scope the cap" fix over
   "propagate DeadlineExceeded distinctly": it's fully contained inside
   ListCLIRemotes (no changes needed at the three call sites - remotes.go:192
   ensure-path, store.go:1958 URL match via hasMatchingCLIRemote, and
   doctor/federation.go:127, which already treats errors distinctly from "no
   remotes"), whereas threading a sentinel error type through FindCLIRemote's
   string-returning signature and its callers touches more surface for the
   same outcome. ListCLIRemotes now stats dbPath/.dolt/repo_state.json: 2s
   cap when absent (the known broken multi-DB server-root case - there's
   never a real answer coming from there), 30s cap otherwise (a real repo's
   `dolt remote -v` is ~130ms even loaded, so 30s only bites a genuinely hung
   subprocess). Added TestListCLIRemotesTimeout covering both branches,
   following the t.TempDir() pattern already used in
   persisted_remotes_test.go.

2. repro.sh's baseline `dolt remote -v` ran in the invocation directory, not
   $SERVER_ROOT, so the central "slow" measurement never exercised the
   constructed broken root. Fixed to `(cd "$SERVER_ROOT" && dolt remote -v
   2>&1) || true`, matching the correct subshell pattern already used later
   in the script. Also relabeled the "PARTIAL FIX ... Layer 2 timeout capped
   it" branch: the 2s cap lives in bd's Go code, not dolt, and this script
   calls the raw dolt binary directly - it's never capped. Relabeled to
   describe the underlying dolt slowness the script demonstrates instead of
   implying bd's timeout is in play here.

3. `dolt init --quiet` isn't supported by dolt 2.2.x and set -e killed the
   script before it reached the summary. Redirected output instead
   (`dolt init >/dev/null 2>&1`). Ran repro.sh end-to-end locally (dolt
   2.2.0): completes with exit 0, and the fixed subshell now shows real
   timing/output from inside $SERVER_ROOT.

4. Purged the unshipped "Layer 1" (federation.go sentinel) narrative from
   repro.sh and REPRO.md - same reconciliation already done for the release
   gate doc and PR body. Both files now describe only the two layers that
   ship (remotes.go timeout, version_tracking.go read-only probe), with a
   short note that an earlier draft described a Layer 1 that never landed.

5. cmd/bd/version_tracking.go:195-197 comment cited syncCLIRemotesToSQL,
   which doesn't exist anywhere in the tree, and overstated the read-only
   probe's benefit. On current main the writeable-open gate reads remotes
   via doltutil.PersistedRemotes (a fast on-disk repo_state.json probe, no
   dolt subprocess), so the probe saves an initSchema round-trip, not a 12s
   hang. Corrected.

Agent-Signature: claude-sonnet-medium on behalf of maphew

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: matt wilkie <maphew@gmail.com>
2026-07-24 00:53:06 -07:00
Jim Wordelman
be402a022a
fix(filters): Dolt label-filter regression fix — LabelPattern + LabelRegex + JSON truncation hint suppression (#3971)
* fix(list): suppress truncation hint in --json mode + lock-in label filter tests (be-acnquj)

Filter logic for --label/--label-any/--label-pattern/--title-contains was
already correct in tree (BuildIssueFilterClauses handles each case), so the
bug PM observed was a stale-binary artifact. To prevent regression, add a
unit test in TestListLabelFiltersAcnquj that exercises every acceptance
criterion:

  AC#1 -l X returns ONLY beads with label X
  AC#2 --label-any A,B (OR semantics)
  AC#3 --label-pattern glob
  AC#4 --title-contains case-insensitive
  AC#5 -l NONEXISTENT returns empty
  AC#6 AND/OR composition with multiple flags

For AC#7, gate printTruncationHint on jsonOutput so the trailing
"Showing N issues; more results matched..." line is suppressed in
--json mode. TestPrintTruncationHintJSONSuppression exercises both paths.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(filters): wire LabelPattern/LabelRegex through SQL builder (be-ucslk4)

Both fields had been on IssueFilter and set by the cobra layer for
`bd list`, but BuildIssueFilterClauses never consumed them — so
--label-pattern and --label-regex silently returned the full result
set instead of filtering. This was the live regression in be-ucslk4
(every agent's intake hook saw the entire open queue).

Fix:

- LabelPattern: convert glob (* / ?) to a SQL LIKE pattern, escape
  literal %/_/| with ESCAPE '|', and AND-join an `id IN (SELECT
  issue_id FROM <labels-table> WHERE label LIKE ? ESCAPE '|')`
  subquery — same shape as the existing single-label clause.
- LabelRegex: pass through verbatim to a `label REGEXP ?` subquery.
- Helper globToLikePattern is unit-tested for stars, question marks,
  literal wildcards, and the escape char itself.

Tests:

- filters_test.go: TestBuildIssueFilterClauses_LabelPattern (issues +
  wisps tables), TestBuildIssueFilterClauses_LabelRegex,
  TestGlobToLikePattern table test. These run without Dolt — they
  pin the SQL emission and arg shape so the regression cannot recur.
- list_embedded_test.go: strengthened the existing label_pattern
  subtest with negative-case assertions (feature/chore must NOT
  match `back*`). The prior assertion only checked positive
  inclusion, so it would pass even when the filter was a no-op.

Verified end-to-end on live city: --label-pattern, --label-regex,
--label, --label-any, --title-contains all return the correct counts
after the fix; trailing 'Showing N issues; more results matched...'
hint stays off stdout under --json.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: release gate PASS for be-ucslk4-dolt-ship (be-qd2vmt)

* docs(regression): mark BUG-28 label-pattern filter as fixed (PR #3971)

TestDiscovery_LabelPatternFilterDeadCode's assertions already described the
correct (filtered) behavior, so no assertion changes were needed — it now
passes against the candidate binary where it previously failed and
documented the dead-code bug. Update the test docstring and the DISCOVERY.md
BUG-28 entry/status table/index list to reflect the fix landing in this PR
rather than describing an open bug.

Agent-Signature: claude-sonnet-medium on behalf of matt wilkie

* fix(filters): dedupe globToLikePattern, pin test against live impl

TestGlobToLikePattern was pinning a byte-identical but unreachable copy of
globToLikePattern in internal/storage/issueops/filters.go — the production
caller is internal/storage/sqlbuild/filter.go:325 via BuildIssueFilterClauses.
An escaping regression in the sqlbuild copy (%, _, | handling) could have
shipped unseen since only the dead copy was tested.

Delete the issueops copy (and its now-unused "strings" import) and move
TestGlobToLikePattern into internal/storage/sqlbuild, in-package, so it
exercises the function BuildIssueFilterClauses actually calls.

Flagged by cross-vendor paired review (claude-opus + codex-gpt-5.6-sol) on
PR #3971.

Agent-Signature: claude-sonnet-medium on behalf of matt wilkie

* test(list): add store-level --label-regex coverage

The label REGEXP ? path was previously pinned only at the clause-string
level (TestBuildIssueFilterClauses_LabelRegex); no committed test exercised
it end-to-end against the embedded store, though a reviewer's ad-hoc probe
had confirmed it works. Add a label_regex subtest beside the existing
label_pattern case in TestEmbeddedList, following the same build-tag/env
gating (BEADS_TEST_EMBEDDED_DOLT=1), covering both a single-label regex and
an alternation across unrelated labels to confirm REGEXP semantics (not just
substring/glob matching).

Flagged by cross-vendor paired review (claude-opus + codex-gpt-5.6-sol) on
PR #3971.

Agent-Signature: claude-sonnet-medium on behalf of matt wilkie

* chore: drop contributor release-gate artifact from PR

release-gates/be-ucslk4-dolt-ship-gate.md is a contributor-process artifact
that doesn't belong in the upstream tree.

Flagged by cross-vendor paired review (claude-opus + codex-gpt-5.6-sol) on
PR #3971.

Agent-Signature: claude-sonnet-medium on behalf of matt wilkie

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: matt wilkie <maphew@gmail.com>
2026-07-24 00:17:02 -07:00
Jim Wordelman
9b3a5c8f9f
cmd: add --mem-profile flag and BEADS_MEM_PROFILE env var (be-tg2o) (#3920)
* feat(cmd): add --mem-profile flag and BEADS_MEM_PROFILE env var (be-tg2o)

Adds heap profiling parity with the existing --profile (CPU) flag:
- --mem-profile FILE writes a pprof heap snapshot on exit
- BEADS_MEM_PROFILE=FILE env var fallback for scripting
- BEADS_MEM_PROFILE_NOGC=1 skips the pre-write GC to capture peak allocation
- BEADS_MEM_STATS=FILE writes a one-line HeapAlloc/HeapSys/HeapInuse/HeapObjects summary

Documents all four knobs in docs/CONFIG.md §Profiling.

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

* docs(cli): regenerate CLI_REFERENCE.md for --mem-profile

CI's "Check doc flags freshness" job failed because the new
--mem-profile global flag added in d05741f10 wasn't reflected in
docs/CLI_REFERENCE.md. Regenerated via:

  ./scripts/generate-cli-docs.sh ./bd

Diff is the single new flag line; website CLI reference pages
already line up so no further changes needed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(cli): drop --mem-profile line from CLI_REFERENCE.md (pinned-generator policy)

CI's "Check doc flags freshness" builds bd from the release pin in
docs/cli-docs.pin (currently v1.1.0) to regenerate docs/CLI_REFERENCE.md,
not from this branch's HEAD. v1.1.0 predates --mem-profile, so the pinned
generator's output omits the flag line and flags this branch's copy as
stale relative to it. Remove the line now; it will reappear automatically
once the pin advances past a release that includes --mem-profile.

Agent-Signature: claude-sonnet-medium on behalf of maphew

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: matt wilkie <maphew@gmail.com>
2026-07-24 00:04:59 -07:00
Jim Wordelman
bc9d854ebb
feat(stats): --no-blocked flag skips blocked-count computation; fix Blocked:0 red render (be-nnqp, be-4b63) (#4022)
* feat(stats): add --no-blocked flag; fix Blocked:0 red render (be-nnqp, be-4b63)

- types.go: BlockedIssues int → *int (nil when --no-blocked skips computation)
- storage: add FastStatisticsStore interface + GetStatisticsNoBlocked to DoltStorage;
  implement in DoltStore and EmbeddedDoltStore (ScanIssueCountsInTx only, no blocked traversal)
- status.go: --no-blocked flag (no short alias), BlockedCountSkipped bool in StatusOutput;
  fast path calls GetStatisticsNoBlocked; human output renders "(skipped)" in muted style
- be-4b63: Blocked:0 now renders plain text; only Blocked:N>0 uses RenderFail (red)
- nil-guard BlockedIssues callers: getAssignedStatistics, status_test.go, queries_test.go,
  examples/library-usage/main.go

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

* docs(cli): regen CLI reference for `bd status --no-blocked`

Regenerates docs/CLI_REFERENCE.md and the website CLI reference pages
(`website/docs/cli-reference/status.md` and the version-1.0.0 / 1.0.4
snapshots) from the live `bd help` output so the doc-flags freshness
check passes.

Picks up the new `--no-blocked` flag, the updated `--no-activity`
description ("Skip git activity summary"), and the matching example
lines added in ddf53438c.

Fixes the CI "Check doc flags freshness" failure on PR #4022.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: release gate PASS for be-nnqp+be-4b63 (bd stats --no-blocked)

* fix(stats): ReadyIssues *int, data-derived skip render, proxied-server warning

Address the adjudicated cross-vendor review on PR #4022:

- internal/types.Statistics.ReadyIssues is now *int, mirroring BlockedIssues:
  nil when --no-blocked skips the computation (readiness needs the blocked
  set), populated by all three backends' full GetStatistics, by
  issueops.GetStatisticsInTx, and by buildAssignedStats. Left nil only in
  the *NoBlocked fast-path variants. JSON now emits `"ready_issues": null`
  instead of a fake 0 a CI consumer could misread as "nothing ready".
- renderStatus derives "(skipped)" rendering from the data itself
  (stats.BlockedIssues/ReadyIssues == nil) instead of the noBlocked flag,
  fixing the --assigned + --no-blocked contradiction where fully-recomputed
  stats were mislabeled as skipped. The noBlocked parameter is gone from
  renderStatus entirely; both call sites (status.go, status_proxied_server.go)
  simplified accordingly.
- Proxied-server mode now prints a one-line stderr warning when --no-blocked
  is passed but not honored, instead of silently discarding the flag; the
  flag's help string documents the limitation.

Agent-Signature: claude-sonnet-medium on behalf of maphew

* test(stats): cover GetStatisticsNoBlocked nil semantics and renderStatus skip branch

- internal/storage/dolt: new TestGetStatisticsNoBlocked_LeavesBlockedAndReadyNil
  asserts the --no-blocked fast path leaves BlockedIssues/ReadyIssues nil
  while the full GetStatistics path on the same store populates both.
- cmd/bd: new TestGetStatisticsNoBlocked (storage-level, same assertion via
  the CLI-facing store handle), TestRenderStatus_SkipJSONEmitsNullNotZero
  (asserts blocked_count_skipped:true plus literal `"blocked_issues": null`
  / `"ready_issues": null` in the JSON envelope),
  TestRenderStatus_SkipHumanRendersSkippedNotZero (asserts the "(skipped)"
  human branch renders for both fields), and
  TestRenderStatus_AssignedIgnoresSkipEvenWithNoBlockedFlag (guards the
  --assigned + --no-blocked fix: fully-populated stats never render
  "(skipped)").
- Update existing statistics assertions in
  internal/storage/conformance/audit_search-counts-stats.go,
  internal/storage/dolt/queries_test.go, and
  internal/storage/domain/db/ready_helpers*_test.go for
  ReadyIssues's int -> *int change.

Agent-Signature: claude-sonnet-medium on behalf of maphew

* docs(cli): drop --no-blocked doc lines from CLI_REFERENCE.md/status.md (pinned-generator policy)

CI's "Check doc flags freshness" job builds bd from the release pin in
docs/cli-docs.pin (currently v1.1.0) to regenerate docs/CLI_REFERENCE.md
and docs/cli-reference/status.md, not from this branch's HEAD. v1.1.0
predates --no-blocked entirely, so the pinned generator's output omits
every --no-blocked reference (use case bullet, both example lines, the
flag description) and also reverts the --no-activity flag description
wording, flagging both files as stale relative to it. Same trap PR #3920
hit for --mem-profile.

Applied the exact patch CI generated and uploaded as the
cli-docs-freshness-patch artifact on the failing job
(run 30063539327 / job 89390739992) verbatim to both files; the lines
will reappear automatically once the pin advances past a release that
includes --no-blocked.

Agent-Signature: claude-sonnet-medium on behalf of maphew

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: matt wilkie <maphew@gmail.com>
2026-07-23 23:52:39 -07:00
Jim Wordelman
f596141325
fix(import): sync issue_prefix from config.yaml after import (be-llaf) (#4029)
* fix(import): sync issue_prefix from config.yaml after import (be-llaf)

After a PG-to-Dolt migration, the Dolt config table may retain a stale
issue_prefix from the old PG configuration. New issues created after
import would then receive the wrong prefix even though config.yaml has
the correct value.

store.Commit (GH#2455) deliberately excludes the config table. A second
CommitWithConfig call after the issues commit applies only when the YAML
and DB values diverge, making this intentional and targeted.

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

* test(import): add TestEmbeddedImport_PrefixSync for be-llaf prefix sync

Covers the new prefix-sync logic in cmd/bd/import.go:269-274: init with
--prefix bd (DB has issue_prefix=bd), overwrite config.yaml with
issue-prefix: be, run bd import, verify DB prefix updated to be.

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

* chore: release gate PASS for be-llaf (fix(import): sync issue_prefix)

* chore(import): hygiene fixes from adjudicated review (be-llaf)

- Drop release-gates/be-llaf-gate.md, a stale contributor-process
  artifact that predates the July rebase (pre-rebase SHAs, old line
  numbers, old CI run) and introduces a directory upstream doesn't
  have.
- Document the issue_prefix sync block's assumption: config.yaml is
  authoritative and existing issue IDs are intentionally left
  unchanged; this deliberately bypasses the `bd config set
  issue_prefix` guard for the import/migration flow and is not a
  rename.
- Add a negative subtest pinning the no-config-key no-clobber path:
  importing with a config.yaml that has no issue-prefix key leaves
  the DB's issue_prefix untouched.

Agent-Signature: claude-sonnet-medium on behalf of matt wilkie

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: matt wilkie <maphew@gmail.com>
2026-07-23 23:40:38 -07:00
matt wilkie
bb9bb74871
test: managed-local proxied lifecycle smoke lane (Linux, offline) (#5004)
* test: managed-local proxied lifecycle smoke lane (Linux, offline)

Every existing proxied CI shard fronts an externally managed Dolt
testcontainer, so a green proxied tier has never proven the production
local-first path: bd launching its loopback proxy, the proxy launching a
locally installed dolt sql-server, and that topology surviving idle
shutdown and transparent restart. This adds the first end-to-end lane for
exactly that path, test-only (no product behavior changes):

- cmd/bd/proxied_local_helpers_test.go: managed-local gate
  (BEADS_TEST_PROXIED_LOCAL=1; missing dolt FAILS rather than skips),
  managed init with a short idle window, pidfile/process/artifact
  inspection primitives, and a held-connection helper that pins the
  process tree up while it is inspected. Written for reuse by
  stale-artifact and process-identity lifecycle tests.
- cmd/bd/proxied_local_lifecycle_linux_test.go: the smoke test — init/
  create/read against the launched local process tree, loopback-only
  proof for both listeners (generated config.yaml AND live socket
  enumeration via /proc), idle shutdown observed, then transparent
  restart with persisted data.
- .github/workflows/proxied-local-smoke.yml: pins the Dolt CLI, builds
  online, then runs the test inside a loopback-only network namespace,
  proving the lifecycle needs no outbound network after installation.

Verified locally on Linux (dolt 2.2.0): plain run passes in ~21s; the
same test passes inside unshare -r -n with only loopback up; with dolt
removed from PATH the lane fails with a clear error instead of skipping.

Agent-Signature: claude-fable-5-high on behalf of matt wilkie

* test: make managed-local smoke fail closed

Agent-Signature: codex-gpt-5.6-sol-high on behalf of matt wilkie
2026-07-23 23:28:22 -07:00
Dustin Brown
9ffe6a7fc7
feat: support compact/gc/ping/dolt clean-databases in proxied-server mode (#5003)
* /{cmd,internal}: wip, missing compact

* /cmd/bd: add compact support

* /cmd/bd: add tests

* address Copilot review feedback on proxied maintenance commands

- gc: track Dolt GC failure; report "GC completed with errors", set
  JSON success=false, and exit non-zero instead of always printing "GC complete"
- gc: scalarCount handles []byte/uint64/float64 in addition to string/int64
- proxied_maintenance: use HandleErrorRespectJSON so --json callers get JSON errors
- clean-databases: fail loudly on rows.Scan error instead of silently skipping
- test: check fmt.Sscanf error in proxiedCommitCount

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(proxied): readonly guard + JSON parity for compact --dolt

Maintainer follow-ups to the proxied maintenance commands:

- runCompactDoltProxiedServer: enforce CheckReadonly("compact") on the
  non-dry-run path, matching the embedded dispatch in compact.go and the
  other proxied handlers (gc, admin compact).
- runCompactDoltProxiedServer: route the Dolt GC failure through
  HandleErrorRespectJSON so --json callers get a structured error,
  consistent with the rest of this PR's proxied paths.
- runCompactProxiedServer: emit remote_refs_pruned / tags_anchoring as
  arrays in --json output, matching the embedded compact_dolt.go schema
  instead of emitting counts under the same keys.

Agent-Signature: claude-fable-5-high on behalf of maphew

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: matt wilkie <maphew@gmail.com>
2026-07-23 22:42:02 -07:00
Marco Del Pin
30fa306b00
test(windows): make the cmd/bd and storage suites pass on Windows (#4809)
* test(windows): resolve the home dir via USERPROFILE

TestGetClaudePluginVersion and two TestDetectBootstrapAction_* cases override
HOME to point discovery at a temp dir, but the code resolves the home dir with
os.UserHomeDir(), which reads USERPROFILE on Windows and HOME elsewhere. Set
both so the tests are hermetic on every platform.

Agent-Signature: claude-code-opus-4.8-high on behalf of Marco Del Pin

* test(windows): use platform-absolute paths in fixtures

Two tests assert behavior gated on filepath.IsAbs but used the POSIX literals
"/absolute/path" / "/var/run/dolt.sock", which filepath.IsAbs reports as NOT
absolute on Windows (no volume) -- so the assertions were silent no-ops there.
Derive platform-absolute paths (t.TempDir()) instead. Affects
TestContextInfo_SaveStripAbsoluteDataDir and TestNewDatabaseServer_BackendExternal.

Agent-Signature: claude-code-opus-4.8-high on behalf of Marco Del Pin

* test: skip embedded hook-firing test on Windows (GH#3800)

The test writes an extensionless #!/bin/sh hook, which Windows CreateProcess
cannot execute (no shebang dispatch), so no payload is ever logged and the
assertions fail. Guard it with the same runtime.GOOS == "windows" skip already
used for this class in internal/hooks/hooks_test.go (GH#3800).

Agent-Signature: claude-code-opus-4.8-high on behalf of Marco Del Pin

* test: skip branch-tracking pull test when the dolt CLI is absent

TestPullWithAutoResolve_BranchTrackingFallbackSuccess builds its file:// remote
with the dolt CLI, so it hard-fails with "exec: dolt: executable file not found"
on hosts without the binary. Guard it with exec.LookPath, matching the existing
guards in this package (bootstrap_test.go, fsck_test.go). The store under test
speaks the MySQL protocol and needs no local dolt binary.

Agent-Signature: claude-code-opus-4.8-high on behalf of Marco Del Pin
2026-07-23 22:25:36 -07:00
matt wilkie
1fedd64456 docs(test): note the parity guardrail checks names, not wiring
The reflection guardrail proves a same-named plan field exists for every
createIssueParams field; it cannot see whether graphApplyNodeIssue passes
the field into its createIssueParams literal. Point at the full-field
round-trip as the wiring backstop so the guardrail's promise isn't
overread.

Agent-Signature: claude-fable-5-xhigh on behalf of matt wilkie
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-23 21:34:31 -07:00
matt wilkie
4103d985d1 fix(create): reject explicit plan ids that already exist
An explicit node id colliding with a stored issue slipped through plan
validation (which only caught intra-plan duplicates) into an insert path
with upsert semantics — the atomic graph create silently rewrote the
existing issue while reporting creation. The upsert behavior is inherited
(bd create --id does the same today), but plans mint ids in bulk, so the
exposure is much larger here.

Add an explicit-ID collision preflight to the shared plan validation:

- graphPlanConfig gains an issueExists probe; embedded supplies it from the
  store (GetIssue spans issues and wisps), proxied from the unit of work's
  per-table getters — bound to the caller's context, so the live proxied
  path probes inside the apply transaction and cannot race a concurrent
  create of the same id. Dry-run validates through the same probe.
- Deliberately not overridable by --force: that flag vouches for a foreign
  prefix, not for destroying existing data.

Also: reword the --mol-type rejection to point at the per-node mol_type
field (the old text claimed plans don't carry molecule semantics, which the
node field contradicts), and document the no-overwrite rule in the --graph
plan supplement.

Agent-Signature: claude-fable-5-xhigh on behalf of matt wilkie
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-23 21:33:38 -07:00
Dustin Brown
b9b4378942
bd sql (proxied-server): multi-statement batches and --database flag (#5002)
* maybe

* /{cmd,internal}: updates to bd sql proxied-server mode

* fix(sql): terminate line comments on CR and scope multi-statement help

Address Copilot review on #5002:
- topLevelStatementCount: `--` and `#` line comments now terminate on CR as
  well as LF, so CR-only line endings can't swallow following statements and
  undercount a batch.
- sql help text: scope the multi-statement batch semantics to proxied-server
  mode alongside --database.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 21:11:32 -07:00
matt wilkie
cecb1a0008 Merge upstream/main into feat/json-import-all-native-fields
Resolves the cmd/bd/create.go conflict with GH#4957 (global-ID prefix
validation): loadEmbeddedIDPrefixes now delegates prefix choice to
selectCreateIDPrefix, so the --global override applies to both the
single-create explicit-ID path (as on main) and the --graph plan
validation path (which shares the helper).

Agent-Signature: claude-fable-5-xhigh on behalf of matt wilkie
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-23 21:09:16 -07:00
ecuthiell
84da9d36a2
test(backup): split embedded effective-value cases (#4946) (#4947)
Keep SQL-server defaults and explicit backup overrides covered in every build. Move only the two embedded auto-detection cases into a CGO-tagged companion so non-CGO runs no longer assert an unavailable storage mode.

Agent-Signature: codex-tui-gpt-5.6-sol-ultra on behalf of Ewen Cuthiell
2026-07-23 18:25:16 -07:00
coffeegoddd☕️✨
2b43fcb408 fix(gate): address copilot review on proxied gate check
Derive the close audit's old status from the in-transaction before issue
(defaulting to open) instead of the pre-transaction evaluation snapshot,
so a status change between evaluation and commit cannot record a stale
old value. Matches close_proxied_server.go.

Drop the stale checkGHRun doc comment referencing the removed
persistDiscoveredRunID boolean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 14:23:13 -07:00
coffeegoddd☕️✨
0c26289138 fix(gate): address proxied gate check review feedback
Emit audit and hooks only after the write transaction commits, so a
serialization retry of the RunTxResult closure never doubles a
non-transactional side effect. proxiedGateClose now carries the old
status and reason for post-commit audit.

Close the read UOW before evaluating gates so no server transaction is
held open across external gh calls; bead-gate lookups ride a fresh
short-lived UOW via proxiedFreshReadGetter.

Fire on_update hooks for gates whose await_id was persisted from a
discovered run ID, matching the embedded hook-decorated store.

Skip re-closing a gate already closed in committed state.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 13:37:02 -07:00
coffeegoddd☕️✨
dfff1307d7 /cmd/bd: gate check support proxied-server mode 2026-07-23 12:57:16 -07:00
matt wilkie
d7b9f4fc52
Use Snappy output for Dolt garbage collection (#4986)
* Use Snappy output for Dolt garbage collection

Pass archive level 0 through every Beads-owned GC path so new table files use Snappy instead of zstd archives. Existing zstd archive decoding remains unchanged.

Refs #4249.

Agent-Signature: amp-unknown-model-unknown-reasoning on behalf of matt wilkie
Amp-Thread-ID: https://ampcode.com/threads/T-019f8d27-e480-774e-bd5a-7051e8e6e378

* fix(dolt-gc): gate archive_level on managed server auto-GC to avoid bricking older external dolt

Paired review on gastownhall/beads#4986 flagged that Beads-managed dolt
sql-server processes still auto-GC into zstd archives: the pinned Dolt
defaults background auto-GC to archive_level 1, and neither server-launch
path set auto_gc_behavior.archive_level: 0.

Both managed-server launch paths now set archive_level: 0 (auto-GC stays
enabled) when the resolved external dolt binary is new enough to support
the key:

- internal/storage/dbproxy/server (via cmd/bd/proxied_server.go's
  config.yaml generator) already wrote a YAML config; it now includes
  auto_gc_behavior when supported.
- internal/doltserver's legacy launcher previously used CLI flags only
  (-H/-P/--loglevel) with no YAML config at all — Dolt's own
  commandLineServerConfig.AutoGCBehavior() is a stub that hardcodes
  archive_level 1 regardless of flags, so CLI-flag mode can never express
  this. It now optionally switches to `--config <generated yaml>` (Dolt
  ignores all other sql-server flags once --config is present, so
  host/port/log-level move into the YAML alongside archive_level).

Both paths gate on internal/doltserver.SupportsArchiveLevelConfig, which
probes `dolt version` and fails closed (omits the key, keeps prior
behavior) on any parse/exec error. This matters because Dolt's YAML loader
uses yaml.UnmarshalStrict (servercfg/yaml_config.go): an older external
dolt binary whose own compiled-in YAMLConfig struct predates
auto_gc_behavior.archive_level (minver 1.52.1) would otherwise hit a hard
parse error and refuse to start, not silently ignore the key. Existing
config.yaml files are left untouched (only fresh bootstraps set the key).

Refs gastownhall/beads#4986.

Agent-Signature: claude-fable-5-high on behalf of matt wilkie
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(compact): fall back to plain dolt gc on older external dolt --archive-level rejection

Paired review on gastownhall/beads#4986 flagged that `bd compact --dolt`
shells out to the PATH `dolt` binary with no version guarantee, unlike the
in-process GC paths pinned by go.mod. Passing --archive-level 0
unconditionally meant an external dolt predating the flag would abort
compact with an unknown-flag error where plain `dolt gc` used to succeed.

runCompactDolt now retries with plain `dolt gc` when the first attempt's
combined output matches isUnknownArchiveLevelFlagError, printing a one-line
notice that the older dolt may still produce zstd archives. The classifier
is deliberately narrow (requires both an "unknown flag"-style phrase and
the archive-level flag name in the output) so a genuine GC failure is never
misclassified as a missing flag and swallowed — real failures still fail
compact as before.

Refs gastownhall/beads#4986.

Agent-Signature: claude-fable-5-high on behalf of matt wilkie
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(dolt-gc): replicate .doltcfg discovery in --config mode; memoize version probe

Delta review round 2 on gastownhall/beads#4986 flagged that the legacy
launcher's new --config mode silently drops Dolt's own .doltcfg discovery:
Dolt's setupDoltConfig (cmd/dolt/commands/sqlserver/sqlserver.go, pinned
module) returns immediately when --config is passed, so the parent
../.doltcfg lookup (privileges.db users, branch_control.db) that flag mode
performs never runs. A deployment previously run in CLI-flag mode that had
a parent .doltcfg would, once the resolved dolt becomes new enough to use
--config mode, silently fall back to a fresh $data_dir/.doltcfg: existing
users and branch controls abandoned, new passwordless root.

internal/doltserver.resolveCfgDir replicates Dolt's own flag-mode discovery
exactly (parent ../.doltcfg if present, else $data_dir/.doltcfg, error via
ErrMultipleDoltCfgDirs if both exist rather than guess) and Start() now
resolves it once per launch and writes it into the generated YAML's
cfg_dir. servercfg.YAMLConfig.CfgDirStr carries no minver tag in the pinned
module (i.e. always supported), so the existing 1.52.1 archive_level gate
stays as the single version gate for --config mode.

Also: filepath.Abs the --config path before exec (the child's cwd is the
data dir, matching the sibling dbproxy/server path's existing defensive
abs), and memoize SupportsArchiveLevelConfig per doltBin (sync.Map) so
Start()/UOW-provider creation does not re-fork `dolt version` on every
call within a process.

Refs gastownhall/beads#4986.

Agent-Signature: claude-fable-5-high on behalf of matt wilkie
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(dolt-gc): reconcile pre-existing managed configs on load; warn on custom ones

Delta review round 2 on gastownhall/beads#4986 flagged that pre-existing
config.yaml files bypass the archive_level plumbing in both directions: an
already-bootstrapped install's config.yaml silently keeps zstd auto-GC
forever (missing key never gets added without a manual regenerate), and a
config already carrying the key can hard-fail a later dolt downgrade via
yaml.UnmarshalStrict on an unrecognized key.

Fresh config.yaml renders now carry a one-line YAML comment marker
identifying them as Beads-managed (invisible to Dolt's own parser, which
treats it as a comment). ensureProxiedServerConfig uses the marker to
decide how to handle an existing default-path file:

  - marker present (Beads-managed): reconcile at load via
    reconcileManagedProxiedServerConfig, which parses the existing YAML
    into the servercfg structs, adds or strips auto_gc_behavior to match
    the current archive-level probe result, and re-renders — preserving
    every other field (including port) via the struct round trip rather
    than string surgery. A no-op when already aligned, so this costs
    nothing on the steady-state path.
  - marker absent (a pre-marker file from an older Beads version, or a
    genuinely user-supplied custom config path): never rewritten. Emits a
    one-line stderr warning instead, covering both directions (zstd may
    still be active with a hint how to opt in; or the file may cause a
    refuse-to-start on this dolt).

Refs gastownhall/beads#4986.

Agent-Signature: claude-fable-5-high on behalf of matt wilkie
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(dolt-gc): preserve sibling auto_gc fields, interpolate custom configs, write atomically

Verification review of the round-2 commits on gastownhall/beads#4986 found
three confirmed issues in cmd/bd/proxied_server.go:

- reconcileManagedProxiedServerConfig tested cfg.BehaviorConfig.AutoGCBehavior
  != nil (the whole block) instead of ArchiveLevel_ specifically. A managed
  config whose block carried only a user-set "enable" neither gained
  archive_level when the binary supported it, nor kept "enable" when the
  whole block was stripped on an unsupported binary. Now inspects and
  mutates only ArchiveLevel_, creating the block if needed to add it and
  removing it only if clearing archive_level leaves it completely empty.

- Validating a custom (env var / sidecar) config via servercfg.NewYamlConfig
  on raw bytes skips Dolt's own environment-variable interpolation
  (servercfg/env_interpolate.go, applied by YamlConfigFromFile before
  parsing) — confirmed by reading the pinned module source. A valid custom
  config using ${VAR}-style values was being rejected before the server
  ever started. ensureProxiedServerConfig and warnUnmanagedProxiedServerConfig
  now parse any unmanaged file (custom path, or a pre-marker default-path
  file) via YamlConfigFromFile; only a Beads-managed file, which never
  contains interpolation syntax, still uses the raw-bytes/NewYamlConfig
  path (inside reconcileManagedProxiedServerConfig).

- Reconciliation rewrote config.yaml with a truncating os.WriteFile, which
  could leave a partial file — blocking every future dolt sql-server
  start — if the process crashed mid-write. Both the reconcile-rewrite and
  the fresh-render write paths now go through the existing atomicWriteFile
  helper (temp file in the same directory, fsync, close, rename), already
  used elsewhere in cmd/bd for exactly this reason.

Tests: TestReconcileManagedProxiedServerConfig_PreservesSiblingFields
(all three directions requested by the review), and
TestEnsureProxiedServerConfig_CustomConfigEnvVarInterpolation.

Refs gastownhall/beads#4986.

Agent-Signature: claude-fable-5-high on behalf of matt wilkie
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(dolt-gc): resolve .doltcfg physically through symlinks; key version cache by file identity

Verification review of the round-2 commits on gastownhall/beads#4986 found
two more confirmed issues:

- resolveCfgDir computed the parent .doltcfg via filepath.Join(doltDir,
  "..", ...), which cleans ".." lexically without touching the filesystem.
  If doltDir is itself a symlink, that yields the symlink's own lexical
  parent directory, not the physical parent of whatever it actually points
  at. Reproduced directly: on Linux, chdir into a symlink makes the kernel
  track the process's cwd physically, so the real `dolt` child process's
  own "../.doltcfg" lookup (a bare relative path resolved against its
  actual, physically-tracked cwd) sees the PHYSICAL parent — diverging
  from the lexical one a naive Go-side filepath.Join would compute. A
  symlinked data directory could therefore miss the very parent .doltcfg
  this whole fix exists to find, re-abandoning existing
  privileges/branch-control. resolveCfgDir now resolves doltDir via
  filepath.EvalSymlinks (falling back to the lexical path on error) before
  computing the parent. TestResolveCfgDir_SymlinkedDataDirFindsPhysicalParent
  reproduces the exact layout and was confirmed to fail without the fix.

- SupportsArchiveLevelConfig's memoization cache was keyed by doltBin path
  alone, so an in-place dolt upgrade or downgrade at that same path kept
  the stale verdict for the rest of the process's lifetime. The cache key
  now includes size+mtime (archiveLevelCacheKey), falling back to an
  uncached probe when the binary can't be stat'd. The test that previously
  codified the staleness (rewriting the binary at the same path and
  asserting the cached result "sticks") is replaced with
  TestSupportsArchiveLevelConfig_MemoizesUnchangedBinary (same identity ->
  still cached, proven via an embedded call counter, not just the
  returned bool) and
  TestSupportsArchiveLevelConfig_InvalidatesOnFileIdentityChange (changed
  mtime -> re-probed).

Refs gastownhall/beads#4986.

Agent-Signature: claude-fable-5-high on behalf of matt wilkie
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(dolt-gc): preserve symlinked configs, field-level warn check, graceful degrade on hand-edited managed files

Verification review of the round-3 commits on gastownhall/beads#4986 found
three narrower issues, all in cmd/bd/proxied_server.go:

- atomicWriteFile's os.Rename destination does not follow a symlink — it
  replaces whatever is directly at that path. Reconciling (or freshly
  rendering) a managed config.yaml that was itself a symlink therefore
  silently replaced the symlink with a regular file at the same location,
  losing the indirection and orphaning whatever it pointed at. Both write
  call sites now resolve the target through filepath.EvalSymlinks first
  (resolveConfigWriteTarget), falling back to the given path when it does
  not exist yet (which also covers a dangling symlink — self-healed by
  writing directly at its location). Test:
  TestEnsureProxiedServerConfig_ManagedConfigBehindSymlinkPreservesSymlink
  reconciles a config.yaml symlink and asserts the symlink itself survives
  while the physical target gets the reconciled content; confirmed it
  fails without the fix (reverted, watched fail, restored).

- warnUnmanagedProxiedServerConfig tested cfg.AutoGCBehavior() != nil (the
  whole block), not archive_level specifically — the same bug the
  reconciler had before round 3, now applied to the warn path. An
  enable-only custom config missed the zstd-risk warning on a capable
  binary and got a false incompatibility warning on an incapable one. Now
  goes through the same field-level check via a new autoGCArchiveLevelIsSet
  helper (type-asserts to the concrete *servercfg.YAMLConfig the pinned
  module's loaders always return, falling back to the block-level check if
  that assertion ever fails). Test:
  TestWarnUnmanagedProxiedServerConfig_EnableOnlyFieldLevel covers both
  directions.

- A managed file's marker only proves Beads generated it ORIGINALLY, not
  that it hasn't been hand-edited since (e.g. a ${VAR} placeholder added
  by an operator). reconcileManagedProxiedServerConfig's raw-bytes parse
  is deliberately non-interpolating, so that now fails to unmarshal.
  Verified the prior behavior first: that parse error propagated as a
  hard error out of ensureProxiedServerConfig, which
  newManagedProxiedServerUOWProvider (cmd/bd/uow_factory.go) returns
  directly — aborting the ENTIRE bd command before ever attempting to
  start the managed server, even though a real dolt process would happily
  interpolate and start against the same file. Now degrades gracefully:
  logs a one-line warning and falls through to the same
  warn-only/never-rewrite treatment as an unmanaged file. Test:
  TestEnsureProxiedServerConfig_ManagedFileWithPlaceholderDegradesGracefully.

Refs gastownhall/beads#4986.

Agent-Signature: claude-fable-5-high on behalf of matt wilkie
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* docs(backup): narrow atomicWriteFile's crash-safe claim instead of changing behavior

Verification review of the round-3 commits on gastownhall/beads#4986 noted
the "crash-safe" doc comment overstates: only the temp file's own contents
are fsynced (not the parent directory entry, so a crash between rename
and a directory fsync could still lose the rename on some filesystems),
and os.Rename's atomic-replace guarantee is a POSIX/Unix property, not
guaranteed on Windows. This helper has an existing caller
(saveBackupState) whose expectations should not change silently, so this
narrows the doc comment to state those caveats precisely rather than
strengthening the implementation. Also notes the symlink-replacement
behavior a caller needs to know about, pointing at
cmd/bd/proxied_server.go's resolveConfigWriteTarget for a case that
resolves the physical target first.

No behavior change.

Refs gastownhall/beads#4986.

Agent-Signature: claude-fable-5-high on behalf of matt wilkie
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-23 08:55:29 -07:00
matt wilkie
3d0031aadf
fix(create): validate global IDs against global prefix (#4957)
* fix(create): validate global IDs against global prefix

Select the opened global store's issue prefix for explicit global IDs while retaining YAML-first validation for ordinary project creates. Add precedence and shared-server integration regressions.

Agent-Signature: codex-gpt-5.6-sol-high on behalf of matt wilkie

* test(create): make global-prefix regression test actually exercise #4646

Write issue-prefix=proj0 into config.yaml explicitly after `bd init`,
since non-no-db init stores the prefix in the DB, not config.yaml (the
generated file only carries a commented `# issue-prefix: ""`). Without
this, the config.yaml assertion always failed when a Dolt container is
available, and the create/show regression steps passed on both patched
and unpatched code because config.GetString("issue-prefix") was empty
in the --global path either way. With config.yaml populated, unpatched
selectCreateIDPrefix would incorrectly prefer the project's YAML prefix
over the global store's prefix even in --global mode, and ID validation
would reject the global ID - so the test now actually guards #4646.

Also replace the hardcoded "global-explicit" prefix literal with
doltserver.GlobalIssuePrefix + "-explicit" to stay coupled to the
constant.

Agent-Signature: claude-fable-5-high on behalf of matt wilkie
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-22 21:48:49 -07:00
matt wilkie
eb266f9db4
fix(plugin): make command argument hints strings (#4969)
Normalize every shared command argument-hint to an explicit YAML string and enforce the schema across LF and CRLF checkouts so Copilot plugin skills load reliably.

Agent-Signature: codex-gpt-5.6-sol-high on behalf of matt wilkie
2026-07-22 21:48:45 -07:00
matt wilkie
418c94b839
feat(setup): redirect beads block to AGENTS.md when CLAUDE.md is a stub (#4838)
* feat(setup): redirect beads block to AGENTS.md when CLAUDE.md is a stub

When CLAUDE.md is a thin pointer that imports AGENTS.md via the
@-include convention (e.g. "@AGENTS.md" on its own line), bd setup claude
now writes the managed BEADS INTEGRATION block to AGENTS.md instead of
duplicating it in the stub. This supports the shared-authoritative-file
pattern used by repos that keep AGENTS.md as the single source of agent
instructions.

The redirect applies to install, check, and remove operations. If
AGENTS.md does not exist, the fallback behavior (writing to CLAUDE.md)
is preserved.

Agent-Signature: amp-gpt-5.4-2026-03-05-high on behalf of maphew

* fix(setup): strip stale CLAUDE.md beads block when AGENTS.md redirect activates

An older bd could have written a beads-managed block directly into CLAUDE.md
before a project adopted the "@AGENTS.md" import-stub pattern; once the
redirect to AGENTS.md activates, that block became an orphaned duplicate that
neither install nor remove ever cleaned up. installClaude now strips a stale
block from CLAUDE.md when the redirect is active (preserving the rest of the
stub), and removeClaude strips it too, alongside removing the AGENTS.md copy
as before.

Agent-Signature: claude-fable-5-high on behalf of matt wilkie

* fix(setup): gate CLAUDE.md strip on successful AGENTS.md injection; preserve shared AGENTS.md block on remove

Addresses two major findings from PR #4838 review:

- installClaude stripped the stale CLAUDE.md beads block whenever the
  AGENTS.md redirect was active, even when installAgents skipped injection
  (e.g. AGENTS.md is a symlink). That deleted the only copy of the beads
  block without writing a replacement. Gate the strip on
  `redirected && !agentsSkipped`.

- removeClaude with the redirect active called removeAgents against
  AGENTS.md, deleting the project-authoritative shared beads section that
  bd init/other agents' setup created and other agents rely on. Limit the
  redirected remove path to stale CLAUDE.md cleanup and leave the shared
  AGENTS.md section intact.

Also addresses minor finding: isAgentsImportStub now also accepts the
`@./AGENTS.md` relative-import form, not just `@AGENTS.md`.

Deferred (minor, ambiguous product intent, needs maintainer input rather
than a guess): blank AGENTS.md gets ProfileMinimal on redirect; whether it
should get the full profile instead is a product decision, not a bug fix.

Added regression tests: TestInstallClaudeRedirectSkipsStripWhenAgentsSymlink,
TestRemoveClaudeRedirectPreservesFullProfileSharedBlock; updated
TestRemoveClaudeRedirectsToAgentsMD and
TestRemoveClaudeRedirectCleansStaleClaudeBlock to assert the shared AGENTS.md
block is preserved on remove; added an @./AGENTS.md case to
TestIsAgentsImportStub.

Agent-Signature: claude-fable-5-high on behalf of matt wilkie
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-22 21:28:53 -07:00
matt wilkie
5659478f56
fix(update): warn on stderr when --notes overwrites existing notes (#4743)
* fix(update): warn on stderr when --notes overwrites existing notes

Agent fleets treat notes as an append-only audit surface; a bare --notes
silently wiped it (GH#4541). Warn (never block, stderr only so --json
stdout stays clean) when --notes discards non-empty differing notes;
point at --append-notes. Regenerated CLI docs for the help-text change.

Fixes #4541

Agent-Signature: claude-fable-5-high on behalf of maphew

* fix(ci): quiet gosec G705 on notes-overwrite warning, un-drift pinned CLI docs

golangci-lint flagged the new stderr warning in warnNotesReplacement as a
gosec G705 (XSS via taint) false positive; every other stderr/stdout
warning sink in cmd/bd carries the same nolint annotation, so match that
convention here.

Separately, docs/CLI_REFERENCE.md and docs/cli-reference/update.md were
hand-edited (in the original notes-warning commit) to describe the new
--notes Usage text before docs/cli-cli-docs.pin existed. Generated CLI
docs are now pinned to the released bd (v1.1.0), which predates this
still-unreleased flag-text change, so the committed docs must keep
matching the pinned build until the pin is bumped at the next release.
Regenerated via ./scripts/generate-cli-docs.sh to revert the two lines
back to the pinned output.

Agent-Signature: claude-fable-5-high on behalf of matt wilkie
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-22 21:27:39 -07:00
matt wilkie
f73831e4b6
fix(import): allow children of deleted parents (#4964)
Skip auxiliary child-counter reconciliation when the routed parent row is absent, while preserving orphan children and propagating real routing or lookup errors.

Agent-Signature: codex-gpt-5.6-sol-high on behalf of matt wilkie
2026-07-22 21:20:37 -07:00
matt wilkie
0368903467
fix(import): preserve bare cross-prefix dependencies (#4963)
Classify dependency targets by issue prefix during two-phase bulk persistence so exported cross-rig edges are restored as external references instead of silently skipped.

Agent-Signature: codex-gpt-5.6-sol-high on behalf of matt wilkie
2026-07-22 21:20:30 -07:00
matt wilkie
a96c1cd4ca
fix(dep): allow matching explicit parent edges (#4956)
Permit parent-child dependencies that match a dotted issue's immediate parent while retaining hierarchy deadlock guards for blocking edges and higher ancestors. Share the rule across direct, bulk, link, and proxied paths and add focused regressions.

Agent-Signature: codex-gpt-5.6-sol-high on behalf of matt wilkie
2026-07-22 21:20:23 -07:00
matt wilkie
4baf3adfed
fix(config): honor disabled Dolt auto-start (#4955)
Prevent config apply from starting a shared Dolt server when the environment or workspace config marks it externally managed. Cover both policy sources in normal and dry-run reconciliation.

Agent-Signature: codex-gpt-5.6-sol-high on behalf of matt wilkie
2026-07-22 21:20:17 -07:00
matt wilkie
ce728d04ce
fix(init): use server-aware diagnostics (#4954)
Route init-time database checks through one shared store so server-mode projects do not require a local .beads/dolt directory. Add a server-backed regression for the successful no-local-directory case.

Agent-Signature: codex-gpt-5.6-sol-high on behalf of matt wilkie
2026-07-22 21:20:10 -07:00
matt wilkie
25441326a9
fix(setup): migrate legacy Codex session hook (#4953)
Recognize the exact historical bd-prime SessionStart pipeline, remove only that nested command, preserve unrelated hooks, and report the legacy-plus-canonical state as stale.

Agent-Signature: codex-gpt-5.6-sol-high on behalf of matt wilkie
2026-07-22 21:20:04 -07:00