Compare commits

...
Sign in to create a new pull request.

47 commits

Author SHA1 Message Date
Julian Knutsen
af9d553565 release: prep v1.3.2-rc.1
RC bump per RELEASING.md "Cut an RC", cut on hotfix/1.3.1. That branch is
the v1.3.1 tag plus the hotfix CI-trigger port (#7217) and the v1.3.2
backports (#7041 and #7044, via #7220).
./scripts/update-versions.sh 1.3.2-rc.1 stamps version.go, the plugin
manifests, marketplace.json, npm package.json, the MCP
pyproject/__init__/uv.lock (1.3.2rc1), default.nix, the .githooks markers
and the winres strings. The PE numeric fields stay at the 1.3.2 base.
./scripts/check-versions.sh is green at 1.3.2-rc.1.

CHANGELOG: a dated [1.3.2-rc.1] section with:
- an upgrade note for #7037: after upgrading from bd <=1.3.0, run
  `bd recompute-blocked` once per workspace, with the reason (migration
  0059 vs dolthub/dolt#11886 on Dolt < 2.4.0 and on the embedded engine)
- Fixed entries for #7031/#7041 and #7032/#7044
- a CI entry for #7148/#7198/#7217
[Unreleased] stays empty.

cmd/bd/info.go: a 1.3.2-rc.1 digest at index 0 of versionChanges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 04:25:26 +00:00
Rongjun GENG
711d238b96 fix(backup): anchor watermark before snapshot (#7044)
Record the commit read before BackupToDir as the newest revision guaranteed
to be in the snapshot. A commit landing during sync then remains pending for
the next backup instead of being hidden by an advanced watermark.

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Rongjun GENG
(cherry picked from commit 874e2866ff)
2026-10-05 04:17:33 +00:00
Rongjun GENG
d9a09105bc fix(purge): preserve transitive live dependents (#7041)
Propagate sweep protection through closed candidates so an open descendant
keeps every candidate ancestor in its protecting dependency chain. Cover the
shared helper, dry-run, real sweep, and all storage contract wirings.

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Rongjun GENG
(cherry picked from commit 5db60f42ac)
2026-10-05 04:17:32 +00:00
Julian Knutsen
adf91f2dc0
Merge pull request #7217 from gastownhall/ci/hotfix-1.3.1-ci-trigger
[hotfix/1.3.1] ci: trigger pull_request CI on hotfix/** branches (port of #7198, adapted, not a cherry-pick)
2026-10-04 21:17:15 -07:00
Julian Knutsen
09e6397f1e ci(hotfix/1.3.1): install pinned golangci-lint instead of the disallowed action
Release-only adaptation; there is no main commit to cherry-pick. The repo's
allowed-actions policy does not list golangci/golangci-lint-action, so with
pull_request now triggering pr.yml on hotfix/** the whole workflow fails at
startup (startup_failure on PR #7217). main dropped the action in #7127
(bc19f6e47) and installs the pinned v2.10.1 release binary with
scripts/ci/install-golangci-lint.sh. This takes that script verbatim from
main (4b2852ce2) and keeps this branch's single Lint job, with
--new-from-rev set to the PR base in place of only-new-issues. Locally,
golangci-lint v2.10.1 --new-from-rev=origin/hotfix/1.3.1 reports 0 issues.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 03:36:31 +00:00
Rongjun GENG
97bfa4c149 ci: trigger pull_request CI on hotfix/** branches, not just release/** (#7148)
Hand port of #7198 (main 3c65c99c29) onto hotfix/1.3.1. NOT a clean
cherry-pick; adapted for this branch:

- conformance.yml and cross-version-smoke.yml: main added `paths:` filters
  that this branch does not have. Only the `branches:` line is changed here;
  the path filters are not brought over.
- CHANGELOG.md: the [Unreleased] entry is dropped. The next release-prep on
  this branch records it in its own section.
- scripts/ci_workflow_test.go: this branch has no readPolicyFile helper and
  no prRiskWorkflowName constant. The test reads the files with os.ReadFile
  and names pr-risk.yml literally. The assertions are unchanged.

The pull_request trigger is read from the PR's merge ref, so this has to be
on hotfix/1.3.1 itself before PRs into it (the v1.3.2 backports) run the
full CI and produce `CI Gate / Required`.

(ported from commit 3c65c99c29)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 03:31:24 +00:00
Julian Knutsen
c1c4b642ac
Merge pull request #7048 from gastownhall/release-prep/v1.3.1
release: prep v1.3.1
2026-09-30 13:47:52 -07:00
Gas City Adopt-PR
498742a275 release: prep v1.3.1
Promote v1.3.1-rc.2 to stable per RELEASING.md "Validate and promote", on
the same branch the RC validated (hotfix/1.3.1, rc.2 = 696e3967be).
./scripts/update-versions.sh 1.3.1 drops the -rc.2 suffix from version.go,
the plugin manifests, marketplace.json, npm package.json, the MCP
pyproject/__init__/uv.lock, default.nix, the .githooks markers and the
winres strings. ./scripts/check-versions.sh is green at 1.3.1.

CHANGELOG: a dated [1.3.1] section, following the [1.1.0] precedent: it
points at [1.3.1-rc.2] and [1.3.1-rc.1] for the full notes and says the
code is unchanged since rc.2. The rc sections are untouched.

cmd/bd/info.go: a 1.3.1 digest at index 0 of versionChanges.

No code changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 19:11:53 +00:00
Julian Knutsen
696e3967be
Merge pull request #6952 from gastownhall/release-prep/v1.3.1-rc.2
release: prep v1.3.1-rc.2
2026-09-29 09:37:58 -07:00
Gas City Adopt-PR
f83654b118 release: prep v1.3.1-rc.2
RC bump per RELEASING.md "Cut an RC", on the #6593 model, cut on
hotfix/1.3.1 (the owner's release branch for 1.3.1, cut from
release/1.3.0). ./scripts/update-versions.sh 1.3.1-rc.2 stamps version.go,
the plugin manifests, marketplace.json, npm package.json, the MCP
pyproject/__init__/uv.lock (1.3.1rc2), default.nix, the .githooks markers
and the winres strings; the PE numeric fields stay at the 1.3.1 base.
./scripts/check-versions.sh is green at 1.3.1-rc.2.

CHANGELOG: a dated [1.3.1-rc.2] section covers everything since
v1.3.1-rc.1: the five release/1.3.0 merges after rc.1 (#6653, #6659,
#6695, #6547, #6652) and the hotfix batches (#6582, #6584, #6694, #6883,
#6719, #6740+#6771, #6563+#6627, #6499, #6744, #6879, #6932-#6935,
#6937, #6938, #6942). Entries parked under [Unreleased] and the post-rc.1
additions inside [1.3.1] move into it, with an upgrade-notes list of the
behaviour changes. The two #6716 bullets are merged into one, the #6584
paragraph that said auto-backup was not wired now defers to the #6879
entry, and #6499, #6563/#6627 and #6547 get entries. The section rc.1
shipped as [1.3.1] is renamed [1.3.1-rc.1] with its body byte-identical to
the v1.3.1-rc.1 tag, following the [1.1.0-rc.N] precedent; the final
1.3.1 prep creates [1.3.1]. [Unreleased] stays empty.

cmd/bd/info.go: a 1.3.1-rc.2 digest at index 0 of versionChanges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 16:08:20 +00:00
Julian Knutsen
655dc0827d
Merge pull request #6947 from gastownhall/hotfix/1.3.1-batch4
hotfix/1.3.1: batch 4 — #6942 (hand port: proxied/uow + remaining routes blocked recheck)
2026-09-29 03:46:24 -07:00
Julian Knutsen
4b49bf2e80 fix(storage): recheck blocked state after commit on the proxied (uow) path and the remaining store routes (#6942)
Extends #6719's post-commit blocked-state recheck (gastownhall/beads#6716) to
every write runner #6719 left uncovered:
- the proxied (uow) write path: every proxied CLI write, bd batch when
  proxied, and bd serve;
- DoltStore.RunInTransaction. It also settles when the regular SQL commit
  lands and only the Dolt commit after it fails (ErrCommitIndeterminate);
- the raw-transaction wisp update, close and delete writers;
- both arms of RemoveDependencyWithOptions;
- the domain/db recomputes that bypassed issueops.
The recording shapes are shared issueops Note* helpers. A failed recheck is
reported through issueops.ReportBlockedRecheckFailure (the
bd.db.blocked_recheck_dropped counter plus a warning) and never returned.

Regression tests fail on main and pass here: a deterministic proxied uow
race in six shapes, RunInTransaction and concurrent wisp-close races,
sqlmock phase tests for the indeterminate commit, and a proxied CLI fan-in
test that runs concurrent `bd close` processes and then checks `bd ready`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit cda2407115)

Hand-ported to hotfix/1.3.1, per the #6942 review (section 5). The code
hunks are unchanged; every conflict came from main-only context:
- Versioned-history scope. It does not exist on the release line. Main's
  context installs ScopeVersionedHistoryTransaction/clearVersionScope/
  releaseVersionScope in internal/storage/dolt/dependencies.go (2 places),
  dolt/transaction.go (runDoltTransactionRecording),
  uow/dolt_sql_provider.go (BeginTx) and uow/doltserver_tx.go (struct,
  releaseConn, poisonConn, release helpers). Resolved by keeping the release
  code without those lines and adding only the blocked-recheck-scope lines.
  In dolt_sql_provider.go the release line keeps its journal-only comment
  wording, extended with the recheck-scope sentence.
- Close label. On the release line, issueops/close.go records with
  noteBlockedRecheck(tx, "close of "+id, ...), the label from the #6719 hand
  port. It now calls NoteStatusChangeBlockedRecheck, which produces the same
  "close of <id>" label through statusChangeRecheckLabel.
- BUILD.bazel (cmd/bd, dolt, issueops, uow) and
  dolt/version_scope_completeness_test.go do not exist on the release line
  and are dropped.
- CHANGELOG.md: the release CHANGELOG is kept. This entry is added verbatim
  before the #6716 entry from the #6719 port, and that entry's list of
  uncovered routes now points at this entry, as on main.
No schema change. go build ./... and go vet (internal/storage, cmd/bd) are clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 10:09:34 +00:00
Julian Knutsen
0cba03281c
Merge pull request #6945 from gastownhall/hotfix/1.3.1-batch3
hotfix/1.3.1: batch 3 — #6932, #6934, #6935, #6933 (hand), #6937 (hand), #6938
2026-09-29 02:55:09 -07:00
Julian Knutsen
b4d81fdf5b fix(beads): make an explicit BEADS_DIR authoritative during discovery (#6938)
* fix(beads): make an explicit BEADS_DIR authoritative during discovery

FindBeadsDir ignored a BEADS_DIR that did not hold project files yet
(missing, empty, or uninitialized) and walked up from the current
directory instead. PersistentPreRun then rebound BEADS_DIR to whatever
ancestor workspace the walk found, so:

- `bd init` refused with "already initialized" because of the parent
  workspace instead of initializing the named directory;
- data commands (`bd list`, `bd create`, ...) read and wrote the
  parent's store.

FindBeadsDir now returns "" for such a BEADS_DIR, matching
FindDatabasePath, which already refused to fall back. Commands that
create a workspace (import/setup default path, bootstrap's
fresh-clone synthesis) target the named directory via the new
beads.ExplicitBeadsDir helper instead of CWD. Behaviour with BEADS_DIR
unset is unchanged.

Tests: FindBeadsDir unit cases (missing/empty/non-project BEADS_DIR,
initialized BEADS_DIR, unset BEADS_DIR still walks up), and a bd
subprocess regression in embedded and proxied-server modes (init under
an initialized parent, list refuses, create lands in the new store).

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

* docs(changelog): note that BEADS_DIR at a project root now errors

Review follow-up for the explicit-BEADS_DIR fix: call out the behaviour
change for BEADS_DIR pointing at a project root (or a not-yet-created
.beads), which previously worked only because discovery walked up.

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

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 51a7c8e324)

hand-resolved: CHANGELOG entry placed under the hotfix's [Unreleased] ### Fixed; cmd/bd/BUILD.bazel and internal/beads/BUILD.bazel dropped (no Bazel on hotfix/1.3.1). Go code applied unchanged.
2026-09-29 09:29:33 +00:00
Julian Knutsen
b2faf48e84 fix(dbproxy): retire the proxy when its Dolt backend exits cleanly (#6937)
* fix(dbproxy): retire the proxy when its Dolt backend exits cleanly

DoltServer supervised `dolt sql-server` with cmd.Wait inside an
errgroup, and Running read the errgroup context. errgroup cancels that
context only for a non-nil result, so a backend that shut down
gracefully (dolt exits 0 on SIGTERM) was reported as running forever.
The proxy's backend health watcher never fired: the proxy stayed up and
adoptable in front of a dead store. With --proxied-server-idle-timeout 0
(the setting Gas City uses) it never went away; `bd dolt status` said
"running" and every command, `bd ping` included, failed until
`bd dolt stop`.

The supervising goroutine now reports a clean exit as errBackendExited,
so Running flips on any backend exit and Stop treats it as benign. This
follows the existing proxied lifecycle contract (child death retires
the owned proxy; the next bd invocation starts a fresh proxy/backend
pair) rather than adding in-proxy restarts: spawn, adoption, stop
epochs and identity already live in the on-demand start path, and a
second restart loop inside the proxy would duplicate that and could
mask a crash-looping backend.

`bd dolt status` no longer headlines a proxy whose managed backend is
gone as "running"; it says the proxy is up but not serving and points
at `bd dolt stop` (for proxies from an older bd). The JSON payload is
unchanged. `bd ping` already verifies by running SELECT 1 through the
proxy, so after this fix a successful ping reflects a live pair.

Tests: DoltServer Running goes false after SIGTERM (clean exit) and
SIGKILL, and Stop succeeds; managed-local lane test that SIGTERMs the
backend with idle timeout 0 and requires the proxy to retire and
`bd ping --json` to succeed on a fresh pair; status render case.

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

* fix(dolt status): report running=false for a proxy over a dead managed backend

Review follow-up: the JSON running field now means "serving" (a live proxy
and, on a managed topology, a live dolt behind it), so scripts that key off
running alone are not fooled by a stranded proxy left by an older bd.
proxy_pid/proxy_port and backend_* are unchanged. Adds the PR link to the
CHANGELOG entry.

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

* docs(changelog): resolve merge markers left by the origin/main merge

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

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit d803ec9126)

hand-resolved: .github/workflows/proxied-local-smoke.yml: the hotfix's lifecycle-test list differs in order and content, so TestManagedLocalProxiedBackendCleanExitRetiresProxy was appended to the hotfix list. CHANGELOG entry placed under the hotfix's [Unreleased] ### Fixed; cmd/bd/BUILD.bazel and internal/storage/dbproxy/server/BUILD.bazel dropped (no Bazel on hotfix/1.3.1).
2026-09-29 09:26:52 +00:00
Julian Knutsen
e25e5a71d3 fix(show): support bd show --watch under --proxied-server (#6933)
bd show --watch was refused in proxied-server mode (proxy.watch.unsupported). The direct and proxied routes now share one watch loop (2s poll, redraw on id:status:updated_at change, SIGINT/SIGTERM stop); the proxied route opens a short read per render/poll. A missing id now exits 1 on both routes, and failed polls keep the last render quietly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 5ac483bc75)

hand-resolved: cmd/bd/proxy_capability.go: the hotfix front door keys on cmd.Name(), not commandRegistryPath; dropped its show --watch refusal block and kept the hotfix's ready block unchanged. cmd/bd/show_proxied_server.go: took main's side (in-runner watch refusal removed). cmd/bd/proxy_capability_test.go: took main's newProxyFrontDoorCommand and create/--repo front-door tests; kept both the hotfix's TestProxyCapabilityRefusalDoesNotNeedProvider and main's TestProxyFrontDoorAdmitsShowWatch. CHANGELOG entry placed under the hotfix's [Unreleased] ### Fixed; cmd/bd/BUILD.bazel dropped (no Bazel on hotfix/1.3.1).
2026-09-29 09:23:59 +00:00
Julian Knutsen
a8e5ccfc10 fix(init): admit a server workspace whose .beads/dolt is empty so the version marker is written (#6935)
A server-mode workspace with an empty .beads/dolt and no .local_version was refused as a legacy workspace, blocking every command including bd init. An empty directory holds no legacy data, so the guard now admits it (server mode only); bd init writes the marker and an existing workspace in that state self-heals on its next command. Refs #5682.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit e3a12f4e5c)

hand-resolved: CHANGELOG entry placed under the hotfix's [Unreleased] ### Fixed; cmd/bd/BUILD.bazel dropped (no Bazel on hotfix/1.3.1). Go code applied unchanged.
2026-09-29 09:12:11 +00:00
Julian Knutsen
66c6a0c9b3 fix(types): one source of truth for issue types across bd types and create (#6934)
bd types and create validation now both resolve custom types through issueops.ComposeCustomTypes in every mode (direct, server, proxied). Server-mode bd types now includes config.yaml types, proxied config set storage-class accepts DB types, and bd types lists the system types (message, molecule, gate, event); JSON gains additive system_types. Custom-type read errors now fail instead of being swallowed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 2bb5337355)

hand-resolved: CHANGELOG entry placed under the hotfix's [Unreleased] ### Fixed; BUILD.bazel files dropped (no Bazel on hotfix/1.3.1). Go code applied unchanged.
2026-09-29 09:11:51 +00:00
Julian Knutsen
84e6faaa2d fix(sql): classify bd sql statements with the SQL parser; never drop result sets (#6932)
Proxied bd sql misclassified WITH [RECURSIVE] ... SELECT as a write and silently returned no rows; CALL result sets were dropped on both paths. Classify statements with the dolthub/vitess parser (internal/storage/sqlclass: Read/Write/Mixed); Mixed commits and renders any rows, so no path silently drops a result set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit c4b1cb699d)

hand-resolved: CHANGELOG entry placed under the hotfix's [Unreleased] ### Fixed; MODULE.bazel and BUILD.bazel files dropped (no Bazel on hotfix/1.3.1). Go code applied unchanged.
2026-09-29 08:47:51 +00:00
Julian Knutsen
dac1e6e91f
Merge pull request #6936 from gastownhall/hotfix/1.3.1-batch2
hotfix/1.3.1: batch 2 — #6719 (hand port), #6740+#6771, #6563+#6627, #6499, #6744, #6879
2026-09-28 22:49:26 -07:00
Gas City Adopt-PR
70867888ff test(release-1.3.x): drop dolt commit from the release-only direct-only refusal loop after #6499 [NOT a cherry-pick]
Release-only test adaptation. On main, TestHistoryDirectOnlyRefusalContract
iterates the keys of its expected map, so #6499 only had to delete the
"dolt commit" entry. The release copy (adapted in 2b27259cb4) iterates an
explicit path list instead, which the pick could not see. That list still
had "dolt commit", which #6499 now permits on the proxied route, so the test
read an empty refusal and failed:
  dolt commit refusal = "" (unexpected end of JSON input)
Seen in the nightly full-test and pr-linux runs dispatched on
hotfix/1.3.1-batch2. The only change is removing "dolt commit" from that list.
The refusal contract for every other path is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 05:20:09 +00:00
Gas City Adopt-PR
d15081d60e test(release-1.3.x): capability matrix expects proxied bd dolt commit to be honored after #6499 [NOT a cherry-pick]
Release-only test adaptation. cmd/bd/topology_capability_matrix_test.go
exists only on the release line (#6579 [release/1.3.0]); main has no copy,
so the #6499 pick could not update it. Its "dolt commit" row still expected
the proxy.dolt_commit.unsupported refusal on every proxied topology, which
#6499 removes (capability_registry.go: permitted("dolt commit")).

The row now expects HONORED on proxied topologies, matching the registry.
Before this change TestManagedLocalProxiedCapabilityMatrix failed on the
dolt commit cell, and every later refusal cell then reported "proxy started
for a refused command" because the honored commit had started the proxy.
No other expectation changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 04:10:59 +00:00
Julian Knutsen
48be70fb7e feat(backup): proxied auto-backup on managed-local, serialized with bd backup sync (#6879)
* feat(backup): run opted-in auto-backup on a managed-local proxied server

managed-local, and #6694 made `bd backup status` admit the remaining gap:
the proxied arm of PersistentPostRunE never called runPostRunAutoBackup,
so backup.enabled=true was inert on every proxied workspace. Close it.

The proxied arm now calls the auto-backup hook before it closes the
provider, under the direct arm's maintenance gate (strict --readonly,
`bd serve`, a migration freeze) plus previews. maybeAutoBackup picks a
backend for the command: the direct store as before, or the proxied
provider's RunNonTx seam, which `bd backup sync` already uses.

The proxied backend is honored exactly where `bd backup sync` is: the
"backup sync" capability row's rule for this workspace's topology, so
managed-local only. Auto-backup registers a server-side backup remote,
which on a server bd does not own is global to every client; an implicit
trigger must not get further than the explicit verb. It never opens a
provider of its own: a command that opened none (`bd dolt stop`) or
closed it (restore) backs nothing up rather than relaunching the server.
The default stays OFF, as on every server-mode workspace.

The register/sync-to-a-local-dir sequence that DoltStore and
EmbeddedDoltStore each carried a copy of moves to
versioncontrolops.BackupToDir (and HEAD lookup to CurrentCommit), so the
proxied backend reuses it instead of adding a third copy.

Tests: TestManagedLocalProxiedAutoBackup (default off, opt-in writes a
restorable backup, change detection, `bd dolt stop` stays quiescent,
restore round trip with issue-set equality; fails against origin/main);
TestManagedLocalProxiedBackupRestoreRefusedWhileAttached pins the restore
design (refused while another bd client holds the workspace, serving
child untouched, succeeds once it detaches); unit tests for the backend
locality gate, the post-run wiring, the status note and BackupToDir.
Both managed-local tests, and the existing round trip, are added to the
proxied-local smoke lane's compiled-in list.

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

* fix(backup): serialize auto-backup and bd backup sync with a workspace backup lock

Review follow-up on #6879. Auto-backup and an explicit bd backup sync
both run under the command's SHARED workspace gate, so nothing stopped
them overlapping, and auto-backup's remove -> add -> sync on one fixed
remote name races a concurrent copy of itself.

A per-workspace flock (.beads/backup.lock, already gitignored by
*.lock) now serializes them in every mode. Auto-backup takes it
non-blocking and skips when held (the throttle is left alone, so a
later command retries). bd backup sync waits up to exclusiveGateWait -
the bound restore's exclusive gate acquisition uses - then fails with
"another backup is running for this workspace" before touching the
store. Restore needs no part in it: its exclusive workspace gate
already excludes every command that could hold the lock.

Tests: lock semantics (refusal while held, bounded wait, release),
auto-backup skipping while held and running once released, and sync
failing loudly without reaching the store.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 4e4ebdb443)

Hand-resolved for hotfix/1.3.1:
- cmd/bd/BUILD.bazel: does not exist on the release line (no Bazel build
  there); the file is dropped, as in #6905.
- .github/workflows/proxied-local-smoke.yml: the release lane list differs
  from main (it has CapabilityMatrix and BackupRoundTrip, lacks
  TrackerUOWConformance). Kept the release list and appended this commit's
  two new tests, AutoBackup and BackupRestoreRefusedWhileAttached
  (BackupRoundTrip was already listed). The backup*.go path-filter hunks
  applied cleanly.
- CHANGELOG.md: context-only conflict. The release CHANGELOG is kept and
  this commit's two Unreleased/Added entries are inserted verbatim before
  the bd purge entry, where main places them.
No code hunk needed changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 03:54:30 +00:00
Harry Miller
4d512abbc2 fix(query): apply bd list's piped-output limit policy to bd query (#6229) (#6744)
* fix(query): apply bd list's piped-output limit policy to bd query (#6229)

Root cause: bd list resolves an unflagged --limit through a policy that
treats piped stdout as unlimited (GH#4094), but bd query read its --limit
flag straight through, so its default of workapi.DefaultQueryLimit (50)
applied to piped output too. `bd query '...' | consumer` silently dropped
every row past 50; the truncation hint did not fire either, because it only
prints when stderr is a terminal.

Fix: factor the unflagged tail of bd list's policy into unflaggedLimit /
resolveUnflaggedLimit in list_input.go and call it from both commands, so
they cannot drift. bd list's switch is unchanged in behavior; bd query's
change is a single localized branch in gatherQueryInput.

Precedence for bd query, mirroring bd list:
  1. explicit --limit (including 0) wins
  2. piped stdout -> 0 (unlimited)
  3. agent mode on a terminal -> 20
  4. otherwise the 50 default
bd list keeps its own --all and list.limit branches ahead of step 2; bd
query has neither (its --all means "include closed", and there is no
query.limit config key), so none was invented.

Agent-Signature: claude-code-opus-5-5-unknown-reasoning on behalf of Harry Miller
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* review: document the query path's absent defensive cap; unstale a reachability comment

Maintainer review fixes for PR #6744 (GH#6229). Both are comment-only; no
behavior changes.

issueops.QueryRequest.Limit now states that nothing backstops it. ListRequest
pairs its Limit with MaxRows, a circuit breaker for an oversized answer, and
neither knob that sets that one (--max-rows, BEADS_MAX_ROWS) is read anywhere
on the query path, so an unlimited query is unbounded in the plain sense. That
was already reachable via `--limit 0`; this PR makes a piped `bd query` reach
it without asking, which is what makes it worth writing down. Recording the
absence is the documented half of the reviewers' choice — threading a MaxRows
twin onto QueryRequest stays available as a follow-up.

unionCountsGoSideSortKeepsTheRightSubset's comment justified its case with
"DefaultQueryLimit means a limit is always set", which this PR falsified for
the CLI half: an unflagged piped `bd query '<expr>' --sort id` now arrives on
the IsGoSideSort path with Limit 0 and no bound. The HTTP surface still brings
a bound, because an absent `limit` parameter resolves to DefaultQueryLimit, so
the clause is requalified rather than dropped. The assertions were never
affected — they pass an explicit Limit: 5.

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

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
(cherry picked from commit 0e317c4fc0)

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 03:53:17 +00:00
Vishnu J
98d9675f5e fix: honor dolt.auto-commit in proxied server mode (#6499)
* fix(dolt): honor dolt.auto-commit=batch/off on the proxied-server write path (#4995)

In proxied-server mode every write minted a Dolt history commit whatever
dolt.auto-commit said. Two causes:

- cmd/bd/main.go never applied issueOpsContext(rootCtx) in the
  proxiedServerMode branch of the root pre-run, so the context carried no
  deferred-commit marker.
- internal/storage/uow/doltserver_tx.go: doltServerTx.Commit ignored
  issueops.VersionCommitDeferred(ctx) and ran CALL DOLT_COMMIT('-Am', ?)
  whenever a message was supplied.

Apply issueOpsContext to rootCtx in the proxied setup, and have
doltServerTx.Commit blank its message under a deferred context so the existing
plain-COMMIT branch persists the write to the working set without advancing
Dolt history. dolt.auto-commit=on is unchanged.

This commit alone strands batch/off writes in the working set; the explicit
flush point (`bd dolt commit`) follows in the later commits of this series.

(Originally recorded as "witness: salvage uncommitted work (ocb-ani)"; the
change itself is unmodified.)

* test(uow,cmd/bd): add regression tests for proxied dolt.auto-commit batch/off (#4995)

Add focused regression tests verifying that proxied dolt.auto-commit batch/off
defer Dolt version commits:
- cmd/bd: TestIssueOpsContextDefersByModeInProxiedServerMode verifies that
  issueOpsContext defers version commits in proxied-server mode when
  dolt.auto-commit is batch or off.
- internal/storage/uow: TestDoltServerTxCommitDefersDoltCommitUnderDeferredContext
  and TestDoltServerTxRunTxWithDeferredContextSkipsDoltCommit verify that
  doltServerTx.Commit blanks the commit message under a deferred context,
  bypassing DOLT_COMMIT and status checks, and executing plain COMMIT to
  persist writes into the working set without advancing Dolt history.

* fix(dolt): add the proxied flush point dolt.auto-commit=batch/off defers to (#4995)

The deferral half of this PR makes dolt.auto-commit=batch/off actually take
effect on the proxied-server write path. On its own that turns batch/off into
"never commit": proxied mode returns from the root pre-run before newDoltStore
runs, so getStore() is nil and `bd dolt commit` has no store to commit
through. Writes pile up in the sql-server working set where `dolt log`,
`dolt push` and backups never see them.

Add the missing half. cmd/bd/dolt_commit_proxied_server.go is the proxied dual
of `bd dolt commit`: it takes the uow.MaintenanceProvider route (RunNonTx) and
runs CALL DOLT_COMMIT('-Am', ?) on a pinned connection, gated on
issueops.HasPendingChanges. It deliberately does not go through
doltServerTx.Commit, which blanks its own message under the deferred context;
routing the flush through the deferral it exists to discharge would make the
flush a no-op. doltCommitCmd dispatches to it on usesProxiedServer(); the
message is built before the branch so both routes name the same default, and
the "Committed." / "Nothing to commit." contract is unchanged.

--dolt-auto-commit's help no longer claims proxied-server routes are
unaffected: it names the proxied flush point and keeps the SIGTERM/SIGHUP
flush marked embedded-only. docs/reference/configuration.md says the same.
`bd vc commit`'s proxied refusal now points at `bd dolt commit`.

Tests:
- cmd/bd/dolt_commit_proxied_integration_test.go: three batch writes leave
  dolt_log unchanged and stay readable, `bd dolt commit` advances it by
  exactly one, a second `bd dolt commit` reports "Nothing to commit." with
  dolt_log unchanged, and one write under --dolt-auto-commit on advances it
  by one. On the PR's original base it failed at the `bd dolt commit` step
  with "no store available". On current main the front door refuses the
  command before that code is reached, so this test is only green together
  with the next commit, which moves `dolt commit` to supported in the proxy
  capability registry.
- TestIssueOpsContextDefersByModeInProxiedServerMode renamed to
  TestIssueOpsContextDefersByModePolicyTable and the proxiedServerMode
  assignment dropped: issueOpsContext branches only on writesCommitNow(),
  never on the storage mode, so the old name over-promised.
- doltserver_tx_test.go: "bd: update bd-4995" -> "bd: update GH#4995", which
  no longer reads as a bead id.

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

* fix(proxy): move `dolt commit` from refused to supported in the capability registry

Main's proxy capability registry (added by #6269, 24a9da6cc) declares
`dolt commit` direct-only: it has a "proxy.dolt_commit.unsupported" refusal
in proxyMaintenanceRefusals (cmd/bd/proxy_capability.go) and is classed
HistoryDirectOnly in historyCapabilityMatrix (cmd/bd/history_capability.go).
The front door therefore refuses `bd dolt commit` in proxied-server mode
before dispatch, so the proxied dual added earlier in this series is
unreachable, and dolt.auto-commit=batch/off has no way to flush.

the history/VC front-door contract, and neither the registry, its tests nor
the docs explain why `dolt commit` was listed. Nothing on main implemented
`dolt commit` for the proxied route at the time, which is consistent with the
entry being a statement of what existed rather than a design decision.

This flips a capability main had declared unsupported, deliberately: the
proxied route now has an implementation (runDoltCommitProxiedServer), and
batch/off need it as their flush point (GH#4995).

Declared the same way as the other proxied-supported command,
`dolt remote remove`: HistoryProxySupported in the history matrix, and no row
in proxyMaintenanceRefusals.

Tests follow: history_capability_test.go moves `dolt commit` from the
direct-only assertions and refusal contract to the proxy-supported ones
(including the nested front-door pass-through), and
history_remote_frontdoor_matrix_test.go drops the refusal row and adds a
`dolt commit` pass-through check to TestHistoryRemoteSupportedFrontDoorParity.

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

* fix(proxy): exempt explicit commit points from the proxied deferral (#4995)

Maintainer review fixup for PR #6499, adopt-pr iterations 1-2.

Major (Contract & Interface Fidelity). The deferral is applied once, to
rootCtx, so it blanketed BOTH commit classes the direct route distinguishes by
which wrapper a verb picks: policy-honoring writes (transactHonoringAutoCommit,
per-verb issueOpsContext) and explicit commit points (transact, which passes
the caller's message whatever the policy says). Under dolt.auto-commit=batch a
proxied `bd batch -m "release batch"` therefore persisted the rows, discarded
the message and minted nothing, while the identical command and config on the
direct route committed it — and batch_proxied_server.go's own contract comment
rejects exactly that ("would persist these writes while silently bypassing
Dolt history"), as does batch.go's "the contract is the same on both backends".

issueops.WithImmediateVersionCommit clears the marker and cmd/bd's
explicitCommitPointContext applies it in the duals whose direct twin calls
transact. Scope is the intersection of the transact call sites with
proxyPermittedPaths: batch, mol bond/pour/squash, mol wisp create, and the
WISP half of mol burn (cook and migrate issues also call transact but are
refused in proxied mode, so they have no dual to exempt). The review sized the
radius at batch + 4 mol verbs; mol wisp create is the same class — its direct
twin reaches cloneSubgraph's transact through spawnMoleculeWithOptions — so it
is exempted with them.

Membership is per commit site, not per command (iteration 2). `bd mol burn` is
two classes on the direct route: wisps go through burnWisps -> transact, while
persistent molecules go through deleteBatch -> issueOpsContext ->
dolt/deleter.go, which returns before DOLT_COMMIT when the context defers.
Exempting the whole command minted one Dolt commit per persistent molecule
under batch/off — on a destructive verb, where the identical direct-route
command defers them all to `bd dolt commit`. runMolBurnProxiedServer now
applies the exemption to the wisp RunTxResult only, and the flag help,
configuration.md and the helper's own radius comment say so.

Minors:

- The flush passes '--author' like DoltStorage.CommitAll, so the one commit
  batch mode keeps is attributed to the bd actor rather than the SQL session
  user (without it dolt_log reads `root <root@localhost>`).
- runDoltCommitProxiedServer calls the shared runProxiedNonTx instead of
  re-implementing its provider checks, so `bd --json dolt commit` keeps the
  JSON error envelope; `dolt commit`'s RunE no longer re-wraps an
  already-reported failure, and runProxiedNonTx's message gains the provider
  %T the open-coded version had.
- The flag help and configuration.md drop two false claims: that the deferral
  covers "every write" in proxied mode (the bd serve plane over the same
  provider never touches rootCtx, so daemon writes still commit per write) and
  that the SIGTERM/SIGHUP flush is "embedded-only" (flushBatchCommitOnShutdown
  gates on an open store, which direct SQL-server mode has; only proxied mode
  lacks one). Both surfaces now name the explicit-commit-point exemption.
- Both user-facing enumerations of that exemption are now derived from the
  explicitCommitPointContext call sites rather than restated (iteration 2):
  they had omitted mol wisp create, listed mol burn wholesale, and implied a
  message-less `bd batch` defers when batch.go synthesizes a default message
  and the dual exempts unconditionally, so every proxied batch commits.
- doltserver_tx.go's ephemeral-form comment names its second entry point —
  RunTx/RunTxResult under a deferred context — where its
  ONLY-dolt_ignored-state rationale stops applying.

Not done: regenerating docs/CLI_REFERENCE.md. Its --dolt-auto-commit drift is
base-preexisting, and the generated CLI docs are built from the release tag
pinned in docs/cli-docs.pin, not from this source, so touching them converts
the drift gate's inherited-drift warn-pass into a failure.

Tests. The uow blanking table gains the immediate-commit arm (tagless, so it
runs in every lane); the proxied integration test gains an explicit-batch-commit
step with a deferred plain create as its control, plus the flush attribution
assertions. Mutation-proved: reverting explicitCommitPointContext to a no-op
reds the new step (dolt_log 80 -> 80, no commit minted), and dropping
'--author' reds the attribution assertion with committer=root.

Iteration 2 adds the WIRING pin those left open — the mechanism was covered,
but deleting `ctx = explicitCommitPointContext(ctx)` from a dual was green in
every lane, which is why the mol burn over-application above was invisible.
dolt_autocommit_exemption_wiring_test.go is tagless and needs no server: a
uow.UnitOfWorkProvider that records the context RunTxResult hands NewUOW and
then refuses observes exactly the context each dual gives its transaction.
Mutation-proved per arm: neutering the exemption at batch/bond/squash reds
those three rows and only those; dropping it from the wisp RunTxResult reds
the wisp arm alone; and restoring the command-wide reassignment reds the
persistent arm alone, reproducing the defect this iteration fixes.

Validation: go build ./..., go vet (cgo and CGO_ENABLED=0), gofmt clean;
internal/storage/issueops; internal/storage/uow -run TestDoltServerTx; the
cmd/bd registry / history / policy / batch / mol / wisp / errors battery; and
the gated real-server lane BEADS_TEST_PROXIED_SERVER=1 green for both
TestProxiedServerBatchDefersThenDoltCommitAdvancesHeadOnce (41s) and
TestProxiedServerMolBurn (33s, all four subtests including the mixed
wisp+persistent burn this iteration changed).

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

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
(cherry picked from commit edb86e3470)

Hand-resolved for hotfix/1.3.1: cmd/bd/history_remote_frontdoor_matrix_test.go
conflicted because main's context around TestHistoryRemoteSupportedFrontDoorParity
includes direct-topology test helpers (snapshotHistoryState,
newDirectHistoryProject, historyCleanEnv, runDirectHistory,
openDirectHistoryDB, startHistoryUnixBridge) that the release line does not
have. Those main-only helpers are NOT brought over; only this commit's own
change to that region (the updated doc comment) is applied. The refusal-row
removal and the new dolt-commit parity assertion applied cleanly. All other
files applied unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 03:51:48 +00:00
Vishnu J
cf08d4e3f9 fix(storage): cascade wisp aux rows in the shared wisp delete path (#6487) (#6627)
deleteIssueRowInTx, behind Transaction.DeleteIssue (bd mol burn) and
DeleteResolvedSetInTx, removed only the wisps row and the dependencies
edges, so on stores lacking the wisp aux FKs every deleted wisp orphaned
its wisp_labels, wisp_events, wisp_comments and wisp_child_counters rows.
#5343 fixed only the DoltStore wisp GC paths.

Move the aux table list and delete into issueops.DeleteWispAuxRowsInTx,
call it from deleteIssueRowInTx, and have the DoltStore paths use the same
helper so the table set cannot drift.

Forward-fix only: cleaning existing orphans needs a batched backfill and
is left to a follow-up. Sibling of #6563 (wisp_dependencies).

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
(cherry picked from commit 3ba08dba1c)
2026-09-29 03:50:45 +00:00
Matthew Doka
26467a8d02 fix(storage): cascade wisp deletes into wisp_dependencies (#6563)
* fix(storage): cascade wisp deletes into wisp_dependencies

DeleteWispFromDependenciesInTx and DeleteWispsFromDependenciesInTx only
cleaned the dependencies table, never wisp_dependencies — even though
DeleteCascadeTables(isWisp=true) declares wisp_dependencies as part of
the wisp deletion set. On stores whose wisp_dependencies table lacks the
migration-0047 FK constraints (like a live production store observed
with only the ck_wisp_dep_one_target CHECK), every wisp deletion
orphaned that wisp's wisp_dependencies rows on both sides, and reaper
scans flagged the leftovers as dangling_parent_ref anomalies that
recurred after each cleanup (~100+ rows/hour under a busy daemon).

Remove the deleted wisp's wisp_dependencies edges as child (issue_id)
and as parent (depends_on_wisp_id) in both the single and batch delete
paths. Two targeted DELETEs per direction rather than one OR query, so
each hits its own index — the ff-tqm pattern; a single OR across both
columns previously caused Dolt i/o timeouts.

Adds TestWispDeleteCascade_CleansUpWispDependencies to the standalone-
server integration harness (the existing wisp_gc_test.go coverage
requires a Docker testcontainer and silently skips without one). The
test drops the fresh-bootstrap FKs first so it exercises the delete
path's own cascade, matching the production schema; it fails without
this fix and covers the single-delete path the Docker tests omit.

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

* fixup(review): pin over-deletion and correct two cascade comments

Maintainer review fixes for PR #6563. No production behavior change.

The new subtests asserted only that the deleted wisp's wisp_dependencies
rows were gone, so an unguarded "DELETE FROM wisp_dependencies" with no
WHERE passed both of them — verified by mutating both helpers and
watching the test stay green. Each subtest now also creates an edge
between two wisps it never deletes (a bystander pair for the single
delete, an out-of-batch pair for the IN (...) form) and asserts that
edge survives. Under the same mutation the test now fails three times
with expected-vs-got. This also replaces the comment that claimed the
surviving wisps' edge set was checked, which it was not: every edge the
subtest created involved the deleted wisp.

dropWispDependencyFKs attributed the FK constraints to migration 0047.
They come from 0021, which creates all three inline in CREATE TABLE;
0058 re-adds two when healing a legacy split store, and 0047's ADD
CONSTRAINT statements are gated on that same legacy path, so neither
runs on the fresh bootstrap this harness uses.

wispAuxCascadeTables exists so the cascade set cannot drift between the
two delete paths, so note there why wisp_dependencies is handled in
issueops instead: its rows are journaled as dependency removals.

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

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
(cherry picked from commit 4213c229a4)
2026-09-29 03:50:42 +00:00
Julian Knutsen
0144dbe76b fix(close): make --json failed[].error route-independent (post-merge #6740) (#6771)
Post-merge review of #6740 (landed range c25059ada..730fb9867) found one
major: the machine-readable `failed[].error` field that PR added carried a
DIFFERENT string for the identical refusal depending on whether the caller
was on the embedded or the proxied-server route — the exact class of route
drift the close rewire exists to remove, shipped in the same commit that
states the principle in a comment. No test pinned the text, so CI was blind
to it.

Two causes, both on the proxied route:

1. The harvest loop copied `pre.errors[i]` — closeProxiedRefusal's DECORATED
   display line — straight into the JSON field, so a blocked id gained
   " (use --force to override)" that the direct route deliberately keeps out
   of the same field. Fixed by carrying the typed error in a parallel
   per-argument slot (`failureErrors`), mirroring the direct route's split,
   and reading that slot in the new closeProxiedFailures.

2. Stripping the decoration was not sufficient: a refusal reaching this route
   has also been wrapped by the layers it passed through, so the undecorated
   typed error still read
     close x-1: db: IssueSQLRepository.CloseChecked x-1: cannot close blocked …
   against the direct route's
     cannot close blocked issue: x-1 is blocked by [x-2]
   closeProxiedTypedRefusal unwraps to the sentence the engine actually wrote
   for the refusal classes the CLI already names by sentinel. Anything else
   keeps its whole chain, where the wrapping is the only thing that says where
   an unexpected failure came from.

Tests: the split and the unwrap are pinned in an untagged file so they run in
the CGO_ENABLED=0 lane too, and the shared assertion is applied by BOTH
integration suites — a new direct-route twin of
close_partial_failure_json_names_the_failed_ids, which also gives the default
route its first pin on reportCloseFailures' jsonOut branch. Every pin was
mutation-proved: reading the display line reds the three decorated classes
while the undecorated open-children control stays green; converging by
stripping the hint from stderr instead reds the human-line half; recording the
decorated line on the direct route reds the twin.

Scope: this is the only entry under the review's Required Changes. The five
non-gating minors (single-id --json report, closeCmd.Long paragraph, text-mode
per-id reprint, the `claimed` JSON type, the CHANGELOG not-found parenthetical)
are deliberately left for separate follow-ups.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
(cherry picked from commit 01bd1f1e54)

Hand-resolved for hotfix/1.3.1: CHANGELOG.md conflicted only on context
(main's Unreleased/Fixed list has entries the release line lacks). The
release CHANGELOG is kept and the same wording change is applied to the
#6648 entry carried by the previous pick. No code hunk needed changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 03:49:46 +00:00
Vishnu J
c296fc9205 Beads #6648: report partial batch-close failure (#6740)
* fix(close): fail partial batch closes

Fixes #6648

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

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

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

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

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

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

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

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

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

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

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

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

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

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

---------

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

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 03:49:22 +00:00
Gas City Adopt-PR
d79ef48048 test(release-1.3.x): black-box regression tests for the #6716 blocked-flag stall [NOT a cherry-pick]
Release-only test addition for the #6719 hand port. The tests #6719 ships
reference symbols the fix introduces, so on the pre-fix release line they
fail only to compile. These two use only store entry points that exist on
both sides of the fix, so they fail behaviourally on hotfix/1.3.1 @
f5a9402790 and pass with the port:

- dolt (server tier): a close through the store's own write runner
  (withWriteTx and withRetryTx) pins its snapshot, a sibling close commits
  on a second connection, the store's close commits last. Pre-fix rb-c
  stays is_blocked=1 and absent from GetReadyWork; post-fix it is ready.
- embeddeddolt: embedded transactions serialize, so the contract is
  pinned instead: a dependent a committed close recomputed is settled on a
  fresh snapshot after commit.

Proxied (uow/domain-db) mode is not covered: #6719 on main does not scope
that route either (see blocked_recheck.go's doc comment and the CHANGELOG
entry), so there is no proxied behaviour to test on this line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 03:48:16 +00:00
Alex
e352b96d60 fix(dolt): recheck dependents' blocked state after a close commits (#6719)
* fix(dolt): recheck dependents' blocked state after a close commits (be-cmn)

A close recomputes its dependents' is_blocked inside its own transaction,
against that transaction's start snapshot. Two concurrent closes of sibling
blockers each see the other blocker still open, so neither writes the shared
dependent's row; both commit without a conflicting cell, and the dependent
stays is_blocked=1 and hidden from `bd ready` until `bd recompute-blocked`.

The in-transaction close and status-change paths now record the dependents
they recomputed (never the closed issue itself) in a transaction-scoped note,
the same shape as the events-journal scope. The store's write-transaction
runners take that note once the transaction has committed and, only when it
is non-empty, run one more short retried transaction that recomputes exactly
those ids on a fresh snapshot. The recheck runs after the retry loop around
the write, so a recheck failure is reported as "write committed;
blocked-state recheck failed" and never replays a write that already landed.
When the recheck changes an issues row it mints a Dolt commit naming the
closed issue, so the corrected flag reaches history like the close's own
rows instead of sitting dirty in the working set. A close with no dependents
records nothing and issues no extra SQL.

This covers every DoltStore write path, including the lifecycle and batch
closers the CLI uses, and the embedded store's withConn. The RunInTransaction
path (doltTransaction.CloseIssue) keeps its pinned-connection commit and is
not scoped; nothing on the CLI's close or update path reaches a close
through it.

Fixes #6716

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

* fix(dolt): recheck blocked state after dependency removals and deletes too (be-cmn)

Only a close and an update to an inactive status recorded a post-commit
blocked recheck. A dependency removal and the three delete paths run the
same in-transaction recompute, can likewise only unblock a dependent, and
so reproduce gastownhall/beads#6716 when they commit last: a `bd close A`
overlapping a `bd dep remove C B` (or a delete of B) leaves C blocked on
every committed snapshot with no recheck to settle it.

Generalize the recording so each unblocking write records the dependents
it recomputed: noteBlockedRecheck now takes a human label for the recheck
commit message and an explicit exclusion set. A close or status update
excludes its own row (a concurrent writer conflicts on it rather than
racing past it); a delete excludes the rows that no longer exist; a
dependency removal excludes nothing, because its dependent is exactly the
row that needs rechecking. Labels stay bounded: a bulk delete of more
than three ids is named by count. The close path's commit message,
"bd: recheck blocked after close of <id>", is unchanged, and a close
through update mints the same message as a close through CloseIssue.

The server tier gains the close-versus-dependency-removal race and a
check that a delete records the deleted row's dependents; the embedded
tier pins the recording contract for a close, a removal and a delete on a
real engine; the issueops unit test pins deduplication, exclusion and the
labels.

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

* fix(dolt): name a committed write's recheck failure with a sentinel (be-cmn)

A recheck failure reaches the caller as an error from the same store call
that just committed its write, indistinguishable from a write that never
landed. Add issueops.ErrBlockedRecheckFailed and wrap both stores' recheck
failures with it, keeping the underlying cause reachable through a second
%w, so a caller can errors.Is a committed-but-unrechecked write apart from
an uncommitted one. The stale flag it leaves is the one bd doctor and
bd recompute-blocked already repair. The CLI's exit-code treatment is a
separate follow-up; this is the storage layer only.

Correct the embedded store's comment, which claimed two withConn callers
in one process overlap as two server sessions do. They do not: commitConn
opens a fresh OpenSQL handle per transaction and OpenSQL waits, with no
elapsed-time limit, for the engine, so a second handle blocks until the
first is cleaned up. Embedded transactions serialize and the skew of
gastownhall/beads#6716 cannot occur there; the recheck stays so the
embedded store honors the same contract as the server store and runs
after the first handle's cleanup, so it cannot deadlock on itself.

Document that the recheck scope is keyed by the DBTX interface value: a
write records into it only when the very *sql.Tx the store scoped reaches
it, and a future DBTX wrapper would silently record nothing, the same
shape as the events-journal scope.

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

* docs(issueops): state the blocked recheck's scope precisely (be-cmn)

The recorded writes are the ones that take a blocker away, not writes
that "can only unblock": removing the one closed child of an
any-children gate blocks its waiter, and the recheck, being a full
recompute, settles that too. Name the writes that add a blocker (reopen,
dependency add, parent-child add) as recomputing the same way without a
recheck, so the remaining gap is written down where the mechanism is.

The exclude list filters one call's ids only; say so, and that a stale
pending id for a row a later write deleted is a harmless no-op.

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

* fix(dolt): keep a failed blocked recheck out of the caller, and scope the coverage claim

Maintainer fixup for the adoption review of #6719 (fixes gastownhall/beads#6716).
Three review majors, plus the cheap non-gating cleanups that sit next to them.
The contributor's commits are left exactly as authored.

1. A post-commit recheck failure no longer reaches the caller of a committed
   write. ErrBlockedRecheckFailed had no consumer, so every store-facing
   caller — CLI, HTTP, the batch closers — still read it as "the write did
   not land" and would retry an applied mutation: the double-apply inversion
   internal/storage/dolt/issue_operations_tx.go documents. The stores now
   wrap the failure with the sentinel and log it. What it leaves behind is
   the stale is_blocked flag `bd doctor` and `bd recompute-blocked` already
   repair, i.e. the state every write had before the recheck existed. This
   also removes #6723 as a prerequisite for shipping.

2. The recheck runs on issueops.BlockedRecheckContext: detached from the
   caller's cancellation — the write it repairs has already committed, so a
   CLI deadline, a disconnected HTTP client or shutdown must not skip the
   repair and leave exactly the stale flag #6716 is about — with its own
   ceiling, and marked so a recheck cannot start another. Termination
   previously rested only on RecomputeIsBlockedInTxWithResult never
   recording, an invariant nothing enforced.

3. The coverage claim is scoped where it was false. Recording only becomes a
   recheck on a transaction one of the two store write runners scoped, and
   `bd batch` reaches neither: it dispatches close, `update status=closed`
   and `dep remove` onto storage.Transaction when local (cmd/bd/batch.go:177)
   and onto uow.RunTxResult when proxied (cmd/bd/batch_proxied_server.go:41).
   5531d0592's message ("This covers every DoltStore write path … nothing on
   the CLI's close or update path reaches a close through it") and the PR
   description said otherwise. The CHANGELOG, blocked_recheck.go's doc
   comment and the PR description now scope the claim and name the uncovered
   routes: uow/domain-db, RunInTransaction (`bd batch`, `bd cook`,
   `bd mol squash`, `bd mol burn`), the legacy RemoveDependencyWithOptions
   (`bd duplicates --merge`), and the wisp writers.

Also non-gating: the recheck's Dolt commit message is bounded (it names up to
three writes and counts the rest), and a write that contributed no id is no
longer named in it. New tests pin the recheck context, the bounded message,
and the store seam the wrapper's unit test could not reach: a close whose
recheck transaction fails still returns nil and stays durable, and the failure
the withConn/commitConn path produces carries ErrBlockedRecheckFailed.

Second review iteration: the scorecard required no changes, and all four
findings were non-gating (one minor, three nits). Each indicted text this
fixup itself introduced rather than the contributor's, so they are fixed here
instead of deferred.

4. A dropped recheck is now counted, not only logged. Swallowing the failure
   in 1 made that log line the only signal a dependent is stale, while the
   convention it was modelled on — post_tx_commit_dropped, for the same
   "post-tx step failed, the write is durable" situation — is a counter *and*
   a line. bd.db.blocked_recheck_dropped is registered beside it and bumped
   on the Dolt side, and both stores' warnings now name the rows left
   unrechecked and point at `bd recompute-blocked`; an operator reading one
   line previously could not tell which issues needed it. The sentence is
   shared from issueops next to the sentinel, which also retires the
   near-duplicate doc comment the two stores carried.

5. The bounded commit message keeps the names it retained: past the limit it
   appends "and N more" instead of collapsing to a bare count, so the commit
   that is the only record of which write triggered a repair no longer
   discards the labels kept for exactly that purpose. N counts the unnamed
   writes, which also removes a skew — Sources deduplicates and SourceCount
   does not, so two equal-sized bulk deletes rendered one label and took the
   count-only form at two writes, not at "more than three" as documented.

6. The CHANGELOG's wisp clause now matches the doc comment and the PR
   description: closes, updates, deletes and demote-to-wisp. An update to an
   inactive status also takes a blocker away, and the narrower list
   under-counted the uncovered routes on the surface users actually read.

7. The Dolt tier's swallow is pinned. Every other test in
   close_recheck_blocked_test.go calls recheckBlockedAfterCommit directly, so
   nothing crossed either runner's tail on the tier #6716 was reported on —
   restoring `return s.recheckBlockedAfterCommit(...)` turned nothing red.
   TestCloseRecheckBlocked_FailureKeepsTheWrite runs a close through
   withRetryTx and through withWriteTx with the recheck forced to fail
   (marking the store closed inside fn, the analog of the embedded test's
   readOnly flip) and asserts nil plus durability.

Gates, this iteration: gofmt clean; go build ./internal/storage/... and
go vet on issueops, dolt and embeddeddolt clean;
go test ./internal/storage/issueops/ ok;
go test -tags gms_pure_go ./internal/storage/embeddeddolt/ -run BlockedRecheck
ok (9s, real engine); go test ./internal/storage/dolt/ -run CloseRecheckBlocked
ok (27s, dolt testcontainer). Iteration 1 additionally ran the full embedded
package (98s) and the dolt subset
'RunInTransaction|BatchCloser|IsBlocked_|CloseRecheck|LifecycleCloseReopen'
(156s). Every new assertion was proved non-vacuous by mutating the change it
pins — reverting CommitMessage to the count-only form, counting all writes
rather than the unnamed ones, dropping the ids and the repair pointer from the
warning, unbounding that id list, and restoring the propagation on each runner
tail — six mutations, each reddening only the assertions that defend it.

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

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>

(cherry picked from commit 1ed5b33303)

Hand-ported to hotfix/1.3.1 (release/1.3.0 base); the pick did not apply
cleanly:
- internal/storage/dolt/store.go (commitWriteTx) and
  internal/storage/embeddeddolt/store.go (commitConn): main's context lines
  install scopeVersionedHistoryTransaction / ScopeVersionedHistoryTransaction,
  a main-only feature absent on the release line. Resolved by keeping the
  release code and adding only the two ScopeBlockedRecheckTransaction lines;
  the versioned-history scope is NOT brought over. Every other hunk in both
  files (runner split, recheck, logging, metric) applied unchanged.
- CHANGELOG.md: main's entry sits in an Unreleased/Fixed list the release
  branch does not have. The release CHANGELOG is kept and the #6716 entry is
  added verbatim under a new Unreleased "### Fixed" heading.
No schema change; issueops, dolt and embeddeddolt build and vet clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 02:17:45 +00:00
Julian Knutsen
f5a9402790
Merge pull request #6905 from gastownhall/hotfix/1.3.1-proxied-backup
hotfix/1.3.1: proxied bd backup + purge wisps-plane/live-dependent protection/--limit
2026-09-28 12:39:50 -07:00
Gas City Adopt-PR
2b27259cb4 test(release-1.3.x): adapt release-only capability tests to the backported proxied backup [NOT a cherry-pick]
Release-only adaptation, not a copy of any main commit. The tests it
touches exist only on release/1.3.0, so there is nothing on main to
pick; every other commit on this branch is a faithful cherry-pick -x.

- topology_capability_matrix_test.go (#6579, release-only S0 matrix):
  flip backup status/sync as #6584's own description says. On
  proxied-local, status is HONORED and sync is ERROR "no backup
  destination configured"; other proxied topologies are REFUSED_TYPED
  with reason design. The runner already orders refusal rows before
  honored ones, so the honored cells no longer start the proxy ahead of
  the no-side-effect refusal checks (the red smoke-lane cells review
  found).
- proxy_capability_test.go: TestProxyMaintenanceAllowsTheSharedConsentVerb
  (#6695, release-only) called validateProxyMaintenanceBeforeProvider,
  which #6582 removes; it now calls validateProxyRegistryBeforeProvider
  for managed-local, with unchanged assertions. Until this commit the
  cmd/bd test package does not compile on the picks above it.
- proxied-local-smoke.yml: run the capability matrix and the backup
  round trip in the compiled-in check, and trigger on cmd/bd/backup*.go.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 15:56:08 +00:00
Julian Knutsen
7c2568c323 feat(purge): live-dependent protection, --wisps-plane selector, hour-precision --older-than, --limit (#6883)
* feat(purge): live-dependent protection, --wisps-plane selector, hour-precision --older-than

An orchestrator's wisp retention step deletes every closed row in the
wisps table older than N hours, except a closed wisp that an
open/hooked/in_progress wisp depends on through parent-child, tracks or
blocks. `bd purge` could not express that: it selected the ephemeral
TIER (so closed --no-history beads, which live in the wisps table, were
left behind), it deleted a closed molecule root whose step was still
open, and it floored --older-than hours to whole days (36h swept rows
24h old). All three land together so `bd purge --wisps-plane
--older-than 168h --force` covers that step.

Live-dependent protection (issueops.SweepRequest.ProtectLiveDependents,
SweepSkips.LiveDependent): a candidate is held back when a live row
depends on it through a SweepLiveDependentEdgeTypes edge (parent-child,
tracks, blocks), read from both dependency tables. "Live" is the same
not-done set the reference scan uses, custom statuses included, so it
is a superset of open/hooked/in_progress. `bd purge` always asks for it
(no opt-out: removing live work's root is `bd delete`'s job); `bd prune`
does not. Reported as live_dependent_skipped in --json.

Wisps-plane selector (issueops.SweepWispsPlane, `--wisps-plane`): the
candidates are every closed row in the wisps TABLE, whatever its
ephemeral/no_history/wisp_type values, via a new single-plane search
(issueops.SearchWispsPlaneInTx) that the store backends call directly
and the unit-of-work provider reaches through
IssueUseCase.SearchWispsPlane, so embedded, server and proxied share one
body. It reaches durable-tier (no-history) rows, so it carries the
durable tier's require-a-filter gate.

--older-than (purge and prune): day values keep their meaning (7, 7d,
2w); anything else is a Go duration taken exactly (36h, 168h, 90m).

Tests: three new Sweeper contract cases (wisps plane clears the whole
table, wisps plane requires a filter, protects live dependents) run on
dolt, embeddeddolt and the uow provider; workapi unit tests; a CLI
retention scenario run in embedded, shared proxied and managed-local
proxied modes (fails against origin/main); TestParseOlderThan.

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

* test(uow): classify IssueUseCase.SearchWispsPlane as a read in the notifying parity partition

TestRecordingIssueUseCaseCoversItsSurface requires every IssueUseCase
method to be either wrapped by the notifying decorator or exempted with
the reason it fires no hook. SearchWispsPlane reads state and changes
none, like SearchIssues beside it.

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

* fix(purge): refuse out-of-range --older-than; add --limit for bounded drains; cross-plane protection test

Review follow-ups on #6883.

--older-than: a day count past what a time.Duration holds (213504d,
30501w) used to wrap silently — 213504d became 25m26s, which on a
destructive command selected almost every closed row. It is now refused
as out of range; ParseDuration already refused oversized h/m/s values.

--limit N (issueops.SweepRequest.Limit, SweepResult.Remaining): one
purge deletes at most N rows, oldest closed_at first (then id), after
every protection, and reports the rest. --json adds remaining and
has_more when --limit is given. At ~15ms/row on the proxied path a
single unbounded sweep of a large backlog can outlive a caller's
deadline, roll back, and never clear; a bounded loop cannot. Negative
limits are ErrValidation at the role and refused at the CLI.

Tests: TestParseOlderThan out-of-range rows; contract cases
LimitTakesTheOldestClosedFirst and ProtectsLiveDependentsAcrossPlanes
(a live issues-table bead depending on a closed wisp via parent-child,
tracks and blocks keeps it) on dolt, embeddeddolt and uow; workapi
units for the ordering and the negative-limit refusal; the CLI
retention scenario now drains with --limit 1 and checks the overflow
refusal. CHANGELOG notes that sub-day Nh values used to round UP to a
day (12h is now taken exactly) and lists the protection under Changed.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 2ec0b2f072)
2026-09-28 15:54:56 +00:00
Julian Knutsen
74dc7154c2 fix(backup): stop attributing proxied auto-backup OFF to a missing git remote (#6694)
Post-merge review of #6584 (landed 7ccb961f7..c69dd3061).

Honoring the backup family on a managed-local proxied server made
`bd backup status` reachable on that topology for the first time — and it
rendered the embedded-mode footnote `(auto: no git remote)`. That reason was
never true there: `isBackupAutoEnabled` returns false because `usesSQLServer()`
short-circuits it, whether or not a remote exists. The same command's help then
told the operator to set `backup.enabled=true` to opt in, which on proxied
changes nothing — the proxied arm of `PersistentPostRunE` never calls
`runPostRunAutoBackup`, so an operator following bd's own instructions gets
silent no-backup.

The status note now comes from `backupAutoStatusNote`, which narrates the reason
the decision actually used: proxied-server first (and regardless of the config
source, since an explicit `backup.enabled=true` is inert there and a bare
`enabled=true` is the misleading half), then sql-server mode — the reason
`bd config get backup.enabled` already reports for the same condition — then the
unchanged embedded git-remote arms. The `backup` help stops advertising the
opt-in on proxied and points at explicit `bd backup sync`, which is honored on
the one proxied shape that reaches these surfaces.

Wiring an auto-backup hook through the new proxied routes is the other half of
the reviewer's fix and is deliberately not taken here: all three reviewers
classified the missing hook as a pre-existing gap #6584 did not claim. Only the
newly produced misinformation is corrected.

`TestBackupAutoStatusNote` pins all seven shapes against the value they are
printed beside; reverting the helper to the pre-fix ordering fails exactly the
three server-mode cases and leaves the four embedded ones green.

(cherry picked from commit e677d90d88)
2026-09-28 15:54:19 +00:00
Julian Knutsen
ca37d8f9fc feat(backup): route the backup family over proxied-server, refused by design off-host (proxied-parity S3) (#6584)
* refactor(proxy): one capability registry, with a reason on every refusal

Proxied-server policy lived in three path tables (a maintenance refusal
map, a history classification map, a transform row list), each with its
own lookup and its own front-door validator, plus a flag matrix. Nothing
forced a new command to appear in any of them, so an unclassified
command sailed past the gate and died in the store factory with
`proxy server store should be uow provider`. That — not the table count
— was the root problem.

One table now (cmd/bd/capability_registry.go), and a test that fails
when a runnable command is missing from it. Adding a command is no
longer a place where policy can be forgotten: it is a build failure
until someone decides whether the proxied front door lets it through.

Every refusal carries a Reason: `design` where refusing is correct and
expected to stay (shared history, multi-repo routing, destructive admin,
storage-format surgery, strict --readonly), `unimplemented` where it is
a gap with a named owner. The reason renders in the refusal JSON,
additive to the frozen {code, error, mutates} contract, and is omitted
on refusals that report a runtime state rather than a policy so a
consumer keying on its presence is never told "" by mistake.

The registry also inventories the 57 untyped refusals commands raise
from their own RunE. Those rows are not enforced — converting them
changes observable output and belongs to the slice that owns each
family — but a source scan now keeps the inventory honest in both
directions.

The store-factory backstop is typed as `proxy.store.unrouted`, the
unreachable duplicate readonly refusal in main.go is gone (the proxied
branch above it already returns for the only config that reaches it),
and with it `backendSupportsStrictReadonly`, which had no other caller.

No outcome changes. Every code, message and exit status is identical,
which #6576's five-topology matrix proves: 90/90 cells unchanged
(HONORED 47, REFUSED_TYPED 24 = 4 design + 20 unimplemented, ERROR 12,
WRONG_ANSWER 4, DEGRADED 3), all five topologies exercised, no skips.

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

* refactor(proxy): `migrate hooks` is an unimplemented refusal, not a design one

The registry filed `migrate hooks` under "storage-format and workspace
surgery against a store other clients may be holding open". That rationale
does not describe it: migrate_hooks.go plans and applies GIT HOOK FILE
migration through doctor.PlanHookMigration, on the local filesystem, and
opens no store at all. Left as it was, proxied-local — the default topology
since 1.3.0 — loses the command permanently, because `design` tells every
later slice the refusal is semantic and settled.

It is not settled, but it is also not free to lift, and the difference is
structural rather than semantic. `migrate hooks` appears on none of main.go's
store-init skip lists, so permitting it makes the root pre-run open the
proxied provider before RunE runs. Measured with the row flipped to
permitted, not reasoned about: on a managed-local workspace
`bd migrate hooks --dry-run` started the proxy AND its dolt child — both
pidfiles present — to print a hook plan for five missing hooks, and on a
workspace with an unreadable sidecar it exited 1 with "failed to open uow
provider: corrupt proxied-server sidecar ..." where it had cleanly refused
before. Trading a typed refusal for a provider-open error is not a lift.

So: Reason=unimplemented with a Tracking item that names the actual work —
put the command on the store-init skip list first, then permit it — which is
S7's, not this slice's. No outcome changes; the row still refuses with the
same code, message and exit status. The registry header now says that
permitting a path costs a provider open, since that is the fact this row
turns on and the one the completeness test cannot see.

Also leaves S7 an explicit instruction on the rows next door. `migrate
issues`, `migrate-personal` and `admin cleanup`/`admin reset` claim `design`
on a topology-blind rationale — "a store other clients may be holding open",
"destructive against a possibly-shared store" — that describes external and
team-server workspaces and does not describe managed-local, which is 1:1 and
bd-owned. They are not reclassified here: the table cannot yet express
"refused, except on managed-local", and narrowing them is semantic work
nobody has done. The comments now say that is why, so the next reader does
not mistake conservatism for a considered verdict.

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

* feat(backup): route the backup family over proxied-server, refuse it by design off-host

A proxied-server workspace had no backup path at all: all five verbs — init,
sync, remove, status, restore — refused. Proxied has been the default topology
since 1.3.0, which made this the highest user-weight gap in the proxied-parity
plan.

The mechanism needed no proxy work. CALL DOLT_BACKUP(...) is ordinary SQL,
RunNonTx already hands out a raw pinned connection (the seam compact --dolt and
gc run on), the UOW DSN sets a connect timeout and no read deadline, and an
active connection keeps the idle reaper from arming — so a backup that takes
minutes is safe from both the driver and the 30s reaper. The work was use
cases, route files and policy rows, and the premise held.

The policy is the interesting half, and it is the first genuinely
topology-differentiated rule in the capability registry. A backup destination
is resolved by the SERVER: `file:///…` names a path on the machine running
dolt. On managed-local that machine and that user are bd's own, because bd
spawned the child. Anywhere else — an external host or socket, or a
beads-team-server database — the URL describes a filesystem bd cannot see, so
honoring the command would either fail at the point of use or, far worse,
report success having written the backup where the operator will never look.
Those shapes stay refused with Reason=design: no plumbing on this side gives bd
a path on somebody else's host.

Team-server is classified by OWNERSHIP, not transport. bts owns the store's
schema and identity whether bd reaches it over a port, a socket, or a child bd
started, and one client registering a server-side backup remote acts on every
client's data — the shape of the storm this command's own help text warns about.

Restore quiesces before it replaces. DOLT_BACKUP('restore') swaps the database
under the server, which is undefined with clients connected, so: the exclusive
workspace gate `bd backup restore` already takes excludes every other gated bd
command (including `bd serve`); this closes the provider the pre-run opened and
shuts the proxy and its dolt child down; it reopens a provider of its own to
run the restore as the only client; then it puts the topology down and reopens
once more to reconcile the project identity and the backup remote — which also
proves the restored database is serviceable. The final shutdown leaves the
workspace quiescent for the next command to relaunch lazily.

Registry rows gain a Topology map and honoredOn(), stated as "refuse, except
here" so a shape nobody thought about — a new transport, or the unknown a
corrupt sidecar produces — inherits the refusal rather than the exemption.
resolveProxiedTopology reads the shape from the workspace and reports unknown
rather than guessing.

`bd backup restore --json` now prints a result object on every topology; it
printed nothing before, which left a caller unable to tell a completed restore
from a skipped one. The four backup subcommands that lacked SilenceUsage/
SilenceErrors no longer follow their error message with "Error: exit code 1"
and a usage block.

Verified by round trip, not by exit codes: TestManagedLocalProxiedBackupRoundTrip
takes a backup on a live managed-local workspace, creates an issue after it,
restores, and asserts the pre-backup issue is back and the post-backup one is
gone, with both pidfiles absent afterwards.
TestProxiedServerBackupRefusedOnExternalTopology pins the typed design refusal
against the shared container and proves a refused command starts nothing and
writes nothing.

Flips four cells of #6576's matrix: `backup status` and `backup sync` go
REFUSED_TYPED/unimplemented -> HONORED and -> ERROR ("no backup destination
configured", the command's own error, same as every direct topology) on
proxied-local, and unimplemented -> design on proxied-external-tcp.

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

* fix(backup): say why proxied backup is refused, and stop calling a cleanup failure a restore failure

Review follow-ups on the proxied backup slice. None of them changes which
commands are honored on which topology; what changes is what the refusal
CLAIMS, and what a restore says when only its teardown failed.

The refusal rationale was true of one destination scheme out of five. It said
"a backup destination is resolved on the server's filesystem, not this
client's" — which describes `file://` and nothing else. resolveDoltBackupURL
passes `https://`, `aws://` and `gs://` straight through, and `bd backup`'s
own help recommends DoltHub by name; for those the server pushes over the
network from its own environment and no filesystem of anybody's is involved.
An operator running `bd backup init https://doltremoteapi.dolthub.com/...` on
an external topology got a permanent verdict explained by a filesystem the
command never touches.

The refusal itself stands, on the reason that is true of every scheme: `CALL
DOLT_BACKUP('add', …)` registers the remote ON THE SERVER, where it is global
to every client connected to it, so one workspace's backup decision becomes
everyone's — the same shape as the auto-backup storm this command's help text
already warns about. The file:// locality problem is now stated as the second,
scheme-specific problem it is. The message keeps its frozen
"<path> is not supported in proxied-server mode" prefix and its
proxy.backup.unsupported code.

The remote-scheme case gets a Tracking item, the way `diff` got "1.4
candidate". The outcome is design; that particular CASE is an open question,
and a design label with no tracking reads as "never" to every later slice.
It is the same server-env credential question S4 has to answer for `dolt
push` on these same topologies. Recorded there too: restore-from-a-remote is
already half-broken in DIRECT mode, because validateBackupRestoreDir stats its
argument, so `bd backup restore https://...` fails everywhere today.

A restore that succeeded and then failed to shut the proxy down reported
"restore failed". The operator's data was back; they were told it was not,
and the obvious next move — run the restore again — was the wrong one.
withQuiescedProxiedProvider now returns teardown failures wrapped in
*proxiedTeardownError instead of flattening them into the operation's error,
and the message the caller renders is split into a function a test can hold
still, because the judgement it encodes (did the data come back) is the point.
Both call sites distinguish now; the second one's "did not reopen" wording was
also wrong for a teardown failure, since it had reopened.

Two smaller things while in here. The guard-rail comment on
newProxiedServerUOWProviderAdopting still said "only two callers legitimately
have no workspace identity to assert" — this slice added a third. That comment
is the register of identity-assertion bypasses, so it now names the third and
why, and says what to do about a fourth. And DirToFileURL was "file://" +
filepath.Abs with no scheme check: it would have turned a DoltHub URL into
file:///cwd/https:/doltremoteapi.dolthub.com/... , a valid-looking URL naming a
directory nobody asked for. Unreachable today, and every caller is a restore
path, which is exactly the capability the tracking item above describes.

CHANGELOG additionally discloses two direct-mode changes this slice makes that
were previously only visible in the diff: `bd backup restore --json` prints a
result object on EVERY topology where it used to print nothing, and the four
backup subcommands that gained SilenceUsage/SilenceErrors no longer follow a
failure with "Error: exit code 1" and a usage block, on every topology.

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

* fix(backup): quiesce failed restore reopens and pin JSON output (bd-obos)

Preserve the primary constructor or operation error while reporting cleanup failures without a successful-restore marker. Exercise a real malformed-backup reopen failure and assert both pidfiles are removed; retain the successful round trip and assert its JSON result.

Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of Julian Knutsen

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit c69dd3061a)
2026-09-28 15:54:04 +00:00
Julian Knutsen
eac2597557 refactor(proxy): one capability registry with a reason on every refusal (proxied-parity S2) (#6582)
* refactor(proxy): one capability registry, with a reason on every refusal

Proxied-server policy lived in three path tables (a maintenance refusal
map, a history classification map, a transform row list), each with its
own lookup and its own front-door validator, plus a flag matrix. Nothing
forced a new command to appear in any of them, so an unclassified
command sailed past the gate and died in the store factory with
`proxy server store should be uow provider`. That — not the table count
— was the root problem.

One table now (cmd/bd/capability_registry.go), and a test that fails
when a runnable command is missing from it. Adding a command is no
longer a place where policy can be forgotten: it is a build failure
until someone decides whether the proxied front door lets it through.

Every refusal carries a Reason: `design` where refusing is correct and
expected to stay (shared history, multi-repo routing, destructive admin,
storage-format surgery, strict --readonly), `unimplemented` where it is
a gap with a named owner. The reason renders in the refusal JSON,
additive to the frozen {code, error, mutates} contract, and is omitted
on refusals that report a runtime state rather than a policy so a
consumer keying on its presence is never told "" by mistake.

The registry also inventories the 57 untyped refusals commands raise
from their own RunE. Those rows are not enforced — converting them
changes observable output and belongs to the slice that owns each
family — but a source scan now keeps the inventory honest in both
directions.

The store-factory backstop is typed as `proxy.store.unrouted`, the
unreachable duplicate readonly refusal in main.go is gone (the proxied
branch above it already returns for the only config that reaches it),
and with it `backendSupportsStrictReadonly`, which had no other caller.

No outcome changes. Every code, message and exit status is identical,
which #6576's five-topology matrix proves: 90/90 cells unchanged
(HONORED 47, REFUSED_TYPED 24 = 4 design + 20 unimplemented, ERROR 12,
WRONG_ANSWER 4, DEGRADED 3), all five topologies exercised, no skips.

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

* refactor(proxy): `migrate hooks` is an unimplemented refusal, not a design one

The registry filed `migrate hooks` under "storage-format and workspace
surgery against a store other clients may be holding open". That rationale
does not describe it: migrate_hooks.go plans and applies GIT HOOK FILE
migration through doctor.PlanHookMigration, on the local filesystem, and
opens no store at all. Left as it was, proxied-local — the default topology
since 1.3.0 — loses the command permanently, because `design` tells every
later slice the refusal is semantic and settled.

It is not settled, but it is also not free to lift, and the difference is
structural rather than semantic. `migrate hooks` appears on none of main.go's
store-init skip lists, so permitting it makes the root pre-run open the
proxied provider before RunE runs. Measured with the row flipped to
permitted, not reasoned about: on a managed-local workspace
`bd migrate hooks --dry-run` started the proxy AND its dolt child — both
pidfiles present — to print a hook plan for five missing hooks, and on a
workspace with an unreadable sidecar it exited 1 with "failed to open uow
provider: corrupt proxied-server sidecar ..." where it had cleanly refused
before. Trading a typed refusal for a provider-open error is not a lift.

So: Reason=unimplemented with a Tracking item that names the actual work —
put the command on the store-init skip list first, then permit it — which is
S7's, not this slice's. No outcome changes; the row still refuses with the
same code, message and exit status. The registry header now says that
permitting a path costs a provider open, since that is the fact this row
turns on and the one the completeness test cannot see.

Also leaves S7 an explicit instruction on the rows next door. `migrate
issues`, `migrate-personal` and `admin cleanup`/`admin reset` claim `design`
on a topology-blind rationale — "a store other clients may be holding open",
"destructive against a possibly-shared store" — that describes external and
team-server workspaces and does not describe managed-local, which is 1:1 and
bd-owned. They are not reclassified here: the table cannot yet express
"refused, except on managed-local", and narrowing them is semantic work
nobody has done. The comments now say that is why, so the next reader does
not mistake conservatism for a considered verdict.

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

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit 7ccb961f77)
2026-09-28 15:53:31 +00:00
Jim Wordelman
aa3c43b6bd
feat(storage): add events/bd_events_journal/bd_events_seq to cursorRealityFloor sentinel set (#6547)
* test(feat): red — Add sentinelFlooredTables to cursorRealityFloor so events/bd_events_journal/bd_events_seq self-heal (release/1.3.0) (refs be-u14.1)

* feat: green — Add sentinelFlooredTables to cursorRealityFloor so events/bd_events_journal/bd_events_seq self-heal (release/1.3.0) (refs be-u14.1)

* chore: release gate PASS for cursor-reality-floor-sentinel-self-heal (be-g69lt)

* chore: remove leaked internal release-gate doc from PR branch

  release-gates/be-g69lt-gate.md

Tracked our internal gc-management/beads-rig release-gate checklist and
should never have been committed to this upstream branch -- it's process
residue from our deploy tooling, not part of the change itself.

Per maintainer bee-ghosttrack's request during review of PR #6571. The
root cause (our deploy tooling auto-committing this file) is already fixed
as of gm-qatxl1; this branch predates that fix, so this commit is cleanup
only -- no other content on this branch is touched.

Ref: be-lk7o3

* fix(schema): pin the floored-sentinel minimum and generalize creator detection

Maintainer review fixups for PR #6547 (adoption review, iteration 1). No
behavior change beyond the probe error-message text.

- Pin the floored loop's intra-loop minimum. Every existing case removed
  exactly one floored sentinel, so `st.replayFloor < floor` was never
  evaluated against a floor an earlier absent sentinel had already set, and
  inverting it to `>` left the whole package green. Adds an "events and
  bd_events_journal both absent" case asserting floor 18 and widens
  allSentinelTablesExcept to variadic; the inversion now fails (floor = 21,
  want 18). The floors ascend in slice order today (18, 21, 21), so this is
  what keeps a future reordering or lower-floored addition from silently
  regressing to "last absent sentinel wins".

- Distinguish the floored-table probe's error wrap from the floor-0 loop's.
  They were byte-identical, so a store-open failure did not say which
  sentinel class failed, and the consequences differ sharply (floor 0 and a
  full series replay vs. floor 18/21).

- Detect both creator shapes in TestSentinelFlooredTablesAreCreatedByTheSeries
  rather than keying on the literal table name "events". The PREPAREd
  conditional CREATE is required of any creator whose table carries a named,
  database-unique constraint (ignored/0019's own comment), so a future floored
  sentinel in that shape would have fallen through to the __temp__ regex and
  failed with a misleading "never created by the series". Both arms are
  mutation-proved to be load-bearing.

- Record in the sentinelFlooredTables comment that events' dolt_ignore pattern
  is version-gated ({"events", 62}) rather than unconditional, and why the
  clamp is safe anyway: the ignored plane is only reached after the main pass
  succeeds, and a main pass from below 62 applies 0062_events_dolt_ignore,
  whose REPLACE INTO dolt_ignore lands before the ignored plane is touched.

Validation: go test -count=1 ./internal/storage/schema/ (ok, 36.5s), go vet
and gofmt clean, git diff --check clean.

---------

Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
2026-09-26 14:27:45 -07:00
Julian Knutsen
bb03a310a9
fix(schema,uow): cover the proxied data-behind path and make its consent step runnable (post-merge #6659) (#6695)
* fix(schema,uow): cover the proxied data-behind path and make its consent step runnable (post-merge #6659)

Post-merge review of the landed range d0063ac..e1e1158 (PR #6659, the
release/1.3.0 backport of #6658) raised two majors. Neither is a regression
from that PR; both are gaps its surface left open.

F-A — the uow/proxied path never reached the #6575 stop, and its blunt body
prescribed the wedge. `doltSQLProvider.initSchema` passed a nil adopter to
`CheckSharedStoreMigrateGate`, so `localDataBehind` short-circuited and routing
could never emit `smartDataBehind`. A proxied store that was level on schema
and behind in data reported `shared-store` instead, whose body is the
designated-migrator recipe — `bd migrate --force` then `bd dolt push` — which
in that state is exactly the #6368 wedge the stop exists to prevent. The
refusal was always safe (the shared arm suppresses the auto-migrate either
way); the guidance was not.

Only `AheadBehind` is wired. It is the complete data-behind predicate, while
leaving `IsStrictAncestor`/`WorkingSetClean` nil keeps `routeAdoptFastForward`
false, so the remote-AHEAD arm on this path keeps the plain adopt directive it
has today. `FastForward` stays nil: it is a write that would promote the schema
for every co-resident client.

The remedy also had to be topology-correct before it could be printed.
`bd dolt pull` is refused at the proxied front door
(`proxy.dolt_pull.unsupported`), as are `bd dolt push`, `bd migrate` and
`bd conflicts` — so the body, agent directive and `options` now name the
machine the pull runs on, and the option id becomes
`pull-first-on-server-host`. The don't-force warning gains
`BD_ALLOW_REMOTE_MIGRATE=1`, the one consent surface the proxy does not refuse.
Read-only proxied opens print the pull-first block instead of the shared
consent template.

The proxied fact is the caller's, not the provider's: `newSQLServerUOWProvider`
is also `bd serve`'s provider for SERVER-mode workspaces, where that pull
works. A new `uow.WithProxiedServerMode()` is set only by
`openProxiedServerUOWProvider`.

F-B — the shared data-behind consent step named a verb that cannot unlock a
remote-backed shared store. `sharedMigrateConsent` has one reader,
`sharedNoRemoteGate`, reachable only on the `!hasRemote` branch; a data-behind
stop has a remote by construction. The four surfaces now name
`SharedConsentCommandForced` (`bd migrate schema --force`) with its `--global`
twin, and the human/JSON `--global` retargets follow. Widening the verb consent
to the remote-backed arm was rejected: it would drop the designated-migrator
confirmation #4259 deliberately requires whenever a remote exists. This mirrors
PR #6692, the main-line remediation for the same defect on #6658, so the two
lines converge rather than diverge.

Tests: the consent step is proven by EXECUTING its path (a text assertion on
`Options()` is how the dead command shipped), with the bare verb as the
counterfactual; the proxied route is driven through `initSchema` against a
mocked behind-clone and asserts the body does not prescribe
`bd migrate --force`; a server-mode open pins that it keeps the runnable-here
remedy; a level clone pins that reading ancestry does not turn a genuine
first-mover into a stop.

Scope: the scorecard's two Required Changes only. Its non-gating items — F-C
(`noticeSharedMigrateRefusal` lacks an `IsDataBehind()` branch), F-D
(`warnRemoteSyncOpenRefusal` verbosity), F-E (`docs` not retargeted), F-F/F-G
(stale comments) — are left for separate follow-ups.

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

* fix(schema,cli): the proxied consent step is not refused — say so (post-merge #6659 iter 2)

Post-merge review iteration 2 of PR #6695 found one major: the proxied
data-behind guidance this PR added asserts that its own prescribed consent
step, `bd migrate schema --force`, is refused at the proxied front door. It
is not.

The refusal table keys on the full command path. `proxyMaintenanceRefusals`
registers the bare `migrate` verb and its hooks/issues/sync children, but has
no `migrate schema` row, so the two-word path misses the lookup and
`validateProxyMaintenanceBeforeProvider` falls through to nil. `bd migrate
schema` then runs its proxied arm, which reports the migration the provider
open already applied under that verb's consent.

That makes the claim wrong in the unsafe direction: `forceOrEnvConsent` is
read BEFORE the data-behind stop is routed, so an operator told "it is refused
here anyway" who types it to confirm applies the migration to a data-behind
shared store — the #6368 wedge, reachable from the exact topology this
remediation was written for. The don't-force warning made it worse by
presenting BD_ALLOW_REMOTE_MIGRATE=1 as the only consent surface this
workspace can reach.

Reworded to the truth on all five surfaces, and pinned so it cannot drift
again:

- dataBehindBody's proxied consent clause now says the step CAN be run here
  and that the precondition is temporal, not locational: run it only after
  the pull lands on the server host.
- the proxied don't-force warning names `bd migrate schema --force` alongside
  BD_ALLOW_REMOTE_MIGRATE=1 as the two reachable consent surfaces, both
  honored before this stop is reached.
- the consent option's When/Risk drop "bd migrate is refused in
  proxied-server mode" and say the pull-first half is load-bearing here
  because this one does NOT fail closed the way the pull does.
- CHANGELOG drops "the one consent surface the proxy does not refuse".
- the same false premise is corrected in the uow test comment.
- TestProxyMaintenanceAllowsTheSharedConsentVerb resolves the command from
  SharedConsentCommandForced through the same cobra lookup the root pre-run
  uses, asserts validateProxyMaintenanceBeforeProvider returns nil for it,
  and keeps the bare `bd migrate` refusal (proxy.migrate.unsupported) as the
  counterfactual. No test called that function with this command before,
  which is why the false wording shipped green.

Also the two non-gating consistency findings from the same iteration:

- `--json` gate["expected"] carries the location qualifier when Proxied, so
  an expected-only reader is not handed a locally-refused command while
  options/hint carry it. Extracted to dataBehindExpectedField so the
  qualifier does not add a branch to handleRemoteMigrateGateJSON (cognitive
  stays 33, cyclomatic 18).
- fallbackReasonNote's data-behind arm gates its remedy on Proxied; the note
  prints after the body, so unqualified it made the last paragraph prescribe
  what the paragraph above called refused.
- smart_remote_migrate_gate.go's injection-site comment no longer says the
  shared UOW provider wires neither callback; it wires AheadBehind only.

Tests: ./internal/storage/schema (full, ok), ./cmd/bd -run
'Migrate|Consent|Proxy|RemoteGate|DataBehind|SharedStore|RemoteSyncOpen'
(ok), ./internal/storage/uow -run 'DataBehind|Proxied|MigrateGate' (ok).

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

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-24 03:46:42 -07:00
Julian Knutsen
1e754a0156
docs(engdocs): proxied-server surfaces an embedder reads, as observed at 1.3.1 (#6652)
* docs(engdocs): write down the proxied-server surfaces an embedder reads, as observed at 1.3.1

An embedder — an external tool linking bd's Go packages, or one running beside
bd against the same workspace — ends up depending on surfaces bd never
published: proxy.pid's field names, the db-proxy-child argv, the shape of
`bd dolt status --json`, whether a Go symbol is exported or reachable only by
type assertion. Eleven of those were asked about; none of them is a contract,
and the answer to "will these hold" is no promise. This writes them down
anyway, as observed behaviour with the commit they were read at, so that an
embedder can build against what the code does instead of guessing.

Framing is deliberate and the document says so twice: descriptive, not a
compatibility contract; every surface may change in any release, including a
patch release. Four are moving in 1.3.1 itself and are given as before/after —
`bd dolt status --json`'s reshape (#6580) has landed and is described in its new
shape; the `bd migrate schema` refusal, the explicit sidecar `idle_timeout`, and
clean-backend-exit handling plus backend-probing adoption (#6651) are decided
but had not landed at d487b9796, so each states current behaviour as current. A
closing section ranks which surfaces are likelier to move, and a final one lists
the claims that would need a running proxy to confirm and were inferred from
source instead.

Four of the eleven pointers the request carried were off, and are corrected
here rather than copied:

- The loopback root/no-password fact is not in the proxy's connection handler
  at all. Only the byte-pump half lives there; the credentials come from
  newManagedProxiedServerUOWProvider passing "root"/"" in cmd/bd/uow_factory.go,
  over a generated sql-server config that binds 127.0.0.1 and declares no users.
- SetEventsJournalEnabled is not on the Storage interface and is not named in
  beads_cgo.go. It is storage.EventsJournalConfigurer, an optional interface in
  internal/storage/storage.go, which is not re-exported publicly — so the
  assertion has to be written against a locally declared method set.
- The shared-store gate's 30s default constant lives in
  internal/storage/uow/dolt_sql_provider.go, not in the provider that applies it.
- The argv pointer stopped at --config and missed --dolt-bin, --database and the
  four --external-* flags.

While verifying #8 a routing fact turned up that an embedder needs more than the
interface question: neither copy of OpenBestAvailable has a proxied arm, and
IsDoltServerMode and IsDoltProxiedServerMode are mutually exclusive, so on a
proxied workspace it falls through to an embedded open over .beads/dolt — the
same directory the proxy's sql-server is serving. Documented, with the
consequence of that open marked as untested here.

Filed under engdocs/ beside EXTENDING.md, which is already the entry point for
"not user-facing; for code that embeds bd", linked from it, and registered in
DOC_INVENTORY.md's Active Docs and Reference Freshness tables. The Last
reviewed / Freshness source markers match check-doc-freshness.sh's format but
the doc is deliberately NOT added to that script's enforced list: putting a
90-day tripwire on a release branch is a maintainer's call.

scripts/check-doc-flags.sh and scripts/check-doc-freshness.sh both pass.

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

* docs(engdocs): describe the data-port capability generically

The prior wording named an integration shape rather than the capability. State
what the byte pump plus the generated config actually let an embedder do.

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

* docs(engdocs): correct five factual claims and drop four promise leaks

Two adversarial reviews returned FIX_FIRST on the observed-surfaces doc.
Corrections, each re-verified against source:

- §8: the embedded fall-through does not open the directory the proxy is
  serving. embeddeddolt hardcodes <beadsDir>/embeddeddolt (newStore,
  cacheKey, HasRepository); the proxy serves the proxied root, default
  <beadsDir>/dolt. The hazard is a silently separate database — empty on a
  workspace born proxied, stale on one that was ever embedded, since no
  mode-migration verb removes that directory — not contention.
- §10: backend_running carries no omitempty, so five keys are always
  present, not four. The doc's own external example contradicted its rule.
- §3: neither readiness probe uses credentials. Both poll
  DatabaseServer.Dial, a bare TCP connect. root/"" belongs to bd's SQL open
  and to DoltServer's shutdown GC.
- §2: the --external-* flags need both conditions — external backend AND a
  set value — and ExternalDoltConfig.Validate makes host/port and socket
  mutually exclusive, so all four never appear together.
- §6: the proxied migrate payload is NOT the direct path's shape. Direct
  emits {status, applied, latest_version}; proxied drops applied and adds
  mode and note.
- §4: Handle.Kill is SIGKILL on macOS too, and the stop epoch advances once
  per call rather than per record.

Promise leaks removed: the invented "would break the same consumers twice"
maintainer policy, flat future tense on an unlanded warning, "safe for an
embedder to poll", and "least likely to move" as a stability signal.

check-doc-flags.sh and check-doc-freshness.sh both pass.

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

* docs(engdocs): drop a Markdown-unsafe escaped quote from the §8 rewrite

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

* docs(engdocs): re-anchor to the rebase base and record the #6575 data-behind stop

Maintainer review fixup for #6652.

The doc landed marked `Read at: d487b9796`, but the branch merges into
`e1e1158dd`, and five of the sources it names as its freshness basis drifted
in between — including §7's sole source. By the doc's own rule that makes the
marker wrong, not merely old.

- Re-anchor `Read at:`/`Last reviewed:` and the four in-body read-commit
  references to `e1e1158dd`, and add the sources the re-read reached:
  `smart_remote_migrate_gate.go`, `internal/storage/embeddeddolt/`,
  `cmd/bd/remote_migrate_gate.go`, `cmd/bd/store_factory.go`,
  `internal/storage/dolt/store.go`.
- §7: record #6575's data-behind stop — trigger, its reporting ahead of
  `shared-store`, the collapse to a single `pull-first` option, the exported
  `IsDataBehind()`/`DataBehindRemedyCommand` an embedder classifies on, and
  the lenient `OpenForRemoteSync` carve-out for the remedy.
- §7: scope the `OpenForRemoteSync` carve-out to the CLI. Both that function
  and the `dolt.Config.RemoteSyncOpen` field live under `internal/`, and none
  of the public open paths takes an option that could request the lenient open,
  so an embedder cannot replicate the remedy in-process: it runs `bd dolt pull`
  out of process, outside proxied mode, and re-opens.
- §7: scope that stop's reachability to the call sites that wire the ancestry
  adopter, rather than asserting a proxied workspace meets it.
  `localDataBehind` reads `FastForwardAdopter.AheadBehind` and reports "not
  behind" when the adopter is nil; of the two production callers of
  `CheckSharedStoreMigrateGate`, only `internal/storage/dolt`'s server-mode
  open wires it. `internal/storage/uow/dolt_sql_provider.go` — the proxied CLI
  path and `bd serve`'s own provider, per `cmd/bd/uow_factory.go` — passes
  nil, so a proxied, remote-backed clone that is data-behind at schema parity
  routes to `smartAutoMigrate` and gets the shared-store refusal, never the
  pull-first one. Embedded mode reaches the stop by the other route,
  `CheckRemoteMigrateGateWithAdopt` with a fully-wired adopter. The proxied
  `dolt pull` observation is re-framed to match: the pull is still the
  precondition and proxied mode still refuses the verb, but the gate never
  names it there. The underlying gap is base behaviour at this commit.
- §7: the trigger is `behind >= 1` whatever `ahead` is, not the narrower
  strict-ancestor relation — `localDataBehind` states that restricting the
  stop to `ahead == 0` "would leave the larger half of the affected cohort
  unprotected". The `DataDiverged` bullet now names `ahead >= 1` as the shape,
  which is why that pull merges rather than fast-forwards.
- §7's "adds two refusals" is deliberately kept. That count is the shared
  form's delta over the remote-backed flow and mirrors the source comment on
  `CheckSharedStoreMigrateGate`; the data-behind stop lives in
  `checkRemoteMigrateGate` underneath, so raising it to three would introduce
  a new error. The section now says so in place.
- §8: four join sites, not three — name `openReadOnly` and scope the
  create-rather-than-fail claim to the read-write path.
- §3: carry the "not verified by running" marker inline beside the MySQL
  client claim, as §11 already does.
- §6: scope the migrate-verb consent to the arm that reads it. The headline
  and the consent bullet said the verb migrates on a proxied workspace
  unconditionally, contradicting §7's own already-correct wording.
  `sharedMigrateConsent` has exactly one non-test read site,
  `sharedNoRemoteGate`, reached only from `checkRemoteMigrateGate`'s
  `if !hasRemote` branch; the comment there scopes it deliberately, because
  with a remote configured #4259's cross-clone fork risk still demands the
  stronger designated-migrator confirmation. A remote-backed shared or proxied
  database consults only `--force` / `BD_ALLOW_REMOTE_MIGRATE` and otherwise
  refuses the pending main-lane migration at the store open. §7's
  `SharedConsentCommand` hedge is deliberately unchanged.
- §6: qualify the `--force` parenthetical in that same consent bullet.
  `bd migrate schema --force` trips `isForcedMigrate`, but the bare
  `bd migrate --force` never gets that far on a proxied workspace:
  `validateProxyMaintenanceBeforeProvider` runs inside the proxied-mode block
  of the root `PersistentPreRunE`, ahead of
  `schema.SetForceAllowRemoteMigrate`, and its full-path lookup matches
  `migrate` and exits with `proxy.migrate.unsupported` before any store opens
  — the refusal §6's own second paragraph already states. `bd migrate schema`
  escapes only because its command path contains a space and returns nil
  first. The clause now scopes the bare verb instead of offering it as an
  unlock on the one workspace that refuses it.
- §6: name the `migrate sync`/`migrate-personal`/`migrate-issues` rows and
  the history-capability gate that runs before the multi-word fall-through.
- Update the "Four of the eleven" count and the `DOC_INVENTORY` freshness row
  to match.

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-09-23 21:59:27 -07:00
Julian Knutsen
e1e1158dd9
release/1.3.0: stop the smart gate auto-migrating a data-behind clone (#6575) (#6659)
* fix(schema): stop the smart gate auto-migrating a data-behind clone (#6575)

Release-branch counterpart of the main-line fix. The four source files are
byte-identical to the main commit; only the CHANGELOG placement differs (a
1.3.1 "Fixed" bullet instead of Unreleased).

The smart migrate gate's first-mover verdict was computed from schema facts
alone: equal content hashes against the cached remote ref, equal max version,
and at-or-above the convergence floor. None of those say anything about where
the clone's branch sits relative to the ref the hashes came from, so a clone
that was level with the remote on SCHEMA but behind it in unpulled DATA commits
satisfied every precondition and was classified a safe first-mover.

It then migrated in place, minting local-only schema commits on a HEAD missing
the remote's data commits. When the pending batch moves a tracked table onto
the dolt_ignore plane (0062's events), every subsequent `bd dolt pull` refuses
to merge (#6368) and the clone can no longer fetch the very commits it was
already behind on. v1.3.0's upgrade audience is largely 1.1-era databases, which
is exactly the cohort reaching this state — this is being field-hit now, which
is why rc.2 is held for it.

The decisive fact was already wired: routeSmartGate's remote-ahead branch
consults adopt.IsStrictAncestor (ahead == 0 && behind >= 1) via
routeAdoptFastForward, and both production call sites supply it. The
equal-version path simply never read it. Read it there too, before granting the
automatic migrate, and stop with a new data-behind fallback reason naming the
one-command remedy.

The predicate does the narrowing for free: a level clone (ahead 0, behind 0) and
a clone with unpushed local commits (ahead > 0) both read false and still
auto-migrate, so only a strictly-behind clone is refused. An inconclusive
ancestry read degrades to the blunt #4515 block rather than assuming level,
matching the file's contract that no fallback is less safe than the blunt gate.
Below-floor outcomes are untouched — the check sits inside the floor arm.

Patch-line discipline: no new schema migration, no new feature surface. The stop
reuses the existing blunt RemoteMigrateGateError with an empty Decision, so
there is no change to the JSON or agent contract — no new Error()/userBody()/
AgentDirective/Options arms. Both shipped escape hatches still work unchanged:
--force/BD_ALLOW_REMOTE_MIGRATE=1 are consulted before the smart gate, and
BD_SMART_GATE=0 still yields the blunt block. Both stay in the release notes.

S0 capability matrix: no cell flips, so no same-commit matrix change is needed.
Verified two independent ways. No matrix fixture configures a Dolt remote — the
direct `dolt push` cell asserts "No remote is configured" and `dolt remote list`
asserts an empty listing — so checkRemoteMigrateGate returns at the hasRemote
check before the smart gate, making routeSmartGate (the only function whose
outcome changes) unreachable in every cell. Independently, matrix fixtures are
created by the binary under test, so schema is at latest and the gate exits
earlier still at len(pending) == 0. The one migrate probe, the `migrate schema`
row, therefore never reaches the changed code.

Regression test builds a genuinely data-behind clone against a real Dolt
server rather than stubbing the fact the bug is about, and adapts to this
branch's own LatestVersion (which lacks 0067). Verified failing at d487b9796
and passing here.

Fixes #6575

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

* fix(schema): give the data-behind stop a working remedy, and widen it

Review follow-up on the #6575 fix. The stop was right; what it told the
operator to do was not reachable, and it protected the rarer half of the
cohort.

F1 (blocker): the refusal prescribed `bd dolt pull`, and `bd dolt pull` was
refused by it. Measured on a real data-behind embedded clone (ahead=0,
behind=1, clean working set) at the previous head: the pull exited 1 printing
"Run `bd dolt pull` first, then retry"; `bd sync` and `bd init --reinit-local`
exited 1 the same way; `bd bootstrap` reported "Database already exists …
Nothing to do." and exited 0; `bd migrate schema --force` then `bd dolt push`
left ahead=1 behind=1 with the push rejected non-fast-forward. The only thing
that moved the clone was BD_ALLOW_REMOTE_MIGRATE=1 — performing the migration
the stop exists to prevent. An embedded workspace has no external `dolt` binary
either, so that was a fence with no gate.

It is the #4566 deadlock one refusal over, so it takes #4566's shape of fix:
a lenient open for the command whose whole purpose is to clear the refused
precondition. Narrower than #4566's, though — the remote-sync open tolerates
ONE gate reason (RemoteMigrateGateError.IsDataBehind) and nothing else. A pull
cannot resolve a fork skew, a below-floor database, a shared-store consent
decision or an opted-out blunt block, so waving it through those would buy
nothing and hide them; the dirty-table and dependency-re-key refusals stay
fatal on this open too. Broadening the existing LenientOpen classification
instead would have granted all of that in one line.

Verified end to end on both shapes, exit codes real: `bd dolt pull` 0
(0,1 -> 0,0), retrying the refused write auto-migrates as a true first-mover,
`bd dolt push` 0. On a diverged clone the pull merges: 0 when it can, 1 with
"merge conflicts in config require operator resolution; merge aborted and
working set restored" when it cannot, and `bd dolt pull --strategy theirs`
then 0 — which is why the diverged guidance names it.

F2 (high): LocalIsStrictAncestorOf is ahead == 0 && behind >= 1, so a clone
with any local commit of its own read "not behind" and still auto-migrated.
Measured at the previous head with ahead=1, behind=1: "safe first-mover", and
the migration ran. bd auto-commits every write, so behind-AND-ahead is the
ORDINARY multi-machine state and the shape the fix protected was the narrower
one. It reaches the identical wedge — the migration lands on a history missing
the remote's commits either way — so the predicate is now behind >= 1 whatever
ahead is, read from LocalAheadBehind (the counts LocalIsStrictAncestorOf was
already computing and discarding). A level clone and a purely-ahead clone have
nothing to pull and still auto-migrate, verified through the CLI.

The remedy differs by shape even though the command does not, so the two stay
separate verdicts all the way out to the message, the agent directive and the
JSON: one is told its pull fast-forwards, the other that it merges and how to
resolve conflicts. An adopter that wires only the older callback keeps the
narrower (pre-widening) reading rather than losing the stop.

F3 (medium): with data-behind outranking fallbackReasonSharedStore, a shared
store's refusal rendered with neither "co-resident" nor "#5920" anywhere —
Options()' sharedRisk only ever decorated the adopt option. The #5920
consequence and the `bd migrate schema` consent step the retry needs there now
travel with this reason, on every surface.

F4 (medium): --json emitted only fallback_reason: "data-behind" while
observed/expected/options stayed the blunt default, whose option 1 is
["bd migrate --force", "bd dolt push"] — the bug followed by a push that is
guaranteed rejected while the clone is still behind — and whose option 2
no-ops. The pull-first remedy lived only in prose --json never emitted.
observed/expected now describe this stop, options is the single pull-first
option, and data_behind_shape says which pull to expect. decision stays absent
and fallback_reason unchanged, so the key agents match on does not move.

The blunt body is REPLACED for this reason rather than decorated: both of its
options were measured wrong here, and leaving them under a note saying "pull
first" is what sent the last round back into the wedge. Error() is deliberately
untouched — the headline stays the blunt #4259 line, and the body's first
sentence accounts for it.

Both escape hatches are unchanged and re-measured: `bd migrate --force` and
BD_ALLOW_REMOTE_MIGRATE=1 are still consulted before the smart gate (exit 0),
and BD_SMART_GATE=0 still yields the blunt gate unconditionally — including
for `bd dolt pull`, which is what opting out means. The two corrections from
the first round are preserved: the "proceeds on its own" promise is still
gated on !e.Shared, and the unparseable-BD_SMART_GATE carve-out still lets
data-behind outrank an env complaint (BD_SMART_GATE=maybe re-measured).

Tests cover both shapes at three levels. The schema routing table pins the
widened predicate, the shape split, the error degradation, the
IsStrictAncestor fallback, and every remedy surface including IsDataBehind's
narrowness; neutralizing the widening fails three of its subtests. The
real-Dolt regression test now runs both shapes over the same two-clone
file:// fixture, measuring ahead/behind rather than stubbing it and asserting
that the strict-ancestor relation is false exactly where the diverged shape
needs the widening. A new embedded test builds a genuinely data-behind
embedded store, proves OpenForRemoteSync gets through the refusal without
migrating, and proves BD_SMART_GATE=0 on the same fixture does NOT.

No S0 matrix cells flip. No matrix fixture configures a Dolt remote, so
routeSmartGate stays unreachable; the only `dolt pull` probes are the
proxied-mode typed refusals, which are classified in historyCapabilityMatrix
before any store opens and are untouched.

This is the release/1.3.0 counterpart of the main-line change, code-identical
to it. Two differences, both from the base: the CHANGELOG entry is the expanded
form of the existing #6575 bullet inside `## [1.3.1] - 2026-09-16`'s `### Fixed`
(same position the bullet already held, so the #6653 CHANGELOG non-conflict is
preserved), and the dolt.Config literal in cmd/bd/main.go has no
PoolReadTimeoutFallback field on this base. The shipped `## [1.3.0]` section is
byte-identical: sha256 798a2ee0b0f0b7a3f0fc017ae01c919807740348a34f5ea8719b82a008533d00,
9169 lines, and the only CHANGELOG hunk is above its header.

This branch's own matrix (cmd/bd/topology_capability_matrix_test.go, absent on
main) was re-checked after the widening: no cell flips. No fixture configures a
Dolt remote (the direct `dolt push` cell asserts "No remote is configured" and
the direct `sync` cell asserts "status": "no-remote"), so routeSmartGate stays
unreachable, and there is no `dolt pull` probe row at all.

Refs #6575
Refs #6368
Refs #4566

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

* fix(schema): retarget the shared data-behind consent verb under --global

Self-review catch on the previous commit's own new text. The #5920 consent verb
the shared data-behind guidance names is TARGET-SCOPED: under --global the
refused open aimed at beads_global, so the project-scoped `bd migrate schema`
would consent the wrong database and leave the refusal in place. The existing
shared-no-remote arm already handles this (printGlobalDatabaseConsentHint and
the JSON retarget), and the new arm had to as well.

The JSON retarget could not simply reuse the Decision test: this stop reaches
the renderer through the default empty-Decision arm, keyed on the fallback
reason, so `e.Decision == "shared-no-remote"` misses it. The human body now
names the --global variant beside the project-scoped one, exactly as the
shared-no-remote body does. The pull itself is target-agnostic and is
deliberately NOT rewritten.

Refs #6575

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

* fix(schema): give the data-behind read path the pull remedy too

Round 2 fixed the write path and the agent payload, but left the two
lenient embedded opens rendering the blunt #4259 coordination block. Those
opens do not fail on this refusal - they warn and carry on - so the warning
IS the whole contract for `bd list`, `bd ready`, `bd show`
(openReadOnlyCommand) and `bd dolt commit` (openWorkingSetReconcile). Both
printed `gateErr` (Error(), the one-line summary) followed by the unchanged
sharedGuidance bullets, so on a data-behind clone the first thing bd said
was:

    • designated migrator (only ONE machine): bd migrate --force && bd dolt push
    • every other clone (another already migrated): bd bootstrap

Measured on a fast-forward clone at the previous head: that migrate lands
v67 on a history the clone is still behind on, and the `bd dolt push` after
it exits 1, rejected non-fast-forward - the #6575 state, reached by
following bd's own instruction, from the same clone whose write path says
in capitals not to run it. `bd bootstrap` no-ops against an existing
workspace. `bd list` is the first thing a 1.1-era upgrader runs and what
agents run constantly, so this was the most-read surface of the whole stop.

Both arms now branch on gateErr.IsDataBehind() and print
gateErr.UserMessage(), which is where the shape-branched pull-first body
already lives - the same thing server mode's warnLenientOpenRefusal has
printed all along. The intent framing is kept rather than replaced: the
command in hand is still succeeding against the old schema, which the
body (written for the fatal refusal) does not say. Refusals that are not
the data-behind stop keep the coordination bullets, which are right for
them; a second test pins that so the new body cannot swallow them.

Verified by running, not asserting - `bd list` and `bd dolt commit` on real
data-behind clones of both shapes, then `bd dolt pull` and a re-run, which
migrates.

Also fixes the agent payload contradicting itself. For data-behind,
AgentDirective calls `bd dolt pull` the single option, Options annotates it
`when: always, for this stop` and `risk: none - a pure fast-forward`, yet
human_decision_required stayed hard-coded true, so an agent keying on that
field stalled for approval of a step the same payload calls unconditional
and riskless - and the cost of that stall is reaching for
`bd migrate --force`. It is now false for exactly that arm. It stays true
when DataDiverged (the pull merges and can need conflict resolution and a
--strategy choice) and when Shared (the payload's second option needs an
operator who can confirm every co-resident client is upgraded, #5920);
getting either backwards would be worse than the contradiction. The `when`
string is deliberately unchanged for both shapes - the pull is the only way
forward either way; it is the risk, not the applicability, that diverging
changes.

Refs #6575

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

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 02:49:16 -07:00
Julian Knutsen
d0063ac894
release/1.3.0: eleven cherry-picks for 1.3.1-rc.2 (#6653)
* fix(storage): include custom active-category statuses in bd ready (#5831) (#5918)

bd ready pins WorkFilter.Status to StatusOpen. BuildReadyWorkWhere treated
that pin as an exact match, so issues in a custom status with category
active never appeared — even though bd statuses --help, the ready_issues
view (migration 0025), and ClaimableSourceStatusesInTx all treat that
category as ready-eligible.

Widen the singular StatusOpen clause to the same predicate the view uses:

  status = ? OR status IN (SELECT name FROM custom_statuses WHERE category = 'active')

Non-open singular statuses stay exact. Built-in open still matches. Custom
wip/done/frozen/unspecified statuses stay out, matching claim's GH-3570
anti-steal set.

Reported by Justin Clemens (@justin-candor).

Addresses #5831

(cherry picked from commit 66aa73bb99)

* fix(cli): `bd list --wisp-type` cannot match a row — register the plane knob it needs (#6098)

`bd list --wisp-type heartbeat` returns an empty listing for EVERY input, and
`bd list` exposes no flag that changes that.

ListRequest.WispType is a predicate, not a plane selector — its own doc says
so, and RunReaderListWispTypeNarrowsTheAdmittedPlaneRatherThanAdmittingIt pins
it. That contract is right and this does not touch it. The doc also names the
way out:

    The combination that answers with rows is IncludeEphemeral (or
    IncludeInfra) plus this, and it is lawful rather than refused.

`bd list` registers neither `--include-ephemeral` nor `--all-types`. So of the
two combinations the doc names, the CLI can express only IncludeInfra — which
admits the plane AND lifts the infra-type exclusions AND changes the template
treatment, three decisions a caller who wanted one classification did not ask
for. The narrow knob the doc names FIRST has no flag at all.

That is the whole defect: the API composes correctly, and the CLI is missing
the other half of the pair.

## What this does

1. Registers `--include-ephemeral` on `bd list`, wired to
   `ListRequest.IncludeEphemeral` — the plane knob alone, off by default, so
   the default listing is byte-identical.

2. Refuses `--wisp-type` when no plane is admitted, with the fix in the hint,
   instead of printing an empty listing.

The refusal is at the CLI layer ONLY. At the API layer the combination stays
lawful and still composes to an empty page: that is the pinned contract, and a
programmatic caller composing filters may legitimately land on it. A human
typing `--wisp-type heartbeat` cannot have meant "prove to me that durable rows
carry no classification", so the CLI is where the guess is safe to make.

An explicit `--type` is deliberately left alone: an infra type routes to the
plane by itself, so the request may well be satisfiable, and this layer cannot
tell which types those are without loading the workspace's infra vocabulary.
Refusing there would reject lawful, answerable requests.

## Verification

    --- PASS: TestListRegistersIncludeEphemeral
    --- PASS: TestGatherListInput_WispTypeWithoutAPlaneIsRefused
    --- PASS: TestGatherListInput_WispTypeWithAPlaneIsAccepted (3 subtests)
    --- PASS: TestGatherListInput_IncludeEphemeralReachesTheRequest

The pair discriminates rather than being trivially green: a guard that refused
every `--wisp-type` would pass the refusal test and fail all three acceptance
subtests, one per route that admits the plane.

`ok github.com/steveyegge/beads/cmd/bd`, `ok
github.com/steveyegge/beads/internal/workapi`, `go build ./...` and `go vet`
clean. `internal/workapi/list.go` and the golden corpus are untouched.

docs/CLI_REFERENCE.md is not regenerated here: the docs pipeline builds from
the release tag in docs/cli-docs.pin (v1.2.2), not from this checkout, so the
new flag appears at the next release bump.

Claude-Session: https://claude.ai/code/session_01X1jMLQTSrCwtzFRS1xeUC6
(cherry picked from commit cbf84cb1c0)

* fix(list): honor --status when combined with --ready (#5924)

* fix(list): honor --status when combined with --ready (#5832)

`bd list --status X --ready` silently dropped --status and returned the
unfiltered ready set (typically open issues). BuildListFilter pinned
StatusOpen whenever ReadyFlag was set, and ReadyFilterFromIssueFilter
hard-coded the same pin, so a custom status or in_progress selector
never reached GetReadyWork.

--ready without --status still defaults to open. An explicit --status
is now the ready-work status selector, matching how other list filters
already compose with --ready. `--status all` remains the no-filter
spelling and keeps the open default.

* fix(list): status-aware --ready footer and honor-path contract docs (#5832)

The query intersection from the prior commit is unchanged. Round-1
review asked the ReadyFlag/Statuses contract comments and the text
footer to describe the honor path: default --ready is still open,
an explicit --status is named instead of "excludes in_progress".

(cherry picked from commit f5a20fb66b)

* fix(doctor): ignore the generated dolt-server-config.yaml (#5978)

doltserver.Start() writes .beads/dolt-server-config.yaml when the resolved
dolt binary supports auto_gc_behavior.archive_level. Its own doc comment
says the file "lives alongside the other gitignored server state files in
beadsDir", but the hyphenated name falls outside the "dolt-server." prefix
shared by the other five entries, so both GitignoreTemplate and
requiredPatterns missed it.

The file holds an absolute cfg_dir and a per-machine port, so committing it
breaks every other clone -- the same reason the template already gives for
'redirect'. It shows up as untracked in every consumer repo whose dolt
supports archive_level. This repo does not see it because its own root
.gitignore has a blanket .beads/* rule.

Add the pattern to requiredPatterns as well as the template: the template
only helps repos initialised after this change, while requiredPatterns is
what missingGitignorePatterns() iterates, so it is what lets bd doctor --fix
append the rule to an existing .beads/.gitignore.

Co-authored-by: Adam Spiers <ai@adamspiers.org>
(cherry picked from commit 671db6560d)

* fix(storage): stop recommending an inert config.yaml key for a missing prefix (#5936)

ReadConfigPrefix gates on the database's config table row `issue_prefix`.
When that row is absent its error told the operator that, "if using
config.yaml, use key 'issue-prefix', not 'issue_prefix'" — but this gate
never consults config.yaml. The YAML value is read one line above the
error solely to populate a debug.Logf diagnostic; it is discarded, so
setting `issue-prefix` in config.yaml leaves the gate failing exactly as
before. Following the advice produces a tracked config field that changes
nothing and misleads the next reader.

Point the message at what actually writes the row — `bd init --prefix` or
`bd bootstrap`, both of which it already named — and say plainly that the
check reads the database's config table so the config.yaml key does not
satisfy it. No resolution behavior changes; this is the error text only.

Reported-by: @ncljesus
Closes #5916

(cherry picked from commit 61ec85181f)

* fix(create): say --file is one issue per ## heading (#5921)

bd create --file/-f is a batch-import route: it creates one issue per
H2 ("##") heading, and ### subsections attach fields to that issue.
The old Usage was "Create multiple issues from markdown file", which
never named those semantics or --body-file. Callers who wanted "one
issue, description loaded from a file" reached for the shortest flag
and got a silent bulk import instead -- reported by @seanmartinsmith
with a 3-section briefing file (## Problem / ## Context / ##
Acceptance Criteria) that became 3 issues instead of one.

gatherCreateInput already rejects a positional title combined with
--file. That is the reporter's literal repro, so this keeps the
rejection and adds a --body-file hint on the error they actually
see. The remaining trap -- --file used alone on a section-headed
file -- is unchanged, because bd cannot tell that apart from a
genuine batch file by content.

Tests: parseMarkdownFile reproduces the trap file; gatherCreateInput
locks in the title+--file rejection and --body-file hint; flag Usage
names the per-heading behavior. The existing TestCreateFromMarkdownFile
binary path already covers well-formed --file creates.

(cherry picked from commit 67b066b58e)

* fix(list): stop truncation hint padding a blank TTY line (#5927)

printTruncationHint fed surrounding newlines through ui.RenderWarn.
lipgloss treats that as a block, pads the blank lines to the widest-line
width (alignTextHorizontal shortAmount = widestLine - lineWidth), and
drops the trailing newline (GH#5685). The next shell prompt then prints
on the same line as a run of spaces.

Keep the newlines outside RenderWarn so the hint is one colored line
with a real trailing newline. Tests construct an explicitly styled
lipgloss Style so the padded blank-line shape fails if the helper is
reverted.

Fixes #5685.

(cherry picked from commit 766c0bd15a)

* fix(setup/claude): keep settings.json's trailing newline and skip no-op rewrites (#5944)

* fix(setup/claude): keep settings.json's trailing newline and skip no-op rewrites (#5693)

bd setup claude (and bd init, which calls it) marshalled the Claude settings
map with json.MarshalIndent and wrote it unconditionally. MarshalIndent emits
no trailing newline, so every run stripped the one Claude Code's own writes
leave behind, and re-wrote the file even when no hook changed. Because bd init
git-adds .claude/settings.json, that surfaced as a staged diff with no
semantic content.

The same marshal-then-write pattern appears at four call sites in claude.go:
installClaude's settings write and its settings.local.json migration, and
removeClaude's settings write and its settings.local.json cleanup. Fixing one
would have left the bug live in the other three, so both halves are now shared
helpers -- marshalSettings appends the newline, writeSettingsIfChanged compares
against the bytes already on disk and returns early when they match -- and all
four sites go through them.

Reported by @maphew.

* chore(setup/claude): use the repo spelling "marshaled" in the new comments

The misspell linter flags British "marshalled"; CI pins golangci-lint
v2.10.1 and runs it with --new-from-merge-base, so both new comment lines
are in scope. Comment text only, no behaviour change.

(cherry picked from commit cad7e17d70)

* fix(gate): evaluate cross-rig bead gates via prefix routes (#5859)

* fix(gate): route cross-rig bead checks (#5857)

Evaluate historical rig:bead gate targets through the current read-only prefix routing seam in direct and proxied-server modes. Preserve local bead gates, reject malformed cross-rig values, and cover the real two-store route with a Dolt integration test.

Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of Klas Hesselman

* fix(gate): address cross-rig review feedback (#5857)

Preserve the original local not-found error when prefix routing is unavailable, document the user-visible behavior, and lock the proxied error contract with a regression test.

Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of Klas Hesselman
(cherry picked from commit cbfc505e39)

* fix(storage/uow): retry transient ping failures during openDB bootstrap (#6003)

* test(uow): red — pingWithRetry does not exist yet for openDB's boot-time ping

Adds TestPingWithRetryRecoversFromATransientBadConn (be-x49l6): a fake
pinger exercising three cases — transient error retries then recovers,
non-transient error fails without retrying, and an already-cancelled
context fails promptly. Fails to compile until pingWithRetry/pinger
are added to dolt_sql_provider.go.

* feat: green — Fix: unretried ping in uow openDB turns a transient Dolt connection drop into a hard CI failure (refs be-x49l6)

* refactor: drop what-comment on pingWithRetry (self-review, refs be-x49l6)

Self-review flagged it as restating the function's own signature/behavior
rather than explaining a non-obvious why; the pinger and
isTransientPingError comments stay since they carry rationale the code
doesn't otherwise convey.

* test(uow): red — a hung boot ping is not bounded per attempt

Adds the two behaviours review #6003 asked for, both failing:

  - a_hung_ping_is_capped_per_attempt_and_retried: blockingPinger stalls
    until its context is cancelled. backoff.Retry bounds only the gap
    between attempts, so with the caller's context handed straight to
    PingContext the call never returns at all. The subtest runs the call
    off-goroutine so this reports as "never returned" instead of a
    package timeout.
  - connection-level_net_error_retries_then_recovers: a *net.OpError
    (connection refused / reset / broken pipe) is currently classified
    non-transient and fails the boot ping outright.

the_caller's_own_deadline_fails_without_retrying passes already and is
kept as the regression guard for the trap #6000 fell into: making
context.DeadlineExceeded retryable must not make the caller's own expiry
retryable too.

pingWithRetry takes attemptTimeout here but does not honour it yet, so
the red is behavioural rather than a compile error.

Refs be-g1i7n.

* fix(uow): bound each boot ping attempt and widen the transient classifier

Review #6003, point 1. backoff.Retry bounds the gap between attempts but
cannot interrupt one in flight, and the DSN sets a dial Timeout (5s) with
no ReadTimeout — so a server that accepts TCP and then stalls
mid-handshake blocked for the caller's entire context, which is the exact
scenario the PR summary claims to fix.

Each attempt now runs under its own context.WithTimeout
(pingAttemptTimeout, 10s — above the 5s dial timeout so a real dial
timeout still surfaces as itself), and context.DeadlineExceeded is
classified transient so the retry loop actually continues.

pingWithRetry checks the caller's context *before* classifying. That is
what keeps the retryable DeadlineExceeded from swallowing the caller's
own expiry — the inverse of the regression #6000 introduced by capping
each attempt and then treating the resulting DeadlineExceeded as
permanent. Covered from both sides:
a_hung_ping_is_capped_per_attempt_and_retried and
the_caller's_own_deadline_fails_without_retrying.

Review #6003, point 2. isTransientPingError stays separate from
internal/storage/dolt's isRetryableError, and now says why in full: that
one is a query-time classifier matching on error text, admitting
migration-lock, read-only and MySQL-1105 shapes a boot ping cannot be in
because nothing has executed on the connection yet. The coverage gap the
review named is closed on this side instead — *net.OpError is transient,
which is refused/reset/broken-pipe portably and by type rather than by
substring, with permanent DNS failures excluded so an unresolvable host
still fails fast instead of spending the whole budget.

Refs be-g1i7n.

(cherry picked from commit c0d8da42de)

* fix(deps): bump dolt/go past upstream manifest-missing-chunk defense (#4070) (#5931)

* fix(deps): bump dolt/go past upstream manifest-missing-chunk defense (#4070)

Pin github.com/dolthub/dolt/go to 796d074977417da931df65202a79e0a7f532a3db.
That hop includes:

- 23ccbf9442275166f168939277a5b4a348a63c9d — reject a file manifest
  update that references a missing table file (the defense itself)
- 796d074977417da931df65202a79e0a7f532a3db — doc/test follow-up to the
  defense commit (no production-semantics change)

A non-atomic backup sync can leave the backup manifest ahead of chunk
files; subsequent syncs then fail with "table file not found" and stay
broken. The upstream defense turns that silent corruption into a loud
failed sync. Beads' previous pin (a6690826d767, 2026-07-15) predates
both commits.

Minimal-churn pin: do not bump to today's dolt tip. go mod tidy did not
force a later version.

This is a mitigation, not a root-cause fix: backup file+manifest publish
remains non-atomic, and backups already in the manifest-ahead state are
not repaired by this change.

Mitigates #4070

* fix(nix): update vendorHash for the dolt/go bump

The go.mod/go.sum bump in this PR invalidates the pinned vendorHash, so
`nix build .#default` fails with a fixed-output hash mismatch. Update it to
the value CI computed:

  specified: sha256-D+KDoLFJHpt9D9rCrtE3NMfL4fgK7UxpdKlCxp5yz5Y=
  got:       sha256-wDU1tw/4t2CetwQl4+zUhlDI70dSasLLI2Gy66ZyhQQ=

The repo documents this coupling in .github/dependabot.yml; the existing
"Update vendorHash for dependabot Go bumps" workflow only fires for
dependabot PRs, so a manual bump is needed here.

(cherry picked from commit 851aa2f20a)

* docs(changelog): record the 1.3.1 cherry-pick behaviour deltas

Documents all eleven picks under the existing `## [1.3.1]` heading. The
six behaviour deltas go under Changed, including the two that are not
pure wins and that a user is most likely to hit without knowing why:

  - bd doctor now warns on every pre-existing workspace until --fix
    appends the new .beads/dolt-server-config.yaml gitignore rule.
  - opening a store against a dead server takes up to ~30s to fail
    instead of failing instantly, because the boot ping is retried.

Also called out as non-obvious: the ready set grows where custom
active-category statuses exist, bare --wisp-type becomes a refusal
rather than an empty success, and the Dolt bump converts a quietly
corrupting backup sync into a loud failing one without repairing
backups already in that state.

The dated `## [1.3.0]` section is shipped and is left byte-identical:
the diff is 165 insertions and 0 deletions, and the [1.3.0]-to-EOF
region still hashes to 798a2ee0b0f0b7a3f0fc017ae01c919807740348a34f5ea8719b82a008533d00.
The `## [1.3.1]` date is left for a later release prep to restamp.

* fix(nix): recompute vendorHash for the release-branch dependency set

The #5931 cherry-pick (510675948) bumps four dolt module pins, which
invalidates the pinned vendorHash. Neither side's value was usable: the
release branch already carried its own dependency bump (d594092eb), so
this pick lands on a vendor set that has existed on neither release/1.3.0
nor main, and #5931's own hash was computed against main's graph.

Taken from the `got:` value the nix-build lane reported for this branch:

  specified: sha256-wDU1tw/4t2CetwQl4+zUhlDI70dSasLLI2Gy66ZyhQQ=
  got:       sha256-DQdauEx5g48Xbxrz4wGLx4vkrQoYQX3FUx+7N/Y6YV4=

go mod tidy after the pick was a no-op, and the dependency delta against
the release tip is exactly the four intended pins, so this hash covers
that change and nothing else.

* docs(changelog): scope the #6003 open-latency entry and correct its bound

The 1.3.1 entry for the openDB bootstrap-ping retry said "up to ~30s" and
named no topology. Both were misleading:

- 30s is the retry BUDGET, not the wall-clock bound. backoff stops
  scheduling new attempts at 30s (MaxElapsedTime, dolt_sql_provider.go)
  but cannot cancel one in flight, and pingAttemptTimeout caps an attempt
  at 10s — so a single open can take ~40s. openAndInitSchema pings twice,
  each with a fresh budget, so the narrow case where the backend satisfies
  the first ping and the schema init and is then unreachable for the
  second reaches ~80s.

- Only unit-of-work provider construction takes that ping, which is a
  minority of topologies: proxied-server (local and external) on every
  command, plus `bd serve` in server/external-server/shared-server
  workspaces, which funnels through newSQLServerUOWProvider. Embedded
  never reaches it (bd serve refuses embedded outright), and an ordinary
  CLI command in a server or shared-server workspace opens a DoltStore
  that takes no such ping. An embedded reader of the old entry would have
  triaged a slowdown that cannot affect them.

CHANGELOG only; the dated [1.3.0] section is unchanged (verified
byte-identical, sha256 798a2ee0…, 9169 lines).

---------

Co-authored-by: Vishnu J <vishnuj81093@gmail.com>
Co-authored-by: Karel Bourgois <karel@voxist.com>
Co-authored-by: Adam Spiers <github@adamspiers.org>
Co-authored-by: Adam Spiers <ai@adamspiers.org>
Co-authored-by: swedeinasia-flow <klas@flownetworks.io>
Co-authored-by: Jim Wordelman <jim@wordelman.name>
2026-09-21 00:23:37 -07:00
Julian Knutsen
d487b9796e
release: prep v1.3.1-rc.1 (#6593)
* release: prep v1.3.1-rc.1

Sanctioned RC bump per RELEASING.md "Cut an RC", on the #6298 model:
./scripts/update-versions.sh 1.3.1-rc.1, which carries the stamp into
version.go, the three plugin.json manifests, marketplace.json, the npm
package.json, the MCP pyproject.toml/__init__.py/uv.lock, default.nix,
the ten .githooks managed-section markers and the winres strings.
scripts/check-versions.sh passes all 24 gates at 1.3.1-rc.1.

Unlike the 1.3.0 RCs, this bump moves the BASE version, so
cmd/bd/winres/manifest.xml changes too (1.3.0.0 -> 1.3.1.0) along with
the winres numeric file_version/product_version (1.3.0 -> 1.3.1). Those
PE fields must be purely numeric; the FileVersion/ProductVersion strings
carry the full 1.3.1-rc.1, and uv.lock carries the PEP 440 normalization
1.3.1rc1 written by `uv lock`, never by hand.

This has to land before the tag: release.yml's verify-version-consistency
compares ${GITHUB_REF_NAME#v} byte-for-byte against the Version string in
cmd/bd/version.go, and every stamp on this branch still read 1.3.0.
Simulated against the working tree with the workflow's own grep/sed
pipeline: the extracted string is exactly "1.3.1-rc.1", on a single
matching line. The tag must be spelled v1.3.1-rc.1.

CHANGELOG: creates the [1.3.1] section dated 2026-09-16 and leaves
[Unreleased] empty but present, which is what #6038 (b3ef65c85) did when
it created [1.3.0] at branch-cut, and what #6298's fixup established for
an RC tag — an entry parked under [Unreleased] ships in no release by
Keep-a-Changelog semantics, yet the RC demonstrably ships it. The three
Fixed bullets already on the branch (#6580 x2, #6578) move under [1.3.1]
by the rename alone; their wording is untouched, and the shipped
[1.3.0] section and everything below it is byte-identical (sha256 of the
[1.3.0]-to-EOF region is unchanged across this commit).

The 2026-09-16 date is provisional. The final 1.3.1 prep must hand-restamp
it to the real release date rather than rerun the beads-release formula's
stamp-changelog step, which sed-inserts a fresh header under [Unreleased]
and never re-dates an existing section — running it against an already
dated [1.3.1] duplicates the heading. Same trap #6298 documented and #6564
then worked around.

cmd/bd/info.go: adds the 1.3.1-rc.1 digest at index 0 of versionChanges,
dated 2026-09-16 so the array stays newest-first with monotonic dates for
TestGetVersionsSinceOrder. It leads with the no-migration note (a 1.3.0
user's upgrade is a binary swap) and then digests the two #6580 changes and
the two #6578 ones. Per the #6298 lesson this key can only reach rc.1 users
by shipping inside the rc.1 binary; omit it and `bd upgrade review` dumps
the whole history at them.

docs/cli-docs.pin is still v1.2.2 on this branch — 1.3.0's docs-pin step
never happened. check-versions.sh explicitly excludes it, so it is not
tag-blocking and is deliberately left for the post-tag docs step.

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

* docs(release): reclassify 1.3.1 behaviour changes and document the config migration

Documentation-only amendment to the v1.3.1-rc.1 prep. No version stamp is
touched; ./scripts/check-versions.sh stays 24/24 at 1.3.1-rc.1.

Three corrections, all inside the `## [1.3.1]` section and its `cmd/bd/info.go`
`versionChanges` twin.

1. The flat->nested config migration is now documented (#6594). #6578 made
   `bd config set <dotted.key>` write a nested mapping, and where a flat
   top-level key of the same literal name exists it deletes that entry and
   re-emits the value nested (`updateNestedYamlKey`). `.beads/config.yaml` is
   not exclusively bd's, so another writer that reads its dotted keys flat
   stops seeing any value migrated this way — and if it re-adds the flat key,
   bd's own readers disagree: Viper-backed reads return the flat value while
   GetStringFromDir returns the nested one. Verified both halves empirically
   against this tree (dual-spelling probe: viper="flatvalue",
   GetStringFromDir="nestedvalue", independent of document order; migration
   probe: `dolt.host` flat entry deleted, sibling `dolt.port` and `other.thing`
   byte-intact). Realistic collisions are `dolt.*`, `export.auto`,
   `backup.enabled`.

2. Two genuine behaviour changes moved out of `### Fixed` into `### Changed`,
   following the 1.3.0-rc.2 precedent in c1e5e49e3: the `bd dolt status --json`
   shape change (#6580), which a parser of the old payload meets on upgrade,
   and the two `bd config set` success->failure cases (#6578). The fix content
   stays in `Fixed` with a pointer; neither statement appears in both sections.

3. `backend_endpoint` added to the documented key list in both CHANGELOG.md and
   info.go. It is a real `omitempty` field on `proxiedDoltStatus`
   (cmd/bd/dolt_proxied_lifecycle.go:63), set only when the sidecar reports an
   external backend — the one topology where `backend_managed` is false and
   nothing else names the server. Both surfaces now carry the same 11 keys as
   the struct.

Validated: `## [1.3.0]`->EOF is byte-identical before and after
(sha256 798a2ee0b0f0b7a3f0fc017ae01c919807740348a34f5ea8719b82a008533d00);
exactly one `## [1.3.1]` heading, `## [Unreleased]` present and empty;
check-versions.sh 24/24; go build/vet ./...; go test ./cmd/bd -run
'TestGetVersionsSinceOrder|TestVersionChangesStructure|TestVersionChangesCoverage|TestVersionChangesJSON|TestGetVersionsSince|TestDisplayVersion'
all PASS, no skips; scripts/ci/pr-lint.sh and scripts/ci/pr-policy.sh green;
`bd info --whats-new` surfaces both amendments end-to-end.

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

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-09-18 17:38:56 -07:00
Julian Knutsen
fa95439006
test(topology): front-door capability matrix across storage topologies (proxied-parity S0) [release/1.3.0] (#6579)
* test(topology): front-door capability matrix across storage topologies (S0)

Characterization test for the proxied-parity work. Records what bd does
TODAY across embedded, direct-local-server, direct-external-server,
proxied-local and proxied-external-tcp — including the behavior that is
wrong — so every later slice flips named rows and the flip is the review
artifact.

18 command probes x 5 topologies = 90 cells. Outcomes are classified so a
reader can tell the classes apart: REFUSED_TYPED carries reason=design
(permanent policy) or reason=unimplemented (a gap a later slice closes),
separately from WRONG_ANSWER, DEGRADED, ERROR and HONORED. Cells that
record a bug carry a knownBad string naming it.

Refusal rows additionally assert the two side-effect invariants from the
existing history matrix: no proxy pidfile materializes (the provider was
never constructed) and durable artifacts are byte-identical.

Findings this matrix pins down beyond the design inventory:
- `bd doctor` exits 0 on EMBEDDED having run no checks, not just proxied.
- root `bd compact` is HONORED proxied; its refusal row is unreachable
  because the gate short-circuits when the command has no --dolt flag.
- `bd dolt status` is correct on both direct server topologies; proxied is
  the sole outlier (running=false, pid 0, while the proxy serves CRUD).

Reuses the existing fixtures rather than adding a harness: bdInit,
newServerModeProject, bdManagedLocalInit, newSharedProxiedProject,
buildEmbeddedBD, runCommandBuffers and snapshotHistoryArtifacts. The only
new fixture is direct-local-server, which had no named helper.

Gating: named TestProxiedServer* so proxied-test-shard.sh discovers it,
which lands it in pr-risk.yml's test-proxied-cmd lane — a lane that runs
on pull_request, not only push-to-main. managed-local is gated on
BEADS_TEST_PROXIED_LOCAL, which only the proxied-local smoke lane sets, so
it gets a second entry point named/filed to match that lane's filters.

No production code changes.

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

* test(topology): tell the post-#6580 truth about proxied dolt start/status

#6580 makes `bd dolt status` truthful on a proxied workspace and turns
`bd dolt start` there into a typed refusal. This matrix still encoded the
pre-#6580 behaviour, so the two PRs are individually green and jointly red:
merged together, `dolt status` on both proxied topologies fails the
`"running": false` marker this table asserted.

- flip the proxied `dolt status` cell from WRONG_ANSWER/`"running": false`
  to HONORED/`"running": true` and drop its knownBad — the defect is fixed,
  not deferred
- add the `dolt start` row the stale deliberatelyNotProbed entry promised:
  REFUSED_TYPED `proxy.dolt_start.conflict` on both proxied topologies,
  REFUSED_UNTYPED on embedded (same command, no code a consumer can branch
  on), HONORED on direct-local where bd really does own the server
- delete deliberatelyNotProbed["dolt start"], which described the hazard
  #6580 fixed as if it were current
- add probe.skipOn so one row can be excused from one topology with the
  reason printed under the table; direct-external is excused from
  `dolt start` because running it there would leave a bd-owned sql-server
  the fixture has no teardown for

This commit depends on #6580. Against a base that lacks it the flipped
cells fail, because there `bd dolt status` still lies.

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

---------

Co-authored-by: Julian Knutsen <julian@gastownhall.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-09-16 02:53:27 -07:00
Julian Knutsen
76860ebdfb
fix(config): dotted keys round-trip through SetYamlConfigInDir/UnsetYamlConfig (bd-zj95, 1.3.1) [release/1.3.0] (#6578)
* fix(config): make a dotted key round-trip through SetYamlConfigInDir (bd-zj95)

SetYamlConfigInDir writes dotted keys; GetStringFromDir reads them by splitting
on the dot and walking nested mappings; UnsetYamlConfig removes them. Those are
three directions of ONE round-trip property, and set/get was broken in two ways,
both reachable from ordinary files:

  - An empty or comment-only config.yaml has no mapping node, so the nested
    writer declined and the caller appended a literal 'dolt.host: ...' line — a
    key whose NAME contains a dot. Nothing that splits on the dot can ever find
    it.
  - A file that already carried such a flat key had it updated in place, which
    preserved the unreadable shape forever.

So a caller could write a value and immediately be unable to read it back. Two
consumers found it the hard way: bd's ownership handoff, whose commit write-set
refused itself on dolt.auto-start, and a Gas City managed city, whose
.beads/config.yaml is entirely flat dotted keys.

Six shipped call sites write a dotted key through this path, and every one of
them is a write into a .beads/config.yaml that may be empty or comment-only —
exactly the shape that produced the unreadable spelling:

  cmd/bd/bootstrap.go:1108         sync.remote
  cmd/bd/dolt.go:481               sync.remote
  cmd/bd/init.go:3386, :3394       sync.remote
  cmd/bd/migrate_dolt_mode.go:810  dolt.shared-server
  cmd/bd/migrate_dolt_mode.go:1168 dolt.shared-server

An empty document now gets a mapping made for it, and a flat key of the name
being written is migrated to the nested form rather than updated in place. Only
the key being written is touched: a dotted key this call does not own belongs to
someone else and is left exactly as they wrote it.

Table test over nine file shapes — absent, empty, comment-only, flat, flat
commented, existing section, unrelated nested, unrelated flat, and mixed — each
asserting both that every key reads back and that no unreadable flat spelling
survives.

(cherry picked from commit cbe9bd6ca03416a76441e560bdec9fa67add99c5)

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

* fix(config): unset a dotted key in the shape the writer produces

Writing a dotted key nested and then being unable to unset it is the same
round-trip break in the other direction. Set, get and unset are three directions
of ONE property, and all three have to agree on the shape: UnsetYamlConfig
comments out the line matching the key, and its pattern only ever matched a FLAT
'sync.remote:' line. Once the writer nests, an unset silently does nothing and
the value stays live — for sync.remote that means bd keeps a remote the operator
asked it to forget.

commentOutYamlKey now walks the nesting, tracking indentation per segment so a
key is commented only when it sits under its OWN parents rather than under some
other section sharing a leaf name. The flat spelling is still handled, because
files written by older bds carry it.

This is what closes the loop for the shipped unset paths — cmd/bd/config.go:578
('bd config unset'), cmd/bd/dolt.go:1761 and
cmd/bd/dolt_remote_proxied_server.go:34 — against the six writers the previous
commit nests: sync.remote at cmd/bd/bootstrap.go:1108, cmd/bd/dolt.go:481 and
cmd/bd/init.go:3386/:3394, and dolt.shared-server at
cmd/bd/migrate_dolt_mode.go:810/:1168.

TestFinalizeSyncedBootstrapWritesConfigFiles moves with it. It required a
literal 'sync.remote: ' line — a key whose name contains a dot, the one shape
GetStringFromDir and viper can never find, because both split on the dot and
walk nested mappings. That assertion passed for exactly as long as the value was
unreadable and failed the moment it became readable, so it now asserts what
bootstrap actually owes its caller: a remote that reads back.

(cherry picked from the internal/config half of commit
7f1ec4799a3e8af0a89b8f97c28ec30082fedbb7)

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

* test(cmd/bd): assert the sync.remote round trip, not a YAML spelling

Six cmd/bd test sites baked the flat spelling. They passed BECAUSE the bug was
present, and that is the part worth recording.

Viper finds a literal dotted key as well as a nested one; GetStringFromDir does
not, because it splits on the dot and walks mappings. So these tests exercised
config.yaml through ONE reader while the value was invisible to the other. They
were green for exactly as long as the value was unreadable, and
TestFinalizeSyncedBootstrapWritesConfigFiles failed on macOS and Linux CI the
moment it became readable. A test that only passes while a bug is live does not
merely fail to catch it — it defends it.

  bootstrap_guard_test.go:84        seed
  bootstrap_test.go:358, :410       seed
  bootstrap_test.go:1330            assert (accepted 'sync.remote: ' OR
                                    'sync-remote: ', neither readable)
  dolt_worktree_remote_test.go:55   assert
  init_remote_test.go:128           seed

All six now assert the round trip through GetStringFromDir, or the caller's own
observable, rather than any YAML text — flat or nested. Asserting the nested
spelling instead would have been the same mistake facing the other way.

The three seeds go through config.SetYamlConfigInDir, the real writer, via a
shared seedSyncRemote helper that asserts the read-back. A fixture can no longer
hand bd a config.yaml that bd itself would never have written.

These are the tests standing over the shipped writers this series fixes:
sync.remote at cmd/bd/bootstrap.go:1108, cmd/bd/dolt.go:481 and
cmd/bd/init.go:3386/:3394, and dolt.shared-server at
cmd/bd/migrate_dolt_mode.go:810/:1168.

(cherry picked from commit b0df00b59d2d68ee5fee313c05dc2300ad66fcef)

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

* fix(config): close the dotted-key round trip the rest of the way

Review of the first three commits found the round trip still open in two
places, both reachable from ordinary files.

An empty or comment-only config.yaml parses to no YAML nodes at all, and
yaml.v3 keeps no trace of its text either — not even the comments. The
writer fabricated a mapping for that case and marshalled it, so the file
it wrote back was the new key and nothing else. `bd init` writes a
template that is comments and nothing else and then persists sync.remote
into it, so every remote-connected init shipped a config.yaml with its
whole documentation deleted. config.yaml is git-tracked: the operator
sees that as a committed diff they did not make. Append the rendered key
to the existing text instead, so nothing already in the file is parsed,
re-emitted or reformatted, and it survives byte for byte.

An unset comments the leaf out and leaves the section holding nothing —
`sync:` and no more. A null is not a mapping, so the next set refused it,
fell through to the flat writer, and put a literal `sync.remote:` back
into the file: the unreadable shape, re-created one command after being
fixed, with bd reporting success while GetStringFromDir saw nothing. A
section with no value under it has nothing to lose, so treat it as the
empty mapping it looks like.

Two shapes that are genuinely unwritable now say so instead of writing
the flat key and claiming success: a parent that already holds a value
(`sync: enabled`), and a file whose top level is not a mapping. Both
returned nil and produced a value no reader could see.

Unset also matched lines inside literal block scalars, so unsetting
sync.remote rewrote text the operator had written under a `notes: |`.
Skip a block scalar's body: it is data, not structure.

Finally, drop normalizeYamlKey and its empty keyAliases map. It has been
an identity function whose comment claimed it renamed keys.

* docs(changelog): record the dotted config key fix under Unreleased

It is the most user-visible fix in 1.3.1 and it was not in the changelog,
so it would not have reached the release notes or `bd upgrade review`.

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 02:52:51 -07:00
Julian Knutsen
87c7375d5f
fix(dolt): contain bd dolt start on proxied workspaces; make bd dolt status truthful [release/1.3.0] (#6580)
* Align proxied-local-smoke Dolt CLI pin with measured 2.2.0 (refs be-egcj2.3) (#6002)

* test(feat): red — Align dolt-sql-server test container version with host DOLT_VERSION pin (refs be-egcj2.3)

* feat: green — Align dolt-sql-server test container version with host DOLT_VERSION pin (refs be-egcj2.3)

* chore(ci): retrigger CI after transient golangci-lint schema-fetch timeout (refs be-fjj0i)

(cherry picked from commit ea89b160fb)

* fix(dolt): contain `bd dolt start` on proxied workspaces; make `bd dolt status` truthful

`bd dolt start` knew nothing about proxied-server mode, and the default
proxied root IS `.beads/dolt` (internal/doltserver/physical_root.go:113-127).
With the proxy tree down it launched an unsupervised `dolt sql-server`
directly over that root; the next ordinary bd command then failed with
`invalid connection` because the relaunched proxy found a foreign server on
its port. With the tree up it adopted the proxy's own dolt child into bd's
classic PID/port records, leaving two managers for one process.

`bd dolt status` read the classic pidfile, which proxied mode never writes,
and reported "not running" against a healthy backend — the wrong answer that
sent operators to `bd dolt start` in the first place.

start is now a typed refusal (`proxy.dolt_start.conflict`): the proxy owns
its child's lifecycle, and an idle reaper means a "started" postcondition bd
could not honor beyond the idle window. status reads the proxy's own records
and reports the proxy and its backend separately, starting nothing.

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

---------

Co-authored-by: Jim Wordelman <jim@wordelman.name>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-09-16 01:13:07 -07:00
Julian Knutsen
f62cc4f072
fix(scripts): make check-doc-flags portable to BSD grep and fail loud on grep errors (#6026) (#6581)
(cherry picked from commit 4c4be78b5c)

Co-authored-by: postoso <postoso@gmail.com>
Co-authored-by: postoso <postoso@users.noreply.github.com>
2026-09-16 01:12:57 -07:00
260 changed files with 20924 additions and 1420 deletions

View file

@ -9,7 +9,7 @@
"name": "beads",
"source": "./plugins/beads",
"description": "AI-supervised issue tracker for coding workflows",
"version": "1.3.0"
"version": "1.3.2-rc.1"
}
]
}

View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh
# --- BEGIN BEADS INTEGRATION v1.3.0 ---
# --- BEGIN BEADS INTEGRATION v1.3.2-rc.1 ---
# This section is managed by beads. Do not remove these markers.
if command -v bd >/dev/null 2>&1; then
export BD_GIT_HOOK=1
@ -56,4 +56,4 @@ if command -v bd >/dev/null 2>&1; then
fi
if [ "$_bd_exit" -ne 0 ]; then exit "$_bd_exit"; fi
fi
# --- END BEADS INTEGRATION v1.3.0 ---
# --- END BEADS INTEGRATION v1.3.2-rc.1 ---

View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh
# --- BEGIN BEADS INTEGRATION v1.3.0 ---
# --- BEGIN BEADS INTEGRATION v1.3.2-rc.1 ---
# This section is managed by beads. Do not remove these markers.
if command -v bd >/dev/null 2>&1; then
export BD_GIT_HOOK=1
@ -56,4 +56,4 @@ if command -v bd >/dev/null 2>&1; then
fi
if [ "$_bd_exit" -ne 0 ]; then exit "$_bd_exit"; fi
fi
# --- END BEADS INTEGRATION v1.3.0 ---
# --- END BEADS INTEGRATION v1.3.2-rc.1 ---

View file

@ -40,7 +40,7 @@ if [ -n "$staged_go_files" ]; then
echo "$staged_go_files" | xargs git add
fi
# --- BEGIN BEADS INTEGRATION v1.3.0 ---
# --- BEGIN BEADS INTEGRATION v1.3.2-rc.1 ---
# This section is managed by beads. Do not remove these markers.
if command -v bd >/dev/null 2>&1; then
export BD_GIT_HOOK=1
@ -97,4 +97,4 @@ if command -v bd >/dev/null 2>&1; then
fi
if [ "$_bd_exit" -ne 0 ]; then exit "$_bd_exit"; fi
fi
# --- END BEADS INTEGRATION v1.3.0 ---
# --- END BEADS INTEGRATION v1.3.2-rc.1 ---

View file

@ -39,7 +39,7 @@ fi
exec < <(printf '%s\n' "$push_refs")
# --- BEGIN BEADS INTEGRATION v1.3.0 ---
# --- BEGIN BEADS INTEGRATION v1.3.2-rc.1 ---
# This section is managed by beads. Do not remove these markers.
if command -v bd >/dev/null 2>&1; then
export BD_GIT_HOOK=1
@ -96,4 +96,4 @@ if command -v bd >/dev/null 2>&1; then
fi
if [ "$_bd_exit" -ne 0 ]; then exit "$_bd_exit"; fi
fi
# --- END BEADS INTEGRATION v1.3.0 ---
# --- END BEADS INTEGRATION v1.3.2-rc.1 ---

View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh
# --- BEGIN BEADS INTEGRATION v1.3.0 ---
# --- BEGIN BEADS INTEGRATION v1.3.2-rc.1 ---
# This section is managed by beads. Do not remove these markers.
if command -v bd >/dev/null 2>&1; then
export BD_GIT_HOOK=1
@ -56,4 +56,4 @@ if command -v bd >/dev/null 2>&1; then
fi
if [ "$_bd_exit" -ne 0 ]; then exit "$_bd_exit"; fi
fi
# --- END BEADS INTEGRATION v1.3.0 ---
# --- END BEADS INTEGRATION v1.3.2-rc.1 ---

View file

@ -5,7 +5,7 @@ name: Conformance
on:
pull_request:
branches: [ main, 'release/**' ]
branches: [ main, 'release/**', 'hotfix/**' ]
merge_group:
concurrency:

View file

@ -10,7 +10,7 @@ on:
# feedback. Release-targeted PRs are exactly the ones where cross-version
# upgrade breakage is most expensive to discover at tag time.
pull_request:
branches: [ main, 'release/**' ]
branches: [ main, 'release/**', 'hotfix/**' ]
# Allow manual trigger with custom version count
workflow_dispatch:

View file

@ -2,7 +2,7 @@ name: PR Risk
on:
pull_request:
branches: [ main, 'release/**' ]
branches: [ main, 'release/**', 'hotfix/**' ]
merge_group:
concurrency:

View file

@ -5,7 +5,7 @@ on:
# release/** is here because release-prep and release-fix PRs are based on
# the release branch, not on main. Without it they run almost no CI and the
# first full signal is the tag build, where a failure burns the tag.
branches: [ main, 'release/**' ]
branches: [ main, 'release/**', 'hotfix/**' ]
merge_group:
concurrency:
@ -1014,14 +1014,20 @@ jobs:
go-version-file: 'go.mod'
cache: false
# golangci/golangci-lint-action is not on this repository's allowed-actions
# list, so a workflow that names it fails at startup. Install the pinned
# release binary (the same script main uses) and report only issues new
# relative to the PR base, as only-new-issues did.
- name: Install golangci-lint
run: ./scripts/ci/install-golangci-lint.sh
- name: golangci-lint
uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9
env:
GOWORK: "off"
with:
version: v2.10.1
only-new-issues: true
args: --config=.golangci.yml --modules-download-mode=readonly --timeout=5m --build-tags=gms_pure_go
NEW_FROM_REV: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}
run: >-
golangci-lint run --config=.golangci.yml --modules-download-mode=readonly
--timeout=5m --build-tags=gms_pure_go --new-from-rev="$NEW_FROM_REV"
windows-make-shell:
name: Windows Make shell (${{ matrix.host }})

View file

@ -21,7 +21,10 @@ on:
paths:
- 'cmd/bd/proxied_local_*'
- 'cmd/bd/proxied_server*.go'
- 'cmd/bd/dolt*.go'
- 'cmd/bd/*_proxied_server.go'
- 'cmd/bd/backup*.go'
- 'cmd/bd/purge*.go'
- 'cmd/bd/db_proxy_child.go'
- 'cmd/bd/init*.go'
- 'cmd/bd/proxied_integration_helpers_test.go'
@ -39,7 +42,10 @@ on:
paths:
- 'cmd/bd/proxied_local_*'
- 'cmd/bd/proxied_server*.go'
- 'cmd/bd/dolt*.go'
- 'cmd/bd/*_proxied_server.go'
- 'cmd/bd/backup*.go'
- 'cmd/bd/purge*.go'
- 'cmd/bd/db_proxy_child.go'
- 'cmd/bd/init*.go'
- 'cmd/bd/proxied_integration_helpers_test.go'
@ -65,8 +71,10 @@ jobs:
env:
CGO_ENABLED: "1"
# Pinned so the lane tests a known dolt CLI, not whatever the installer
# resolves on a given day. Bump deliberately.
DOLT_VERSION: 2.2.2
# resolves on a given day. Bump deliberately, and only in lockstep with
# the measured pin in scripts/ci/install-dolt.sh (see "Which Dolt
# version to install" in docs/architecture/dolt.md).
DOLT_VERSION: 2.2.0
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
@ -102,7 +110,17 @@ jobs:
TestManagedLocalProxiedLegacyRecordFailClosed \
TestManagedLocalProxiedOrphanBackendReaped \
TestManagedLocalProxiedNProcessColdStartConvergence \
TestManagedLocalProxiedStopStartInterleave
TestManagedLocalProxiedStopStartInterleave \
TestManagedLocalProxiedDoltStatusReportsLiveTopology \
TestManagedLocalProxiedDoltStartRefusesOverLiveProxy \
TestManagedLocalProxiedDoltStartRefusesWithProxyDown \
TestManagedLocalProxiedDoltLifecycleLeavesOtherTopologiesAlone \
TestManagedLocalProxiedPurgeWispsPlaneRetention \
TestManagedLocalProxiedCapabilityMatrix \
TestManagedLocalProxiedBackupRoundTrip \
TestManagedLocalProxiedAutoBackup \
TestManagedLocalProxiedBackupRestoreRefusedWhileAttached \
TestManagedLocalProxiedBackendCleanExitRetiresProxy
do
if ! grep -qx "$test_name" <<<"$listed"; then
echo "managed-local lifecycle test $test_name is missing; got: '$listed'" >&2

View file

@ -5,7 +5,7 @@ on:
push:
branches: [main]
pull_request:
branches: [main, 'release/**']
branches: [main, 'release/**', 'hotfix/**']
# Allow manual trigger
workflow_dispatch:

View file

@ -7,6 +7,799 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [1.3.2-rc.1] - 2026-10-05
First release candidate for 1.3.2, a patch on top of 1.3.1 with **no schema
migration**: upgrading from 1.3.1 is a binary swap. It fixes `bd purge`
deleting the closed root of a chain that still has live work under it, and an
auto-backup watermark that could claim a commit the snapshot does not contain.
It also carries an upgrade note for stores migrated by 1.3.0 or 1.3.1
([#7037](https://github.com/gastownhall/beads/issues/7037)).
### Upgrade notes
- **After upgrading from bd ≤1.3.0, run `bd recompute-blocked` once per
workspace** ([#7037](https://github.com/gastownhall/beads/issues/7037)).
Migration 0059, first shipped in 1.3.0, recomputes the denormalized
`is_blocked` flag with a recursive query. On Dolt servers older than 2.4.0,
and on the embedded engine, a query-planner bug
([dolthub/dolt#11886](https://github.com/dolthub/dolt/issues/11886), fixed
in Dolt 2.4.0) drops the query's `parent-child` edge filter. Blockedness then
spreads across every dependency type, including `relates-to`,
`discovered-from` and `tracks`. Beads that are not actually blocked are
marked blocked and silently disappear from `bd ready` and `bd list --ready`.
The flag is stored, so the damage persists until it is recomputed: nothing in
1.3.2 repairs it automatically.
`bd recompute-blocked` rebuilds the flag from the dependency graph. It is
idempotent and reports `rows_corrected`. It applies to every workspace whose
store crossed migration 0059 under bd 1.3.0 or later, which includes a
workspace now on 1.3.1 that was originally created by 1.2.x or earlier.
Running it on a workspace that was not affected changes nothing.
### Fixed
- **`bd purge` keeps the whole closed chain above a live bead, not just its
direct parent** ([#7041](https://github.com/gastownhall/beads/pull/7041),
fixes [#7031](https://github.com/gastownhall/beads/issues/7031)). The
live-dependent protection added in 1.3.1 only protected a closed candidate
that a not-done bead pointed at directly. Take a closed root R, a closed child
S1 and an open grandchild S2. S1 was protected because S2 is live, but R was
not, because its only dependent S1 is closed. Purge deleted R, which orphaned
S1 and S2, and `--dry-run` reported the same deletion. Protection now
propagates through closed candidates until nothing changes, on every backend
(dolt server, embedded, proxied/uow). An orchestrator retention sweep
(`bd purge --wisps-plane --older-than ...`) is the common way to hit this.
- **The backup watermark no longer runs ahead of the snapshot**
([#7044](https://github.com/gastownhall/beads/pull/7044), fixes
[#7032](https://github.com/gastownhall/beads/issues/7032)). Auto-backup read
Dolt HEAD *after* the sync and recorded that as the newest commit backed up.
A commit that landed during the sync was therefore recorded as backed up even
though the snapshot did not contain it, and auto-backup reported "no changes
since last backup" until HEAD moved again. HEAD is now read before the sync,
so such a commit stays pending for the next backup. Only opted-in auto-backup
(`backup.enabled: true`) was affected; `bd backup sync` does not record a
commit watermark.
### CI
- PRs into `hotfix/**` branches now run full CI, including the required
`CI Gate / Required` check
([#7198](https://github.com/gastownhall/beads/pull/7198), fixes
[#7148](https://github.com/gastownhall/beads/issues/7148); ported to this
branch in [#7217](https://github.com/gastownhall/beads/pull/7217)).
## [1.3.1] - 2026-09-30
First stable release of the 1.3.1 patch line. It ships the same code as
[1.3.1-rc.2]; the only change since that candidate is the version stamp. The
full notes are in the [1.3.1-rc.2] and [1.3.1-rc.1] sections below, which
together cover everything since [1.3.0].
There is **no schema migration**: upgrading from 1.3.0, 1.3.1-rc.1 or
1.3.1-rc.2 is a binary swap.
### Upgrade notes
- Coming from 1.3.0, read the upgrade notes in [1.3.1-rc.2] and the
**Changed** entries in [1.3.1-rc.1]. The rc.1 change most likely to affect
scripts is the new `bd dolt status --json` shape on a proxied workspace
([#6580](https://github.com/gastownhall/beads/pull/6580)).
- Coming from 1.3.1-rc.2, nothing changes in behaviour.
## [1.3.1-rc.2] - 2026-09-29
Second release candidate for 1.3.1, still a patch line on top of 1.3.0 with
**no schema migration**: upgrading from 1.3.0 or 1.3.1-rc.1 is a binary swap.
It adds the proxied-server `bd backup` family and opt-in auto-backup on
managed-local workspaces, a `bd purge` that can run an orchestrator's wisp
retention sweep, and fixes for the #6716 fan-in stall, partial batch closes,
`bd sql` result sets, `bd show --watch`, `bd types`, `BEADS_DIR` discovery and
proxy liveness, plus eleven fixes from `main` ([#6653](https://github.com/gastownhall/beads/pull/6653)) and the smart-gate
data-behind stop ([#6659](https://github.com/gastownhall/beads/pull/6659), [#6695](https://github.com/gastownhall/beads/pull/6695)). Engineering notes for embedders
reading proxied-server surfaces are in `engdocs/` ([#6652](https://github.com/gastownhall/beads/pull/6652)).
### Upgrade notes
These behaviour changes can affect scripts; each is detailed below.
- `bd show --watch <id>` exits 1 when the id cannot be found (it used to exit
0), on both the direct and proxied routes.
- `bd sql` in direct server mode prints `OK` / `{"status":"ok"}` for a
multi-statement write or a write the parser cannot classify, instead of
`OK, N rows affected` / `{"rows_affected":N}`. `bd sql --readonly` refuses
statements it cannot parse (for example `PRAGMA`) instead of running them
as reads.
- A failure to read the custom issue types now fails `bd types`,
`bd create --graph` and `bd config set storage-class.*` instead of being
treated as "no custom types".
- `BEADS_DIR` must point at the `.beads` directory itself. A `BEADS_DIR` that
names a project root, or a `.beads` that does not exist yet, now fails with
"no beads database found" instead of silently resolving to the nearest
workspace above the current directory.
- `bd purge` always keeps closed beads a live bead depends on
(`live_dependent_skipped`); there is no flag to turn this off.
- `--older-than` on `bd purge` and `bd prune` is exact at hour precision:
`12h` no longer rounds up to a day, so `bd prune --older-than 12h` deletes
rows it used to keep.
- `bd close` with several ids exits non-zero when any of them fails to close.
- Unflagged piped `bd query` is no longer capped at 50 rows.
- On a proxied workspace with `dolt.auto-commit` set to `batch` or `off`,
writes are no longer committed to Dolt history one by one; run
`bd dolt commit` to flush them.
- `bd backup sync` fails after waiting 5 seconds if another backup of the same
workspace is running.
- `bd ready` / `bd list --ready` include issues in custom `active`-category
statuses, and a store open against an unreachable Dolt server on a
proxied-server workspace or under `bd serve` retries for up to ~40s before
failing. Both come from [#6653](https://github.com/gastownhall/beads/pull/6653); see **Changed**.
### Added
- **`bd backup` works on a proxied-server workspace bd runs the Dolt server
for** ([#6584](https://github.com/gastownhall/beads/pull/6584)). `bd backup init`, `sync`, `remove`, `status` and `restore` are routed
over the proxied provider; before this, a proxied workspace — the default
topology since 1.3.0 — had no backup path at all. `bd backup restore` stops
the proxy and its Dolt child before replacing the database and leaves the
workspace quiescent, so the next command relaunches against the restored
data.
The family stays **refused by design** on a proxied workspace pointed at a
Dolt server bd does not own (an external host, socket, or a beads-team-server
database): `CALL DOLT_BACKUP('add', …)` registers the backup remote on the
*server*, where it is global to every client connected to it, so one
workspace's backup decision would silently become everyone's — the shape
`bd backup`'s own help text already warns about for auto-backup. A `file://`
destination has a second problem on top, since the server resolves that path
on its own filesystem. The refusal keeps the `proxy.backup.unsupported` code
and now carries `"reason": "design"`; a backup story for those deployments
belongs to whoever runs the server. Whether a *remote-scheme* destination
(DoltHub, `aws://`, `gs://`) should eventually be allowed there is recorded as
an open question rather than settled — the server pushes those over the
network from its own environment, which is the same credential question the
next slice has to answer for `dolt push`.
`bd backup status` and `bd backup` help no longer attribute auto-backup being
OFF on a server topology to a missing git remote, which was never the reason
there ([#6694](https://github.com/gastownhall/beads/pull/6694)). Auto-backup
itself is opt-in on this topology; see the next entry.
- **Auto-backup runs on a managed-local proxied-server workspace**
([#6879](https://github.com/gastownhall/beads/pull/6879)). The
proxied arm of the post-command hook now calls auto-backup, so an explicit
`backup.enabled=true` (or `BD_BACKUP_ENABLED=1`) takes the same throttled,
change-detected Dolt-native backup into `.beads/backup` it takes in direct
mode, through the proxied provider's non-transactional seam. Before this the
opt-in was inert on every proxied workspace and `bd backup status` said so.
The default stays OFF, as on every server-mode workspace: many bd clients
share one server. It is honored exactly where `bd backup sync` is — a
proxied server bd started itself — and stays inert on an external or
team-server topology, strict `--readonly`, `bd serve`, a preview
(`--dry-run`/`--inspect`) and a migration freeze. A command that opened no
provider (e.g. `bd dolt stop`) backs nothing up rather than relaunching the
server to do so. `bd backup status` now reports the proxied default as
`auto: off in proxied-server mode; set backup.enabled=true to opt in`.
- **Auto-backup and `bd backup sync` no longer overlap.** A per-workspace
backup lock (`.beads/backup.lock`) serializes them in every mode:
auto-backup skips when another backup holds it, and `bd backup sync` waits
up to 5 seconds (the bound restore uses for the workspace gate) and then
fails with "another backup is running for this workspace".
- **`bd purge` covers an orchestrator's wisp retention sweep**
([#6883](https://github.com/gastownhall/beads/pull/6883)). Three changes
that together let `bd purge --wisps-plane --older-than 168h --force` replace
a raw `DELETE FROM wisps` retention step:
- **Live-dependent protection, always on.** `bd purge` no longer deletes a
closed bead that a live bead depends on through a `parent-child`,
`tracks` or `blocks` edge — a closed molecule root whose step is still
open, a closed wisp a live convoy tracks, a closed blocker of live work.
"Live" is any status that is not done, including custom statuses. The
held-back count is reported as `live_dependent_skipped` in `--json` (and
on its own line in text output). The protection is on the role
(`issueops.SweepRequest.ProtectLiveDependents`); `bd prune` does not ask
for it.
- **`--wisps-plane`** selects every closed row stored in the wisps table,
including `--no-history` beads, which the default ephemeral selection
leaves to `bd prune`. It works on embedded, server and proxied
workspaces, and because it reaches durable-tier rows it requires
`--older-than` or `--pattern`, like `bd prune`
(`issueops.SweepWispsPlane`).
- **`--older-than` accepts hour and finer durations** (`36h`, `168h`,
`90m`, down to `1s`) on both `bd purge` and `bd prune`. Day values (`7`,
`7d`, `2w`) are unchanged. An `Nh` value used to be converted to whole
days: floored above a day (`36h` swept rows only 24 hours old) and
rounded UP to one day below it (`12h` kept everything younger than 24
hours). Both are now taken exactly, so `bd prune --older-than 12h` now
deletes rows closed 12–24 hours ago that it used to keep. A value too
large to represent (e.g. `213504d`) is now refused instead of silently
wrapping to a tiny age.
- **`--limit N`** caps one `bd purge` run at N beads, oldest-closed first
(`issueops.SweepRequest.Limit`), so a large backlog drains in bounded
transactions; `--json` then adds `remaining` and `has_more`. Loop while
`has_more` is true.
### Changed
- **Proxied-server refusals now say *why* they refuse** ([#6582](https://github.com/gastownhall/beads/pull/6582)). The JSON a refused
command prints gains a `reason` field next to the existing `code`, `error`
and `mutates`: `design` for a refusal that is expected to stay (shared
history, multi-repo routing, destructive admin, strict `--readonly`) and
`unimplemented` for a capability gap with a named owner. Every existing code,
message and exit status is unchanged, and `reason` is absent on refusals that
report a runtime state rather than a policy, so existing consumers are
unaffected. The policy behind it moved into one registry
(`cmd/bd/capability_registry.go`) that every command must appear in.
- **A command with no proxied-server route now fails with a typed error**
(`proxy.store.unrouted`) instead of the bare string `proxy server store
should be uow provider`.
- **`bd backup restore --json` prints a result object on every topology**
(`{"restored": true, "source": "<dir>"}`). It previously printed nothing at
all, which left a caller unable to tell a completed restore from a silently
skipped one. This applies to direct/embedded workspaces too, not only proxied
ones.
- **`bd backup init`, `sync`, `remove` and `restore` no longer print a usage
block after a failure.** They now silence cobra's own error and usage
rendering like the rest of the CLI, so a failure is one error line on stderr
instead of the message followed by `Error: exit code 1` and the full usage
text. Exit statuses are unchanged; this applies on every topology.
- **`bd purge` keeps closed beads a live bead depends on, always**
([#6883](https://github.com/gastownhall/beads/pull/6883)). A closed bead that a not-done bead depends on through
`parent-child`, `tracks` or `blocks` is no longer purged (reported as
`live_dependent_skipped`), so a purge that used to delete a closed molecule
root under a live step now leaves it. There is no flag to turn this off.
See the `--wisps-plane` entry under Added.
- **`--older-than` on `bd purge` and `bd prune` is taken at hour precision**
([#6883](https://github.com/gastownhall/beads/pull/6883)). An `Nh` value is no longer rounded to whole days: `12h` used to
round UP to one day and now means 12 hours, so `bd prune --older-than 12h`
deletes rows closed 12–24 hours ago that it used to keep; `36h` used to floor
to one day and now means 36 hours. Day values (`7`, `7d`, `2w`) are
unchanged. See the `bd purge` entry under Added.
- **`dolt.auto-commit=batch` and `off` now take effect on a proxied-server
workspace, and `bd dolt commit` works there** ([#6499](https://github.com/gastownhall/beads/pull/6499),
[#4995](https://github.com/gastownhall/beads/issues/4995)). Every proxied write used to mint a Dolt history commit
whatever `dolt.auto-commit` said, and `bd dolt commit` was refused with
`proxy.dolt_commit.unsupported`. Under `batch`/`off` a proxied write now
lands in the server's working set without advancing Dolt history, and
`bd dolt commit` is the flush point, as on the direct route. Commands that
are explicit commit points (`bd batch`, `bd mol bond`/`pour`/`squash`,
`bd mol wisp create`, and the wisp half of `bd mol burn`) still commit, and
`bd serve` writes still commit per write. `on`, the default, is unchanged.
**Behaviour change:** a proxied workspace that set `batch` or `off` and was
getting per-write commits anyway now accumulates uncommitted changes until
`bd dolt commit`, and `dolt log`, `dolt push` and backups do not see them
before that. `bd vc commit`'s proxied refusal now points at `bd dolt commit`.
- **`bd ready` and `bd list --ready` now return issues whose custom status is in
the `active` category** ([#5918](https://github.com/gastownhall/beads/pull/5918),
[#5831](https://github.com/gastownhall/beads/issues/5831)). The ready query
treated its `open` pin as an exact match, so a workspace that defined, say,
`triaged:active` never saw those issues in ready work — even though
`bd statuses`, the `ready_issues` view, and claim eligibility all already
counted that category as ready. **The ready set grows on upgrade** for any
workspace using custom active statuses: counts and dashboards will read higher,
and `bd ready` can hand out issues it used to withhold. Custom
`wip`/`done`/`frozen`/unspecified statuses stay out, and `in_progress` stays
out, both unchanged.
- **`bd list --wisp-type <t>` with no plane admitted is now a refusal instead of
an empty listing** ([#6098](https://github.com/gastownhall/beads/pull/6098)).
`--wisp-type` narrows an admitted plane rather than admitting one, so alone it
could not match any row and exited 0 with an empty result for every input. It
now fails with a hint naming `--include-ephemeral`. A script that ran it and
read the empty output as "no such wisps" now sees an error — which is the
point: the old success answered a question it had not asked. The refusal is
CLI-only; the equivalent API request stays lawful and still composes to an
empty page.
- **The `--ready` footer names the status pin that actually applied**
([#5924](https://github.com/gastownhall/beads/pull/5924)). With no `--status`
(or `--status all`) the line is unchanged: `open only — --ready excludes
in_progress`. With an explicit `--status` it now reads `<selector> only`
instead of reusing the default-open sentence, which is no longer true once the
selector is honored (see **Fixed**). Anything scraping that parenthetical for
a `--status`-plus-`--ready` run sees new text — though that combination also
returned the wrong rows before this release. Note that the default sentence now
understates the set, since custom active statuses join it (above); the footer
and `--ready` help text are corrected upstream on main
([#6187](https://github.com/gastownhall/beads/issues/6187),
[#6188](https://github.com/gastownhall/beads/issues/6188)).
- **`bd doctor` reports a new missing gitignore pattern on every workspace
created before this release, until `bd doctor --fix` is run**
([#5978](https://github.com/gastownhall/beads/pull/5978)).
`.beads/dolt-server-config.yaml` joined the required `.beads/.gitignore`
patterns (see **Fixed**), so a workspace that was clean a moment ago now
warns. `bd doctor --fix` appends the rule and silences it; workspaces
initialised after this release get it from the template and never warn.
- **Opening a store against an unreachable Dolt server now takes up to ~40s to
fail instead of failing at once — on proxied-server workspaces, and under
`bd serve`** ([#6003](https://github.com/gastownhall/beads/pull/6003)). The
bootstrap ping is retried for up to 30 seconds, each attempt capped at 10s, so
a server still coming up is waited out rather than turned into a hard failure
(see **Fixed**). The cost is that a genuinely dead or misconfigured endpoint no
longer errors immediately: an interactive command against a stopped server, and
any script or CI step that counted on a fast failure, now waits out the retry
budget first. Durable rejections — bad credentials, unknown database, a
hostname that does not resolve — are still reported immediately without
retrying.
Only the paths that build a unit-of-work provider take that ping, so this is a
minority of topologies: every command in a proxied-server workspace, local or
external, and `bd serve` in a server, external-server or shared-server
workspace, which builds its own provider through the same funnel. **Embedded —
the default — is unaffected entirely**; `bd serve` refuses it outright, and no
embedded command can slow down here. An ordinary CLI command in a server or
shared-server workspace is also unaffected: it opens a Dolt store, which does
not take this ping. Only that mode's `bd serve` startup does.
The 30s figure is the retry budget, not the wall-clock bound. It stops
*scheduling* attempts at 30s but cannot cancel one already in flight, and each
attempt carries its own 10s cap, so ~40s is the honest worst case for a single
open. A provider open pings twice — once for the schema-init connection, once
for the database pool — each with a fresh budget, so a backend that satisfies
the first ping and the schema init and is then unreachable for the second can
push one command to ~80s. That ordering is narrow, but it is reachable.
- **A backup sync that would leave the backup's manifest ahead of its chunk
files now fails at that point instead of corrupting the backup quietly**
([#5931](https://github.com/gastownhall/beads/pull/5931),
[#4070](https://github.com/gastownhall/beads/issues/4070)). The Dolt bump
brings upstream's defense, which rejects a manifest update referencing a
missing table file. Previously that update was accepted and only some later
sync failed, confusingly, with `table file not found` — and stayed broken. A
sync that used to appear to succeed can now report a failure; that failure is
the corruption being caught at the moment it happens. This is a mitigation,
not a root-cause fix: backup file-and-manifest publish is still non-atomic,
and **backups already in the manifest-ahead state are not repaired** by
upgrading — they surface as a failing sync and have to be re-seeded.
### Fixed
- **An explicit `BEADS_DIR` is authoritative during workspace discovery.**
When `BEADS_DIR` named a directory without project files yet (missing,
empty, or not initialized), discovery ignored it and walked up from the
current directory instead, then rebound `BEADS_DIR` to whatever ancestor
workspace it found. `bd init` refused with "already initialized" because of
the parent workspace, and data commands such as `bd create` and `bd list`
read and wrote the parent's store. Discovery now reports no workspace for
such a `BEADS_DIR`, so `bd init` initializes the named directory and other
commands fail with "no beads database found". `bd import`/`bd setup` and
`bd bootstrap` target the named directory when they create a workspace.
Behaviour with `BEADS_DIR` unset is unchanged. **Behaviour change:** a
`BEADS_DIR` that points at a project root rather than its `.beads`
directory (for example `BEADS_DIR=$repo` instead of `BEADS_DIR=$repo/.beads`),
or at a `.beads` that does not exist yet, used to work by accident because
discovery walked up to the nearest workspace; it now fails with "no beads
database found". Point `BEADS_DIR` at the `.beads` directory itself.
([#6938](https://github.com/gastownhall/beads/pull/6938))
- **A proxied workspace's proxy retires when its Dolt backend exits
cleanly.** The proxy noticed its `dolt sql-server` child exiting only when
the exit status was non-zero. A backend that shut down gracefully (for
example on SIGTERM) left the proxy up and adoptable in front of a dead store:
with `--proxied-server-idle-timeout 0` it never went away, `bd dolt status`
called it running, and every command failed until `bd dolt stop`. The proxy
now retires on any backend exit, as it already did on a crash, so the next bd
command (including `bd ping`) starts a fresh proxy and backend. `bd dolt
status` no longer reports a proxy whose managed backend is gone as running:
the text says "not serving" and the JSON reports `running: false` (with
`proxy_pid` still set), including for a stranded proxy started by an older
bd. ([#6937](https://github.com/gastownhall/beads/pull/6937))
- **`bd show --watch` works under `--proxied-server`.** It was refused with
`proxy.watch.unsupported` although the provider can answer the poll the way
`bd list --watch` already does, so every proxied workspace — the default
transport for managed-local setups — had no way to watch a bead. The proxied
route now shares the direct route's loop: render once, re-read every 2s,
redraw only when the issue's status or `updated_at` changes, stop cleanly on
Ctrl+C/SIGTERM, and require exactly one id. Each poll opens its own short
unit of work, so a long watch never pins a transaction, and a poll that
fails (the issue was deleted, the backend blipped) keeps the last render
without printing, as on the direct route. On both routes a watch whose id
cannot be found now exits 1 instead of 0 ([#6933](https://github.com/gastownhall/beads/pull/6933)).
- **A server-mode workspace with an empty `.beads/dolt` is no longer refused
as legacy**
([#5682](https://github.com/gastownhall/beads/issues/5682),
[#6935](https://github.com/gastownhall/beads/pull/6935)). bd creates `.beads/dolt` on use even when the data lives on an
external Dolt server, and leaves it empty. When the gitignored
`.local_version` witness was missing — after a fresh checkout, or when a
provisioner created the empty root before `bd init --server --external` —
the legacy-upgrade guard refused every command, `bd init` included, as a
"legacy Dolt server workspace", and no bd command could repair it. An empty
root holds nothing a legacy release could have left, so the guard now admits
it: `bd init` writes the witness, and an existing workspace in that state
re-seeds it on the next command. A pre-1.0 witness, or a `.beads/dolt` that
holds anything, is still refused.
- **`bd types` now lists exactly the types `bd create --type` accepts**
([#6934](https://github.com/gastownhall/beads/pull/6934)). The two resolved
the type set through different code and could disagree: a server-mode
workspace's `bd types` dropped `.beads/config.yaml` `types.custom` entries
once the database had any custom type, although create accepts them; in
proxied mode `bd config set storage-class.<type>` checked `config.yaml` alone
and refused custom types registered in the database; and the built-in system
types `message`, `molecule`, `gate` and `event` were never listed. Every
mode now composes custom types by one rule (the `custom_types` table, else
the `types.custom` config row, always unioned with `config.yaml`). `bd types`
gains a "System types" section, and `bd types --json` an additive
`system_types` field; `core_types` and `custom_types` are unchanged. A
failure to read the custom types now fails `bd types`, `bd create --graph`
and `bd config set storage-class.*` instead of being silently treated as "no
custom types".
- **`bd sql` no longer drops the rows of CTE queries or CALL result sets**
([#6932](https://github.com/gastownhall/beads/pull/6932)). In proxied-server
mode, `WITH name(cols) AS (...) SELECT ...` and `WITH RECURSIVE ...` queries
were misread as writes and printed `OK, 0 rows affected` with no error; they
now return their rows. Statements are now classified with the Dolt SQL
parser (shared by the proxied and direct paths): reads return rows, plain
writes (including CTE-prefixed `UPDATE`/`DELETE`) commit and report
`rows_affected`, and anything that may both write and return rows (`CALL`,
`EXPLAIN ANALYZE` of a write, `RETURNING`) or that the parser cannot
classify is committed and prints whatever rows it returns, so
`CALL DOLT_BRANCH(...)`-style result sets are rendered instead of discarded.
Visible changes for scripts: in direct server mode a multi-statement write,
or a single write statement the parser cannot classify, now prints `OK` /
`{"status":"ok"}` (as proxied mode already did) instead of
`OK, N rows affected` / `{"rows_affected":N}`; and `--readonly` now refuses
statements it cannot parse (for example `PRAGMA`) instead of treating them
as reads.
- **Unblocking two blockers of one dependent at the same time no longer leaves
the dependent stuck as blocked** ([#6716](https://github.com/gastownhall/beads/issues/6716); [#6719](https://github.com/gastownhall/beads/pull/6719), [#6942](https://github.com/gastownhall/beads/pull/6942)).
Closing both blockers in parallel (formula fan-in with parallel workers), or
a close racing a `bd dep remove` or a delete of the other, could leave the
dependent `is_blocked=1` and missing from `bd ready` until
`bd recompute-blocked`. A write that takes a blocker away (a close, an update
to an inactive status, a dependency removal, a delete) now rechecks the
dependents it recomputed once its transaction has committed. This covers the
Dolt store write transactions, every write the proxied-server (uow/domain-db)
route serves — under `--proxied-server`, the default topology, that is
`bd close` (single and batch), `bd update --status`, `bd dep remove`,
`bd delete`, `bd batch` and `bd serve` — `RunInTransaction` (`bd batch`
direct, `bd cook`, `bd mol squash`/`burn`, and SDK callers that close or
update inside a transaction), the wisp close, update and delete writers, and
the legacy dependency removal behind `bd duplicates --merge`. Demote-to-wisp
moves a row between planes without taking a blocker away and is unchanged.
- **`bd close` now exits non-zero when any issue in a batch fails to close**
([#6648](https://github.com/gastownhall/beads/issues/6648); [#6740](https://github.com/gastownhall/beads/pull/6740), [#6771](https://github.com/gastownhall/beads/pull/6771)). A batch with one
refused id used to exit 0 as long as another id closed, so scripts could not
tell that part of the batch was left open. The closable ids still close, the
refusals are still printed, and a final `Error: N of M issues failed to close`
line is added; ids that were already closed still count as success. Both the
direct and proxied-server routes behave this way for ids the close policy or
the engine refuses. (An id that cannot be *resolved* at all is unchanged and
still differs by route: the direct route aborts the whole command before any
close runs, while the proxied route refuses that argument and closes the
rest.) In `--json` mode the summary is instead a compact JSON line on stderr
naming the failed ids, matching `bd update`'s partial-failure report, while
stdout keeps the usual closed-issues array. Each `failed[]` entry carries the
refusal as the engine worded it, identically on both routes; the `--force`
hint and the route's own framing stay on the human-readable stderr line, which
is unchanged. `--claim-next` still claims when
part of the batch closed — the claim commits inside the batch's own
transaction and a sibling's refusal does not roll it back — so the summary
names the claimed id rather than leaving it silently assigned.
- **`bd query` no longer silently stops at 50 rows when its output is piped**
([#6229](https://github.com/gastownhall/beads/issues/6229), [#6744](https://github.com/gastownhall/beads/pull/6744)). `bd list` has
treated piped stdout as unlimited since GH#4094, but `bd query` read its
`--limit` default of 50 straight through, so `bd query '...' | consumer`
dropped every row past 50 with no hint. An unflagged `bd query` now resolves
through the same policy as `bd list`: an explicit `--limit` wins, piped
stdout is unlimited, agent mode on a terminal gets 20, and a terminal gets 50.
- **Deleting or purging a wisp no longer leaves orphan rows behind on stores
without the wisp foreign keys** ([#6563](https://github.com/gastownhall/beads/pull/6563), [#6627](https://github.com/gastownhall/beads/pull/6627), [#6487](https://github.com/gastownhall/beads/issues/6487)).
On a store whose `wisp_dependencies` and wisp auxiliary tables lack the
migration-0047 FK constraints, every wisp delete (including `bd purge`,
`bd mol burn` and wisp GC) left its `wisp_dependencies` edges on both sides
and its `wisp_labels`, `wisp_events`, `wisp_comments` and
`wisp_child_counters` rows in place, which showed up as dangling parent
references and store bloat. The delete paths now remove them. This is a
forward fix: orphans already in a store are not cleaned up.
- **A clone missing its local `events`, `bd_events_journal` or `bd_events_seq`
table recreates it on open** ([#6547](https://github.com/gastownhall/beads/pull/6547)). Those tables are dolt-ignored, so
a fresh clone can arrive at the latest schema version without them, and bd
then treated the schema as complete and never created them. Their absence
now makes the migration runner replay the migrations that create them, from
each table's own floor rather than from zero.
- **The smart migrate gate no longer auto-migrates a clone whose data is behind
the remote** ([#6575](https://github.com/gastownhall/beads/issues/6575)). The
gate's first-mover verdict was computed from schema facts alone — equal
migration content hashes against the cached remote ref, at the same version,
at or above the convergence floor — and none of those say where the clone's
branch sits relative to that ref. A clone level with the remote on *schema*
but behind it in unpulled *data* commits satisfied every precondition, was
classified a safe first-mover, and migrated in place, minting local-only
schema commits on a HEAD missing those commits. When the pending batch moves
a tracked table onto the `dolt_ignore` plane, every later `bd dolt pull` then
refuses with `local changes would be stomped by merge: events`
([#6368](https://github.com/gastownhall/beads/issues/6368)) while `dolt
status` reads clean — and the clone can no longer fetch the very commits it
was behind on. Upgrading from a 1.1-era database is the ordinary way in, so
this release's upgrade audience is the exposed one. The gate now reads the
branch position its callers already supply and stops with guidance naming the
remedy: run `bd dolt pull`, then re-run what you were blocked on, and the
migrate proceeds as a true first-mover.
The stop applies whenever the clone has commits left to pull, whether or not
it also has commits of its own. bd auto-commits every write, so a clone that
is both behind and ahead is the ordinary multi-machine state, and it reaches
the same wedge; it is told its pull will *merge* rather than fast-forward, and
how to resolve conflicts if it reports them. A clone that is level with the
remote, or that only has unpushed local commits with nothing to pull, still
auto-migrates exactly as before.
**`bd dolt pull` works from the refused state.** It opens the store too, so
on a refused clone it would otherwise hit the very refusal that prescribes
it — and an embedded workspace has no external `dolt` binary to fall back to,
which would leave `BD_ALLOW_REMOTE_MIGRATE=1` (performing the migration the
stop exists to prevent) as the only way forward. `bd dolt pull` now opens
leniently for this one refusal, the way `bd dolt commit` does for the
dirty-working-set refusal
([#4566](https://github.com/gastownhall/beads/issues/4566)); every other gate
refusal still fails that open. This supersedes the [1.3.0] upgrade note's
statement that the pending-migration gate refuses `bd dolt pull` as well as
`bd dolt push`: for the data-behind stop it does not, by design.
Commands that keep working through the stop say the same thing. `bd list`,
`bd ready` and `bd show` succeed against the old schema, and `bd dolt commit`
still commits the working set; on embedded storage all of them used to print
the blunt migrate-or-adopt coordination bullets while doing so — naming
`bd migrate --force && bd dolt push`, which on a data-behind clone applies
the migration this stop exists to prevent and then fails the push
non-fast-forward, and `bd bootstrap`, which no-ops against an existing
workspace. They now print the pull-first guidance, shape-branched the same
way the fatal refusal is, alongside the note that the command in hand
continued at the current schema. Refusals that are *not* the data-behind stop
keep the coordination bullets, which are right for them.
`--json` callers get the same remedy the terminal does: `observed`,
`expected` and `options` describe the pull (a single `pull-first` option)
rather than the migrate-or-adopt decision that does not apply here, plus a
`data_behind_shape` of `fast-forward` or `diverged`. `fallback_reason` stays
`data-behind`. For the fast-forward shape on a non-shared store — one
unconditional option, no local commits, nothing discarded —
`human_decision_required` is now `false`, so an agent can run the pull
instead of stalling for approval of a step the same payload calls riskless.
It stays `true` for the diverged shape (the pull merges and can need conflict
resolution) and on a shared store (the follow-up consent step needs an
operator who can confirm every co-resident client is upgraded). On a shared
Dolt sql-server the guidance carries #5920's consequence — migrating promotes
the schema for every co-resident client, and clients still on an older bd
refuse the database until upgraded — and names the consent step the retry
needs there: `bd migrate schema --force`. It is the forced form because this
stop always has a remote configured (behind-ness is read from the
remote-tracking ref), and the bare `bd migrate schema` consent is only read
for a shared database with *no* remote; the flag consents to migrating a
remote-backed shared store, and by then the pull has landed the commits the
clone was missing.
**Proxied-server mode reaches the stop too, and is told where to run the
remedy.** The store-open gate on that path supplied no branch-position
callback, so a proxied clone that was level on schema and behind in data
could never be classified data-behind: it got the blunt shared-store refusal,
whose body is the designated-migrator recipe — `bd migrate --force` then
`bd dolt push` — which in this state is the wedge the stop exists to prevent.
It now routes to the same data-behind stop as every other topology. Because
`bd dolt pull` is refused at the proxied front door
(`proxy.dolt_pull.unsupported`), along with `bd dolt push`, the bare
`bd migrate` and `bd conflicts`, the guidance there names the machine the pull
has to run on rather than printing a command this binary rejects; the `--json`
option is `pull-first-on-server-host`, and `expected` carries the same
qualifier so a single-field reader is not handed a locally-refused command.
The shared-store consent step is the other way round: `bd migrate schema
--force` is *not* refused here — the refusal table keys on the command path
and has no `migrate schema` row — so the guidance says it can be run from this
workspace but only after the pull lands on the server host, and the warning
against forcing past the stop names it alongside `BD_ALLOW_REMOTE_MIGRATE=1`
as the two consent surfaces this topology can still reach. Read-only proxied
opens print the same pull-first block instead of the shared-consent template.
Both existing workarounds keep working unchanged: `BD_SMART_GATE=0` opts out
of the smart gate entirely (which means the blunt gate applies to `bd dolt
pull` too — that is what opting out is), and running `bd dolt pull` before the
first open after upgrading avoids the state to begin with. `bd migrate
--force` / `BD_ALLOW_REMOTE_MIGRATE=1` are still consulted before the gate and
still override it.
- **`bd list --status <s> --ready` honors `--status`**
([#5924](https://github.com/gastownhall/beads/pull/5924),
[#5832](https://github.com/gastownhall/beads/issues/5832)). Combining the two
silently dropped `--status` and returned the unfiltered ready set, because the
ready path pinned `open` in two places regardless of what was asked for, so a
custom status or `in_progress` never reached the ready query. An explicit
`--status` is now the ready-work status selector, matching how the other list
filters already compose with `--ready`. `--ready` with no `--status` still
defaults to open, and `--status all` remains the no-filter spelling. The footer
wording moves with it — see **Changed**.
- **`bd list --wisp-type` can reach rows at all**
([#6098](https://github.com/gastownhall/beads/pull/6098)). `bd list` now
registers `--include-ephemeral`, the plane knob `--wisp-type` needs, off by
default so the default listing is byte-identical. `bd list
--include-ephemeral --wisp-type heartbeat` is the working spelling. Before
this, the only way to admit the wisp plane from `bd list` was `--type
<infra-type>`, which also lifts the infra-type exclusions and changes template
treatment — three decisions for a caller who wanted one classification. Bare
`--wisp-type` is now refused rather than empty; see **Changed**.
- **`bd doctor` knows about the generated `.beads/dolt-server-config.yaml`**
([#5978](https://github.com/gastownhall/beads/pull/5978)).
`doltserver.Start()` writes that file when the resolved dolt binary supports
`auto_gc_behavior.archive_level`, but the hyphenated name falls outside the
`dolt-server.` prefix its five sibling server-state entries share, so neither
the gitignore template nor the required-pattern list covered it. It holds an
absolute `cfg_dir` and a per-machine port, so committing it breaks every other
clone — the same reason the template already gives for `redirect`. It shows up
as untracked in every consumer repo whose dolt supports `archive_level`. It is
now in both lists: the template covers new workspaces, and the required
patterns are what `bd doctor --fix` appends to an existing
`.beads/.gitignore` — see **Changed** for the warning that implies.
- **The missing-prefix error stops recommending a config key that does nothing**
([#5936](https://github.com/gastownhall/beads/pull/5936),
[#5916](https://github.com/gastownhall/beads/issues/5916)). When the database's
`issue_prefix` config row was absent, the error advised using the
`issue-prefix` key in `config.yaml` — but that gate only reads the database's
config table, so following the advice produced a tracked config field that
changed nothing and misled the next reader. The message now points at
`bd init --prefix` or `bd bootstrap`, which is what writes the row, and says
plainly which store the check reads. Error text only; resolution behaviour is
unchanged.
- **`bd create --file` says that it creates one issue per `##` heading**
([#5921](https://github.com/gastownhall/beads/pull/5921)). The usage string was
"Create multiple issues from markdown file", which named neither the per-H2
semantics nor `--body-file`. Someone wanting "one issue, description loaded
from a file" reached for the shortest flag and got a silent bulk import — a
briefing file with `## Problem` / `## Context` / `## Acceptance Criteria`
became three issues. The usage now names the behaviour, and the existing
rejection of a positional title combined with `--file` carries a `--body-file`
hint. `--file` alone on a section-headed file is unchanged: bd cannot tell that
apart from a genuine batch file by content.
- **The list truncation hint no longer leaves a padded blank line under the
shell prompt** ([#5927](https://github.com/gastownhall/beads/pull/5927),
[#5685](https://github.com/gastownhall/beads/issues/5685)). The hint passed its
surrounding newlines through the warning renderer, which treats them as a
block, pads the blank lines out to the widest line's width, and drops the
trailing newline — so the next prompt printed on top of a run of spaces. The
newlines are kept outside the renderer now, leaving one coloured line with a
real trailing newline.
- **`bd setup claude` and `bd init` stop rewriting `.claude/settings.json` on
every run** ([#5944](https://github.com/gastownhall/beads/pull/5944),
[#5693](https://github.com/gastownhall/beads/issues/5693)). The settings map
was marshaled without a trailing newline and written unconditionally, so each
run stripped the newline Claude Code's own writes leave behind and rewrote the
file even when no hook had changed. Because `bd init` git-adds that file, it
surfaced as a staged diff with no semantic content. The write now keeps the
trailing newline and is skipped when the bytes match what is already on disk,
at all four call sites — the settings write and the `settings.local.json`
migration on install, and both again on remove.
- **`bd gate check` resolves bead gates whose target lives in a prefix-routed
rig** ([#5859](https://github.com/gastownhall/beads/pull/5859)). After a local
miss, the evaluator follows the target bead ID through `routes.jsonl` and reads
the owning store without writing to it; previously such a gate stayed pending
until someone resolved it manually. This covers explicit gate checks in
embedded, server, and proxied-server command paths. The legacy
`<rig>:<bead-id>` await value remains accepted for compatibility, a malformed
cross-rig value is rejected, and when prefix routing is unavailable the original
local not-found error is preserved.
- **A transient connection drop while opening a Dolt store is retried instead of
failing the command**
([#6003](https://github.com/gastownhall/beads/pull/6003)). The bootstrap ping
in the unit-of-work provider was unretried, so a server still finishing startup
— or one that reset the connection mid-handshake — became a hard failure.
Connection-level shapes (`driver.ErrBadConn`, `mysql.ErrInvalidConn`, EOF, any
`*net.OpError`) are now retried for up to 30s, each attempt capped at 10s so a
server that accepts TCP and then stalls cannot block for the caller's whole
context. Durable rejections and an unresolvable hostname still fail without
retrying. See **Changed** for the latency this adds against a dead endpoint.
## [1.3.1-rc.1] - 2026-09-16
### Changed
- **`bd dolt status --json` changes shape on a proxied workspace**
([#6580](https://github.com/gastownhall/beads/pull/6580)). It now emits
`{"mode": "proxied-server", "root": ..., "running": <proxy up>, "proxy_pid":
..., "proxy_port": ..., "backend_managed": ..., "backend_running": ...,
"backend_pid": ..., "backend_port": ..., "backend_endpoint": ...,
"idle_timeout": ...}` instead of the always-false `{"running": false, "pid":
0, "port": 0}` — `pid` and `port` are gone, replaced by the `proxy_*` and
`backend_*` pairs. `running` no longer reports a bd-managed dolt PID file; it
describes the proxy, the endpoint every bd command connects through, so it is
now usually true where it used to be always false. `backend_managed` is false
on external proxied topologies, where the dolt server is not bd's process to
report on and `backend_endpoint` names it instead. Anything parsing the old
payload changes behaviour on upgrade. Direct-server, shared, embedded and
externally-managed workspaces keep the output they had.
- **`bd config set <dotted.key>` deletes a flat top-level key of the same
literal name** ([#6578](https://github.com/gastownhall/beads/pull/6578)).
Dotted keys are now written as a nested mapping (see **Fixed** below for why),
and where the file already carried the flat spelling — a top-level key whose
*name* contains the dot, such as `dolt.host: "10.0.0.1"` — that entry is
removed and the value re-emitted under `dolt:`. Only the key being written is
touched; other dotted keys, including ones bd did not write, are left exactly
as they are.
`.beads/config.yaml` is not exclusively bd's, so this can be visible outside
bd: an external tool that both writes *and* reads flat dotted keys there will
stop seeing any value bd migrates this way. Any dotted key bd stores in
`config.yaml` rather than the database can collide; in practice that means
`dolt.*`, `export.auto`, and `backup.enabled`. If the other writer then
re-adds its flat key, the file carries both spellings and bd's own readers
disagree — Viper-backed reads (`bd config get`, and the `dolt.auto-start`
lookup on the store-open path) return the **flat** value, while
`GetStringFromDir` returns the **nested** one, so a `bd config set` can be
shadowed by a stale flat entry. Tracked as
[#6594](https://github.com/gastownhall/beads/issues/6594). Until that lands,
in a workspace whose config another tool maintains, let that tool own its
keys, or check `.beads/config.yaml` for a duplicated key after running
`bd config set`.
- **Two `bd config set` writes that used to exit 0 now exit 1**
([#6578](https://github.com/gastownhall/beads/pull/6578)), because both wrote
a value no reader could see: setting a dotted key under a parent that already
holds a scalar (`sync: enabled`, then `bd config set sync.remote`), and
setting one in a file whose top level is not a mapping. A script that
tolerated the old exit 0 now has to handle the failure.
### Fixed
- **`bd dolt start` no longer puts a second sql-server over a proxied
workspace's data directory.** On a proxied-server workspace the default root
IS `.beads/dolt`, and `bd dolt start` knew nothing about proxied mode: with
the proxy quiesced it launched an unsupervised `dolt sql-server` directly
over that root, after which ordinary bd commands failed (`invalid
connection`) because the relaunched proxy found a foreign server on its
port; with the proxy live it instead adopted the proxy's own dolt child into
bd's classic PID/port records, leaving two managers for one process. It is
now a typed refusal with code `proxy.dolt_start.conflict`. The proxy owns
its backend's lifecycle — it starts on demand and `bd dolt stop` shuts it
down. Direct-server and embedded workspaces are unaffected.
- **`bd dolt status` tells the truth on a proxied workspace.** It read the
classic PID file, which proxied mode never writes, and so reported `Dolt
server: not running` while the proxy was serving CRUD — the wrong answer
that sent operators to `bd dolt start` in the first place. It now reads the
proxy's own records and reports the proxy and its dolt backend separately,
without starting either. The `--json` payload changes shape to carry that —
see **Changed** above before parsing it.
- **A dotted config key now round-trips: what `bd config set` writes,
`bd config get` and bd's own readers find**
([#6578](https://github.com/gastownhall/beads/pull/6578), bd-zj95). Setting a
key like `sync.remote` or `dolt.host` into a `config.yaml` with no matching
section appended a key whose *name* contained the dot — a top-level
`sync.remote: "..."` — instead of nesting it under `sync:`. Viper finds a key
spelled that way; the direct reader `GetStringFromDir` splits on the dot and
walks nested mappings, so it does not. The value was set and invisible at the
same time depending on which reader asked, and `bd init --remote` in a fresh
workspace was the ordinary way in: the remote was recorded and then not found.
Dotted keys are written nested now, and `bd config unset` removes the nested
form — it only ever matched the flat spelling, so unsetting
`sync.remote` silently left the remote live. Keys the write does not own,
including dotted ones somebody else put there, are left exactly as they are.
Two consequences of the nested write — the flat-key migration and two new
failure exits — are under **Changed** above.
## [1.3.0] - 2026-09-15
The first tested release off `main` since the 1.1 line. [1.2.2] was a recovery

View file

@ -385,27 +385,28 @@ func testAuditReadyTypeAndPinnedExclusions(t *testing.T, f Factory) {
// Statuses, the legacy open/in_progress default when both are empty, and a
// custom (non-built-in) status flowing through the same IN clause.
//
// THIS IS THE ONLY OBSERVER OF THE OR-SET ARM, AND IT COVERS EVERY SEAM THE ARM
// IS REACHABLE FROM. No role can ask for it — publicops.ReadyRequest carries no
// status field of any kind, which RunReadyCounterCountsOnlyTheOpenRowsItsListingLists
// says from the other side — and no in-tree caller sets it either. Every builder
// that renders a ready query sends the SINGULAR status: workapi.BuildReadyFilter
// and BuildReadyCountFilter send StatusOpen, and ReadyFilterFromIssueFilter sends
// StatusOpen while dropping IssueFilter.Statuses, which BuildListFilter has
// already resolved to open under --ready (issueops/reader_ready_scope.go states
// that override and why the projection has nothing to drop). What is left is the
// storage seam this file runs against, which backend.DoltStorage publishes to
// out-of-tree backends — so Statuses is a public filter field whose only reachable
// consumer class is exactly the one RunAll is the proof obligation for.
// THE OR-SET ARM IS REACHABLE FROM `bd list --status a,b --ready`.
// ReadyFilterFromIssueFilter copies IssueFilter.Statuses onto the ready-work
// filter instead of dropping it, and BuildListFilter no longer always
// resolves --ready to open: an explicit selector is the intersection
// (GH#5832; issueops/reader_ready_scope.go states the honor path).
// publicops.ReadyRequest still carries no status field of any kind, which
// RunReadyCounterCountsOnlyTheOpenRowsItsListingLists says from the other
// side, so `bd ready` — workapi.BuildReadyFilter and BuildReadyCountFilter —
// still send the SINGULAR StatusOpen. The list --ready path is the in-tree
// caller that sets Statuses. This file remains the storage-seam observer
// for the OR-set arm against backend.DoltStorage, which publishes the field
// to out-of-tree backends; RunAll is still the proof obligation for that
// seam.
//
// The unit-of-work provider's ready union renders this arm from the same shared
// builder (sqlbuild.BuildReadyWorkWhere), applied to the wisps table as well as
// issues where the classic stack projects the wisp plane onto a types.IssueFilter
// instead. Its copy is deliberately unpinned rather than overlooked: that provider
// is not a storage.DoltStorage, so no external caller reaches it, and no in-tree
// caller sets Statuses at all. Promoting a status set onto ReadyRequest is what
// would make it reachable, and would move this case to reader_contract.go beside
// RunReaderReadySetOwnsItsStatusPinnedAndTemplateDecisions, where all three
// is not a storage.DoltStorage, so no external caller reaches it. A status set on
// ReadyRequest would additionally make `bd ready` vote on this case, and would
// move it to reader_contract.go beside
// RunReaderReadySetOwnsItsStatusPinnedAndTemplateDecisions, where the ready-role
// wirings would vote on it.
func testAuditReadyMultiStatusFilter(t *testing.T, f Factory) {
s := f(t)

View file

@ -637,6 +637,12 @@ var roleContractCases = []roleContract{
RunSweeperEmptyMatchIsZeroAndNil,
RunSweeperRecordsExactlyOneHistoryEntry,
RunSweeperDoesNotMutateTheCallerRequest,
RunSweeperWispsPlaneClearsTheWholeWispsTable,
RunSweeperWispsPlaneRequiresAFilter,
RunSweeperProtectsLiveDependents,
RunSweeperProtectsTransitiveLiveDependents,
RunSweeperProtectsLiveDependentsAcrossPlanes,
RunSweeperLimitTakesTheOldestClosedFirst,
),
roleCases("TreeWalker", "TreeWalker()", oncePerRole,

View file

@ -89,6 +89,11 @@ type SweeperFixture struct {
// by hand. A nil Exec means "this backend cannot seed raw rows", and the
// case that needs it SKIPS with that reason rather than passing quietly.
Exec func(ctx context.Context, statements []SQLStatement) error
// AddDependencies wires edges between seeded rows, filled from the
// backend's DependencyEditor role so each adapter routes an edge to the
// dependency table of its source's plane itself. The live-dependent case
// needs it; a nil hook SKIPS that case with the reason.
AddDependencies func(ctx context.Context, req publicops.AddDependenciesRequest) error
}
// sweeperClosedAt is the stamp every seeded candidate carries, and
@ -345,7 +350,7 @@ func RunSweeperDryRunChangesNothing(t *testing.T, ctx context.Context, fixture S
IDPattern: sweeperPattern(fixture, "dry"),
}
preview := sweeperSweep(t, ctx, fixture, sweeperWithDryRun(request, true))
preview := sweeperSweep(t, ctx, fixture, sweeperAsDryRun(request))
if !preview.DryRun {
t.Error("preview.DryRun = false; the result must echo the request it answered")
}
@ -356,7 +361,7 @@ func RunSweeperDryRunChangesNothing(t *testing.T, ctx context.Context, fixture S
// A second preview: a dry run that had deleted anything reports a smaller
// number here.
if again := sweeperSweep(t, ctx, fixture, sweeperWithDryRun(request, true)); again.Swept != preview.Swept {
if again := sweeperSweep(t, ctx, fixture, sweeperAsDryRun(request)); again.Swept != preview.Swept {
t.Fatalf("second preview Swept = %d, first = %d: the first preview changed the store", again.Swept, preview.Swept)
}
@ -556,7 +561,7 @@ func RunSweeperRecordsExactlyOneHistoryEntry(t *testing.T, ctx context.Context,
}
before := sweeperHistory(t, ctx, fixture)
sweeperSweep(t, ctx, fixture, sweeperWithDryRun(request, true))
sweeperSweep(t, ctx, fixture, sweeperAsDryRun(request))
if after := sweeperHistory(t, ctx, fixture); after != before {
t.Errorf("history went %d -> %d across a DRY RUN, want no entry at all", before, after)
}
@ -609,6 +614,273 @@ func RunSweeperDoesNotMutateTheCallerRequest(t *testing.T, ctx context.Context,
}
}
// RunSweeperWispsPlaneClearsTheWholeWispsTable pins issueops.SweepWispsPlane:
// the selection is the wisps TABLE, so a closed no-history bead — durable-tier,
// and left alone by SweepEphemeral (RunSweeperLeavesNoHistoryBeadsToTheDurableTier)
// — goes with the closed ephemeral wisp, while a closed issues-plane row the
// same pattern admits stays.
func RunSweeperWispsPlaneClearsTheWholeWispsTable(t *testing.T, ctx context.Context, fixture SweeperFixture) {
t.Helper()
wisp := sweeperSeedClosedIssue(t, ctx, fixture, "plane", true)
durable := sweeperSeedClosedIssue(t, ctx, fixture, "plane", false)
noHistory := sweeperIssue(fixture, "plane", "nohist", false)
noHistory.NoHistory = true
if err := fixture.CreateWisp(ctx, noHistory, "sweeper-seed"); err != nil {
t.Fatalf("seeding %s: %v", noHistory.ID, err)
}
pinned := sweeperSeed(t, ctx, fixture, sweeperIssue(fixture, "plane", "pinned", true), func(issue *types.Issue) {
issue.Pinned = true
})
request := publicops.SweepRequest{
Tier: publicops.SweepWispsPlane,
IDPattern: sweeperPattern(fixture, "plane"),
ClosedBefore: &sweeperCutoff,
}
preview := sweeperSweep(t, ctx, fixture, sweeperAsDryRun(request))
if preview.Swept != 2 {
t.Fatalf("dry-run Swept = %d, want 2 (the ephemeral wisp and the no-history bead)", preview.Swept)
}
sweeperAssertWispRows(t, ctx, fixture, 3, wisp, noHistory.ID, pinned)
result := sweeperSweep(t, ctx, fixture, request)
if result.Swept != 2 {
t.Errorf("Swept = %d, want 2 (the ephemeral wisp and the no-history bead)", result.Swept)
}
if result.Skipped.Pinned != 1 {
t.Errorf("Skipped.Pinned = %d, want 1 — the plane selector does not override pinning", result.Skipped.Pinned)
}
sweeperAssertWispRows(t, ctx, fixture, 0, wisp, noHistory.ID)
sweeperAssertWispRows(t, ctx, fixture, 1, pinned)
sweeperAssertIssueRows(t, ctx, fixture, 1, durable)
}
// RunSweeperWispsPlaneRequiresAFilter pins that the wisps-plane tier carries
// the durable tier's require-a-filter gate: it reaches no-history beads, which
// are durable-tier. The refusal is asserted with its effect, as the durable
// case does.
func RunSweeperWispsPlaneRequiresAFilter(t *testing.T, ctx context.Context, fixture SweeperFixture) {
t.Helper()
id := sweeperSeedClosedIssue(t, ctx, fixture, "planegate", true)
result, err := fixture.Sweeper.Sweep(ctx, publicops.SweepRequest{Tier: publicops.SweepWispsPlane})
if !errors.Is(err, publicops.ErrValidation) {
t.Fatalf("Sweep(wisps-plane, no cutoff, no pattern) error = %v, want ErrValidation", err)
}
if result.Swept != 0 {
t.Errorf("refused sweep reported Swept = %d, want 0", result.Swept)
}
sweeperAssertWispRows(t, ctx, fixture, 1, id)
}
// RunSweeperProtectsLiveDependents pins issueops.SweepRequest.ProtectLiveDependents:
// a closed row a LIVE row depends on through parent-child, tracks or blocks is
// held back and counted, while a closed row reached only by a non-structural
// edge, or only by a dependent that is itself closed, is swept.
//
// The live sources carry three different not-done statuses (open,
// in_progress, hooked), because "live" is the not-done set and not "open".
// It runs on the wisps-plane tier with a cutoff — the request an
// orchestrator's retention sweep sends — after proving on a dry run that the
// same rows ARE candidates without the protection.
func RunSweeperProtectsLiveDependents(t *testing.T, ctx context.Context, fixture SweeperFixture) {
t.Helper()
if fixture.AddDependencies == nil {
t.Skip("fixture has no AddDependencies hook; cannot wire the edges this case needs")
}
live := func(name string, status types.Status) string {
issue := sweeperIssue(fixture, "live", name, true)
issue.Status = status
issue.ClosedAt = nil
return sweeperSeed(t, ctx, fixture, issue, nil)
}
closed := func(name string) string {
return sweeperSeed(t, ctx, fixture, sweeperIssue(fixture, "live", name, true), nil)
}
parent := closed("parent")
openChild := live("child-open", types.StatusOpen)
tracked := closed("tracked")
convoy := live("convoy", types.StatusInProgress)
blocker := closed("blocker")
hooked := live("hooked", types.StatusHooked)
related := closed("related")
relater := live("relater", types.StatusOpen)
doneParent := closed("done-parent")
doneChild := closed("done-child")
if err := fixture.AddDependencies(ctx, publicops.AddDependenciesRequest{
Actor: "sweeper-seed",
Edges: []publicops.DependencyEdge{
{IssueID: openChild, DependsOnID: parent, Type: publicops.DepParentChild},
{IssueID: convoy, DependsOnID: tracked, Type: publicops.DepTracks},
{IssueID: hooked, DependsOnID: blocker, Type: publicops.DepBlocks},
{IssueID: relater, DependsOnID: related, Type: publicops.DepRelated},
{IssueID: doneChild, DependsOnID: doneParent, Type: publicops.DepParentChild},
},
}); err != nil {
t.Fatalf("wiring dependencies: %v", err)
}
request := publicops.SweepRequest{
Tier: publicops.SweepWispsPlane,
IDPattern: sweeperPattern(fixture, "live"),
ClosedBefore: &sweeperCutoff,
}
unprotected := sweeperSweep(t, ctx, fixture, sweeperAsDryRun(request))
if unprotected.Swept != 6 || unprotected.Skipped.LiveDependent != 0 {
t.Fatalf("unprotected dry run: Swept = %d, LiveDependent = %d; want 6 and 0 — "+
"the protection must be asked for", unprotected.Swept, unprotected.Skipped.LiveDependent)
}
request.ProtectLiveDependents = true
result := sweeperSweep(t, ctx, fixture, request)
if result.Skipped.LiveDependent != 3 {
t.Errorf("Skipped.LiveDependent = %d, want 3 (the parent, the tracked bead and the blocker)",
result.Skipped.LiveDependent)
}
if result.Swept != 3 {
t.Errorf("Swept = %d, want 3 (the related-only bead and the closed parent/child pair)", result.Swept)
}
sweeperAssertWispRows(t, ctx, fixture, 3, parent, tracked, blocker)
sweeperAssertWispRows(t, ctx, fixture, 0, related, doneParent, doneChild)
sweeperAssertWispRows(t, ctx, fixture, 4, openChild, convoy, hooked, relater)
}
// RunSweeperProtectsTransitiveLiveDependents pins that protection propagates
// through closed candidates: an open grandchild keeps both its closed parent
// and closed grandparent. Otherwise sweeping the grandparent orphans a live
// hierarchy even though the direct parent was correctly retained.
func RunSweeperProtectsTransitiveLiveDependents(t *testing.T, ctx context.Context, fixture SweeperFixture) {
t.Helper()
if fixture.AddDependencies == nil {
t.Skip("fixture has no AddDependencies hook; cannot wire the hierarchy this case needs")
}
root := sweeperSeed(t, ctx, fixture, sweeperIssue(fixture, "transitive", "root", true), nil)
middle := sweeperSeed(t, ctx, fixture, sweeperIssue(fixture, "transitive", "middle", true), nil)
leafIssue := sweeperIssue(fixture, "transitive", "leaf", true)
leafIssue.Status = types.StatusOpen
leafIssue.ClosedAt = nil
leaf := sweeperSeed(t, ctx, fixture, leafIssue, nil)
if err := fixture.AddDependencies(ctx, publicops.AddDependenciesRequest{
Actor: "sweeper-seed",
Edges: []publicops.DependencyEdge{
{IssueID: middle, DependsOnID: root, Type: publicops.DepParentChild},
{IssueID: leaf, DependsOnID: middle, Type: publicops.DepParentChild},
},
}); err != nil {
t.Fatalf("wiring transitive hierarchy: %v", err)
}
request := publicops.SweepRequest{
Tier: publicops.SweepWispsPlane,
IDPattern: sweeperPattern(fixture, "transitive"),
ClosedBefore: &sweeperCutoff,
ProtectLiveDependents: true,
}
preview := sweeperSweep(t, ctx, fixture, sweeperAsDryRun(request))
if preview.Swept != 0 || preview.Skipped.LiveDependent != 2 {
t.Fatalf("dry run: Swept = %d, LiveDependent = %d; want 0 and 2", preview.Swept, preview.Skipped.LiveDependent)
}
result := sweeperSweep(t, ctx, fixture, request)
if result.Swept != 0 || result.Skipped.LiveDependent != 2 {
t.Fatalf("sweep: Swept = %d, LiveDependent = %d; want 0 and 2", result.Swept, result.Skipped.LiveDependent)
}
sweeperAssertWispRows(t, ctx, fixture, 3, root, middle, leaf)
}
// RunSweeperProtectsLiveDependentsAcrossPlanes pins that the live-dependent
// protection reads BOTH dependency tables: a closed wisp that a live DURABLE
// (issues-table) bead depends on through parent-child, tracks or blocks is
// kept, whatever not-done status the durable source carries.
func RunSweeperProtectsLiveDependentsAcrossPlanes(t *testing.T, ctx context.Context, fixture SweeperFixture) {
t.Helper()
if fixture.AddDependencies == nil {
t.Skip("fixture has no AddDependencies hook; cannot wire the edges this case needs")
}
durableLive := func(name string, status types.Status) string {
issue := sweeperIssue(fixture, "xplane", name, false)
issue.Status = status
issue.ClosedAt = nil
return sweeperSeed(t, ctx, fixture, issue, nil)
}
closedWisp := func(name string) string {
return sweeperSeed(t, ctx, fixture, sweeperIssue(fixture, "xplane", name, true), nil)
}
parent := closedWisp("parent")
tracked := closedWisp("tracked")
blocker := closedWisp("blocker")
loose := closedWisp("loose")
child := durableLive("child", types.StatusOpen)
convoy := durableLive("convoy", types.StatusInProgress)
waiter := durableLive("waiter", types.StatusDeferred)
if err := fixture.AddDependencies(ctx, publicops.AddDependenciesRequest{
Actor: "sweeper-seed",
Edges: []publicops.DependencyEdge{
{IssueID: child, DependsOnID: parent, Type: publicops.DepParentChild},
{IssueID: convoy, DependsOnID: tracked, Type: publicops.DepTracks},
{IssueID: waiter, DependsOnID: blocker, Type: publicops.DepBlocks},
},
}); err != nil {
t.Fatalf("wiring cross-plane dependencies: %v", err)
}
result := sweeperSweep(t, ctx, fixture, publicops.SweepRequest{
Tier: publicops.SweepWispsPlane,
IDPattern: sweeperPattern(fixture, "xplane"),
ClosedBefore: &sweeperCutoff,
ProtectLiveDependents: true,
})
if result.Skipped.LiveDependent != 3 || result.Swept != 1 {
t.Errorf("Swept = %d, LiveDependent = %d; want 1 (the unlinked wisp) and 3", result.Swept, result.Skipped.LiveDependent)
}
sweeperAssertWispRows(t, ctx, fixture, 3, parent, tracked, blocker)
sweeperAssertWispRows(t, ctx, fixture, 0, loose)
sweeperAssertIssueRows(t, ctx, fixture, 3, child, convoy, waiter)
}
// RunSweeperLimitTakesTheOldestClosedFirst pins issueops.SweepRequest.Limit:
// one call deletes at most Limit rows, oldest closed_at first, and reports the
// rest as Remaining; the next call picks up where it stopped.
func RunSweeperLimitTakesTheOldestClosedFirst(t *testing.T, ctx context.Context, fixture SweeperFixture) {
t.Helper()
seed := func(name string, closed time.Time) string {
return sweeperSeed(t, ctx, fixture, sweeperIssue(fixture, "limit", name, true), func(issue *types.Issue) {
issue.ClosedAt = &closed
})
}
newest := seed("newest", sweeperClosedAt)
middle := seed("middle", sweeperClosedAt.Add(-24*time.Hour))
oldest := seed("oldest", sweeperClosedAt.Add(-48*time.Hour))
request := publicops.SweepRequest{
Tier: publicops.SweepEphemeral,
IDPattern: sweeperPattern(fixture, "limit"),
Limit: 2,
}
first := sweeperSweep(t, ctx, fixture, request)
if first.Swept != 2 || first.Remaining != 1 {
t.Fatalf("first limited sweep: Swept = %d, Remaining = %d; want 2 and 1", first.Swept, first.Remaining)
}
sweeperAssertWispRows(t, ctx, fixture, 0, oldest, middle)
sweeperAssertWispRows(t, ctx, fixture, 1, newest)
second := sweeperSweep(t, ctx, fixture, request)
if second.Swept != 1 || second.Remaining != 0 {
t.Fatalf("second limited sweep: Swept = %d, Remaining = %d; want 1 and 0", second.Swept, second.Remaining)
}
sweeperAssertWispRows(t, ctx, fixture, 0, newest)
if _, err := fixture.Sweeper.Sweep(ctx, publicops.SweepRequest{
Tier: publicops.SweepEphemeral, IDPattern: sweeperPattern(fixture, "limit"), Limit: -1,
}); !errors.Is(err, publicops.ErrValidation) {
t.Fatalf("negative Limit error = %v, want ErrValidation", err)
}
}
// --- fixture helpers -------------------------------------------------------
// sweeperPattern is the glob that scopes one case's ids: a sweep is asked of a
@ -664,8 +936,8 @@ func sweeperSeedOpen(t *testing.T, ctx context.Context, fixture SweeperFixture,
return sweeperSeed(t, ctx, fixture, issue, nil)
}
func sweeperWithDryRun(request publicops.SweepRequest, dryRun bool) publicops.SweepRequest {
request.DryRun = dryRun
func sweeperAsDryRun(request publicops.SweepRequest) publicops.SweepRequest {
request.DryRun = true
return request
}

View file

@ -40,7 +40,12 @@ Auto-backup default:
dir and full-sync the whole database — a self-amplifying storm. To back up
a shared server, run 'bd backup' explicitly (or set backup.enabled=true and
coordinate destinations). 'bd config get backup.enabled' shows the effective
value and its source.`,
value and its source.
A proxied-server workspace is server mode too: auto-backup is OFF by
default and backup.enabled=true opts in. Both the opt-in and the five
backup verbs above are honored only on a managed-local proxied server —
one bd started itself; on a Dolt server bd does not own they are refused.`,
GroupID: "sync",
}
@ -56,7 +61,9 @@ func newBackupStatusCommand(sizeDatabase backupSizeFunc) *cobra.Command {
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
if usesProxiedServer() {
return HandleErrorRespectJSON("backup status is not supported in proxied-server mode")
if err := requireLocalProxiedBackup("backup status"); err != nil {
return err
}
}
evt := metrics.NewCommandEvent("backup-status")
defer func() {
@ -124,14 +131,9 @@ func newBackupStatusCommand(sizeDatabase backupSizeFunc) *cobra.Command {
// Show config (effective values with source)
enabled := isBackupAutoEnabled()
interval := config.GetDuration("backup.interval")
enabledSource := config.GetValueSource("backup.enabled")
enabledNote := ""
if enabledSource == config.SourceDefault {
if enabled {
enabledNote = " (auto: git remote detected)"
} else {
enabledNote = " (auto: no git remote)"
}
if note := backupAutoStatusNote(enabled); note != "" {
enabledNote = " (" + note + ")"
}
fmt.Printf("\nConfig: enabled=%v%s interval=%s\n",
enabled, enabledNote, interval)

View file

@ -2,6 +2,7 @@ package main
import (
"context"
"errors"
"fmt"
"os"
"strings"
@ -40,6 +41,36 @@ func isBackupAutoEnabled() bool {
return primeHasGitRemote()
}
// backupAutoStatusNote returns the parenthetical `bd backup status`
// prints after the effective backup.enabled value, or "" when the value
// speaks for itself. Callers pass the value isBackupAutoEnabled()
// already computed so the note cannot disagree with the number beside
// it — and so status does not re-run the git-remote probe.
//
// The note narrates the reason the decision actually used. An explicit
// backup.enabled needs no note: the source explains it, and every shape
// that reaches `bd backup status` honors it — including a managed-local
// proxied server, whose post-run arm runs auto-backup (every other proxied
// shape is refused by requireLocalProxiedBackup before status renders).
// A server-mode default is OFF whether or not a git remote exists, so it
// must not be attributed to the remote; before these arms existed, status
// did exactly that.
func backupAutoStatusNote(enabled bool) string {
if config.GetValueSource("backup.enabled") != config.SourceDefault {
return ""
}
if usesProxiedServer() {
return "auto: off in proxied-server mode; set backup.enabled=true to opt in"
}
if usesSQLServer() {
return "auto: off in sql-server mode"
}
if enabled {
return "auto: git remote detected"
}
return "auto: no git remote"
}
// clientServerShareFilesystem reports whether the configured Dolt
// server runs on a filesystem the bd client can also see — i.e.
// whether a file:// URL constructed on the client is meaningful to
@ -88,6 +119,21 @@ func clientServerShareFilesystem() bool {
// bd sessions don't need a chatty repeat on every command.
var autoBackupSkipNoticeOnce sync.Once
// autoBackupBackendForCommand returns the storage this command's auto-backup
// runs against, or ok=false when there is nothing it may back up.
func autoBackupBackendForCommand() (localBackupBackend, bool) {
if usesProxiedServer() {
return proxiedAutoBackupBackend()
}
if store == nil {
return nil, false
}
if lm, ok := storage.UnwrapStore(store).(storage.LifecycleManager); ok && lm.IsClosed() {
return nil, false
}
return directLocalBackup{store: store}, true
}
// maybeAutoBackup runs a Dolt-native backup if enabled and the throttle interval has passed.
// Called from PersistentPostRun after auto-commit.
func maybeAutoBackup(ctx context.Context) {
@ -102,10 +148,8 @@ func maybeAutoBackup(ctx context.Context) {
if !isBackupAutoEnabled() {
return
}
if store == nil {
return
}
if lm, ok := storage.UnwrapStore(store).(storage.LifecycleManager); ok && lm.IsClosed() {
backend, ok := autoBackupBackendForCommand()
if !ok {
return
}
@ -115,7 +159,11 @@ func maybeAutoBackup(ctx context.Context) {
// constructs is meaningless to the server — register fails on
// every command. Skip cleanly with a one-time INFO so operators
// know auto-backup is silent on purpose.
if !clientServerShareFilesystem() {
//
// Proxied workspaces do not consult the host: proxiedAutoBackupBackend
// has already required managed-local, where bd spawned the server on
// this filesystem itself.
if !usesProxiedServer() && !clientServerShareFilesystem() {
autoBackupSkipNoticeOnce.Do(func() {
if !isQuiet() && !jsonOutput {
fmt.Fprintln(os.Stderr,
@ -153,7 +201,7 @@ func maybeAutoBackup(ctx context.Context) {
}
// Change detection: skip if nothing changed
currentCommit, err := store.GetCurrentCommit(ctx)
currentCommit, err := backend.CurrentCommit(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "Warning: auto-backup skipped: failed to get current commit: %v\n", err)
return
@ -163,8 +211,21 @@ func maybeAutoBackup(ctx context.Context) {
return
}
// One backup at a time per workspace (backup_lock.go). Auto-backup never
// waits: a held lock means a backup is already running.
release, err := acquireBackupLock(0)
if err != nil {
if errors.Is(err, errBackupBusy) {
debug.Logf("backup: skipping — another backup is running\n")
return
}
fmt.Fprintf(os.Stderr, "Warning: auto-backup skipped: %v\n", err)
return
}
defer release()
// Run the backup (force=true since we already checked change detection above)
if _, err := runBackupExport(ctx, true); err != nil {
if _, err := runBackupExport(ctx, backend, true); err != nil {
if !isQuiet() && !jsonOutput {
fmt.Fprintf(os.Stderr, "Warning: auto-backup failed: %v\n", err)
}

View file

@ -0,0 +1,240 @@
//go:build cgo && unix
package main
import (
"context"
"encoding/json"
"os"
"path/filepath"
"slices"
"strings"
"testing"
"time"
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
"github.com/steveyegge/beads/internal/storage/dbproxy/server"
"github.com/steveyegge/beads/internal/workspacegate"
)
// autoBackupOptIn is the explicit opt-in a server-mode workspace needs, with
// the throttle collapsed so every command in a test is due.
var autoBackupOptIn = []string{"BD_BACKUP_ENABLED=true", "BD_BACKUP_INTERVAL=1ms"}
// TestManagedLocalProxiedAutoBackup is the claim this slice makes: on a
// managed-local proxied workspace, an explicit backup.enabled=true makes the
// post-command hook take a Dolt-native backup into .beads/backup, exactly as
// it does in direct mode — and that backup restores.
//
// Like the explicit-verb round trip next door, the proof is a restore, not an
// exit code: an auto-backup that wrote a manifest nobody can restore from would
// pass every other assertion here.
//
// Named TestManagedLocalProxied* so the proxied-local smoke lane runs it.
func TestManagedLocalProxiedAutoBackup(t *testing.T) {
requireManagedLocalProxiedEnv(t)
bd := buildEmbeddedBD(t)
p := bdManagedLocalInit(t, bd, "bkauto", 5*time.Minute)
autoDir := filepath.Join(p.beadsDir, "backup")
manifest := filepath.Join(autoDir, "manifest")
// Server mode defaults auto-backup OFF: many clients share one server.
// Nothing may be written without the opt-in.
bdProxiedCreate(t, bd, p.dir, "no opt-in, no backup", "-p", "2")
if _, err := os.Stat(manifest); err == nil {
t.Fatalf("auto-backup ran without an opt-in: %s exists", manifest)
}
// With the opt-in, one ordinary write is enough.
created := proxiedAutoBackupCreate(t, bd, p, "captured by auto-backup")
if _, err := os.Stat(manifest); err != nil {
t.Fatalf("opted-in auto-backup produced no manifest at %s: %v", manifest, err)
}
state := readProxiedAutoBackupState(t, bd, p)
if state.LastDoltCommit == "" || state.Timestamp.IsZero() {
t.Fatalf("auto-backup did not record its watermark: %+v", state)
}
wantIDs := proxiedIssueIDs(t, bd, p)
if !slices.Contains(wantIDs, created) {
t.Fatalf("precondition: %s missing from %v", created, wantIDs)
}
// A read-only command with nothing new to capture must not advance the
// watermark: change detection runs before the backup, as in direct mode.
if _, stderr, err := bdProxiedRunBuffersWithEnv(t, bd, p.dir, autoBackupOptIn, "list", "--json"); err != nil {
t.Fatalf("bd list with auto-backup opted in: %v\n%s", err, stderr)
}
if again := readProxiedAutoBackupState(t, bd, p); again.LastDoltCommit != state.LastDoltCommit {
t.Fatalf("auto-backup advanced with no new commit: %q -> %q", state.LastDoltCommit, again.LastDoltCommit)
}
// `bd dolt stop` opens no provider, so its post-run hook has nothing to
// back up — and must not relaunch the server it just stopped to find out.
if _, stderr, err := bdProxiedRunBuffersWithEnv(t, bd, p.dir, autoBackupOptIn, "dolt", "stop"); err != nil {
t.Fatalf("bd dolt stop: %v\n%s", err, stderr)
}
assertManagedProxiedQuiescent(t, p, "bd dolt stop with auto-backup opted in")
// Diverge from the backup, then restore it and compare.
after := bdProxiedCreate(t, bd, p.dir, "created after the auto-backup", "-p", "2")
out, err := bdProxiedRun(t, bd, p.dir, "backup", "restore", autoDir, "--force", "--json")
if err != nil {
t.Fatalf("bd backup restore %s --force: %v\n%s", autoDir, err, out)
}
gotIDs := proxiedIssueIDs(t, bd, p)
if slices.Contains(gotIDs, after.ID) {
t.Fatalf("restore kept %s, created after the auto-backup; got %v", after.ID, gotIDs)
}
if !slices.Equal(gotIDs, wantIDs) {
t.Fatalf("restored issues differ from the auto-backed-up set:\n got %v\n want %v", gotIDs, wantIDs)
}
}
// TestManagedLocalProxiedBackupRestoreRefusedWhileAttached pins the restore
// design choice: restore REPLACES the database, so it refuses while any other
// bd command is attached to the workspace, and in that case touches nothing —
// the serving child keeps running and the data stays as it was.
//
// "Attached" is what another bd process holds for its lifetime: a SHARED
// workspace gate. The test holds exactly that, in-process, rather than racing
// a second process into position.
func TestManagedLocalProxiedBackupRestoreRefusedWhileAttached(t *testing.T) {
requireManagedLocalProxiedEnv(t)
bd := buildEmbeddedBD(t)
p := bdManagedLocalInit(t, bd, "bkatt", 5*time.Minute)
bdProxiedCreate(t, bd, p.dir, "in the backup", "-p", "1")
dest := filepath.Join(t.TempDir(), "dolt-backup")
if out, err := bdProxiedRun(t, bd, p.dir, "backup", "init", dest); err != nil {
t.Fatalf("bd backup init: %v\n%s", err, out)
}
if out, err := bdProxiedRun(t, bd, p.dir, "backup", "sync"); err != nil {
t.Fatalf("bd backup sync: %v\n%s", err, out)
}
after := bdProxiedCreate(t, bd, p.dir, "not in the backup", "-p", "1")
before := proxiedIssueIDs(t, bd, p)
proxyPID := readManagedProxyPidFile(t, p)
backendPID := readManagedBackendPidFile(t, p)
if proxyPID == nil || backendPID == nil {
t.Fatal("precondition: the managed topology should be serving")
}
gates, err := buildWorkspaceGateSet(p.beadsDir)
if err != nil {
t.Fatalf("resolve workspace gates: %v", err)
}
held, err := workspacegate.AcquireAll(context.Background(), workspacegate.Shared,
workspacegate.Options{Reason: "test: attached bd client"}, gates...)
if err != nil {
t.Fatalf("hold the workspace gate: %v", err)
}
released := false
release := func() {
if !released {
released = true
if err := held.Release(); err != nil {
t.Errorf("release workspace gate: %v", err)
}
}
}
t.Cleanup(release)
stdout, _, err := bdProxiedRunBuffers(t, bd, p.dir, "backup", "restore", dest, "--force", "--json")
if err == nil {
t.Fatalf("bd backup restore succeeded while another bd client was attached:\n%s", stdout)
}
var refusal struct {
Error string `json:"error"`
}
if jerr := json.Unmarshal([]byte(stdout[strings.Index(stdout, "{"):]), &refusal); jerr != nil {
t.Fatalf("restore refusal is not JSON on stdout: %v\n%s", jerr, stdout)
}
if !strings.Contains(refusal.Error, "other bd commands are using this workspace") {
t.Fatalf("restore refusal does not say why: %q", refusal.Error)
}
// Refused means untouched: the serving topology is the same processes.
if pf := readManagedProxyPidFile(t, p); pf == nil || pf.Pid != proxyPID.Pid || !processAlive(pf.Pid) {
t.Fatalf("refused restore disturbed the proxy: before %+v, now %+v", proxyPID, pf)
}
if pf := readManagedBackendPidFile(t, p); pf == nil || pf.Pid != backendPID.Pid || !processAlive(pf.Pid) {
t.Fatalf("refused restore disturbed the dolt child: before %+v, now %+v", backendPID, pf)
}
release()
if got := proxiedIssueIDs(t, bd, p); !slices.Equal(got, before) || !slices.Contains(got, after.ID) {
t.Fatalf("refused restore changed the data:\n got %v\n want %v", got, before)
}
// Once the other client detaches, the same restore goes through.
if out, err := bdProxiedRun(t, bd, p.dir, "backup", "restore", dest, "--force", "--json"); err != nil {
t.Fatalf("bd backup restore after the client detached: %v\n%s", err, out)
}
if slices.Contains(proxiedIssueIDs(t, bd, p), after.ID) {
t.Fatalf("restore after detach did not replace the database: %s is still here", after.ID)
}
}
// proxiedAutoBackupCreate creates an issue with auto-backup opted in and
// returns its ID.
func proxiedAutoBackupCreate(t *testing.T, bd string, p proxiedProject, title string) string {
t.Helper()
stdout, stderr, err := bdProxiedRunBuffersWithEnv(t, bd, p.dir, autoBackupOptIn, "create", title, "-p", "2", "--silent")
if err != nil {
t.Fatalf("bd create with auto-backup opted in: %v\n%s", err, stderr)
}
if strings.Contains(stderr, "auto-backup") {
t.Fatalf("auto-backup reported a problem:\n%s", stderr)
}
id := strings.TrimSpace(stdout)
if id == "" {
t.Fatalf("bd create --silent printed no ID; stderr:\n%s", stderr)
}
return id
}
// readProxiedAutoBackupState reads the auto-backup watermark through
// `bd backup status --json`, the surface an operator uses.
func readProxiedAutoBackupState(t *testing.T, bd string, p proxiedProject) backupState {
t.Helper()
out, err := bdProxiedRun(t, bd, p.dir, "backup", "status", "--json")
if err != nil {
t.Fatalf("bd backup status --json: %v\n%s", err, out)
}
start := strings.Index(string(out), "{")
if start < 0 {
t.Fatalf("bd backup status --json produced no JSON:\n%s", out)
}
var status struct {
Backup backupState `json:"backup"`
}
if err := json.Unmarshal(out[start:], &status); err != nil {
t.Fatalf("parse backup status JSON: %v\n%s", err, out)
}
return status.Backup
}
// proxiedIssueIDs lists every issue ID in the workspace, sorted.
func proxiedIssueIDs(t *testing.T, bd string, p proxiedProject) []string {
t.Helper()
var ids []string
for _, issue := range bdProxiedListJSON(t, bd, p, "--all") {
ids = append(ids, issue.ID)
}
slices.Sort(ids)
return ids
}
// assertManagedProxiedQuiescent fails when either managed-local pidfile is
// present, i.e. something relaunched the topology.
func assertManagedProxiedQuiescent(t *testing.T, p proxiedProject, after string) {
t.Helper()
for _, name := range []string{proxy.PIDFileName, server.PIDFileName} {
if _, err := os.Stat(filepath.Join(p.proxyRoot, name)); err == nil {
t.Fatalf("after %s, %s is present: the topology was relaunched", after, name)
}
}
}

View file

@ -0,0 +1,142 @@
package main
import (
"context"
"database/sql"
"os"
"testing"
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/configfile"
"github.com/steveyegge/beads/internal/storage/uow"
)
// fakeMaintenanceProvider is a proxied provider stand-in exposing the
// non-transactional seam proxied auto-backup runs on. It never opens a
// connection; the tests here only assert whether it would be used.
type fakeMaintenanceProvider struct {
uow.UnitOfWorkProvider
runs int
}
func (f *fakeMaintenanceProvider) RunNonTx(context.Context, func(context.Context, *sql.Conn) error) error {
f.runs++
return nil
}
func (f *fakeMaintenanceProvider) Close(context.Context) error { return nil }
// TestProxiedAutoBackupBackendFollowsLocality pins where auto-backup may run on
// a proxied workspace: exactly where `bd backup sync` is honored. Auto-backup
// registers a server-side backup remote, which on a server bd does not own is
// global to every client of it — the storm the explicit verbs refuse by design
// — so an implicit trigger must not get further than the explicit one. An
// unreadable sidecar resolves to the unknown topology and fails closed.
//
// Cannot be parallel: mutates the proxiedServerMode and uowProvider globals.
func TestProxiedAutoBackupBackendFollowsLocality(t *testing.T) {
for _, tc := range []struct {
name string
sidecar string
noProvider bool
wantBackend bool
}{
{name: "managed-local with an open provider", sidecar: `{}`, wantBackend: true},
{name: "managed-local with no provider open", sidecar: `{}`, noProvider: true},
{name: "external tcp", sidecar: `{"external":{"host":"db.example.com","port":3306}}`},
{name: "external unix socket", sidecar: `{"external":{"socket":"/tmp/dolt.sock"}}`},
{name: "unreadable sidecar", sidecar: `{not json`},
} {
t.Run(tc.name, func(t *testing.T) {
beadsDir := prepareBackupStatusTest(t)
proxiedServerMode = true
if err := os.WriteFile(configfile.ProxiedServerClientInfoPath(beadsDir), []byte(tc.sidecar), 0o600); err != nil {
t.Fatalf("write proxied sidecar: %v", err)
}
oldProvider := uowProvider
t.Cleanup(func() { uowProvider = oldProvider })
fake := &fakeMaintenanceProvider{}
uowProvider = fake
if tc.noProvider {
uowProvider = nil
}
backend, ok := autoBackupBackendForCommand()
if ok != tc.wantBackend {
t.Fatalf("autoBackupBackendForCommand() ok = %v, want %v", ok, tc.wantBackend)
}
if !ok {
return
}
if _, isProxied := backend.(proxiedLocalBackup); !isProxied {
t.Fatalf("backend = %T, want proxiedLocalBackup", backend)
}
if fake.runs != 0 {
t.Fatalf("resolving the backend ran %d maintenance call(s); it must not touch the server", fake.runs)
}
})
}
}
// TestPersistentPostRunProxiedRunsAutoBackup pins the wiring: the proxied arm
// of PersistentPostRunE calls the auto-backup hook, under the same gate the
// direct arm's maintenance net uses, plus previews.
//
// Before this hook existed the proxied arm only pruned the journal and closed
// the provider, so backup.enabled=true was inert on every proxied workspace.
//
// Cannot be parallel: mutates PersistentPostRunE's package globals.
func TestPersistentPostRunProxiedRunsAutoBackup(t *testing.T) {
for _, tc := range []struct {
name string
cmd func() *cobra.Command
readonly bool
want int
}{
{name: "ordinary command", cmd: func() *cobra.Command { return &cobra.Command{Use: "list"} }, want: 1},
{name: "strict readonly", cmd: func() *cobra.Command { return &cobra.Command{Use: "list"} }, readonly: true},
{name: "bd serve", cmd: func() *cobra.Command { return &cobra.Command{Use: serveCmdName} }},
{name: "preview", cmd: func() *cobra.Command {
c := &cobra.Command{Use: "list"}
c.Flags().Bool("dry-run", false, "")
if err := c.Flags().Set("dry-run", "true"); err != nil {
t.Fatalf("set --dry-run: %v", err)
}
return c
}},
} {
t.Run(tc.name, func(t *testing.T) {
t.Chdir(t.TempDir())
t.Setenv("BEADS_DIR", "")
oldStore, oldProvider := store, uowProvider
oldReadonly, oldProxied := readonlyMode, proxiedServerMode
oldRootCtx, oldRootCancel := rootCtx, rootCancel
oldSpan, oldProfile, oldTrace := commandSpan, profileFile, traceFile
oldBackup := runPostRunAutoBackup
t.Cleanup(func() {
store, uowProvider = oldStore, oldProvider
readonlyMode, proxiedServerMode = oldReadonly, oldProxied
rootCtx, rootCancel = oldRootCtx, oldRootCancel
commandSpan, profileFile, traceFile = oldSpan, oldProfile, oldTrace
runPostRunAutoBackup = oldBackup
})
calls := 0
runPostRunAutoBackup = func(context.Context) { calls++ }
store, uowProvider = nil, nil
readonlyMode = tc.readonly
proxiedServerMode = true
rootCtx, rootCancel = context.Background(), nil
commandSpan, profileFile, traceFile = nil, nil, nil
if err := rootCmd.PersistentPostRunE(tc.cmd(), nil); err != nil {
t.Fatalf("PersistentPostRunE: %v", err)
}
if calls != tc.want {
t.Fatalf("auto-backup hook calls = %d, want %d", calls, tc.want)
}
})
}
}

View file

@ -123,6 +123,147 @@ func TestIsBackupAutoEnabled(t *testing.T) {
}
}
// TestBackupAutoStatusNote pins the reason `bd backup status` prints beside
// the effective backup.enabled value against the reason isBackupAutoEnabled
// actually used — the two are computed in different files and drifted apart
// once already.
//
// The regression this locks down arrived with the proxied-parity S3 slice
// (PR #6584): honoring the backup family on managed-local made `bd backup
// status` reachable on a proxied server for the first time, where it rendered
// the embedded-mode footnote "(auto: no git remote)". On any sql-server shape
// the value is false because usesSQLServer() short-circuits, whether or not a
// remote exists, so that reason was simply untrue. Since the proxied post-run
// arm gained its auto-backup hook, an explicit opt-in on proxied is honored
// and needs no caveat.
//
// Cannot be parallel: mutates the proxiedServerMode global, primeHasGitRemote
// and env vars.
func TestBackupAutoStatusNote(t *testing.T) {
tests := []struct {
name string
envVal string // "\x00" = not set, otherwise explicit backup.enabled
hasRemote bool
sharedServer bool // BEADS_DOLT_SHARED_SERVER=1 → usesSQLServer() true
proxied bool // proxiedServerMode → usesProxiedServer() true
wantEnabled bool
wantNote string
}{
{
name: "embedded default + git remote → unchanged",
envVal: "\x00",
hasRemote: true,
wantEnabled: true,
wantNote: "auto: git remote detected",
},
{
name: "embedded default + no git remote → unchanged",
envVal: "\x00",
hasRemote: false,
wantEnabled: false,
wantNote: "auto: no git remote",
},
{
name: "embedded explicit → no note, the source explains it",
envVal: "true",
hasRemote: false,
wantEnabled: true,
wantNote: "",
},
{
// Pre-fix this case printed "auto: no git remote" even with a
// remote configured: server mode, not the remote, is the reason.
name: "sql-server default + git remote → server mode, not the remote",
envVal: "\x00",
hasRemote: true,
sharedServer: true,
wantEnabled: false,
wantNote: "auto: off in sql-server mode",
},
{
// Non-proxied server mode keeps its post-run hook, so an explicit
// opt-in really does work there and needs no caveat.
name: "sql-server explicit opt-in → no note",
envVal: "true",
hasRemote: false,
sharedServer: true,
wantEnabled: true,
wantNote: "",
},
{
// Proxied is server mode: the default is off whether or not a
// remote exists, and the note names the opt-in that now works.
name: "proxied default → off, names the opt-in, not the remote",
envVal: "\x00",
hasRemote: true,
proxied: true,
wantEnabled: false,
wantNote: "auto: off in proxied-server mode; set backup.enabled=true to opt in",
},
{
// The proxied post-run arm runs auto-backup on managed-local (the
// only proxied shape status renders on), so an explicit opt-in is
// real there and needs no caveat.
name: "proxied explicit opt-in → honored, no note",
envVal: "true",
hasRemote: false,
proxied: true,
wantEnabled: true,
wantNote: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Same isolation as TestIsBackupAutoEnabled: a leaked BEADS_DIR or
// a cwd inside the repo tree lets Initialize() load an ambient
// config.yaml whose explicit backup.enabled wins over the computed
// default these cases assert on (be-yjp4z).
t.Chdir(t.TempDir())
t.Setenv("BEADS_DIR", "")
t.Setenv("BEADS_TEST_IGNORE_REPO_CONFIG", "1")
orig := primeHasGitRemote
primeHasGitRemote = func() bool { return tt.hasRemote }
t.Cleanup(func() { primeHasGitRemote = orig })
origProxied := proxiedServerMode
proxiedServerMode = tt.proxied
t.Cleanup(func() { proxiedServerMode = origProxied })
if tt.sharedServer {
t.Setenv("BEADS_DOLT_SHARED_SERVER", "1")
} else {
os.Unsetenv("BEADS_DOLT_SHARED_SERVER")
t.Cleanup(func() { os.Unsetenv("BEADS_DOLT_SHARED_SERVER") })
}
if tt.envVal == "\x00" {
os.Unsetenv("BD_BACKUP_ENABLED")
t.Cleanup(func() { os.Unsetenv("BD_BACKUP_ENABLED") })
} else {
t.Setenv("BD_BACKUP_ENABLED", tt.envVal)
}
config.ResetForTesting()
t.Cleanup(func() { config.ResetForTesting() })
if err := config.Initialize(); err != nil {
t.Fatalf("config.Initialize: %v", err)
}
// Take the value the way backup status does, so the note is pinned
// against the number it is printed beside rather than a literal.
enabled := isBackupAutoEnabled()
if enabled != tt.wantEnabled {
t.Fatalf("isBackupAutoEnabled() = %v, want %v", enabled, tt.wantEnabled)
}
if got := backupAutoStatusNote(enabled); got != tt.wantNote {
t.Errorf("backupAutoStatusNote(%v) = %q, want %q", enabled, got, tt.wantNote)
}
})
}
}
// TestClientServerShareFilesystem_GH3523 pins the gating logic that
// suppresses auto-backup's file:// register when the Dolt server
// runs on a different filesystem from the client. Pre-fix every

View file

@ -46,10 +46,13 @@ DoltHub (recommended for cloud backup):
After adding, run 'bd backup sync' to push your data.`,
Args: cobra.ExactArgs(1),
// As on `backup status`: the failures here are configuration and I/O
// errors, not usage errors, and cobra's default prints the message, then
// "Error: exit code 1", then the whole usage block — three things where one
// was wanted, and on --json it lands after the JSON object.
SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
if usesProxiedServer() {
return HandleErrorRespectJSON("backup init is not supported in proxied-server mode")
}
evt := metrics.NewCommandEvent("backup-init")
defer func() {
if c := metrics.Global(); c != nil {
@ -60,6 +63,10 @@ After adding, run 'bd backup sync' to push your data.`,
ctx := rootCtx
rawPath := args[0]
if usesProxiedServer() {
return runBackupInitProxied(ctx, rawPath)
}
if store == nil {
return fmt.Errorf("no store available")
}
@ -124,10 +131,9 @@ backup location configured with 'bd backup init'.
The backup is atomic — if the sync fails, the previous backup state is preserved.
Run 'bd backup init <path>' first to configure a destination.`,
SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
if usesProxiedServer() {
return HandleErrorRespectJSON("backup sync is not supported in proxied-server mode")
}
evt := metrics.NewCommandEvent("backup-sync")
defer func() {
if c := metrics.Global(); c != nil {
@ -136,6 +142,23 @@ Run 'bd backup init <path>' first to configure a destination.`,
}()
ctx := rootCtx
if usesProxiedServer() {
if err := requireLocalProxiedBackup("backup sync"); err != nil {
return err
}
}
release, err := acquireBackupLock(backupLockWait)
if err != nil {
if errors.Is(err, errBackupBusy) {
return HandleErrorRespectJSON("%v; retry when it completes", err)
}
return HandleErrorRespectJSON("%v", err)
}
defer release()
if usesProxiedServer() {
return runBackupSyncProxied(ctx)
}
if store == nil {
return fmt.Errorf("no store available")
}
@ -358,7 +381,14 @@ func showDoltBackupStatusJSON() map[string]interface{} {
// doltBackupSize returns the active database size when the current store
// instance can measure its storage locally. Unsupported backends preserve the
// optional status-field contract instead of failing the command.
//
// Proxied mode has no store to ask — the provider owns the connection — so the
// fork lives here, where "which backend measures this database" is already the
// question being answered.
func doltBackupSize(ctx context.Context) (int64, bool, error) {
if usesProxiedServer() {
return doltBackupSizeProxied(ctx)
}
if store == nil {
return 0, false, fmt.Errorf("no storage backend is open")
}
@ -405,11 +435,10 @@ var backupRemoveCmd = &cobra.Command{
This unregisters the backup remote from Dolt and removes the local
backup configuration. The backup data at the destination is not deleted.`,
Aliases: []string{"rm"},
Aliases: []string{"rm"},
SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
if usesProxiedServer() {
return HandleErrorRespectJSON("backup remove is not supported in proxied-server mode")
}
evt := metrics.NewCommandEvent("backup-remove")
defer func() {
if c := metrics.Global(); c != nil {
@ -418,6 +447,9 @@ backup configuration. The backup data at the destination is not deleted.`,
}()
ctx := rootCtx
if usesProxiedServer() {
return runBackupRemoveProxied(ctx)
}
if store == nil {
return fmt.Errorf("no store available")
}
@ -435,7 +467,7 @@ backup configuration. The backup data at the destination is not deleted.`,
}
// Also remove backup_export if it exists (auto-export may have created it at same URL)
_ = bs.BackupRemove(ctx, "backup_export")
_ = bs.BackupRemove(ctx, versioncontrolops.ExportBackupName)
// Remove local config
if path, err := doltBackupConfigPath(); err == nil {

View file

@ -122,9 +122,35 @@ func atomicWriteFile(path string, data []byte) error {
return nil
}
// localBackupBackend is what a Dolt-native backup into a local directory needs
// from storage: the commit it would capture, and the backup itself. The direct
// store supplies one (directLocalBackup) and so does the proxied provider
// (proxiedLocalBackup, backup_proxied_server.go).
type localBackupBackend interface {
CurrentCommit(ctx context.Context) (string, error)
BackupToDir(ctx context.Context, dir string) error
}
// directLocalBackup is localBackupBackend over an embedded or sql-server store.
type directLocalBackup struct {
store storage.DoltStorage
}
func (b directLocalBackup) CurrentCommit(ctx context.Context) (string, error) {
return b.store.GetCurrentCommit(ctx)
}
func (b directLocalBackup) BackupToDir(ctx context.Context, dir string) error {
bs, ok := storage.UnwrapStore(b.store).(storage.BackupStore)
if !ok {
return fmt.Errorf("storage backend does not support backup operations")
}
return bs.BackupDatabase(ctx, dir)
}
// runBackupExport performs a Dolt-native backup to .beads/backup/.
// Returns the updated state.
func runBackupExport(ctx context.Context, force bool) (*backupState, error) {
func runBackupExport(ctx context.Context, backend localBackupBackend, force bool) (*backupState, error) {
dir, err := backupDir()
if err != nil {
return nil, err
@ -135,24 +161,23 @@ func runBackupExport(ctx context.Context, force bool) (*backupState, error) {
return nil, err
}
// Read the watermark before the sync. A concurrent commit may land while
// BackupToDir is running; recording a later HEAD would claim that commit is
// present in a snapshot that started before it existed.
currentCommit, err := backend.CurrentCommit(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get current commit: %w", err)
}
// Change detection: skip if nothing changed (unless forced)
if !force {
currentCommit, err := store.GetCurrentCommit(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get current commit: %w", err)
}
if currentCommit == state.LastDoltCommit && state.LastDoltCommit != "" {
debug.Logf("backup: no changes since last backup (commit %s)\n", truncateHash(currentCommit))
return state, nil
}
}
bs, ok := storage.UnwrapStore(store).(storage.BackupStore)
if !ok {
return nil, fmt.Errorf("storage backend does not support backup operations")
}
if err := bs.BackupDatabase(ctx, dir); err != nil {
if err := backend.BackupToDir(ctx, dir); err != nil {
// Persist the attempt time even on failure so the throttle
// interval (checked by maybeAutoBackup via state.Timestamp)
// applies to the next command. Without this, a sync that keeps
@ -169,11 +194,8 @@ func runBackupExport(ctx context.Context, force bool) (*backupState, error) {
return nil, err
}
// Update watermarks
currentCommit, err := store.GetCurrentCommit(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get current commit for state: %w", err)
}
// The pre-sync commit is the newest commit this backup is guaranteed to
// contain. If HEAD moved during the sync, the next backup must see it.
state.LastDoltCommit = currentCommit
state.Timestamp = time.Now().UTC()

View file

@ -63,13 +63,10 @@ func TestRunBackupExport_PersistsThrottleOnFailure(t *testing.T) {
t.Fatalf("precondition: expected zero timestamp, got %v", st.Timestamp)
}
oldStore := store
fake := &failingBackupStore{commit: "deadbeef", backupErr: errors.New("sync to backup: server too busy")}
store = fake
t.Cleanup(func() { store = oldStore })
before := time.Now().UTC()
if _, err := runBackupExport(context.Background(), true); err == nil {
if _, err := runBackupExport(context.Background(), directLocalBackup{store: fake}, true); err == nil {
t.Fatal("expected runBackupExport to return the sync error, got nil")
}
if fake.backupCalls != 1 {

View file

@ -0,0 +1,55 @@
package main
import (
"context"
"os"
"path/filepath"
"testing"
"github.com/steveyegge/beads/internal/config"
)
type advancingBackupBackend struct {
commit string
backupCommit string
commitAfterSync string
}
func (b *advancingBackupBackend) CurrentCommit(context.Context) (string, error) {
return b.commit, nil
}
func (b *advancingBackupBackend) BackupToDir(context.Context, string) error {
b.backupCommit = b.commit
b.commit = b.commitAfterSync
return nil
}
func TestRunBackupExportWatermarkDoesNotAdvancePastSnapshot(t *testing.T) {
for _, force := range []bool{false, true} {
t.Run(map[bool]string{false: "changed", true: "forced"}[force], func(t *testing.T) {
repo := t.TempDir()
if err := os.MkdirAll(filepath.Join(repo, ".git"), 0o755); err != nil {
t.Fatal(err)
}
t.Setenv("BD_BACKUP_GIT_REPO", repo)
config.ResetForTesting()
t.Cleanup(config.ResetForTesting)
if err := config.Initialize(); err != nil {
t.Fatalf("config.Initialize: %v", err)
}
backend := &advancingBackupBackend{commit: "head-before-sync", commitAfterSync: "head-after-sync"}
state, err := runBackupExport(context.Background(), backend, force)
if err != nil {
t.Fatalf("runBackupExport: %v", err)
}
if backend.backupCommit != "head-before-sync" {
t.Fatalf("backup captured %q, want head-before-sync", backend.backupCommit)
}
if state.LastDoltCommit != backend.backupCommit {
t.Fatalf("watermark = %q, backup captured %q; a commit that landed during sync must remain pending", state.LastDoltCommit, backend.backupCommit)
}
})
}
}

71
cmd/bd/backup_lock.go Normal file
View file

@ -0,0 +1,71 @@
package main
import (
"errors"
"fmt"
"os"
"path/filepath"
"time"
"github.com/steveyegge/beads/internal/beads"
"github.com/steveyegge/beads/internal/lockfile"
)
// The backup lock serializes the two writers of a workspace's Dolt backup:
// post-command auto-backup and an explicit `bd backup sync`. Both run under the
// command's SHARED workspace gate, so the gate alone lets them overlap, and the
// auto-backup body does remove → add → sync on one fixed remote name — two
// concurrent runs race each other's registration and full-sync the database
// twice. Restore needs no part in it: it holds the workspace gate EXCLUSIVELY,
// which already excludes every command that could take this lock.
//
// The two callers wait differently, and deliberately:
// - auto-backup does not wait. Another backup running means one is already
// happening; it skips, and the throttle picks it up on a later command.
// - `bd backup sync` waits up to backupLockWait — the same bound an exclusive
// workspace-gate acquisition (restore) uses — and then fails with an error
// naming the busy lock, so an operator is never told it synced when it
// did not.
const backupLockFileName = "backup.lock"
// backupLockWait bounds how long `bd backup sync` waits for another backup.
// A var so tests can shorten it.
var backupLockWait = exclusiveGateWait
// errBackupBusy is returned when another backup holds the lock past the wait.
var errBackupBusy = errors.New("another backup is running for this workspace")
const backupLockPoll = 50 * time.Millisecond
// acquireBackupLock takes the workspace's backup lock, polling up to wait
// (zero means one non-blocking attempt). The returned release must be called.
func acquireBackupLock(wait time.Duration) (release func(), err error) {
beadsDir := beads.FindBeadsDir()
if beadsDir == "" {
return nil, fmt.Errorf("backup lock: %s", activeWorkspaceNotFoundError())
}
path := filepath.Join(beadsDir, backupLockFileName)
f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0o600) //nolint:gosec // path is the workspace's own lock file
if err != nil {
return nil, fmt.Errorf("backup lock: open %s: %w", path, err)
}
deadline := time.Now().Add(wait)
for {
err := lockfile.FlockExclusiveNonBlocking(f)
if err == nil {
return func() {
_ = lockfile.FlockUnlock(f)
_ = f.Close()
}, nil
}
if !lockfile.IsLocked(err) {
_ = f.Close()
return nil, fmt.Errorf("backup lock: %s: %w", path, err)
}
if !time.Now().Before(deadline) {
_ = f.Close()
return nil, errBackupBusy
}
time.Sleep(backupLockPoll)
}
}

133
cmd/bd/backup_lock_test.go Normal file
View file

@ -0,0 +1,133 @@
package main
import (
"context"
"errors"
"os"
"strings"
"testing"
"time"
)
// TestBackupLockSerializesBackups pins the lock itself: a second holder is
// refused while the first holds it, a bounded wait gives up with errBackupBusy,
// and releasing makes it available again.
//
// Cannot be parallel: prepareBackupStatusTest mutates package globals.
func TestBackupLockSerializesBackups(t *testing.T) {
prepareBackupStatusTest(t)
release, err := acquireBackupLock(0)
if err != nil {
t.Fatalf("first acquisition: %v", err)
}
if _, err := acquireBackupLock(0); !errors.Is(err, errBackupBusy) {
t.Fatalf("non-blocking acquisition while held = %v, want errBackupBusy", err)
}
start := time.Now()
if _, err := acquireBackupLock(150 * time.Millisecond); !errors.Is(err, errBackupBusy) {
t.Fatalf("bounded wait while held = %v, want errBackupBusy", err)
}
if waited := time.Since(start); waited < 100*time.Millisecond {
t.Fatalf("bounded wait returned after %s; it must poll for the wait it was given", waited)
}
release()
again, err := acquireBackupLock(0)
if err != nil {
t.Fatalf("acquisition after release: %v", err)
}
again()
}
// TestAutoBackupSkipsWhileAnotherBackupRuns: auto-backup never waits on the
// lock. With it held the backup does not run and the throttle state is left
// alone, so the next command retries; once released, the same call backs up.
func TestAutoBackupSkipsWhileAnotherBackupRuns(t *testing.T) {
prepareBackupStatusTest(t)
t.Setenv("BD_BACKUP_ENABLED", "true")
t.Setenv("BD_BACKUP_INTERVAL", "1ms")
t.Setenv("BD_GIT_HOOK", "")
initConfigForTest(t)
oldStore := store
fake := &failingBackupStore{commit: "c1"}
store = fake
t.Cleanup(func() { store = oldStore })
release, err := acquireBackupLock(0)
if err != nil {
t.Fatalf("hold the backup lock: %v", err)
}
maybeAutoBackup(context.Background())
if fake.backupCalls != 0 {
t.Fatalf("auto-backup ran %d backup(s) while another backup held the lock", fake.backupCalls)
}
dir, err := backupDir()
if err != nil {
t.Fatal(err)
}
if st, _ := loadBackupState(dir); !st.Timestamp.IsZero() {
t.Fatalf("a skipped auto-backup advanced the throttle to %v", st.Timestamp)
}
release()
maybeAutoBackup(context.Background())
if fake.backupCalls != 1 {
t.Fatalf("auto-backup ran %d backup(s) after the lock was released, want 1", fake.backupCalls)
}
}
// TestBackupSyncFailsWhenAnotherBackupHoldsTheLock: an explicit sync waits
// backupLockWait for another backup and then fails loudly, before touching the
// store — it never reports a sync it did not do.
func TestBackupSyncFailsWhenAnotherBackupHoldsTheLock(t *testing.T) {
prepareBackupStatusTest(t)
oldWait := backupLockWait
backupLockWait = 100 * time.Millisecond
t.Cleanup(func() { backupLockWait = oldWait })
oldStore := store
fake := &failingBackupStore{commit: "c1"}
store = fake
t.Cleanup(func() { store = oldStore })
release, err := acquireBackupLock(0)
if err != nil {
t.Fatalf("hold the backup lock: %v", err)
}
defer release()
var runErr error
stderr := captureStderrForBackupLockTest(t, func() {
runErr = backupSyncCmd.RunE(backupSyncCmd, nil)
})
if runErr == nil {
t.Fatal("bd backup sync succeeded while another backup held the lock")
}
if !strings.Contains(stderr, "another backup is running") {
t.Fatalf("sync refusal does not say why; stderr:\n%s", stderr)
}
if fake.backupCalls != 0 {
t.Fatalf("refused sync still reached the store (%d backup calls)", fake.backupCalls)
}
}
func captureStderrForBackupLockTest(t *testing.T, fn func()) string {
t.Helper()
stdioMutex.Lock()
defer stdioMutex.Unlock()
r, w, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
old := os.Stderr
os.Stderr = w
fn()
os.Stderr = old
_ = w.Close()
buf := make([]byte, 1<<16)
n, _ := r.Read(buf)
_ = r.Close()
return string(buf[:n])
}

View file

@ -0,0 +1,107 @@
//go:build cgo
package main
import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
"github.com/steveyegge/beads/internal/storage/dbproxy/server"
)
// TestProxiedServerBackupRefusedOnExternalTopology is the other half of slice
// S3: the backup family is honored on managed-local and refused BY DESIGN
// against a Dolt server bd does not own.
//
// The refusal matters more than the capability. `CALL DOLT_BACKUP('add', …)`
// registers the remote on the server, where it is global to every client of
// that server, so one workspace's backup decision becomes everyone's. With a
// file:/// destination there is a second problem on top: the server resolves
// that path on its own filesystem, so honoring it here would either fail at the
// point of use or write the backup to a directory on the server's host that the
// operator asking for it will never look in. The second outcome is worse than
// any refusal.
//
// Named TestProxiedServer* so .github/scripts/proxied-test-shard.sh runs it in
// the external lane, which is the only one with an external Dolt server.
func TestProxiedServerBackupRefusedOnExternalTopology(t *testing.T) {
requireProxiedServerEnv(t)
bd := buildEmbeddedBD(t)
p := newSharedProxiedProject(t, bd, "bkext")
dest := filepath.Join(t.TempDir(), "dolt-backup")
// Refusals are decided before the provider is constructed, so take the
// topology down first: a pidfile appearing during one of these commands
// would mean the refusal came too late to have cost nothing.
if err := proxy.Shutdown(p.proxyRoot); err != nil {
t.Logf("proxy.Shutdown(%s) before the refusal probes: %v", p.proxyRoot, err)
}
for _, tc := range []struct {
name string
args []string
}{
{"status", []string{"backup", "status"}},
{"init", []string{"backup", "init", dest}},
{"sync", []string{"backup", "sync"}},
{"remove", []string{"backup", "remove"}},
{"restore", []string{"backup", "restore", dest}},
} {
t.Run(tc.name, func(t *testing.T) {
args := append([]string{"--json"}, tc.args...)
out, err := bdProxiedRun(t, bd, p.dir, args...)
if err == nil {
t.Fatalf("bd %s succeeded on an external proxied topology:\n%s",
strings.Join(tc.args, " "), out)
}
var refusal struct {
Code string `json:"code"`
Error string `json:"error"`
Mutates bool `json:"mutates"`
Reason string `json:"reason"`
}
start := strings.Index(string(out), "{")
if start < 0 {
t.Fatalf("no typed refusal JSON:\n%s", out)
}
if err := json.Unmarshal(out[start:], &refusal); err != nil {
t.Fatalf("parse refusal JSON: %v\n%s", err, out)
}
if refusal.Code != "proxy.backup.unsupported" {
t.Errorf("code = %q, want proxy.backup.unsupported", refusal.Code)
}
if refusal.Mutates {
t.Errorf("refusal reported mutates=true")
}
// design, not unimplemented: no later slice is going to lift this.
if refusal.Reason != string(ProxyReasonDesign) {
t.Errorf("reason = %q, want design", refusal.Reason)
}
// The reason has to be the one that is true of every destination
// scheme. "resolved on the server's filesystem" is a file://
// property, and `bd backup init` also takes https/aws/gs.
if !strings.Contains(refusal.Error, "the backup remote is registered on the server, where it is global to every client") {
t.Errorf("refusal message does not say why: %q", refusal.Error)
}
// Nothing was started and nothing was written: the refusal is free.
for _, name := range []string{proxy.PIDFileName, server.PIDFileName} {
if _, err := os.Stat(filepath.Join(p.proxyRoot, name)); err == nil {
t.Errorf("a refused backup command started the topology (%s)", name)
}
}
if _, err := os.Stat(filepath.Join(p.beadsDir, "dolt-backup.json")); err == nil {
t.Errorf("a refused backup command wrote the local backup config")
}
if _, err := os.Stat(dest); err == nil {
t.Errorf("a refused backup command created %s", dest)
}
})
}
}

View file

@ -0,0 +1,208 @@
//go:build cgo && unix
package main
import (
"context"
"encoding/json"
"os"
"path/filepath"
"slices"
"strings"
"testing"
"time"
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
"github.com/steveyegge/beads/internal/storage/dbproxy/server"
"github.com/steveyegge/beads/internal/storage/versioncontrolops"
)
// TestManagedLocalProxiedBackupRoundTrip is the claim slice S3 makes: a
// managed-local proxied workspace can take a Dolt-native backup and get its
// data back from it.
//
// It is deliberately a ROUND TRIP rather than a pair of exit-code assertions.
// A backup command that reports success without producing a restorable
// artifact is the failure that matters here, and the only way to rule it out is
// to restore the artifact and look at the issues that come back: the issue
// created BEFORE the backup must survive, and the one created AFTER it must be
// gone. Both directions are load-bearing — a restore that changed nothing would
// pass the first check alone.
//
// Named TestManagedLocalProxied* so the proxied-local smoke lane
// (.github/workflows/proxied-local-smoke.yml) runs it; that lane is the only
// one that sets BEADS_TEST_PROXIED_LOCAL.
func TestManagedLocalProxiedBackupRoundTrip(t *testing.T) {
requireManagedLocalProxiedEnv(t)
bd := buildEmbeddedBD(t)
p := bdManagedLocalInit(t, bd, "bkrt", 5*time.Minute)
before := bdProxiedCreate(t, bd, p.dir, "survives the restore", "-p", "1")
// Status first: it is the read-only probe that proves the route exists at
// all, and it must answer with a real measured size rather than the
// "optional field omitted" the external topologies produce.
status := readProxiedBackupStatus(t, bd, p)
if status.Dolt.Configured {
t.Fatalf("fresh workspace reports a configured backup: %+v", status.Dolt)
}
if status.DatabaseSize.Bytes <= 0 {
t.Fatalf("backup status measured no database: %+v", status.DatabaseSize)
}
dest := filepath.Join(t.TempDir(), "dolt-backup")
if out, err := bdProxiedRun(t, bd, p.dir, "backup", "init", dest); err != nil {
t.Fatalf("bd backup init %s: %v\n%s", dest, err, out)
}
if out, err := bdProxiedRun(t, bd, p.dir, "backup", "sync"); err != nil {
t.Fatalf("bd backup sync: %v\n%s", err, out)
}
// A Dolt backup is a chunk store with a manifest; an empty directory here
// would mean the command reported a success it did not perform.
if _, err := os.Stat(filepath.Join(dest, "manifest")); err != nil {
t.Fatalf("backup sync produced no manifest at %s: %v", dest, err)
}
after := bdProxiedCreate(t, bd, p.dir, "must not survive the restore", "-p", "1")
out, err := bdProxiedRun(t, bd, p.dir, "backup", "restore", dest, "--force", "--json")
if err != nil {
t.Fatalf("bd backup restore %s --force: %v\n%s", dest, err, out)
}
var result struct {
Restored bool `json:"restored"`
Source string `json:"source"`
}
if err := json.Unmarshal(out, &result); err != nil {
t.Fatalf("parse restore JSON: %v\n%s", err, out)
}
if !result.Restored || result.Source != dest {
t.Fatalf("unexpected restore result: %+v; want restored=true, source=%s", result, dest)
}
// The restore quiesces the topology and leaves it down, so the next command
// relaunches against the restored data. Assert that rather than assume it:
// a restore that ran with the old server still up would be the undefined
// case this design exists to avoid.
for _, name := range []string{proxy.PIDFileName, server.PIDFileName} {
if _, err := os.Stat(filepath.Join(p.proxyRoot, name)); err == nil {
t.Fatalf("restore left %s in place; the topology should be quiescent afterwards", name)
}
}
issues := bdProxiedListJSON(t, bd, p)
var ids []string
for _, issue := range issues {
ids = append(ids, issue.ID)
}
if !slices.Contains(ids, before.ID) {
t.Fatalf("restore lost the issue the backup contained (%s); got %v", before.ID, ids)
}
if slices.Contains(ids, after.ID) {
t.Fatalf("restore did not replace the database: %s was created after the backup and is still here; got %v",
after.ID, ids)
}
// The restore registers its source as the backup destination, so a plain
// `bd backup sync` works straight afterwards with no second init.
restored := readProxiedBackupStatus(t, bd, p)
if !restored.Dolt.Configured || !strings.HasSuffix(restored.Dolt.BackupURL, dest) {
t.Fatalf("restore did not register %s as the backup destination: %+v", dest, restored.Dolt)
}
if out, err := bdProxiedRun(t, bd, p.dir, "backup", "sync"); err != nil {
t.Fatalf("bd backup sync after restore: %v\n%s", err, out)
}
if out, err := bdProxiedRun(t, bd, p.dir, "backup", "remove"); err != nil {
t.Fatalf("bd backup remove: %v\n%s", err, out)
}
removed := readProxiedBackupStatus(t, bd, p)
if removed.Dolt.Configured {
t.Fatalf("backup remove left the destination configured: %+v", removed.Dolt)
}
// Removing the destination unregisters the remote; it does not delete the
// backup, which is what makes `bd backup remove` safe to run.
if _, err := os.Stat(filepath.Join(dest, "manifest")); err != nil {
t.Fatalf("backup remove deleted the backup data at %s: %v", dest, err)
}
if out, err := bdProxiedRun(t, bd, p.dir, "backup", "sync"); err == nil {
t.Fatalf("bd backup sync succeeded with no destination configured:\n%s", out)
}
}
// A backup with a malformed migration table can replace the database but fail
// the following provider construction at schema initialization. That failure must
// still leave both processes down, even though no provider was returned.
func TestManagedLocalProxiedBackupRestoreReopenFailure(t *testing.T) {
requireManagedLocalProxiedEnv(t)
bd := buildEmbeddedBD(t)
p := bdManagedLocalInit(t, bd, "bkrf", 5*time.Minute)
dest := filepath.Join(t.TempDir(), "malformed-backup")
if out, err := bdProxiedRun(t, bd, p.dir, "backup", "init", dest); err != nil {
t.Fatalf("backup init: %v\n%s", err, out)
}
// Damage the migration table in the backup, then repair the live table so
// the command's initial provider can open normally. Only its post-restore
// constructor will see the malformed table and fail after starting Dolt.
held := openHeldManagedProxiedConn(t, bd, p)
ctx := context.Background()
if _, err := held.Conn.ExecContext(ctx, "ALTER TABLE schema_migrations RENAME COLUMN version TO broken_version"); err != nil {
t.Fatalf("damage migration table: %v", err)
}
if _, err := held.Conn.ExecContext(ctx, "CALL DOLT_COMMIT('-Am', 'Simulate a malformed migration table in the backup')"); err != nil {
t.Fatalf("commit malformed migration table: %v", err)
}
if err := versioncontrolops.BackupSync(ctx, held.Conn, proxiedBackupTargetName); err != nil {
t.Fatalf("back up malformed schema: %v", err)
}
if _, err := held.Conn.ExecContext(ctx, "ALTER TABLE schema_migrations RENAME COLUMN broken_version TO version"); err != nil {
t.Fatalf("repair live migration table: %v", err)
}
held.Release()
out, err := bdProxiedRun(t, bd, p.dir, "backup", "restore", dest, "--force")
if err == nil {
t.Fatalf("restore unexpectedly reopened a malformed schema:\n%s", out)
}
if !strings.Contains(string(out), "the restored database did not reopen") || !strings.Contains(string(out), "schema") {
t.Fatalf("expected post-restore schema initialization failure, got:\n%s", out)
}
if strings.Contains(string(out), "restored and reconciled") {
t.Fatalf("failed reopen reported successful reconciliation:\n%s", out)
}
for _, name := range []string{proxy.PIDFileName, server.PIDFileName} {
if _, err := os.Stat(filepath.Join(p.proxyRoot, name)); !os.IsNotExist(err) {
t.Errorf("failed reopen should remove %s; stat error: %v", name, err)
}
}
}
type proxiedBackupStatus struct {
Dolt struct {
Configured bool `json:"configured"`
BackupURL string `json:"backup_url"`
BackupName string `json:"backup_name"`
} `json:"dolt"`
DatabaseSize struct {
Bytes int64 `json:"bytes"`
} `json:"database_size"`
}
func readProxiedBackupStatus(t *testing.T, bd string, p proxiedProject) proxiedBackupStatus {
t.Helper()
out, err := bdProxiedRun(t, bd, p.dir, "backup", "status", "--json")
if err != nil {
t.Fatalf("bd backup status --json: %v\n%s", err, out)
}
start := strings.Index(string(out), "{")
if start < 0 {
t.Fatalf("bd backup status --json produced no JSON:\n%s", out)
}
var status proxiedBackupStatus
if err := json.Unmarshal(out[start:], &status); err != nil {
t.Fatalf("parse backup status JSON: %v\n%s", err, out)
}
return status
}

View file

@ -0,0 +1,285 @@
package main
import (
"encoding/json"
"errors"
"os"
"path/filepath"
"strings"
"testing"
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/configfile"
)
// TestProxiedRestoreFailureMessage pins the one distinction the operator acts
// on: whether the data came back. A teardown failure happens after the step
// succeeded, so reporting it as "restore failed" is not a wording nit — it
// tells someone whose database IS restored to restore it again.
func TestProxiedRestoreFailureMessage(t *testing.T) {
boom := errors.New("proxy shutdown: connection refused")
for _, tc := range []struct {
name string
afterReconcile bool
err error
wantContains []string
wantMissing []string
}{
{
name: "restore itself failed",
err: errors.New("DOLT_BACKUP: no such backup"),
// No claim that anything was restored.
wantContains: []string{"restore failed", "no such backup"},
wantMissing: []string{"the data is restored"},
},
{
name: "restore succeeded, teardown failed",
err: &proxiedTeardownError{err: boom},
wantContains: []string{"the data is restored", "bd dolt stop --force", "bd backup init"},
wantMissing: []string{"restore failed"},
},
{
name: "reconcile failed for real",
afterReconcile: true,
err: errors.New("open provider: schema is behind"),
wantContains: []string{"the restored database did not reopen", "schema is behind"},
wantMissing: []string{"restore failed"},
},
{
name: "reconcile succeeded, teardown failed",
afterReconcile: true,
err: &proxiedTeardownError{err: boom},
wantContains: []string{"the data is restored and reconciled", "bd dolt stop --force"},
// Nothing left to re-register: the reconcile already ran.
wantMissing: []string{"restore failed", "bd backup init"},
},
} {
t.Run(tc.name, func(t *testing.T) {
got := proxiedRestoreFailureMessage("/tmp/backup", tc.afterReconcile, tc.err)
for _, want := range tc.wantContains {
if !strings.Contains(got, want) {
t.Errorf("message %q does not contain %q", got, want)
}
}
for _, unwanted := range tc.wantMissing {
if strings.Contains(got, unwanted) {
t.Errorf("message %q must not contain %q", got, unwanted)
}
}
})
}
}
// backupFamilyPaths is every registry path the backup family owns. Keeping the
// list in one place is what makes "the whole family moves together" an
// assertion rather than a convention.
var backupFamilyPaths = []string{
"backup", "backup init", "backup sync", "backup remove", "backup status", "backup restore",
}
// TestProxiedBackupHonoredOnlyOnManagedLocal is the locality policy.
//
// A Dolt backup destination is resolved by the SERVER: CALL DOLT_BACKUP('add',
// name, 'file:///…') names a path on the machine running dolt, not on the
// machine running bd. On managed-local that is the same machine and the same
// user, because bd spawned the child itself. On every other proxied shape it is
// somebody else's filesystem, so honoring the command would either fail at the
// point of use or — much worse — succeed and write the backup somewhere the
// operator cannot see. That is why these stay refused with Reason=design.
func TestProxiedBackupHonoredOnlyOnManagedLocal(t *testing.T) {
for _, path := range backupFamilyPaths {
row, ok := LookupCapabilityRow(path, "")
if !ok {
t.Fatalf("%q has no registry row", path)
}
if got := row.ruleFor(ProxyTopologyManagedLocal); got.Outcome != ProxyOutcomeHonored {
t.Errorf("%q on managed-local: outcome %q, want honored", path, got.Outcome)
}
for _, topology := range []ProxyTopology{
ProxyTopologyExternalTCP, ProxyTopologyExternalUnix,
ProxyTopologyTeamServer, ProxyTopologyUnknown,
} {
got := row.ruleFor(topology)
if got.Outcome != ProxyOutcomeRefused {
t.Errorf("%q on %s: outcome %q, want refused", path, topology, got.Outcome)
}
if got.Reason != ProxyReasonDesign {
t.Errorf("%q on %s: reason %q, want design", path, topology, got.Reason)
}
if got.Code != "proxy.backup.unsupported" {
t.Errorf("%q on %s: code %q, want the frozen proxy.backup.unsupported", path, topology, got.Code)
}
if !strings.Contains(got.Message, "is not supported in proxied-server mode") {
t.Errorf("%q on %s: message %q dropped the frozen prefix", path, topology, got.Message)
}
}
}
}
// TestProxiedBackupGateRefusesByTopology exercises the gate itself rather than
// the table, so a row that is right while the validator ignores the topology
// still fails.
func TestProxiedBackupGateRefusesByTopology(t *testing.T) {
newBackupCmd := func(sub string) *cobra.Command {
root := &cobra.Command{Use: "bd"}
parent := &cobra.Command{Use: "backup"}
child := &cobra.Command{Use: sub}
parent.AddCommand(child)
root.AddCommand(parent)
return child
}
for _, sub := range []string{"init", "sync", "remove", "status", "restore"} {
t.Run(sub, func(t *testing.T) {
if err := validateProxyRegistryBeforeProvider(newBackupCmd(sub), ProxyTopologyManagedLocal); err != nil {
t.Fatalf("managed-local: gate refused %q: %v", sub, err)
}
err := validateProxyRegistryBeforeProvider(newBackupCmd(sub), ProxyTopologyExternalTCP)
if err == nil {
t.Fatalf("external-tcp: gate permitted %q", sub)
}
})
}
}
// TestProxiedBackupRefusalJSONCarriesDesignReason pins what a consumer sees.
// The three frozen fields are unchanged and reason now says "design", which is
// the difference that matters: this refusal is not waiting on a later slice.
func TestProxiedBackupRefusalJSONCarriesDesignReason(t *testing.T) {
t.Setenv("BD_JSON_ENVELOPE", "")
oldJSON := jsonOutput
jsonOutput = true
t.Cleanup(func() { jsonOutput = oldJSON })
root := &cobra.Command{Use: "bd"}
parent := &cobra.Command{Use: "backup"}
child := &cobra.Command{Use: "sync"}
parent.AddCommand(child)
root.AddCommand(parent)
out := captureStdout(t, func() error {
_ = validateProxyRegistryBeforeProvider(child, ProxyTopologyExternalTCP)
return nil
})
for _, want := range []string{
`"code": "proxy.backup.unsupported"`,
`"mutates": false`,
`"reason": "design"`,
} {
if !strings.Contains(out, want) {
t.Fatalf("refusal JSON missing %s:\n%s", want, out)
}
}
}
// TestResolveProxiedTopology covers the resolution the gate depends on. The
// team-server case is the one worth reading twice: ownership beats transport,
// because a bts-managed database is somebody else's store whether bd reaches it
// over a socket, a port, or a child it spawned itself.
func TestResolveProxiedTopology(t *testing.T) {
for _, tc := range []struct {
name string
cfg configfile.Config
sidecar *configfile.ProxiedServerClientInfo
rawCfg string // when set, written verbatim instead of cfg
rawCar string // when set, written verbatim instead of sidecar
want ProxyTopology
}{
{
name: "managed local has no external block",
cfg: configfile.Config{DoltMode: configfile.DoltModeProxiedServer},
sidecar: &configfile.ProxiedServerClientInfo{},
want: ProxyTopologyManagedLocal,
},
{
name: "no sidecar at all is still managed local",
cfg: configfile.Config{DoltMode: configfile.DoltModeProxiedServer},
sidecar: nil,
want: ProxyTopologyManagedLocal,
},
{
name: "external host and port",
cfg: configfile.Config{DoltMode: configfile.DoltModeProxiedServer},
sidecar: &configfile.ProxiedServerClientInfo{
External: &configfile.ExternalDoltConfig{Host: "db.example.com", Port: 3306},
},
want: ProxyTopologyExternalTCP,
},
{
name: "external unix socket",
cfg: configfile.Config{DoltMode: configfile.DoltModeProxiedServer},
sidecar: &configfile.ProxiedServerClientInfo{
External: &configfile.ExternalDoltConfig{Socket: "/var/run/dolt.sock"},
},
want: ProxyTopologyExternalUnix,
},
{
name: "team server beats the transport",
cfg: configfile.Config{DoltMode: configfile.DoltModeProxiedServer, DoltTeamServer: true},
sidecar: &configfile.ProxiedServerClientInfo{
External: &configfile.ExternalDoltConfig{Host: "bts.example.com", Port: 3306},
},
want: ProxyTopologyTeamServer,
},
{
name: "team server on a local child is still team server",
cfg: configfile.Config{DoltMode: configfile.DoltModeProxiedServer, DoltTeamServer: true},
sidecar: &configfile.ProxiedServerClientInfo{},
want: ProxyTopologyTeamServer,
},
{
name: "unreadable sidecar fails closed",
cfg: configfile.Config{DoltMode: configfile.DoltModeProxiedServer},
rawCar: "{ not json",
want: ProxyTopologyUnknown,
},
{
name: "unreadable workspace config fails closed",
rawCfg: "{ not json",
want: ProxyTopologyUnknown,
},
} {
t.Run(tc.name, func(t *testing.T) {
beadsDir := filepath.Join(t.TempDir(), ".beads")
if err := os.MkdirAll(beadsDir, 0o750); err != nil {
t.Fatal(err)
}
switch {
case tc.rawCfg != "":
writeTestFile(t, configfile.ConfigPath(beadsDir), tc.rawCfg)
default:
cfg := tc.cfg
cfg.Backend = configfile.BackendDolt
data, err := json.Marshal(cfg)
if err != nil {
t.Fatal(err)
}
writeTestFile(t, configfile.ConfigPath(beadsDir), string(data))
}
switch {
case tc.rawCar != "":
writeTestFile(t, configfile.ProxiedServerClientInfoPath(beadsDir), tc.rawCar)
case tc.sidecar != nil:
data, err := json.Marshal(tc.sidecar)
if err != nil {
t.Fatal(err)
}
writeTestFile(t, configfile.ProxiedServerClientInfoPath(beadsDir), string(data))
}
if got := resolveProxiedTopology(beadsDir); got != tc.want {
t.Fatalf("resolveProxiedTopology = %q, want %q", got, tc.want)
}
})
}
}
func writeTestFile(t *testing.T, path, body string) {
t.Helper()
if err := os.WriteFile(path, []byte(body), 0o600); err != nil {
t.Fatal(err)
}
}

View file

@ -0,0 +1,542 @@
package main
import (
"context"
"database/sql"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"time"
"github.com/steveyegge/beads/internal/beads"
"github.com/steveyegge/beads/internal/configfile"
"github.com/steveyegge/beads/internal/debug"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
"github.com/steveyegge/beads/internal/storage/issueops"
"github.com/steveyegge/beads/internal/storage/uow"
"github.com/steveyegge/beads/internal/storage/versioncontrolops"
)
// Dolt-native backup over the proxied-server provider.
//
// The mechanism needed no proxy work at all: CALL DOLT_BACKUP(...) is ordinary
// SQL, RunNonTx already hands out a raw pinned connection (the seam `compact
// --dolt` and `gc` run on), the UOW DSN sets a connect timeout but no read
// deadline, and an active connection keeps the idle reaper from arming — so a
// backup that takes minutes is safe from both the driver and the 30s reaper.
//
// What the family DID need is the locality policy, which lives in the registry
// (see capability_registry.go's backup rows) because it is what the front door
// enforces. The guard below repeats it at the route because these functions are
// reachable from RunE, and a route that trusts the gate is one refactor away
// from writing a backup onto a host it does not own.
//
// None of these routes touch commandDidWrite or commandDidExplicitDoltCommit.
// Those two drive the post-run Dolt auto-commit, which is an embedded/direct
// concern — PersistentPostRunE's proxied branch never reads them — and the
// other proxied routes leave them alone for the same reason.
// proxiedBackupTargetName is the Dolt backup remote bd registers. Same name the
// direct path uses, so a workspace that changes topology still finds its
// destination.
const proxiedBackupTargetName = defaultDoltBackupName
// requireLocalProxiedBackup re-checks the locality policy at the route.
// Defense in depth, not a second policy: the rule and its wording come from the
// same registry row the pre-provider gate consults, so the two cannot drift.
func requireLocalProxiedBackup(path string) error {
rule, ok := proxiedBackupRule(path)
if !ok {
// Unreachable: TestProxyCapabilityRegistryCoversCommandTree fails the
// build for a backup path with no row. Refuse rather than guess.
return HandleErrorRespectJSON("%s has no proxied-server capability row", path)
}
if rule.Outcome == ProxyOutcomeHonored {
return nil
}
return HandleProxyCapabilityError(proxyCapabilityErrorFor(rule))
}
// proxiedBackupRule resolves the registry rule for a backup path on this
// workspace's proxied topology. ok is false only for a path with no row.
func proxiedBackupRule(path string) (proxyCapabilityRule, bool) {
row, ok := LookupCapabilityRow(path, "")
if !ok {
return proxyCapabilityRule{}, false
}
return row.ruleFor(resolveProxiedTopology(beads.FindBeadsDir())), true
}
// proxiedAutoBackupBackend returns the backend post-command auto-backup runs
// against on a proxied-server workspace, or ok=false when it must not run.
//
// Auto-backup is a `bd backup sync` nobody typed, so it is honored exactly
// where that verb is — the "backup sync" registry row, i.e. managed-local
// only. Anywhere else the backup remote it registers would land on a server bd
// does not own, where it is global to every client; that is the storm the
// explicit verbs refuse by design, and an implicit trigger must not reopen it.
//
// It never opens a provider of its own. A command that did not open one (or
// closed it, as restore does) has no live topology to back up, and opening one
// here would relaunch a server the command may just have stopped.
func proxiedAutoBackupBackend() (localBackupBackend, bool) {
if rule, ok := proxiedBackupRule("backup sync"); !ok || rule.Outcome != ProxyOutcomeHonored {
debug.Logf("backup: skipping auto-backup — proxied topology does not honor backup sync\n")
return nil, false
}
if uowProvider == nil {
return nil, false
}
mp, ok := uowProvider.(uow.MaintenanceProvider)
if !ok {
debug.Logf("backup: skipping auto-backup — provider %T has no maintenance seam\n", uowProvider)
return nil, false
}
return proxiedLocalBackup{provider: mp}, true
}
// proxiedLocalBackup is localBackupBackend over the proxied provider's
// non-transactional seam, the one `bd backup sync` uses.
//
// No pre-backup commit: change detection compares HEAD, and every proxied
// write transaction already ends in DOLT_COMMIT('-Am') (uow doltServerTx), so
// HEAD is where the data is — the invariant direct mode gets from running
// auto-commit just before auto-backup.
type proxiedLocalBackup struct {
provider uow.MaintenanceProvider
}
func (b proxiedLocalBackup) CurrentCommit(ctx context.Context) (string, error) {
var hash string
err := b.provider.RunNonTx(ctx, func(ctx context.Context, conn *sql.Conn) error {
var err error
hash, err = versioncontrolops.CurrentCommit(ctx, conn)
return err
})
return hash, err
}
func (b proxiedLocalBackup) BackupToDir(ctx context.Context, dir string) error {
return b.provider.RunNonTx(ctx, func(ctx context.Context, conn *sql.Conn) error {
return versioncontrolops.BackupToDir(ctx, conn, conn, dir)
})
}
// proxiedActiveDatabase asks the server which database the provider opened,
// rather than re-deriving it from the workspace config. The provider already
// resolved that question (metadata.json, then --database/--db), and a second
// ladder here would be a second answer waiting to disagree with it.
func proxiedActiveDatabase(ctx context.Context) (string, error) {
var database string
err := runProxiedNonTx(ctx, func(ctx context.Context, conn *sql.Conn) error {
var name sql.NullString
if err := conn.QueryRowContext(ctx, "SELECT DATABASE()").Scan(&name); err != nil {
return fmt.Errorf("resolve active database: %w", err)
}
if !name.Valid || name.String == "" {
return fmt.Errorf("the proxied connection has no database selected")
}
database = name.String
return nil
})
return database, err
}
// runBackupInitProxied registers the backup destination, mirroring the direct
// path's conflict handling: Dolt refuses a second remote at an address another
// one already holds, and a re-init to a new path has to replace the old entry
// rather than fail.
func runBackupInitProxied(ctx context.Context, rawPath string) error {
if err := requireLocalProxiedBackup("backup init"); err != nil {
return err
}
backupURL := resolveDoltBackupURL(rawPath)
err := runProxiedNonTx(ctx, func(ctx context.Context, conn *sql.Conn) error {
addErr := versioncontrolops.BackupAdd(ctx, conn, proxiedBackupTargetName, backupURL)
if addErr == nil {
return nil
}
switch {
case strings.Contains(addErr.Error(), "already exists"):
// Same name, different URL: replace it.
_ = versioncontrolops.BackupRemove(ctx, conn, proxiedBackupTargetName)
case versioncontrolops.ExtractAddressConflictName(addErr) != "":
// A different name (auto-export registers "backup_export") already
// points at this URL; take the address over.
_ = versioncontrolops.BackupRemove(ctx, conn, versioncontrolops.ExtractAddressConflictName(addErr))
default:
return addErr
}
return versioncontrolops.BackupAdd(ctx, conn, proxiedBackupTargetName, backupURL)
})
if err != nil {
return HandleErrorRespectJSON("failed to add backup destination: %v", err)
}
if err := saveDoltBackupConfig(backupURL); err != nil {
fmt.Fprintf(os.Stderr, "Warning: backup registered but failed to save config: %v\n", err)
}
if jsonOutput {
return outputJSON(map[string]interface{}{
"backup_url": backupURL,
"backup_name": proxiedBackupTargetName,
"initialized": true,
})
}
fmt.Printf("Backup destination configured: %s\n", backupURL)
fmt.Println("Run 'bd backup sync' to push your data.")
return nil
}
// runBackupSyncProxied pushes the database to the configured destination.
func runBackupSyncProxied(ctx context.Context) error {
if err := requireLocalProxiedBackup("backup sync"); err != nil {
return err
}
start := time.Now()
err := runProxiedNonTx(ctx, func(ctx context.Context, conn *sql.Conn) error {
if err := commitWorkingSetBeforeBackup(ctx, conn); err != nil {
// Same posture as the direct path: a failed pre-backup commit
// means the backup may miss the newest writes, which is worth
// saying out loud and is not worth refusing to back up over.
fmt.Fprintf(os.Stderr, "Warning: failed to commit pending changes: %v\n", err)
}
return versioncontrolops.BackupSync(ctx, conn, proxiedBackupTargetName)
})
if err != nil {
if strings.Contains(err.Error(), "no backup") || strings.Contains(err.Error(), "not found") {
return HandleErrorRespectJSON("no backup destination configured. Run 'bd backup init <path>' first")
}
return HandleErrorRespectJSON("backup sync failed: %v", err)
}
elapsed := time.Since(start)
if err := updateDoltBackupState(elapsed); err != nil {
fmt.Fprintf(os.Stderr, "Warning: backup synced but failed to update state: %v\n", err)
}
if jsonOutput {
return outputJSON(map[string]interface{}{
"synced": true,
"duration": elapsed.String(),
})
}
fmt.Printf("Backup synced in %s\n", elapsed.Round(time.Millisecond))
return nil
}
// commitWorkingSetBeforeBackup is the proxied twin of the direct path's
// "bd: pre-backup commit". DOLT_BACKUP syncs COMMITTED history, so anything
// still in the working set would silently be missing from the backup.
//
// It is normally a no-op: every proxied write transaction ends in
// DOLT_COMMIT('-Am') (uow doltServerTx.Commit), so the working set is already
// clean. The pending check is what keeps this from minting an empty commit on
// every sync — Dolt rejects those server-side and logs each one.
func commitWorkingSetBeforeBackup(ctx context.Context, conn *sql.Conn) error {
pending, err := issueops.HasPendingChanges(ctx, conn)
if err != nil {
return fmt.Errorf("check pending changes: %w", err)
}
if !pending {
return nil
}
if _, err := conn.ExecContext(ctx, "CALL DOLT_COMMIT('-Am', ?)", "bd: pre-backup commit"); err != nil {
if issueops.IsNothingToCommitError(err) {
return nil
}
return err
}
return nil
}
// runBackupRemoveProxied unregisters the destination and drops the local
// sidecars. The backup data itself is left alone, as in direct mode.
func runBackupRemoveProxied(ctx context.Context) error {
if err := requireLocalProxiedBackup("backup remove"); err != nil {
return err
}
err := runProxiedNonTx(ctx, func(ctx context.Context, conn *sql.Conn) error {
if err := versioncontrolops.BackupRemove(ctx, conn, proxiedBackupTargetName); err != nil {
return err
}
// auto-export may have registered a second remote at the same URL.
_ = versioncontrolops.BackupRemove(ctx, conn, versioncontrolops.ExportBackupName)
return nil
})
if err != nil {
if strings.Contains(err.Error(), "not found") || strings.Contains(err.Error(), "no backup") {
return HandleErrorRespectJSON("no backup destination configured")
}
return HandleErrorRespectJSON("failed to remove backup: %v", err)
}
if path, err := doltBackupConfigPath(); err == nil {
_ = os.Remove(path)
}
if path, err := doltBackupStatePath(); err == nil {
_ = os.Remove(path)
}
if jsonOutput {
return outputJSON(map[string]interface{}{"removed": true})
}
fmt.Println("Backup destination removed.")
return nil
}
// doltBackupSizeProxied measures the managed-local database on disk, which is
// what `bd backup status` reports on every other topology that can answer.
//
// It reads the directory rather than asking Dolt because that is what the
// direct stores do (DoltStore.ActiveDatabaseSize measures
// localActiveDatabaseDir), so the number means the same thing in both modes.
// The database NAME still comes from the server, so the directory measured is
// the one this connection is actually using.
func doltBackupSizeProxied(ctx context.Context) (int64, bool, error) {
beadsDir := beads.FindBeadsDir()
if beadsDir == "" {
return 0, false, nil
}
root, err := resolveProxiedServerRootPath(beadsDir)
if err != nil {
return 0, false, nil
}
database, err := proxiedActiveDatabase(ctx)
if err != nil {
return 0, false, err
}
dir := filepath.Join(root, database)
if _, err := os.Stat(dir); err != nil {
// No local directory means nothing bd can measure; the status contract
// treats size as optional rather than failing the command.
return 0, false, nil
}
size, err := storage.MeasureDirectorySize(ctx, dir)
if err != nil {
return 0, false, fmt.Errorf("measure active database directory %q: %w", dir, err)
}
return size, true, nil
}
// runBackupRestoreProxied restores the database from a Dolt backup, quiescing
// the topology first.
//
// DOLT_BACKUP('restore') REPLACES the database under the server. Doing that
// while clients hold connections to it is undefined, so the restore runs with
// bd as the only client and nothing else pointed at the store:
//
// 1. `bd backup restore` already holds the workspace and physical-root gates
// EXCLUSIVELY (commandNeedsExclusiveGate), so no other gated bd command —
// including `bd serve` — is using this workspace.
// 2. This function closes the provider the root pre-run opened and shuts the
// proxy and its dolt child down, so no connection survives into the
// replace.
// 3. It reopens a provider of its own, which relaunches the topology with
// exactly one client, and runs the restore on that.
// 4. It shuts the topology down again and reopens once more to finish: the
// reopen proves the restored database is serviceable, and it is where the
// project identity and the backup remote are reconciled. A connection
// pinned across the replace would be reading a database that no longer
// exists underneath it.
//
// The final shutdown leaves the workspace quiescent, so the next bd command
// relaunches lazily against the restored data.
func runBackupRestoreProxied(ctx context.Context, dir string, force bool) error {
if err := requireLocalProxiedBackup("backup restore"); err != nil {
return err
}
beadsDir := beads.FindBeadsDir()
if beadsDir == "" {
return HandleErrorRespectJSON("%s", activeWorkspaceNotFoundError())
}
root, err := resolveProxiedServerRootPath(beadsDir)
if err != nil {
return HandleErrorRespectJSON("%v", err)
}
backupURL, err := versioncontrolops.DirToFileURL(dir)
if err != nil {
return HandleErrorRespectJSON("%v", err)
}
// Ask the live provider which database to replace before taking it away.
database, err := proxiedActiveDatabase(ctx)
if err != nil {
return HandleErrorRespectJSON("%v", err)
}
if err := quiesceProxiedTopology(ctx, root); err != nil {
return HandleErrorRespectJSON("%v", err)
}
if err := withQuiescedProxiedProvider(ctx, beadsDir, database, root, func(ctx context.Context, conn *sql.Conn) error {
return versioncontrolops.BackupRestore(ctx, conn, backupURL, database, force)
}); err != nil {
return HandleErrorRespectJSON("%s", proxiedRestoreFailureMessage(dir, false, err))
}
if err := withQuiescedProxiedProvider(ctx, beadsDir, database, root, func(ctx context.Context, conn *sql.Conn) error {
return reconcileRestoredProxiedWorkspace(ctx, conn, beadsDir, dir, force)
}); err != nil {
return HandleErrorRespectJSON("%s", proxiedRestoreFailureMessage(dir, true, err))
}
return nil
}
// proxiedRestoreFailureMessage renders what the operator is told when one of
// the two quiesced steps fails.
//
// The distinction it makes is the only one that matters here: DID THE DATA COME
// BACK. A teardown failure happens after the step succeeded, so saying "restore
// failed" would be false, and the obvious response to it — run the restore
// again — is the wrong one. Split out from the call sites so that judgement is
// something a test can hold still (TestProxiedRestoreFailureMessage).
//
// afterReconcile distinguishes the two steps, because a teardown failure costs
// the operator different follow-up work either side of the reconcile: before
// it, the backup destination has not been re-registered yet.
func proxiedRestoreFailureMessage(dir string, afterReconcile bool, err error) string {
var teardown *proxiedTeardownError
if errors.As(err, &teardown) {
if afterReconcile {
return fmt.Sprintf("restored from %s, but shutting the proxied server down afterwards failed: %v; "+
"the data is restored and reconciled — run 'bd dolt stop --force' before the next command", dir, teardown)
}
return fmt.Sprintf("restored from %s, but shutting the proxied server down afterwards failed: %v; "+
"the data is restored — run 'bd dolt stop --force', then 'bd backup init %s' to re-register the "+
"backup destination, which this run did not reach", dir, teardown, dir)
}
if afterReconcile {
return fmt.Sprintf("restored from %s, but the restored database did not reopen: %v", dir, err)
}
return fmt.Sprintf("restore failed: %v", err)
}
// quiesceProxiedTopology drops this process's provider and stops the proxy and
// its dolt child, so nothing holds the database that is about to be replaced.
func quiesceProxiedTopology(ctx context.Context, root string) error {
if uowProvider != nil {
if err := uowProvider.Close(ctx); err != nil {
return fmt.Errorf("close the proxied provider before restoring: %w", err)
}
uowProvider = nil
}
if err := proxy.Shutdown(root); err != nil {
return fmt.Errorf("stop the proxied server before restoring: %w; "+
"run 'bd dolt stop --force' and retry", err)
}
return nil
}
// proxiedTeardownError marks a failure that happened AFTER the operation
// succeeded, while putting the topology back down. It exists so the caller can
// tell the two apart in what it prints. Flattening them is what made a restore
// that completed and then failed to shut the proxy down report "restore
// failed": the operator is told their data did not come back when it did, and
// the obvious response — run the restore again — is the wrong one.
type proxiedTeardownError struct{ err error }
func (e *proxiedTeardownError) Error() string { return e.err.Error() }
func (e *proxiedTeardownError) Unwrap() error { return e.err }
// withQuiescedProxiedProvider relaunches the topology for one operation and
// puts it back down afterwards, so each step either side of the replace runs on
// a connection that was opened after it.
//
// The provider ADOPTS whatever identity the database carries: a restore is
// precisely the operation after which the workspace's recorded project id and
// the database's may legitimately differ, and asserting the old one would
// refuse the connection that is supposed to reconcile them. That makes this the
// third caller of newProxiedServerUOWProviderAdopting; its doc comment is the
// register of identity-assertion bypasses and names this one.
//
// A teardown failure is returned wrapped in *proxiedTeardownError, and only
// when the operation itself succeeded. If opening or running the operation
// failed, preserve that error and append any cleanup failure without the
// success marker. Shutdown is attempted even if construction fails after
// starting the topology but before returning a provider.
func withQuiescedProxiedProvider(ctx context.Context, beadsDir, database, root string, fn func(context.Context, *sql.Conn) error) (err error) {
var provider uow.UnitOfWorkProvider
defer func() {
var closeErr error
if provider != nil {
closeErr = provider.Close(ctx)
}
stopErr := proxy.Shutdown(root)
if teardownErr := errors.Join(closeErr, stopErr); teardownErr != nil {
if err != nil {
err = errors.Join(err, fmt.Errorf("shut down the proxied server after failure: %w", teardownErr))
} else {
err = &proxiedTeardownError{err: teardownErr}
}
}
}()
provider, err = newProxiedServerUOWProviderAdopting(ctx, beadsDir, database)
if err != nil {
return err
}
maintenance, ok := provider.(uow.MaintenanceProvider)
if !ok {
return fmt.Errorf("the proxied provider does not support maintenance operations")
}
return maintenance.RunNonTx(ctx, fn)
}
// reconcileRestoredProxiedWorkspace is the post-restore bookkeeping, mirroring
// the direct path: adopt the restored database's project identity when the
// restore overwrote one, and register the restore source as the backup
// destination so `bd backup sync` works without a separate init.
//
// Both are best-effort with a warning, as in direct mode. The restore itself
// has already succeeded by this point, and failing the command over bookkeeping
// would tell the operator their data did not come back when it did.
func reconcileRestoredProxiedWorkspace(ctx context.Context, conn *sql.Conn, beadsDir, dir string, force bool) error {
if force {
if err := syncProjectIDFromProxiedDB(ctx, conn, beadsDir); err != nil {
fmt.Fprintf(os.Stderr, "Warning: failed to sync project ID after restore: %v\n", err)
}
}
backupURL := resolveDoltBackupURL(dir)
_ = versioncontrolops.BackupRemove(ctx, conn, proxiedBackupTargetName)
if err := versioncontrolops.BackupAdd(ctx, conn, proxiedBackupTargetName, backupURL); err != nil {
fmt.Fprintf(os.Stderr, "Warning: failed to register backup remote: %v\n", err)
return nil
}
if err := saveDoltBackupConfig(backupURL); err != nil {
fmt.Fprintf(os.Stderr, "Warning: backup registered but failed to save config: %v\n", err)
}
return nil
}
// syncProjectIDFromProxiedDB copies the restored database's _project_id into
// metadata.json, so the identity check does not reject later connections. The
// direct path reads it through the store; there is no store in proxied mode, so
// it goes through the same issueops accessor the store itself uses rather than
// a second copy of the query.
func syncProjectIDFromProxiedDB(ctx context.Context, conn *sql.Conn, beadsDir string) error {
dbID, err := issueops.GetMetadataInTx(ctx, conn, "_project_id")
if err != nil || dbID == "" {
return err
}
cfg, err := configfile.Load(beadsDir)
if err != nil {
return err
}
if cfg == nil || cfg.ProjectID == dbID {
return nil
}
cfg.ProjectID = dbID
return cfg.Save(beadsDir)
}

View file

@ -30,11 +30,10 @@ Use --force to overwrite an existing database with the backup contents.
The database must already be initialized (run 'bd init' first if needed).
To initialize and restore in one step, use: bd init && bd backup restore`,
Args: cobra.MaximumNArgs(1),
Args: cobra.MaximumNArgs(1),
SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
if usesProxiedServer() {
return HandleErrorRespectJSON("backup restore is not supported in proxied-server mode")
}
evt := metrics.NewCommandEvent("backup-restore")
defer func() {
if c := metrics.Global(); c != nil {
@ -61,14 +60,24 @@ To initialize and restore in one step, use: bd init && bd backup restore`,
force, _ := cmd.Flags().GetBool("force")
if err := runBackupRestore(ctx, store, dir, force); err != nil {
if usesProxiedServer() {
if err := runBackupRestoreProxied(ctx, dir, force); err != nil {
return err
}
} else if err := runBackupRestore(ctx, store, dir, force); err != nil {
return err
}
if !jsonOutput {
fmt.Printf("%s Restore complete\n", ui.RenderPass("✓"))
// One success report for both topologies. Under --json this used to
// print nothing at all, which left a caller unable to tell a completed
// restore from a silently skipped one.
if jsonOutput {
return outputJSON(map[string]interface{}{
"restored": true,
"source": dir,
})
}
fmt.Printf("%s Restore complete\n", ui.RenderPass("✓"))
return nil
},
}

View file

@ -10,6 +10,7 @@ import (
"testing"
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/configfile"
)
func TestBackupStatusSizeErrorRespectsOutputMode(t *testing.T) {
@ -159,25 +160,62 @@ func TestBackupStatusIncludesAvailableDatabaseSize(t *testing.T) {
})
}
func TestBackupStatusProxiedGuardDoesNotMeasureSize(t *testing.T) {
prepareBackupStatusTest(t)
proxiedServerMode = true
called := false
sizeDatabase := func(context.Context) (int64, bool, error) {
called = true
return 1, true, nil
}
// TestBackupStatusProxiedGuardFollowsLocality replaces a test that asserted a
// blanket proxied refusal. Since slice S3 the guard is scoped to locality: bd
// owns the dolt process on a managed-local workspace and can honor the command
// there, while an external one is still refused — and a refused command must
// not go on to measure anything, because the directory it would measure belongs
// to a server on another host.
func TestBackupStatusProxiedGuardFollowsLocality(t *testing.T) {
for _, tc := range []struct {
name string
sidecar string
wantMeasure bool
}{
{
name: "external topology is refused without measuring",
sidecar: `{"external":{"host":"db.example.com","port":3306}}`,
wantMeasure: false,
},
{
name: "managed local is honored and measures",
sidecar: `{}`,
wantMeasure: true,
},
} {
t.Run(tc.name, func(t *testing.T) {
beadsDir := prepareBackupStatusTest(t)
proxiedServerMode = true
if err := os.WriteFile(configfile.ProxiedServerClientInfoPath(beadsDir), []byte(tc.sidecar), 0o600); err != nil {
t.Fatalf("write proxied sidecar: %v", err)
}
cmd := newBackupStatusTestRoot(sizeDatabase)
cmd.SetArgs([]string{"backup", "status"})
_, _, err := executeBackupStatusCommand(t, cmd)
assertExitCode(t, err, 1)
if called {
t.Fatal("proxied-server guard called database size provider")
measured := false
sizeDatabase := func(context.Context) (int64, bool, error) {
measured = true
return 1, true, nil
}
cmd := newBackupStatusTestRoot(sizeDatabase)
cmd.SetArgs([]string{"backup", "status"})
_, _, err := executeBackupStatusCommand(t, cmd)
if tc.wantMeasure {
if err != nil {
t.Fatalf("backup status on managed-local: %v", err)
}
} else {
assertExitCode(t, err, 1)
}
if measured != tc.wantMeasure {
t.Fatalf("size provider called = %v, want %v", measured, tc.wantMeasure)
}
})
}
}
func prepareBackupStatusTest(t *testing.T) {
// prepareBackupStatusTest builds a throwaway workspace and returns its .beads
// directory, so a caller can drop workspace files (the proxied sidecar) into it.
func prepareBackupStatusTest(t *testing.T) string {
t.Helper()
beadsDir := filepath.Join(t.TempDir(), ".beads")
@ -198,6 +236,7 @@ func prepareBackupStatusTest(t *testing.T) {
proxiedServerMode = oldProxiedServerMode
resetCommandContext()
})
return beadsDir
}
func newBackupStatusTestRoot(sizeDatabase backupSizeFunc) *cobra.Command {

View file

@ -38,6 +38,9 @@ func runBatchProxiedServer(ctx context.Context, ops []batchOp, commitMsg string)
if uowProvider == nil {
return nil, HandleErrorRespectJSON("proxied-server UOW provider not initialized")
}
// Explicit commit point, like `transact` on the direct route: the commit
// carries the caller's message whatever dolt.auto-commit says (GH#4995).
ctx = explicitCommitPointContext(ctx)
return uow.RunTxResult(ctx, uowProvider, func(ctx context.Context, uw uow.UnitOfWork) ([]batchOpResult, string, error) {
// Built per attempt, not per call: a retried batch must report the
// results of the attempt that actually committed.

View file

@ -186,7 +186,9 @@ Examples:
if isGitRepo() && !isBareGitRepo() {
if originURL, err := gitOriginGetURL(); err == nil && originURL != "" {
if gitOriginHasDoltDataRef() {
if fallbackDir := beads.GetWorktreeFallbackBeadsDir(); fallbackDir != "" {
if explicitDir := beads.ExplicitBeadsDir(); explicitDir != "" {
beadsDir = explicitDir
} else if fallbackDir := beads.GetWorktreeFallbackBeadsDir(); fallbackDir != "" {
beadsDir = fallbackDir
} else {
cwd, err := os.Getwd()

View file

@ -79,13 +79,7 @@ func TestIsGitCodeRepoURL(t *testing.T) {
// Returns a cleanup function that resets config state.
func setupSyncRemoteConfig(t *testing.T, beadsDir, remote string) func() {
t.Helper()
if err := os.WriteFile(
filepath.Join(beadsDir, "config.yaml"),
[]byte("sync.remote: "+remote+"\n"),
0o644,
); err != nil {
t.Fatalf("write config.yaml: %v", err)
}
seedSyncRemote(t, beadsDir, remote)
config.ResetForTesting()
t.Setenv("BEADS_DIR", beadsDir)
t.Setenv("BEADS_TEST_IGNORE_REPO_CONFIG", "1")

View file

@ -355,9 +355,7 @@ func TestDetectBootstrapAction_ExplicitSyncRemotePreservesRemotesAPIURL(t *testi
t.Fatal(err)
}
const syncRemote = "http://myserver:7007/mydb"
if err := os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte("sync.remote: "+syncRemote+"\n"), 0o644); err != nil {
t.Fatal(err)
}
seedSyncRemote(t, beadsDir, syncRemote)
t.Setenv("BEADS_DIR", beadsDir)
t.Setenv("BEADS_TEST_IGNORE_REPO_CONFIG", "1")
if err := config.Initialize(); err != nil {
@ -407,9 +405,7 @@ func TestDetectBootstrapAction_ExistingEmbeddedDBWithSyncRemoteIsNoOp(t *testing
t.Fatal(err)
}
const syncRemote = "http://myserver:7007/mydb"
if err := os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte("sync.remote: "+syncRemote+"\n"), 0o644); err != nil {
t.Fatal(err)
}
seedSyncRemote(t, beadsDir, syncRemote)
t.Setenv("BEADS_DIR", beadsDir)
t.Setenv("BEADS_TEST_IGNORE_REPO_CONFIG", "1")
if err := config.Initialize(); err != nil {
@ -1327,8 +1323,18 @@ func TestFinalizeSyncedBootstrapWritesConfigFiles(t *testing.T) {
// sync.remote must be persisted so subsequent fresh clones (and
// bootstrap retries) can rediscover the remote without re-probing
// origin refs.
if !strings.Contains(yaml, "sync.remote: ") && !strings.Contains(yaml, "sync-remote: ") {
t.Errorf("config.yaml does not contain sync.remote entry:\n%s", yaml)
//
// Asserted by READING it back rather than by matching a spelling. This used
// to require a literal `sync.remote: ` line, which is a key whose name
// contains a dot — the shape config.GetStringFromDir and viper can never
// find, because both split on the dot and walk nested mappings. The writer
// now nests (bd-zj95), so the old assertion passed for exactly as long as
// the value was unreadable and failed the moment it became readable. What
// bootstrap owes its caller is a remote that can be read back, so that is
// what this checks.
if got := config.GetStringFromDir(beadsDir, "sync.remote"); got != syncRemote {
t.Errorf("config.GetStringFromDir(%q, \"sync.remote\") = %q, want %q:\n%s",
beadsDir, got, syncRemote, yaml)
}
if !strings.Contains(yaml, syncRemote) {
t.Errorf("config.yaml does not contain sync remote URL %q:\n%s", syncRemote, yaml)

View file

@ -0,0 +1,676 @@
package main
import (
"sort"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
// The proxied-server capability registry: one table for every command path.
//
// Before this file the policy lived in three separate tables — a maintenance
// refusal map, a history classification map, and a transform row list — each
// with its own lookup and its own front-door validator. Nothing forced a new
// command to appear in any of them, so an unclassified command sailed past the
// gate and died deep in the store factory with an untyped error. The fix is not
// a fourth table: it is one table plus a test that fails when a command is
// missing from it (TestProxyCapabilityRegistryCoversCommandTree).
//
// WHAT A ROW MEANS. Outcome describes what the PRE-PROVIDER GATE does with the
// path on a proxied-server workspace, nothing more:
//
// ProxyOutcomeRefused the gate refuses with a typed ProxyCapabilityError
// before any workspace side effect
// ProxyOutcomeRefusedInRunE the gate lets the path through and the command
// refuses inside its own RunE with an untyped
// string; recorded here so the untyped surface is
// inventoried rather than invisible. Not enforced.
// ProxyOutcomeHonored the gate lets the path through. It does NOT
// promise a proxied route exists: a permitted
// command with no route still fails at the store
// factory with proxy.store.unrouted.
//
// Permitting a path also COSTS something, and the cost is invisible from this
// table: unless the command is on one of main.go's store-init skip lists, the
// root pre-run opens the proxied provider before RunE runs — which starts the
// proxy and its dolt child, creates the database and migrates the schema. For a
// command that genuinely uses the store that is the point. For a store-free one
// it is pure side effect, and on a workspace whose topology cannot be resolved
// it turns a clean typed refusal into a provider-open error. So "this command
// touches no store" is an argument for permitting it only once the command is
// also off the store-init path; see the `migrate hooks` row. Nothing here
// asserts that, and TestProxyCapabilityRegistryCoversCommandTree cannot see it.
//
// REASON is the load-bearing field. "design" means refusing is correct and is
// expected to stay that way — the semantics are undefined or unsafe against a
// backend that may be shared. "unimplemented" means the refusal is a capability
// gap with a named slice that closes it, and Tracking says which. Every later
// slice measures itself by turning "unimplemented" rows into honored ones; the
// count of remaining "unimplemented" rows is the completion signal for the whole
// proxied-parity effort. Assign the field row by row, from the command's actual
// semantics — a bulk assignment would destroy the only information it carries.
//
// The reason also renders in the refusal JSON, additive to the frozen
// {code, error, mutates} contract (see buildJSONCapabilityError). Codes are
// frozen; messages are informative-only.
// ProxyRefusalReason distinguishes a deliberate policy refusal from a
// not-yet-built one.
type ProxyRefusalReason string
const (
// ProxyReasonDesign: the command is refused on purpose and is expected to
// stay refused. Lifting it would need a semantic decision, not plumbing.
ProxyReasonDesign ProxyRefusalReason = "design"
// ProxyReasonUnimplemented: the command could work over the proxied
// provider; nobody has routed it yet. Tracking names the work item.
ProxyReasonUnimplemented ProxyRefusalReason = "unimplemented"
)
// Tracking values name the plan-of-record work item for an unimplemented
// refusal. These are the slices of the proxied-parity plan; a row gets a GitHub
// issue or bead ID instead once one is filed for it.
// S3 has no entry: it landed, and its rows carry Reason=design rather than a
// tracking item.
const (
trackVersionCtl = "proxied-parity S4 (dolt commit/push/pull/remote)"
trackSync = "proxied-parity S5 (bd sync)"
trackDegradation = "proxied-parity S6 (doctor, config show, degradations)"
trackLongTail = "proxied-parity S7 (long-tail policy pass)"
)
// capabilityRow is one command-path policy row. ArgSet is the sorted set of
// execution-altering flags that were set (for example "--auto-merge --dry-run"),
// empty for the bare path; a row keyed on an ArgSet wins over the bare row, which
// is how `duplicates --auto-merge --dry-run` stays honored while
// `duplicates --auto-merge` is refused.
//
// Topology overrides Rule on the proxied shapes named in it and is empty for
// every row whose answer is the same everywhere — which is all of them but the
// backup family. See honoredOn.
type capabilityRow struct {
Path string
ArgSet string
Rule proxyCapabilityRule
Topology map[ProxyTopology]proxyCapabilityRule
History HistoryCapabilityClass
Note string
}
// ruleFor resolves the row's policy on one proxied topology.
func (r capabilityRow) ruleFor(topology ProxyTopology) proxyCapabilityRule {
if rule, ok := r.Topology[topology]; ok {
return rule
}
return r.Rule
}
// honoredOn narrows a refusal to the shapes where it is actually true: the row
// goes on refusing everywhere except the topologies named here.
//
// The direction is deliberate. A row states its refusal first and then lists
// the exceptions, so a shape nobody thought about — a new transport, or the
// unknown a corrupt sidecar produces — inherits the refusal rather than the
// exemption.
func (r capabilityRow) honoredOn(topologies ...ProxyTopology) capabilityRow {
r.Topology = make(map[ProxyTopology]proxyCapabilityRule, len(topologies))
for _, topology := range topologies {
r.Topology[topology] = proxyCapabilityRule{Outcome: ProxyOutcomeHonored}
}
return r
}
// display renders the row's key the way its refusal message names it.
func (r capabilityRow) display() string {
if r.ArgSet == "" {
return r.Path
}
return r.Path + " " + r.ArgSet
}
func (r capabilityRow) withHistory(class HistoryCapabilityClass) capabilityRow {
r.History = class
return r
}
// asParentGroup marks a row whose path is a command GROUP. Cobra answers a
// non-runnable parent with its help text before PersistentPreRunE, so the gate
// never sees it; the row is kept because it is the parent every child row
// inherits its code from, and because a parent that later gains a Run must not
// silently become permitted.
func (r capabilityRow) asParentGroup() capabilityRow {
r.Note = "parent group: cobra shows help instead of reaching the gate"
return r
}
func (r capabilityRow) withMessage(message string) capabilityRow {
r.Rule.Message = message
return r
}
// refusedPath builds a typed front-door refusal for a bare command path.
func refusedPath(path, code string, reason ProxyRefusalReason, tracking string) capabilityRow {
return refusedArgs(path, "", code, reason, tracking)
}
// refusedArgs builds a typed front-door refusal keyed on a flag set.
func refusedArgs(path, argSet, code string, reason ProxyRefusalReason, tracking string) capabilityRow {
row := capabilityRow{Path: path, ArgSet: argSet}
row.Rule = proxyCapabilityRule{
Outcome: ProxyOutcomeRefused,
Code: code,
Message: row.display() + " is not supported in proxied-server mode",
ExitCode: 1,
Reason: reason,
Tracking: tracking,
}
return row
}
// refusedInRunE records a command that the gate permits and that then refuses
// itself with an untyped string from RunE. The row carries no message: the
// string lives in the command, and duplicating it here would rot. The scan in
// TestProxyCapabilityRegistryCoversInlineRefusals keeps the two in step.
//
// The reason is always "unimplemented" and the owner is always the long-tail
// slice, because an untyped string inside RunE is not a considered policy
// statement: a refusal decided on purpose belongs in the gate, typed, where a
// consumer can read it. Anything here is a family nobody has routed yet.
func refusedInRunE(path, site string) capabilityRow {
return capabilityRow{
Path: path,
Rule: proxyCapabilityRule{
Outcome: ProxyOutcomeRefusedInRunE, ExitCode: 1,
Reason: ProxyReasonUnimplemented, Tracking: trackLongTail,
},
Note: "untyped refusal in " + site,
}
}
// permitted records that the gate lets a path through. See the header: this is
// a statement about the gate, not a promise that a proxied route exists.
func permitted(path string) capabilityRow {
return capabilityRow{Path: path, Rule: proxyCapabilityRule{Outcome: ProxyOutcomeHonored}}
}
// backupRefusal builds one backup-family row: honored where bd owns the Dolt
// server, refused by design everywhere else. The code stays
// proxy.backup.unsupported — consumers have been keying on it since 1.3.0 and
// the refusal it names has not changed, only its reason and its scope — and the
// message keeps the frozen "<path> is not supported in proxied-server mode"
// prefix, with the reason appended.
//
// The message leads with SERVER-GLOBAL STATE rather than with the filesystem,
// because only the filesystem half is scheme-specific. `bd backup init` accepts
// https/aws/gs as well as file:// (resolveDoltBackupURL) and the help text
// recommends DoltHub; for those a server-side push over the network with the
// server's own credentials is a coherent thing to ask for, and "the destination
// is on the server's disk" says nothing about it. What is true of every scheme
// is that `CALL DOLT_BACKUP('add', …)` registers the remote ON THE SERVER,
// where it is global to every client of that server — one workspace's backup
// decision silently becomes everyone's, which is the shape of the auto-backup
// storm this command's own help text warns about.
//
// backupRemoteSchemeTracking is why these rows carry a Tracking item despite
// being Reason=design: the outcome is settled, the remote-scheme CASE is not.
func backupRefusal(path string) capabilityRow {
return refusedPath(path, "proxy.backup.unsupported", ProxyReasonDesign, backupRemoteSchemeTracking).
withMessage(path + " is not supported in proxied-server mode against a Dolt server bd does not own: " +
"the backup remote is registered on the server, where it is global to every client, " +
"and a file:// destination names a filesystem this client cannot see").
honoredOn(ProxyTopologyManagedLocal)
}
// backupRemoteSchemeTracking records the one part of the backup refusal that is
// a question rather than a verdict, so refusing the family off-host does not
// silently foreclose it. A remote-scheme destination (DoltHub, aws://, gs://)
// needs no filesystem bd can see — the server pushes it over the network from
// its own environment, which is exactly the credential story S4 has to settle
// for `dolt push` on these same topologies. Whether a per-client backup remote
// on a shared server is ever acceptable is the open part; the plumbing is not.
//
// Note also that the DoltHub story is already half-built in DIRECT mode:
// `bd backup init https://…` and `bd backup sync` work, but
// `bd backup restore https://…` does not, because validateBackupRestoreDir
// os.Stats its argument and rejects anything that is not an existing directory
// on every topology. Pre-existing, not something this slice changed.
const backupRemoteSchemeTracking = "open question, not a verdict: remote-scheme (DoltHub/aws/gs) backup on a server " +
"bd does not own — revisit with S4, which settles the same server-env credential question for dolt push"
// proxyCapabilityRegistry is the whole path-keyed policy. Rows for permitted
// paths are appended from proxyPermittedPaths by init.
var proxyCapabilityRegistry = []capabilityRow{
// --- doctor -------------------------------------------------------------
// Diagnosis needs no version-control surface; the checks simply have no
// proxied dual yet. S6 splits them into client-local and store-backed.
refusedPath("doctor", "proxy.doctor.unsupported", ProxyReasonUnimplemented, trackDegradation),
// --- backup / restore ---------------------------------------------------
// CALL DOLT_BACKUP(...) is pure SQL over a connection proxied mode already
// owns, so routing this family needed no proxy work at all — see
// backup_proxied_server.go.
//
// What it did need is the ownership policy, which is the first genuinely
// topology-differentiated rule in this table. A backup remote belongs to the
// SERVER, not to the client that asked for it: `CALL DOLT_BACKUP('add', …)`
// registers it in the server's own configuration, where it is global to
// every client connected to that server. On managed-local "every client" is
// this workspace, because bd spawned the child itself. Anywhere else one
// operator's backup decision silently becomes everyone's — the same shape as
// the auto-backup storm this command's help text already warns about, and
// the reason team-server is the sharpest case: bts owns the store.
//
// A file:// destination adds a second, scheme-specific problem on top: it
// names a path on the machine running dolt, so off-host the command either
// fails at the point of use or, far worse, reports success having written
// the backup somewhere the operator will never look for it.
//
// Hence: honored on managed-local, refused by design everywhere else. The
// OUTCOME is design — server-global state is not something plumbing on this
// side can make per-client, and a backup story for those shapes belongs to
// whoever runs the server. The remote-scheme case (DoltHub, aws://, gs://,
// which resolveDoltBackupURL accepts and backup.go recommends) is the part
// that is a question rather than a verdict, and it is not silently
// foreclosed: see backupRemoteSchemeTracking, which every row below carries.
backupRefusal("backup").asParentGroup(),
backupRefusal("backup init"),
backupRefusal("backup sync"),
backupRefusal("backup remove"),
backupRefusal("backup status"),
backupRefusal("backup restore"),
// --- version control over a shared history ------------------------------
// Refused by design: these mutate or traverse a history that several
// clients share through one connection, and the per-client semantics
// (whose working set? whose branch head?) are undefined. `diff` is the one
// plausible 1.4 candidate, via the dolt_diff system tables.
refusedPath("branch", "proxy.branch.unsupported", ProxyReasonDesign, "").
withHistory(HistoryDirectOnly),
refusedPath("diff", "proxy.diff.unsupported", ProxyReasonDesign, "1.4 candidate: dolt_diff system tables"),
refusedPath("flatten", "proxy.flatten.unsupported", ProxyReasonDesign, "").
withHistory(HistoryDirectOnly),
refusedPath("conflicts", "proxy.conflicts.unsupported", ProxyReasonDesign, "").
withHistory(HistoryDirectOnly).
asParentGroup(),
refusedPath("conflicts list", "proxy.conflicts.unsupported", ProxyReasonDesign, ""),
refusedPath("conflicts show", "proxy.conflicts.unsupported", ProxyReasonDesign, ""),
refusedPath("conflicts resolve", "proxy.conflicts.unsupported", ProxyReasonDesign, ""),
refusedPath("vc", "proxy.vc.unsupported", ProxyReasonDesign, "").
withHistory(HistoryDirectOnly).
asParentGroup(),
refusedPath("vc merge", "proxy.vc.unsupported", ProxyReasonDesign, ""),
refusedPath("vc commit", "proxy.vc.unsupported", ProxyReasonDesign, ""),
refusedPath("vc status", "proxy.vc.unsupported", ProxyReasonDesign, ""),
refusedPath("federation", "proxy.federation.unsupported", ProxyReasonDesign, "").
withHistory(HistoryDirectOnly).
asParentGroup(),
refusedPath("federation sync", "proxy.federation.unsupported", ProxyReasonDesign, ""),
refusedPath("federation status", "proxy.federation.unsupported", ProxyReasonDesign, ""),
refusedPath("federation add-peer", "proxy.federation.unsupported", ProxyReasonDesign, ""),
refusedPath("federation remove-peer", "proxy.federation.unsupported", ProxyReasonDesign, ""),
refusedPath("federation list-peers", "proxy.federation.unsupported", ProxyReasonDesign, ""),
// --- multi-repo routing -------------------------------------------------
// Routing to another workspace bypasses the proxied root entirely, which is
// the same reason --repo is N/A mode-wide.
refusedPath("repo", "proxy.repo.unsupported", ProxyReasonDesign, "").
withHistory(HistoryDirectOnly).
asParentGroup(),
refusedPath("repo add", "proxy.repo.unsupported", ProxyReasonDesign, ""),
refusedPath("repo remove", "proxy.repo.unsupported", ProxyReasonDesign, ""),
refusedPath("repo list", "proxy.repo.unsupported", ProxyReasonDesign, ""),
refusedPath("repo sync", "proxy.repo.unsupported", ProxyReasonDesign, ""),
// --- dolt version-control verbs -----------------------------------------
// CALL DOLT_PUSH/DOLT_PULL are SQL procedures and the generic repository
// that wraps them is already written; these need a use case and a route,
// not proxy work. `dolt remote remove` is already routed, which is the
// precedent — and `dolt commit` has now followed it: GH#4995 supplied the
// use case (it is the flush point dolt.auto-commit=batch/off defers to) and
// runDoltCommitProxiedServer supplied the route, so its row moved to the
// routed-history block below.
refusedPath("dolt push", "proxy.dolt_push.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
withHistory(HistoryDirectOnly),
refusedPath("dolt pull", "proxy.dolt_pull.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
withHistory(HistoryDirectOnly),
refusedPath("dolt remote", "proxy.dolt_remote.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
withHistory(HistoryDirectOnly).
asParentGroup(),
refusedPath("dolt remote add", "proxy.dolt_remote.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
withHistory(HistoryDirectOnly),
refusedPath("dolt remote list", "proxy.dolt_remote.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
withHistory(HistoryDirectOnly),
refusedPath("dolt remote reset-data", "proxy.dolt_remote.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
withHistory(HistoryDirectOnly),
refusedPath("sync", "proxy.sync.unsupported", ProxyReasonUnimplemented, trackSync).
withHistory(HistoryDirectOnly),
// --- migration and workspace surgery ------------------------------------
// Storage-format and workspace surgery against a store other clients may be
// holding open. `migrate schema` is the exception and is already routed:
// the provider open runs it under the migration gate.
//
// S7 MUST RE-EXAMINE THE ROWS BELOW PER TOPOLOGY. "A store other clients may
// be holding open" describes external and team-server workspaces; it does
// not describe managed-local, which is 1:1 and bd-owned — bd spawned the
// dolt child itself. A row cannot yet say "refused, except on managed-local"
// (S3's backup locality policy is the slice that adds per-topology rules),
// so the blanket refusal is the only thing this table can express today.
// These rows keep it because nobody has done the semantic work to narrow
// them, not because the work has been done and come out this way.
refusedPath("migrate", "proxy.migrate.unsupported", ProxyReasonDesign, ""),
refusedPath("migrate sync", "proxy.migrate.unsupported", ProxyReasonDesign, ""),
// `migrate hooks` is the one row in this block the surgery rationale never
// described: it plans and applies GIT HOOK FILE migration (migrate_hooks.go
// -> doctor.PlanHookMigration) on the local filesystem and opens no store at
// all. It is refused for a structural reason instead — the command is wired
// into the store-opening path it does not need. It is on none of main.go's
// store-init skip lists, so permitting it makes the root pre-run open the
// proxied provider before RunE ever runs. Measured, not assumed: with this
// row flipped to permitted, `bd migrate hooks --dry-run` on a managed-local
// workspace started the proxy AND its dolt child (both pidfiles present) to
// print a hook plan, and on a workspace with an unreadable sidecar it exited
// 1 with "failed to open uow provider: corrupt proxied-server sidecar ..."
// where it had cleanly refused before. Trading a typed refusal for a
// connection error is not a lift. The honest fix is to take the command off
// the store path first, which is S7's job, not this slice's.
refusedPath("migrate hooks", "proxy.migrate.unsupported", ProxyReasonUnimplemented,
trackLongTail+" (specifically: put `migrate hooks` on main.go's store-init skip list, then permit it)"),
refusedPath("migrate issues", "proxy.migrate.unsupported", ProxyReasonDesign, ""),
refusedPath("migrate-issues", "proxy.migrate.unsupported", ProxyReasonDesign, ""),
refusedPath("migrate-personal", "proxy.migrate.unsupported", ProxyReasonDesign, ""),
// --- destructive admin --------------------------------------------------
// Same topology-blind rationale as the migrate block above, and the same
// instruction to S7: "destructive against a possibly-shared store" is a
// claim about external and team-server shapes. On managed-local the store is
// this workspace's alone, and `bd admin reset` there is no more shared than
// it is in embedded mode, where it is honored. Re-examine per topology.
refusedPath("admin cleanup", "proxy.admin.unsupported", ProxyReasonDesign, ""),
refusedPath("admin reset", "proxy.admin.unsupported", ProxyReasonDesign, ""),
// --- issue compaction ---------------------------------------------------
// `bd admin compact` without --dolt is the description-rewriting pass; only
// the --dolt arm has a proxied route (runCompactDoltProxiedServer). The
// --dolt arm is decided by flag VALUE, so the gate keeps a value-aware
// branch for it and lands here when the flag is off.
refusedPath("admin compact", "proxy.compact.unsupported", ProxyReasonUnimplemented, trackLongTail).
withMessage("only 'compact --dolt' is supported in proxied-server mode"),
// `bd restore` recovers a COMPACTED ISSUE's original text, not a backup —
// the backup verb is `bd backup restore`. Its snapshot read is ordinary
// CRUD; only its fallback path (reconstructing from Dolt history when no
// snapshot was archived) touches version control.
refusedPath("restore", "proxy.restore.unsupported", ProxyReasonUnimplemented, trackLongTail),
// --- gates, formulas, swarm, merge slots --------------------------------
// Ordinary CRUD over a store with no version-control surface. They stay
// refused because nothing downstream has asked for them, which is this
// codebase's standing rule for lifting a refusal — not because the proxied
// topology makes them wrong.
refusedPath("gate discover", "proxy.gate.unsupported", ProxyReasonUnimplemented, trackLongTail),
refusedPath("cook", "proxy.formula.unsupported", ProxyReasonUnimplemented, trackLongTail),
refusedPath("ship", "proxy.formula.unsupported", ProxyReasonUnimplemented, trackLongTail),
refusedPath("swarm create", "proxy.swarm.unsupported", ProxyReasonUnimplemented, trackLongTail),
refusedPath("swarm list", "proxy.swarm.unsupported", ProxyReasonUnimplemented, trackLongTail),
refusedPath("merge-slot create", "proxy.merge_slot.unsupported", ProxyReasonUnimplemented, trackLongTail),
refusedPath("merge-slot check", "proxy.merge_slot.unsupported", ProxyReasonUnimplemented, trackLongTail),
refusedPath("merge-slot acquire", "proxy.merge_slot.unsupported", ProxyReasonUnimplemented, trackLongTail),
refusedPath("merge-slot release", "proxy.merge_slot.unsupported", ProxyReasonUnimplemented, trackLongTail),
// --- transforms ---------------------------------------------------------
// ID rewrites walk every reference in the store. They need a routed
// multi-statement transaction, which the UOW can express; nobody has
// written it. The arg-set rows are what let the read-only preview of a
// duplicate merge stay honored while the merge itself is refused.
refusedPath("rename", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
refusedPath("rename-prefix", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
refusedArgs("rename-prefix", "--dry-run", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
refusedArgs("rename-prefix", "--repair", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
refusedArgs("rename-prefix", "--dry-run --repair", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
refusedPath("duplicate", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
refusedArgs("duplicate", "--of", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
refusedPath("supersede", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
refusedArgs("supersede", "--with", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
refusedArgs("duplicates", "--auto-merge", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
// The dry run reports what the merge WOULD do without writing anything, so
// it rides the read path plain `duplicates` already uses.
{Path: "duplicates", ArgSet: "--auto-merge --dry-run", Rule: proxyCapabilityRule{Outcome: ProxyOutcomeHonored}},
// --- routed history -----------------------------------------------------
// The paths that already have a proxied route, recorded so the class is
// asserted rather than remembered.
permitted("history").withHistory(HistoryProxySupported),
permitted("dolt remote remove").withHistory(HistoryProxySupported),
// `dolt commit` is routed by runDoltCommitProxiedServer. It is also the
// flush point dolt.auto-commit=batch/off defers to (GH#4995), so refusing it
// at the front door would leave those modes with no way to flush.
permitted("dolt commit").withHistory(HistoryProxySupported),
// --- untyped refusals inside RunE ---------------------------------------
// The gate permits these paths and the command refuses itself with a bare
// string, so a JSON consumer gets no code and no mutates flag. They are
// listed to inventory that surface, not to enforce it: converting them to
// typed refusals changes observable output and belongs to the slice that
// owns each family. Tracker verbs are ordinary store reads plus a network
// call; nothing about the proxied topology makes them wrong.
refusedInRunE("ado status", "ado.go"),
refusedInRunE("ado projects", "ado.go"),
refusedInRunE("ado sync", "ado.go"),
refusedInRunE("github status", "github.go"),
refusedInRunE("github repos", "github.go"),
refusedInRunE("github sync", "github.go"),
refusedInRunE("gitlab status", "gitlab.go"),
refusedInRunE("gitlab projects", "gitlab.go"),
refusedInRunE("gitlab sync", "gitlab.go"),
refusedInRunE("notion status", "notion.go"),
refusedInRunE("notion init", "notion.go"),
refusedInRunE("notion connect", "notion.go"),
refusedInRunE("notion sync", "notion.go"),
refusedInRunE("create-form", "create_form.go"),
}
// proxyPermittedPaths lists every command path the proxied front door lets
// through. It exists so that a command added without a policy decision fails
// TestProxyCapabilityRegistryCoversCommandTree instead of shipping — the whole
// point of the registry. Being listed here says the GATE permits the path; a
// permitted command with no proxied route still fails at the store factory with
// proxy.store.unrouted.
var proxyPermittedPaths = []string{
// issue CRUD and queries
"assign", "batch", "blocked", "children", "close", "comment", "count", "create",
"defer", "delete", "duplicates", "edit", "export", "find-duplicates", "forget",
"gc", "graph", "graph check", "heartbeat", "import", "info", "lint", "link",
"list", "note", "orphans", "priority", "promote", "prune", "purge", "q", "query",
"ready", "recompute-blocked", "reclaim", "reopen", "search", "set-state", "show",
"stale", "status", "statuses", "tag", "types", "unclaim", "undefer", "update",
// comments, dependencies, labels, key-value
"comments", "comments add", "comments list",
"dep", "dep add", "dep cycles", "dep list", "dep relate", "dep remove", "dep tree", "dep unrelate",
"kv clear", "kv get", "kv list", "kv set",
"label add", "label list", "label list-all", "label propagate", "label remove",
// molecules, epics, todos, state
"epic close-eligible", "epic status",
"mol bond", "mol burn", "mol current", "mol distill", "mol last-activity", "mol pour",
"mol progress", "mol ready", "mol seed", "mol show", "mol squash", "mol stale",
"mol wisp", "mol wisp create", "mol wisp gc", "mol wisp list",
"state", "state list", "todo", "todo add", "todo done", "todo list",
// gates, rules, provenance, audit, upgrade review
"audit label", "audit record",
"gate add-waiter", "gate check", "gate create", "gate list", "gate resolve", "gate show",
"provenance by-ref", "provenance log", "provenance record",
"rules audit", "rules compact",
"upgrade ack", "upgrade review", "upgrade status",
// workspace lifecycle and configuration
"bootstrap", "config apply", "config drift", "config get", "config list", "config set",
"config set-many", "config show", "config unset", "config validate", "context",
"init", "init-safety", "onboard", "preflight", "quickstart", "schema", "setup", "where",
"version", "worktree create", "worktree info", "worktree list", "worktree remove",
// storage, history and migration paths that are already routed or store-free
"compact", "events export", "events prune", "events tail",
"dolt clean-databases", "dolt killall", "dolt set", "dolt show", "dolt status",
"dolt start", "dolt stop", "dolt test",
"migrate from-proxied-server-to-server", "migrate from-proxied-server-to-shared-server",
"migrate from-server-to-proxied-server", "migrate from-shared-server-to-proxied-server",
"migrate legacy-sqlite", "migrate schema",
// formulas (parser-only), agent memory, swarm reads
"formula convert", "formula list", "formula schema", "formula show",
"mail", "memories", "ping", "prime", "recall", "remember",
"swarm status", "swarm validate",
// human-in-the-loop queue
"human", "human dismiss", "human list", "human respond", "human stats",
// trackers: the verbs with no proxied refusal of any kind
"ado pull", "ado push", "github pull", "github push", "gitlab pull", "gitlab push",
"jira pull", "jira push", "jira status", "jira sync",
"linear pull", "linear push", "linear status", "linear sync", "linear teams",
"notion pull", "notion push",
// hooks, metrics, serving and internal entry points
"hooks install", "hooks list", "hooks run", "hooks uninstall",
"metrics", "metrics example", "metrics off", "metrics on",
"serve", "sql",
"codex-hook", "cursor-hook", "db-proxy-child", "send-metrics",
}
func init() {
for _, path := range proxyPermittedPaths {
proxyCapabilityRegistry = append(proxyCapabilityRegistry, permitted(path))
}
proxyCapabilityIndex = make(map[string]capabilityRow, len(proxyCapabilityRegistry))
for _, row := range proxyCapabilityRegistry {
proxyCapabilityIndex[capabilityKey(row.Path, row.ArgSet)] = row
}
}
// proxyCapabilityIndex is proxyCapabilityRegistry keyed for lookup. Duplicate
// keys are rejected by TestProxyCapabilityRegistryHasNoDuplicateRows rather
// than by a panic here: a typo must fail the build, not every bd invocation.
var proxyCapabilityIndex map[string]capabilityRow
func capabilityKey(path, argSet string) string { return path + "\x00" + argSet }
// LookupCapabilityRow returns the row for an exact path/arg-set key.
func LookupCapabilityRow(path, argSet string) (capabilityRow, bool) {
row, ok := proxyCapabilityIndex[capabilityKey(path, argSet)]
return row, ok
}
// capabilityRowFor resolves a command to its row, preferring the row keyed on
// the flags the invocation actually set over the bare path.
//
// The fallback to the bare row is what lets one table serve both halves of the
// old policy: a path row refuses whatever flags were passed unless a more
// specific row says otherwise, so `backup sync --dry-run` is still refused by
// the `backup sync` row. The predecessor of the arg-set half matched exactly or
// not at all, which meant an unlisted flag combination on a refused path
// slipped through; no such combination exists among the commands that carry
// these flags, so nothing changes today, and the fallback is why none can
// appear later.
func capabilityRowFor(cmd *cobra.Command) (capabilityRow, bool) {
path := commandRegistryPath(cmd)
if argSet := commandPolicyArgSet(cmd); argSet != "" {
if row, ok := LookupCapabilityRow(path, argSet); ok {
return row, true
}
}
return LookupCapabilityRow(path, "")
}
// commandRegistryPath is the registry key for a command: its full path with the
// root name removed, for example "dolt remote add".
func commandRegistryPath(cmd *cobra.Command) string {
return strings.TrimSpace(strings.TrimPrefix(cmd.CommandPath(), cmd.Root().Name()))
}
// proxyPolicyArgFlags are the flags that take part in a capability key. Only
// flags that alter a command's execution belong here: output, tracing and other
// inherited root flags must never bypass a refusal by changing the key.
var proxyPolicyArgFlags = map[string]bool{
"auto-merge": true, "dry-run": true, "repair": true, "of": true, "with": true,
}
// commandPolicyArgSet renders the set flags that take part in the key, sorted so
// the key does not depend on the order the user typed them.
func commandPolicyArgSet(cmd *cobra.Command) string {
var args []string
cmd.Flags().Visit(func(f *pflag.Flag) {
if proxyPolicyArgFlags[f.Name] {
args = append(args, "--"+f.Name)
}
})
sort.Strings(args)
return strings.Join(args, " ")
}
// validateProxyRegistryBeforeProvider is the path-keyed half of the proxied
// front door: it rejects direct-only commands before migrations, auto-start or
// provider construction, so a refusal leaves the workspace untouched. The
// flag-keyed half is validateProxyCapabilitiesBeforeProvider.
//
// topology is the workspace's proxied shape (resolveProxiedTopology). It is a
// parameter rather than a lookup inside so the gate can be exercised for every
// shape without a workspace on disk.
func validateProxyRegistryBeforeProvider(cmd *cobra.Command, topology ProxyTopology) error {
if cmd == nil {
return nil
}
// `compact` is the one rule that a flag VALUE decides rather than a flag's
// presence, so it cannot be expressed as an arg-set row. `bd compact` and
// `bd rules compact` have no --dolt flag at all and are never refused here;
// `bd admin compact --dolt` has a proxied route and falls through to it.
if cmd.Name() == "compact" {
if cmd.Flags().Lookup("dolt") == nil {
return nil
}
if dolt, _ := cmd.Flags().GetBool("dolt"); dolt {
return nil
}
}
row, ok := capabilityRowFor(cmd)
if !ok {
return nil
}
rule := row.ruleFor(topology)
if rule.Outcome != ProxyOutcomeRefused {
return nil
}
return HandleProxyCapabilityError(proxyCapabilityErrorFor(rule))
}
func proxyCapabilityErrorFor(rule proxyCapabilityRule) *ProxyCapabilityError {
return &ProxyCapabilityError{
Code: rule.Code,
Message: rule.Message,
ExitCode: rule.ExitCode,
Mutates: rule.Mutates,
Reason: rule.Reason,
}
}
// HistoryCapabilityClass classifies history/version-control commands on the
// proxied topology without coupling them to a particular backend engine.
type HistoryCapabilityClass string
const (
HistoryProxySupported HistoryCapabilityClass = "proxy-supported"
HistoryDirectOnly HistoryCapabilityClass = "direct-only"
)
// LookupHistoryCapability classifies an exact command path. Paths with no
// history classification are intentionally absent so callers cannot
// accidentally advertise support.
func LookupHistoryCapability(commandPath string) (HistoryCapabilityClass, bool) {
row, ok := LookupCapabilityRow(commandPath, "")
if !ok || row.History == "" {
return "", false
}
return row.History, true
}

View file

@ -12,13 +12,17 @@ func TestHistoryCapabilityMatrixExactPaths(t *testing.T) {
if got, ok := LookupHistoryCapability("history"); !ok || got != HistoryProxySupported {
t.Fatalf("history = %q, %v; want proxy-supported", got, ok)
}
for _, path := range []string{"branch", "conflicts", "repo", "federation", "vc", "flatten", "dolt push", "dolt pull", "dolt commit", "dolt remote", "sync"} {
for _, path := range []string{"branch", "conflicts", "repo", "federation", "vc", "flatten", "dolt push", "dolt pull", "dolt remote", "sync"} {
if got, ok := LookupHistoryCapability(path); !ok || got != HistoryDirectOnly {
t.Errorf("%q = %q, %v; want direct-only", path, got, ok)
}
}
if got, ok := LookupHistoryCapability("dolt remote remove"); !ok || got != HistoryProxySupported {
t.Fatalf("dolt remote remove = %q, %v; want proxy-supported", got, ok)
// dolt commit is the flush point dolt.auto-commit=batch/off defers to
// (GH#4995), so it must stay reachable on the proxied route.
for _, path := range []string{"dolt remote remove", "dolt commit"} {
if got, ok := LookupHistoryCapability(path); !ok || got != HistoryProxySupported {
t.Fatalf("%s = %q, %v; want proxy-supported", path, got, ok)
}
}
for _, path := range []string{"dolt remote add", "dolt remote list", "dolt remote reset-data"} {
if got, ok := LookupHistoryCapability(path); !ok || got != HistoryDirectOnly {
@ -31,7 +35,7 @@ func TestSyncRefusesBeforeProvider(t *testing.T) {
root := &cobra.Command{Use: "bd"}
cmd := &cobra.Command{Use: "sync"}
root.AddCommand(cmd)
err := validateProxyMaintenanceBeforeProvider(cmd)
err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal)
if err == nil {
t.Fatalf("sync refusal = %#v", err)
}
@ -50,7 +54,6 @@ func TestHistoryDirectOnlyRefusalContract(t *testing.T) {
"flatten": {"proxy.flatten.unsupported", "flatten is not supported in proxied-server mode"},
"dolt push": {"proxy.dolt_push.unsupported", "dolt push is not supported in proxied-server mode"},
"dolt pull": {"proxy.dolt_pull.unsupported", "dolt pull is not supported in proxied-server mode"},
"dolt commit": {"proxy.dolt_commit.unsupported", "dolt commit is not supported in proxied-server mode"},
"dolt remote add": {"proxy.dolt_remote.unsupported", "dolt remote add is not supported in proxied-server mode"},
"dolt remote list": {"proxy.dolt_remote.unsupported", "dolt remote list is not supported in proxied-server mode"},
"dolt remote reset-data": {"proxy.dolt_remote.unsupported", "dolt remote reset-data is not supported in proxied-server mode"},
@ -59,7 +62,7 @@ func TestHistoryDirectOnlyRefusalContract(t *testing.T) {
oldProvider := uowProvider
oldJSON := jsonOutput
t.Cleanup(func() { uowProvider = oldProvider; jsonOutput = oldJSON })
for _, path := range []string{"branch", "conflicts", "repo", "federation", "vc", "flatten", "dolt push", "dolt pull", "dolt commit", "dolt remote add", "sync"} {
for _, path := range []string{"branch", "conflicts", "repo", "federation", "vc", "flatten", "dolt push", "dolt pull", "dolt remote add", "sync"} {
parts := strings.Split(path, " ")
root := &cobra.Command{Use: "bd"}
cmd := &cobra.Command{Use: parts[0]}
@ -71,7 +74,7 @@ func TestHistoryDirectOnlyRefusalContract(t *testing.T) {
}
uowProvider = nil
jsonOutput = true
out := captureStdout(t, func() error { _ = validateProxyMaintenanceBeforeProvider(cmd); return nil })
out := captureStdout(t, func() error { _ = validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal); return nil })
var got map[string]any
want := expected[path]
if err := json.Unmarshal([]byte(out), &got); err != nil || got["code"] != want.code || got["error"] != want.message || got["mutates"] != false {
@ -94,7 +97,7 @@ func TestHistoryNestedFrontDoorsRefuseAndSupportedPathsPass(t *testing.T) {
"conflicts resolve": {"proxy.conflicts.unsupported", "conflicts resolve is not supported in proxied-server mode"},
"federation sync": {"proxy.federation.unsupported", "federation sync is not supported in proxied-server mode"},
}
for _, path := range []string{"vc merge", "vc commit", "repo add", "conflicts resolve", "federation sync", "dolt remote remove"} {
for _, path := range []string{"vc merge", "vc commit", "repo add", "conflicts resolve", "federation sync", "dolt remote remove", "dolt commit"} {
parts := strings.Split(path, " ")
root := &cobra.Command{Use: "bd"}
cmd := &cobra.Command{Use: parts[0]}
@ -104,8 +107,8 @@ func TestHistoryNestedFrontDoorsRefuseAndSupportedPathsPass(t *testing.T) {
cmd.AddCommand(child)
cmd = child
}
err := validateProxyMaintenanceBeforeProvider(cmd)
if path == "dolt remote remove" {
err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal)
if path == "dolt remote remove" || path == "dolt commit" {
if err != nil {
t.Fatalf("supported %s refused: %v", path, err)
}
@ -118,9 +121,9 @@ func TestHistoryNestedFrontDoorsRefuseAndSupportedPathsPass(t *testing.T) {
t.Fatalf("%s exit=%v, want 1", path, err)
}
var got map[string]any
// validateProxyMaintenanceBeforeProvider renders the typed refusal to
// validateProxyRegistryBeforeProvider renders the typed refusal to
// stdout in JSON mode; the command must retain its nested path.
out := captureStdout(t, func() error { _ = validateProxyMaintenanceBeforeProvider(cmd); return nil })
out := captureStdout(t, func() error { _ = validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal); return nil })
if err := json.Unmarshal([]byte(out), &got); err != nil {
t.Fatalf("%s refusal JSON: %v (%q)", path, err, out)
}
@ -132,7 +135,7 @@ func TestHistoryNestedFrontDoorsRefuseAndSupportedPathsPass(t *testing.T) {
root := &cobra.Command{Use: "bd"}
history := &cobra.Command{Use: "history"}
root.AddCommand(history)
if err := validateProxyMaintenanceBeforeProvider(history); err != nil {
if err := validateProxyRegistryBeforeProvider(history, ProxyTopologyManagedLocal); err != nil {
t.Fatalf("history --events supported path refused: %v", err)
}
}

View file

@ -0,0 +1,423 @@
package main
import (
"errors"
"os"
"path/filepath"
"regexp"
"sort"
"strings"
"testing"
"github.com/spf13/cobra"
)
// cobraBuiltinCommands are added to the tree by cobra itself, not by bd, and
// only once something calls Execute — which another test in this package does
// (completions_test.go runs __complete). Without this set the completeness test
// below would pass or fail depending on test ORDER, which is the worst possible
// property for a policy gate.
var cobraBuiltinCommands = map[string]bool{
"help": true, "completion": true, "__complete": true, "__completeNoDesc": true,
}
// walkCommandPaths returns every command path in the tree, with the runnable
// ones flagged. Runnable is the property that matters: cobra returns ErrHelp
// for a non-runnable parent before PersistentPreRunE, so a group command never
// reaches the capability gate at all.
func walkCommandPaths(root *cobra.Command) map[string]bool {
paths := map[string]bool{}
var walk func(c *cobra.Command)
walk = func(c *cobra.Command) {
if cobraBuiltinCommands[c.Name()] {
return
}
if path := commandRegistryPath(c); path != "" {
paths[path] = c.Runnable()
}
for _, sub := range c.Commands() {
walk(sub)
}
}
walk(root)
return paths
}
// TestProxyCapabilityRegistryCoversCommandTree is the reason this registry
// exists. Every command that can actually run must state what the proxied front
// door does with it. A new command with no row fails here, at build time, rather
// than shipping and dying in the store factory with an untyped error — which is
// how every scattered refusal in this codebase got there.
//
// Adding a row is not a formality: choose the outcome deliberately.
// - the command works over the proxied provider, or never opens a store at
// all => add its path to proxyPermittedPaths
// - the command must not run on a shared/proxied store => add a refusedPath
// row with Reason=design and say why in a comment
// - the command could work but nobody has routed it => add a refusedPath row
// with Reason=unimplemented and a Tracking item
func TestProxyCapabilityRegistryCoversCommandTree(t *testing.T) {
var missing []string
for path, runnable := range walkCommandPaths(rootCmd) {
if !runnable {
continue
}
if _, ok := LookupCapabilityRow(path, ""); !ok {
missing = append(missing, path)
}
}
sort.Strings(missing)
if len(missing) > 0 {
t.Fatalf("%d command(s) have no proxied-server capability row:\n %s\n\n"+
"Add each to cmd/bd/capability_registry.go: proxyPermittedPaths if the proxied "+
"front door should let it through, or a refusedPath row with a Reason if it should not.",
len(missing), strings.Join(missing, "\n "))
}
}
// TestProxyCapabilityRegistryHasNoStaleRows is the other direction: a row whose
// command no longer exists is policy for nothing, and would hide the renamed
// command's own missing row behind a green test.
func TestProxyCapabilityRegistryHasNoStaleRows(t *testing.T) {
tree := walkCommandPaths(rootCmd)
var stale []string
for _, row := range proxyCapabilityRegistry {
if _, ok := tree[row.Path]; !ok {
stale = append(stale, row.display())
}
}
sort.Strings(stale)
if len(stale) > 0 {
t.Fatalf("registry rows for commands that do not exist:\n %s", strings.Join(stale, "\n "))
}
}
func TestProxyCapabilityRegistryHasNoDuplicateRows(t *testing.T) {
seen := map[string]bool{}
for _, row := range proxyCapabilityRegistry {
key := capabilityKey(row.Path, row.ArgSet)
if seen[key] {
t.Errorf("duplicate registry row for %q: one of them is dead and the lookup silently picks the last", row.display())
}
seen[key] = true
}
}
// TestProxyCapabilityRegistryRowInvariants pins the contract every row must
// satisfy. The Reason rules are the load-bearing ones: a refusal with no reason
// is exactly the tribal knowledge this registry replaces, and an unimplemented
// refusal with no tracking item is a gap nobody owns.
func TestProxyCapabilityRegistryRowInvariants(t *testing.T) {
for _, row := range proxyCapabilityRegistry {
assertCapabilityRuleInvariants(t, row.display(), row.Rule)
for topology, rule := range row.Topology {
assertCapabilityRuleInvariants(t, row.display()+" on "+string(topology), rule)
if topology == ProxyTopologyUnknown {
t.Errorf("%s: a row must not name the unknown topology; unknown exists so an unclassifiable "+
"workspace INHERITS the refusal, and exempting it would invert that", row.display())
}
}
if row.History == HistoryDirectOnly && row.Rule.Outcome != ProxyOutcomeRefused {
t.Errorf("%s: classified direct-only but the gate does not refuse it", row.display())
}
if row.History == HistoryProxySupported && row.Rule.Outcome != ProxyOutcomeHonored {
t.Errorf("%s: classified proxy-supported but the gate refuses it", row.display())
}
}
}
// assertCapabilityRuleInvariants checks one rule — a row's default or one of
// its per-topology overrides. Both have to satisfy the same contract: a
// topology override is policy a consumer sees, not a footnote.
func assertCapabilityRuleInvariants(t *testing.T, where string, rule proxyCapabilityRule) {
t.Helper()
switch rule.Outcome {
case ProxyOutcomeRefused:
if rule.Code == "" || rule.Message == "" || rule.ExitCode != 1 {
t.Errorf("%s: refusal must carry a code, a message and exit 1, got %#v", where, rule)
}
if rule.Mutates {
t.Errorf("%s: a refusal never mutates", where)
}
if !strings.HasPrefix(rule.Code, "proxy.") {
t.Errorf("%s: code %q must be in the stable proxy.* namespace", where, rule.Code)
}
case ProxyOutcomeRefusedInRunE:
if rule.Code != "" {
t.Errorf("%s: an untyped RunE refusal has no code; if it has one it belongs in the gate", where)
}
case ProxyOutcomeHonored:
if rule.Reason != "" {
t.Errorf("%s: Reason explains a refusal; an honored row must not carry one", where)
}
default:
t.Errorf("%s: unexpected outcome %q", where, rule.Outcome)
}
if rule.Outcome == ProxyOutcomeRefused || rule.Outcome == ProxyOutcomeRefusedInRunE {
switch rule.Reason {
case ProxyReasonDesign, ProxyReasonUnimplemented:
default:
t.Errorf("%s: refusal must declare Reason design or unimplemented, got %q", where, rule.Reason)
}
if rule.Reason == ProxyReasonUnimplemented && rule.Tracking == "" {
t.Errorf("%s: an unimplemented refusal needs a Tracking item naming who closes it", where)
}
}
}
// inlineProxiedRefusal matches the untyped refusals commands raise from their
// own RunE, e.g. HandleErrorRespectJSON("gitlab sync is not supported in
// proxied-server mode").
var inlineProxiedRefusal = regexp.MustCompile(`HandleErrorRespectJSON\("([^"]*proxied-server mode)"\)`)
// inlineProxiedMessages classifies the messages that do not name their command
// path in the standard "<path> is not supported ..." shape. A path maps the
// message to its registry row; an empty string records a message that mentions
// proxied mode without being a capability refusal at all. Keeping both explicit
// is what lets the scan below be exhaustive rather than best-effort.
var inlineProxiedMessages = map[string]string{
"only 'compact --dolt' is supported in proxied-server mode": "admin compact",
// Not a refusal: --database is the flag that only MAKES SENSE on a proxied
// workspace, so this fires on the direct topologies.
"--database (or a --db value naming a database) is only supported in proxied-server mode": "",
}
// TestProxyCapabilityRegistryCoversInlineRefusals scans the package for
// refusals raised inside RunE and requires each one to resolve to a registry
// row. Those strings are the untyped half of the refusal surface — no code, no
// mutates flag, nothing a JSON consumer can classify — and before the registry
// they were discoverable only by grep.
//
// The scan runs in both directions on purpose: a new inline refusal must be
// registered, and a ProxyOutcomeRefusedInRunE row whose string has been deleted
// must be flipped to its new outcome by the slice that deleted it.
func TestProxyCapabilityRegistryCoversInlineRefusals(t *testing.T) {
entries, err := os.ReadDir(".")
if err != nil {
t.Fatalf("read package dir: %v", err)
}
found := map[string]string{} // registry path -> file it was found in
for _, entry := range entries {
name := entry.Name()
if entry.IsDir() || !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") {
continue
}
src, err := os.ReadFile(filepath.Clean(name))
if err != nil {
t.Fatalf("read %s: %v", name, err)
}
for _, match := range inlineProxiedRefusal.FindAllStringSubmatch(string(src), -1) {
message := match[1]
path, ok := inlineRefusalPath(message)
if !ok {
t.Errorf("%s: %q mentions proxied-server mode but does not name a command path; "+
"add it to inlineProxiedMessages so it can be checked against the registry "+
"(map it to \"\" if it is not a capability refusal)", name, message)
continue
}
if path == "" {
continue // documented non-refusal
}
found[path] = name
}
}
for path, file := range found {
argSet := ""
if base, args, split := strings.Cut(path, " --"); split {
argSet = "--" + args
path = base
}
row, ok := LookupCapabilityRow(path, argSet)
if !ok {
t.Errorf("%s refuses %q inside RunE with no registry row; the front door and the command disagree about what bd supports",
file, strings.TrimSpace(path+" "+argSet))
continue
}
if row.Rule.Outcome == ProxyOutcomeHonored {
t.Errorf("%s refuses %q inside RunE, but the registry says the front door honors it", file, row.display())
}
}
for _, row := range proxyCapabilityRegistry {
if row.Rule.Outcome != ProxyOutcomeRefusedInRunE {
continue
}
if _, ok := found[row.Path]; !ok {
t.Errorf("%s is recorded as an untyped RunE refusal but no such refusal exists in the package any more (%s); "+
"flip the row to its new outcome", row.display(), row.Note)
}
}
}
func inlineRefusalPath(message string) (string, bool) {
if path, ok := inlineProxiedMessages[message]; ok {
return path, true
}
path, ok := strings.CutSuffix(message, " is not supported in proxied-server mode")
if !ok {
return "", false
}
// conflicts.go says "bd conflicts ..."; the registry keys on the path.
return strings.TrimPrefix(path, "bd "), true
}
// TestProxyCapabilityRegistryReasonsAreAssignedIndividually guards the one way
// this registry could become useless while staying green: reasons assigned in
// bulk. Every later slice reads these to decide what is left to do, so both
// values have to be genuinely represented, and the design refusals — the claim
// a reviewer will challenge — are listed here by name.
func TestProxyCapabilityRegistryReasonsAreAssignedIndividually(t *testing.T) {
wantDesign := map[string]bool{
"branch": true, "diff": true, "flatten": true,
"conflicts": true, "conflicts list": true, "conflicts show": true, "conflicts resolve": true,
"vc": true, "vc merge": true, "vc commit": true, "vc status": true,
"federation": true, "federation sync": true, "federation status": true,
"federation add-peer": true, "federation remove-peer": true, "federation list-peers": true,
"repo": true, "repo add": true, "repo remove": true, "repo list": true, "repo sync": true,
// `migrate hooks` is deliberately NOT here: it migrates git hook files
// and opens no store, so the surgery rationale the rest of this block
// rests on does not describe it. Its refusal is structural — the
// command is on none of main.go's store-init skip lists — which makes
// it unimplemented with a tracking item, not design.
"migrate": true, "migrate sync": true, "migrate issues": true,
"migrate-issues": true, "migrate-personal": true,
"admin cleanup": true, "admin reset": true,
// The backup family's DEFAULT rule is the design refusal; managed-local
// overrides it to honored (TestProxiedBackupHonoredOnlyOnManagedLocal).
// It is design because a backup remote is registered on the SERVER,
// where it is global to every client of that server — true of every
// destination scheme, unlike the filesystem half, which is a file://
// property only. These rows carry a Tracking item anyway
// (backupRemoteSchemeTracking): the outcome is settled, the
// remote-scheme case is an open question and must not read as closed.
"backup": true, "backup init": true, "backup sync": true,
"backup remove": true, "backup status": true, "backup restore": true,
}
gotDesign := map[string]bool{}
unimplemented := 0
for _, row := range proxyCapabilityRegistry {
switch row.Rule.Reason {
case ProxyReasonDesign:
gotDesign[row.display()] = true
case ProxyReasonUnimplemented:
unimplemented++
}
}
for path := range wantDesign {
if !gotDesign[path] {
t.Errorf("%q is no longer refused by design; if that is intended, update this test and say why in the PR", path)
}
}
for path := range gotDesign {
if !wantDesign[path] {
t.Errorf("%q claims Reason=design and is not in the reviewed list; a design refusal is a semantic claim that needs review", path)
}
}
if unimplemented == 0 {
t.Error("no unimplemented refusals left — either the work is done or the reasons were bulk-assigned")
}
}
// TestProxyCapabilityArgSetFallsBackToBarePath pins the lookup rule that lets
// one table carry both the path policy and the flag policy: a flag combination
// with no row of its own inherits the bare path's verdict rather than escaping
// it. Written against the real command tree so it exercises the flags these
// commands actually declare.
func TestProxyCapabilityArgSetFallsBackToBarePath(t *testing.T) {
for _, tc := range []struct {
path string
flags []string
want ProxyCapabilityOutcome
wantMsg string
}{
// Covered by an explicit row: the message names the flags.
{"rename-prefix", []string{"dry-run"}, ProxyOutcomeRefused, "rename-prefix --dry-run is not supported in proxied-server mode"},
// No row for this combination: it inherits the refused bare row rather
// than slipping past the gate.
{"rename-prefix", []string{"dry-run", "auto-merge"}, ProxyOutcomeRefused, "rename-prefix is not supported in proxied-server mode"},
// Inheriting an honored bare row is equally load-bearing: this is the
// read-only preview and it must keep working.
{"duplicates", []string{"dry-run"}, ProxyOutcomeHonored, ""},
} {
t.Run(tc.path+" "+strings.Join(tc.flags, " "), func(t *testing.T) {
root := &cobra.Command{Use: "bd"}
cmd := &cobra.Command{Use: tc.path}
root.AddCommand(cmd)
for _, flag := range tc.flags {
cmd.Flags().Bool(flag, false, "")
if err := cmd.Flags().Set(flag, "true"); err != nil {
t.Fatal(err)
}
}
row, ok := capabilityRowFor(cmd)
if !ok {
t.Fatalf("no row resolved for %q with %v", tc.path, tc.flags)
}
if row.Rule.Outcome != tc.want || row.Rule.Message != tc.wantMsg {
t.Fatalf("row = outcome %q message %q, want %q / %q",
row.Rule.Outcome, row.Rule.Message, tc.want, tc.wantMsg)
}
})
}
}
// TestProxyRefusalJSONCarriesReason pins the additive half of the JSON
// contract. {code, error, mutates} is frozen and parsed downstream; reason is
// new, and it must appear without disturbing the three fields that were already
// there.
func TestProxyRefusalJSONCarriesReason(t *testing.T) {
t.Setenv("BD_JSON_ENVELOPE", "")
oldJSON := jsonOutput
jsonOutput = true
t.Cleanup(func() { jsonOutput = oldJSON })
for _, tc := range []struct {
path, code string
reason ProxyRefusalReason
}{
{"branch", "proxy.branch.unsupported", ProxyReasonDesign},
{"sync", "proxy.sync.unsupported", ProxyReasonUnimplemented},
} {
t.Run(tc.path, func(t *testing.T) {
root := &cobra.Command{Use: "bd"}
cmd := &cobra.Command{Use: tc.path}
root.AddCommand(cmd)
out := captureStdout(t, func() error {
_ = validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal)
return nil
})
for _, want := range []string{
`"code": "` + tc.code + `"`,
`"error": "` + tc.path + ` is not supported in proxied-server mode"`,
`"mutates": false`,
`"reason": "` + string(tc.reason) + `"`,
} {
if !strings.Contains(out, want) {
t.Fatalf("refusal JSON missing %s:\n%s", want, out)
}
}
})
}
}
// TestProxiedStoreUnroutedIsTyped covers the backstop: a permitted command with
// no proxied route used to die with a bare string that no consumer could tell
// from a real store failure.
func TestProxiedStoreUnroutedIsTyped(t *testing.T) {
var typed *ProxyCapabilityError
err := errProxiedStoreUnrouted()
if !errors.As(err, &typed) {
t.Fatalf("store backstop error = %#v, want *ProxyCapabilityError", err)
}
if typed.Code != "proxy.store.unrouted" || typed.ExitCode != 1 || typed.Mutates {
t.Fatalf("store backstop = %#v", typed)
}
if typed.Reason != ProxyReasonUnimplemented {
t.Fatalf("store backstop reason = %q, want unimplemented", typed.Reason)
}
}

View file

@ -58,24 +58,25 @@ func TestProxyTransformCapabilityRows(t *testing.T) {
}
}
}
row, ok := lookupTransformCapability(cmd)
row, ok := capabilityRowFor(cmd)
if !ok {
t.Fatalf("lookup(%q, %q) missing row", tc.path, tc.argument)
}
if row.Path != tc.path || row.Argument != tc.argument || row.Outcome != tc.outcome {
if row.Path != tc.path || row.ArgSet != tc.argument || row.Rule.Outcome != tc.outcome {
t.Fatalf("row = %#v, want path=%q argument=%q outcome=%q", row, tc.path, tc.argument, tc.outcome)
}
if tc.outcome == ProxyOutcomeRefused {
if row.Code != tc.code || row.Message != tc.message || row.ExitCode != tc.exit || row.Mutates != tc.mutates {
t.Fatalf("refusal fields = code=%q message=%q exit=%d mutates=%t", row.Code, row.Message, row.ExitCode, row.Mutates)
if row.Rule.Code != tc.code || row.Rule.Message != tc.message || row.Rule.ExitCode != tc.exit || row.Rule.Mutates != tc.mutates {
t.Fatalf("refusal fields = code=%q message=%q exit=%d mutates=%t",
row.Rule.Code, row.Rule.Message, row.Rule.ExitCode, row.Rule.Mutates)
}
typed := transformCapabilityError(row)
var typed error = proxyCapabilityErrorFor(row.Rule)
var got *ProxyCapabilityError
if !errors.As(typed, &got) || got.Code != tc.code || got.ExitCode != 1 || got.Mutates {
t.Fatalf("typed refusal = %#v", typed)
}
}
if err := validateProxyTransformBeforeProvider(cmd); tc.outcome == ProxyOutcomeHonored && err != nil {
if err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal); tc.outcome == ProxyOutcomeHonored && err != nil {
t.Fatalf("honored transform refused: %v", err)
}
})
@ -85,11 +86,11 @@ func TestProxyTransformCapabilityRows(t *testing.T) {
func TestProxyDuplicatesAutoMergeDryRunMatrix(t *testing.T) {
cmd := transformTestCommand("duplicates", "auto-merge", "dry-run")
_ = cmd.Flags().Set("auto-merge", "true")
if err := validateProxyTransformBeforeProvider(cmd); err == nil {
if err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal); err == nil {
t.Fatalf("non-dry auto-merge error = %v", err)
}
_ = cmd.Flags().Set("dry-run", "true")
if err := validateProxyTransformBeforeProvider(cmd); err != nil {
if err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal); err != nil {
t.Fatalf("dry-run auto-merge refused: %v", err)
}
}
@ -103,7 +104,7 @@ func TestProxyTransformRefusalRendering(t *testing.T) {
jsonOutput = false
var textErr string
stderr := captureStderr(t, func() {
err := validateProxyTransformBeforeProvider(cmd)
err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal)
if code, ok := exitCodeFromError(err); !ok || code != 1 {
t.Fatalf("exit = %v, want 1", err)
}
@ -115,7 +116,7 @@ func TestProxyTransformRefusalRendering(t *testing.T) {
jsonOutput = true
stdout := captureStdout(t, func() error {
_ = validateProxyTransformBeforeProvider(cmd)
_ = validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal)
return nil
})
var envelope map[string]any
@ -140,8 +141,8 @@ func TestProxyTransformMatcherIgnoresInheritedOutputFlags(t *testing.T) {
if err := root.PersistentFlags().Set("json", "true"); err != nil {
t.Fatal(err)
}
row, ok := lookupTransformCapability(cmd)
if !ok || row.Argument != "--auto-merge" || row.Outcome != ProxyOutcomeRefused {
row, ok := capabilityRowFor(cmd)
if !ok || row.ArgSet != "--auto-merge" || row.Rule.Outcome != ProxyOutcomeRefused {
t.Fatalf("row with inherited --json = %#v, ok=%v", row, ok)
}
}
@ -163,7 +164,7 @@ func TestProxyTransformRefusalHasNoProviderOrFileMutation(t *testing.T) {
t.Cleanup(func() { uowProvider = oldProvider })
cmd := transformTestCommand("supersede")
err := validateProxyTransformBeforeProvider(cmd)
err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal)
if err == nil {
t.Fatal("expected transform refusal")
}

View file

@ -2,6 +2,7 @@ package main
import (
"context"
"encoding/json"
"fmt"
"os"
"strings"
@ -145,6 +146,7 @@ the flags appear in the command line.`,
closedIssues := []*types.Issue{}
closedCount := 0
alreadyClosed := 0
var failures []closeIDFailure
firstSettledID := ""
for i, id := range resolvedIDs {
@ -153,10 +155,15 @@ the flags appear in the command line.`,
// The CLI's own close policy refused this argument, so the
// batch never saw it.
fmt.Fprintln(os.Stderr, plan.refusals[i])
failures = append(failures, closeIDFailure{ID: id, Error: plan.refusals[i]})
continue
}
if res.Err != nil {
fmt.Fprintln(os.Stderr, closeDirectRefusal(id, res.Err))
// The typed error, not the decorated display line: the --force
// hint closeDirectRefusal appends is advice for a human reader,
// and the id already has its own field.
failures = append(failures, closeIDFailure{ID: id, Error: res.Err.Error()})
continue
}
@ -318,6 +325,17 @@ the flags appear in the command line.`,
// claimed store anyway: the batch committed the claim, but the sweep
// below still has to name it if a molecule auto-close made the store
// dirty again.
//
// A batch that also REFUSED an id still reports its claim here, and
// that is deliberate (#6648). The claim landed inside the batch's
// transaction alongside the survivors and a sibling's refusal does not
// roll it back, so suppressing the report would not un-claim anything —
// it would only leave an issue assigned to this actor with nothing on
// stdout or stderr saying so. The claim is announced here and named
// again in reportCloseFailures' summary, so a caller that exits on the
// nonzero status can still see what it owns. Retrying the same command
// does not stack claims: the survivor is already closed the second time
// round, nothing lands, and an empty batch earns no claim.
var claimedNextIssue *types.Issue
if claimNext && closedForCommand && !continueFlag {
if claimedNext != nil {
@ -370,6 +388,9 @@ the flags appear in the command line.`,
}
totalAttempted := len(resolvedIDs)
if len(failures) > 0 {
return reportCloseFailures(failures, totalAttempted, closeClaimedID(claimedNextIssue), jsonOutput)
}
if totalAttempted > 0 && closedCount == 0 && alreadyClosed == 0 {
return SilentExit()
}
@ -377,6 +398,88 @@ the flags appear in the command line.`,
},
}
// closeIDFailure records one issue id a batch close refused, and why. It
// mirrors updateIDFailure (update.go) on purpose: `bd close` and `bd update`
// are the two write verbs that take a list of ids, so a caller that learned to
// read one partial-failure report should not have to learn a second shape.
type closeIDFailure struct {
ID string `json:"id"`
Error string `json:"error"`
}
// closeClaimedID names the issue --claim-next claimed on this run, or "" when
// the run claimed nothing.
func closeClaimedID(claimed *types.Issue) string {
if claimed == nil {
return ""
}
return claimed.ID
}
// reportCloseFailures emits the partial-failure summary both close routes end
// on and returns the nonzero exit that #6648 added. Every refusal has already
// been printed inline, in the order the ids were typed; this is the summary
// that says how much of the batch was left open.
//
// Both routes report through here so the wording and the JSON shape are stated
// once instead of hand-rolled per route. Each route still passes its own
// denominator, because only it knows what it attempted — the direct route
// counts resolved ids, the proxied one counts arguments.
//
// The summary is suppressed for a single-id batch deliberately: one inline
// refusal is already unambiguous about which id failed, and suppressing it
// keeps single-id stderr byte-identical to what it was before close learned to
// fail a partial batch.
//
// In --json mode the summary is one compact JSON line on stderr — the shape
// reportUpdateFailures established — so a consumer that sees exit 1 can read
// WHICH ids failed instead of scraping English prose, while stdout keeps the
// plain closed-issues array a successful close emits. claimedNextID names the
// issue --claim-next claimed on this run, if any: that claim is committed
// inside the batch's own transaction and a sibling's refusal does not roll it
// back, so the report names it rather than pretending it did not happen.
func reportCloseFailures(failures []closeIDFailure, total int, claimedNextID string, jsonOut bool) error {
if total <= 1 {
return SilentExit()
}
msg := fmt.Sprintf("%d of %d issues failed to close", len(failures), total)
if !jsonOut {
fmt.Fprintf(os.Stderr, "Error: %s\n", msg)
if claimedNextID != "" {
fmt.Fprintf(os.Stderr, "Note: --claim-next already claimed %s; it stays assigned to you.\n", claimedNextID)
}
return SilentExit()
}
inner := map[string]interface{}{
"error": msg,
"failed": failures,
}
if claimedNextID != "" {
inner["claimed"] = claimedNextID
}
var payload interface{}
if jsonEnvelopeEnabled() {
payload = map[string]interface{}{
"schema_version": JSONSchemaVersion,
"data": inner,
}
} else {
inner["schema_version"] = JSONSchemaVersion
payload = inner
}
data, err := json.Marshal(payload)
if err != nil {
// Marshaling flat strings cannot realistically fail; fall back to the
// text summary rather than exiting with nothing said at all.
fmt.Fprintf(os.Stderr, "Error: %s\n", msg)
} else {
fmt.Fprintln(os.Stderr, string(data))
}
return SilentExit()
}
func init() {
registerCloseReasonFlag(closeCmd)
closeCmd.Flags().String("resolution", "", "Alias for --reason (Jira CLI convention)")
@ -568,7 +671,7 @@ func checkGateSatisfaction(issue *types.Issue) error {
case issue.AwaitType == "timer":
resolved, escalated, reason, err = checkTimer(issue, time.Now())
case issue.AwaitType == "bead":
resolved, reason = checkBeadGate(rootCtx, store, issue.AwaitID)
resolved, reason = checkBeadGate(rootCtx, routedBeadGateGetter{localStore: store}, issue.AwaitID)
if resolved {
return nil
}

View file

@ -113,6 +113,154 @@ func TestEmbeddedClose(t *testing.T) {
}
})
// A batch still closes the IDs it can close, but a caller must receive a
// nonzero exit when any sibling was refused. Otherwise an orchestrator can
// record the whole batch as complete while a blocked issue remains open.
t.Run("mixed_batch_refusal_exits_nonzero_after_closing_survivor", func(t *testing.T) {
blocker := bdCreate(t, bd, dir, "Mixed batch blocker", "--type", "task")
blocked := bdCreate(t, bd, dir, "Mixed batch blocked", "--type", "task")
closable := bdCreate(t, bd, dir, "Mixed batch closable", "--type", "task")
bdDepAdd(t, bd, dir, blocked.ID, blocker.ID)
out := bdCloseFail(t, bd, dir, closable.ID, blocked.ID)
if !strings.Contains(out, "1 of 2 issues failed to close") {
t.Errorf("expected partial-close summary, got: %s", out)
}
if got := bdShow(t, bd, dir, closable.ID); got.Status != types.StatusClosed {
t.Errorf("closable issue status = %s, want closed", got.Status)
}
if got := bdShow(t, bd, dir, blocked.ID); got.Status != types.StatusOpen {
t.Errorf("blocked issue status = %s, want open", got.Status)
}
})
// The direct-route twin of TestProxiedClose/
// close_partial_failure_json_names_the_failed_ids. Two things were asserted
// on the proxied route only: that exit 1 comes with a payload naming the
// failed ids while stdout keeps the success-shaped closed-issues array, and
// that failed[].error is the TYPED error rather than the decorated line
// stderr shows a person. This is the default route — what most scripts and
// the parity harness exercise — so a regression in reportCloseFailures'
// jsonOut branch was previously invisible to CI on the route most callers
// are on, and the two routes could drift on the field's contents with
// nothing failing.
t.Run("close_partial_failure_json_names_the_failed_ids", func(t *testing.T) {
jdir, _, _ := bdInit(t, bd, "--prefix", "jf")
closable := bdCreate(t, bd, jdir, "JSON closable", "--type", "task")
blocker := bdCreate(t, bd, jdir, "JSON blocker", "--type", "task")
blocked := bdCreate(t, bd, jdir, "JSON blocked", "--type", "task")
bdDepAdd(t, bd, jdir, blocked.ID, blocker.ID)
cmd := exec.Command(bd, "close", "--json", closable.ID, blocked.ID)
cmd.Dir = jdir
cmd.Env = bdEnv(jdir)
stdoutBuf, stderrBuf, err := runCommandBuffers(t, cmd)
stdout, stderr := stdoutBuf.String(), stderrBuf.String()
if err == nil {
t.Fatalf("expected a partial batch close to exit nonzero\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
}
// stdout keeps the success shape: just the survivor.
start := strings.Index(stdout, "[")
if start < 0 {
t.Fatalf("expected the closed-issues array on stdout, got:\n%s", stdout)
}
var closed []*types.Issue
if jsonErr := json.Unmarshal([]byte(stdout[start:]), &closed); jsonErr != nil {
t.Fatalf("parse closed array: %v\nraw: %s", jsonErr, stdout[start:])
}
if len(closed) != 1 || closed[0].ID != closable.ID {
t.Fatalf("stdout closed array = %d issue(s), want only the survivor %s\nraw: %s", len(closed), closable.ID, stdout[start:])
}
// stderr's last line is the failure report.
line := lastJSONObjectLine(stderr)
if line == "" {
t.Fatalf("expected a compact JSON failure line on stderr, got:\n%s", stderr)
}
var report struct {
Error string `json:"error"`
Failed []struct {
ID string `json:"id"`
Error string `json:"error"`
} `json:"failed"`
}
if jsonErr := json.Unmarshal([]byte(line), &report); jsonErr != nil {
t.Fatalf("parse failure report: %v\nraw: %s", jsonErr, line)
}
if report.Error != "1 of 2 issues failed to close" {
t.Errorf("failure report error = %q, want the N of M summary", report.Error)
}
if len(report.Failed) != 1 || report.Failed[0].ID != blocked.ID {
t.Fatalf("failure report named %+v, want exactly the refused id %s", report.Failed, blocked.ID)
}
assertCloseFailedErrorIsTyped(t, report.Failed[0].Error, stderr)
if got := bdShow(t, bd, jdir, closable.ID); got.Status != types.StatusClosed {
t.Errorf("closable issue status = %s, want closed despite the refused sibling", got.Status)
}
if got := bdShow(t, bd, jdir, blocked.ID); got.Status != types.StatusOpen {
t.Errorf("blocked issue status = %s, want open", got.Status)
}
})
// The --claim-next × partial-failure interaction, adjudicated rather than
// left implicit (#6648). --claim-next rides inside the batch transaction
// and fires whenever something LANDED, so a mixed batch claims and then
// exits 1. The claim is durable — the refused sibling does not roll it back
// — so the contract pinned here is "the claim stands and the failure
// summary names it", NOT "the claim is silently suppressed": suppressing
// only the report would leave an issue assigned to this actor with nothing
// saying so, which is strictly worse than announcing it.
//
// Its own project, because the assertion depends on exactly which issue is
// ready at claim time: once `closable` closes, `blocker` is the only ready
// issue left (`blocked` still depends on it), so the claim is deterministic.
t.Run("mixed_batch_claim_next_names_the_claim_it_kept", func(t *testing.T) {
kdir, _, _ := bdInit(t, bd, "--prefix", "kn")
closable := bdCreate(t, bd, kdir, "Claim-next batch closable", "--type", "task")
blocker := bdCreate(t, bd, kdir, "Claim-next batch blocker", "--type", "task")
blocked := bdCreate(t, bd, kdir, "Claim-next batch blocked", "--type", "task")
bdDepAdd(t, bd, kdir, blocked.ID, blocker.ID)
out := bdCloseFail(t, bd, kdir, closable.ID, blocked.ID, "--claim-next")
if !strings.Contains(out, "1 of 2 issues failed to close") {
t.Errorf("expected the partial-close summary, got: %s", out)
}
if !strings.Contains(out, "already claimed "+blocker.ID) {
t.Errorf("expected the failure summary to name the claim it kept (%s), got: %s", blocker.ID, out)
}
if got := bdShow(t, bd, kdir, closable.ID); got.Status != types.StatusClosed {
t.Errorf("closable issue status = %s, want closed", got.Status)
}
if got := bdShow(t, bd, kdir, blocked.ID); got.Status != types.StatusOpen {
t.Errorf("blocked issue status = %s, want open", got.Status)
}
// The claim really landed: the report is not describing a claim that
// was rolled back with the refusal.
if got := bdShow(t, bd, kdir, blocker.ID); got.Assignee == "" {
t.Errorf("claimed issue %s assignee = %q, want it assigned: the claim commits inside the batch transaction and the refused sibling does not undo it",
blocker.ID, got.Assignee)
}
// And retrying does NOT stack a second claim, which is what makes
// keeping the first one safe. `closable` is already closed on the way
// back through, so the batch lands nothing and an empty batch earns no
// claim (see the already-closed re-close subtest below). `spare` is
// created only now, so it is the one ready issue a repeat claim could
// take — without it this assertion would pass vacuously, since the
// first run left nothing else ready.
spare := bdCreate(t, bd, kdir, "Claim-next batch spare", "--type", "task")
out = bdCloseFail(t, bd, kdir, closable.ID, blocked.ID, "--claim-next")
if strings.Contains(out, "already claimed "+spare.ID) {
t.Errorf("a retry claimed %s as well, got: %s", spare.ID, out)
}
if got := bdShow(t, bd, kdir, spare.ID); got.Assignee != "" {
t.Errorf("retrying the same failed batch claimed a second issue (%s assignee = %q); the leak must be bounded at the one claim the first run earned",
spare.ID, got.Assignee)
}
})
// Proves the S7 delegation: `bd close` on a blocked issue now surfaces the
// engine's atomic guard (storage.ErrCloseBlocked) rather than a duplicated
// CLI pre-check. The refusal must be atomic — the issue stays open because the

View file

@ -0,0 +1,281 @@
package main
import (
"fmt"
"strings"
"testing"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/issueops"
)
// assertCloseFailedErrorIsTyped checks one failed[].error entry against the
// route-parity contract both close routes owe a --json consumer: the field
// carries the typed error, while the line a person reads keeps the --force hint.
//
// The two integration suites share it, which is the point — a contract that is
// supposed to be identical per route should be asserted by identical code. It is
// written against the RELATIONSHIP between the two spellings rather than a
// transcribed sentence so neither suite has to hardcode how the engine renders a
// blocker list: closeDirectRefusal and closeProxiedRefusal both produce exactly
// the typed error plus the hint, so the typed error must appear on stderr with
// the hint appended and must not contain the hint itself.
//
// Lives in an untagged file so it is compiled in the CGO_ENABLED=0 lane too,
// alongside the pins below; its callers are the cgo-gated suites.
func assertCloseFailedErrorIsTyped(t *testing.T, failedError, stderr string) {
t.Helper()
const hint = " (use --force to override)"
if !strings.HasPrefix(failedError, "cannot close blocked issue:") {
t.Errorf("failed[].error = %q, want the engine's typed ErrCloseBlocked vocabulary: both routes must spell one refusal one way",
failedError)
}
if strings.Contains(failedError, hint) {
t.Errorf("failed[].error = %q carries the --force hint; that decoration is advice for a human reader and belongs on the stderr line only",
failedError)
}
if want := failedError + hint; !strings.Contains(stderr, want) {
t.Errorf("stderr is missing the decorated refusal %q; the hint must still reach the person reading it\nstderr:\n%s",
want, stderr)
}
}
// The route-parity contract for the machine-readable half of the partial-failure
// report: `failed[].error` carries the TYPED error on both routes, and the
// decorated display line stays on stderr where a human reads it.
//
// The direct route already splits the two (close.go records res.Err.Error() in
// closeIDFailure while printing closeDirectRefusal's decorated line). The proxied
// route used to copy pre.errors — the display line — into the JSON field, so the
// same blocked-id refusal answered "cannot close blocked issue: X is blocked by
// [Y]" embedded and "... (use --force to override)" proxied. These live here
// rather than in the proxied integration suite because nothing in the split needs
// a server: the refusal slots are filled by closeProxiedOutcomes and read by
// closeProxiedFailures, both pure.
func TestCloseProxiedFailuresRecordTheTypedErrorNotTheDisplayLine(t *testing.T) {
blockedErr := fmt.Errorf("%w: pb-2 is blocked by [pb-1]", storage.ErrCloseBlocked)
// arg 0 closes, arg 1 is refused by the engine.
args := []string{"pb-3", "pb-2"}
pre := closeProxiedPreflight{
items: []issueops.BatchCloseItem{
{IssueID: "pb-3", Reason: "done"},
{IssueID: "pb-2", Reason: "done"},
},
itemArgs: []int{0, 1},
before: map[string]*types.Issue{"pb-3": {ID: "pb-3"}},
errors: make([]string, len(args)),
failureErrors: make([]string, len(args)),
}
outcomes, _ := closeProxiedOutcomes(&pre, issueops.CloseBatchResult{
Outcomes: []issueops.CloseOutcome{
{IssueID: "pb-3", Issue: &types.Issue{ID: "pb-3"}, Changed: true},
{IssueID: "pb-2", Err: blockedErr},
},
})
if len(outcomes) != 1 || outcomes[0].id != "pb-3" {
t.Fatalf("outcomes = %+v, want only the survivor pb-3", outcomes)
}
failures := closeProxiedFailures(&pre, args)
if len(failures) != 1 || failures[0].ID != "pb-2" {
t.Fatalf("failures = %+v, want exactly the refused id pb-2", failures)
}
// The machine field is the typed error, byte for byte.
if failures[0].Error != blockedErr.Error() {
t.Errorf("failed[].error = %q, want the typed error %q: a --json consumer keying off this field must see the same string on both routes",
failures[0].Error, blockedErr.Error())
}
if strings.Contains(failures[0].Error, "use --force to override") {
t.Errorf("failed[].error = %q, must not carry the --force hint: that is advice for a human reader, and the direct route records res.Err.Error() here",
failures[0].Error)
}
// ...and the human line keeps the decoration. Without this half the fix
// could have passed by stripping the hint from stderr too, which is a
// different regression.
if want := closeProxiedRefusal("pb-2", blockedErr); pre.errors[1] != want {
t.Errorf("stderr line = %q, want the decorated refusal %q", pre.errors[1], want)
}
if !strings.Contains(pre.errors[1], "use --force to override") {
t.Errorf("stderr line = %q, want it to keep the --force hint for the person reading it", pre.errors[1])
}
}
// Every engine refusal class closeProxiedRefusal decorates, checked against the
// typed error it decorates. ErrCloseOpenChildren is in the table on purpose: it
// passes through undecorated, so it is the row that would still pass if the fix
// had been written as "special-case the blocked hint" instead of "record the
// typed error".
func TestCloseProxiedFailuresTypedErrorPerRefusalClass(t *testing.T) {
tests := []struct {
name string
err error
}{
{
name: "blocked gains the force hint on stderr",
err: fmt.Errorf("%w: rc-1 is blocked by [rc-9]", storage.ErrCloseBlocked),
},
{
name: "not found is rewritten on stderr",
err: fmt.Errorf("%w: rc-1", storage.ErrNotFound),
},
{
name: "default class is wrapped on stderr",
err: fmt.Errorf("dolt: connection reset"),
},
{
name: "open children passes through undecorated",
err: &storage.CloseOpenChildrenError{IssueID: "rc-1", OpenChildren: 2},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
args := []string{"rc-1"}
pre := closeProxiedPreflight{
items: []issueops.BatchCloseItem{{IssueID: "rc-1", Reason: "done"}},
itemArgs: []int{0},
before: map[string]*types.Issue{},
errors: make([]string, len(args)),
failureErrors: make([]string, len(args)),
}
closeProxiedOutcomes(&pre, issueops.CloseBatchResult{
Outcomes: []issueops.CloseOutcome{{IssueID: "rc-1", Err: tc.err}},
})
failures := closeProxiedFailures(&pre, args)
if len(failures) != 1 {
t.Fatalf("failures = %+v, want one", failures)
}
if failures[0].Error != tc.err.Error() {
t.Errorf("failed[].error = %q, want the typed error %q", failures[0].Error, tc.err.Error())
}
if pre.errors[0] != closeProxiedRefusal("rc-1", tc.err) {
t.Errorf("stderr line = %q, want closeProxiedRefusal's spelling %q", pre.errors[0], closeProxiedRefusal("rc-1", tc.err))
}
})
}
}
// The second half of the route-parity contract, and the one the decoration fix
// alone does not deliver: a refusal that reached the proxied route arrives
// wrapped by the layers it travelled through, so even the undecorated typed
// error read differently per route until closeProxiedTypedRefusal unwrapped it.
//
// The wrapper strings here are transcribed from the two production sites named
// in that function's comment, and the "want" column is the byte-identical
// string the direct route records for the same refusal.
func TestCloseProxiedTypedRefusalUnwrapsTheRoleWrappers(t *testing.T) {
blocked := fmt.Errorf("%w: wr-1 is blocked by [wr-2]", storage.ErrCloseBlocked)
openChildren := &storage.CloseOpenChildrenError{IssueID: "wr-1", OpenChildren: 3}
unexpected := fmt.Errorf("dolt: connection reset")
// What the role actually hands back: db/issue.go wraps, then issue.go wraps.
roleWrapped := func(inner error) error {
return fmt.Errorf("close wr-1: %w", fmt.Errorf("db: IssueSQLRepository.CloseChecked wr-1: %w", inner))
}
tests := []struct {
name string
err error
want string
}{
{
name: "blocked, unwrapped",
err: blocked,
want: blocked.Error(),
},
{
name: "blocked, wrapped by the role",
err: roleWrapped(blocked),
want: blocked.Error(),
},
{
name: "open children, wrapped by the role",
err: roleWrapped(openChildren),
want: openChildren.Error(),
},
{
// No sentinel to converge on, and the chain is the only thing that
// says where the failure came from, so it is kept whole.
name: "unexpected error keeps its whole chain",
err: roleWrapped(unexpected),
want: "close wr-1: db: IssueSQLRepository.CloseChecked wr-1: dolt: connection reset",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if got := closeProxiedTypedRefusal(tc.err); got != tc.want {
t.Errorf("closeProxiedTypedRefusal = %q, want %q", got, tc.want)
}
})
}
// The walk must stop AT the refusal, not at the bare sentinel underneath
// it: unwrapping one link too far would drop the subject and leave every
// blocked id reporting the same reasonless sentence.
if got := closeProxiedTypedRefusal(roleWrapped(blocked)); got == storage.ErrCloseBlocked.Error() {
t.Errorf("closeProxiedTypedRefusal = %q, which is the bare sentinel: the id and its blockers were unwrapped away", got)
}
}
// A refusal decided by the CLI's own close policy has no separate display form,
// so both fields hold the one sentence closeProxiedCheckOne returned — and the
// failures still come back in the order the caller typed the ids, across a mix
// of policy and engine refusals. errors is what decides WHICH arguments failed,
// so a policy slot with an empty failureErrors twin would be a silent
// reason-less entry; this pins that it is not.
func TestCloseProxiedFailuresKeepPolicyRefusalsAndTypedOrder(t *testing.T) {
policyRefusal := "cannot close mx-1: gate not satisfied"
engineErr := fmt.Errorf("%w: mx-3 is blocked by [mx-9]", storage.ErrCloseBlocked)
// arg 0 refused by policy, arg 1 closes, arg 2 refused by the engine.
args := []string{"mx-1", "mx-2", "mx-3"}
pre := closeProxiedPreflight{
items: []issueops.BatchCloseItem{
{IssueID: "mx-2", Reason: "done"},
{IssueID: "mx-3", Reason: "done"},
},
itemArgs: []int{1, 2},
before: map[string]*types.Issue{"mx-2": {ID: "mx-2"}},
errors: make([]string, len(args)),
failureErrors: make([]string, len(args)),
}
// closeProxiedRunPreflight fills both slots for a policy refusal.
pre.errors[0] = policyRefusal
pre.failureErrors[0] = policyRefusal
closeProxiedOutcomes(&pre, issueops.CloseBatchResult{
Outcomes: []issueops.CloseOutcome{
{IssueID: "mx-2", Issue: &types.Issue{ID: "mx-2"}, Changed: true},
{IssueID: "mx-3", Err: engineErr},
},
})
failures := closeProxiedFailures(&pre, args)
want := []closeIDFailure{
{ID: "mx-1", Error: policyRefusal},
{ID: "mx-3", Error: engineErr.Error()},
}
if len(failures) != len(want) {
t.Fatalf("failures = %+v, want %+v", failures, want)
}
for i := range want {
if failures[i] != want[i] {
t.Errorf("failures[%d] = %+v, want %+v", i, failures[i], want[i])
}
}
// An entry never goes out reason-less. No production writer can reach this
// state — both fill the twin — but the degradation is defined rather than
// accidental, because an empty reason is the one answer a caller asking why
// an id failed cannot use.
pre.failureErrors[0] = ""
if got := closeProxiedFailures(&pre, args); got[0].Error != policyRefusal {
t.Errorf("failures[0].Error = %q, want the display line %q as the fallback", got[0].Error, policyRefusal)
}
}

View file

@ -0,0 +1,84 @@
//go:build cgo
package main
import (
"bytes"
"encoding/json"
"fmt"
"os/exec"
"strings"
"sync"
"testing"
"github.com/steveyegge/beads/internal/types"
)
// TestProxiedServerCloseSiblingBlockersFanIn is gastownhall/beads#6716 end to
// end on the proxied CLI: the fan-in of a formula whose parallel workers
// close the two blockers of one step at the same time. Each round closes the
// blockers with two concurrent `bd close` processes and then requires the
// dependent in `bd ready`. Without the post-commit recheck on the uow path a
// round whose closes overlap leaves the dependent is_blocked=1 and missing
// from ready work. The interleaving is not pinned here (see
// TestProxiedBlockedRecheckAfterRacingUnblocks in internal/storage/uow for
// the deterministic race); this proves the settled CLI outcome.
func TestProxiedServerCloseSiblingBlockersFanIn(t *testing.T) {
requireSharedProxiedServer(t)
t.Parallel()
bd := buildEmbeddedBD(t)
p := newSharedProxiedProject(t, bd, "fan")
const rounds = 6
for round := 0; round < rounds; round++ {
a := bdProxiedCreate(t, bd, p.dir, fmt.Sprintf("round %d blocker a", round)).ID
b := bdProxiedCreate(t, bd, p.dir, fmt.Sprintf("round %d blocker b", round)).ID
c := bdProxiedCreate(t, bd, p.dir, fmt.Sprintf("round %d fan-in", round)).ID
for _, blocker := range []string{a, b} {
if out, err := bdProxiedRun(t, bd, p.dir, "dep", "add", c, blocker); err != nil {
t.Fatalf("round %d: dep add %s %s: %v\n%s", round, c, blocker, err, out)
}
}
var wg sync.WaitGroup
errs := make([]string, 2)
for i, id := range []string{a, b} {
wg.Add(1)
go func() {
defer wg.Done()
cmd := exec.Command(bd, "close", id)
cmd.Dir = p.dir
cmd.Env = bdProxiedEnv(p.dir)
var stderr bytes.Buffer
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
errs[i] = fmt.Sprintf("close %s: %v\n%s", id, err, stderr.String())
}
}()
}
wg.Wait()
if joined := strings.TrimSpace(strings.Join(errs, "")); joined != "" {
t.Fatalf("round %d: %s", round, joined)
}
out, err := bdProxiedRun(t, bd, p.dir, "ready", "--json", "--limit", "0")
if err != nil {
t.Fatalf("round %d: bd ready: %v\n%s", round, err, out)
}
start := bytes.IndexByte(out, '[')
if start < 0 {
t.Fatalf("round %d: bd ready printed no JSON array: %s", round, out)
}
var ready []types.Issue
if err := json.Unmarshal(out[start:], &ready); err != nil {
t.Fatalf("round %d: parse bd ready: %v\n%s", round, err, out)
}
found := false
for _, issue := range ready {
found = found || issue.ID == c
}
if !found {
t.Fatalf("round %d: %s has both blockers closed but is missing from bd ready", round, c)
}
}
}

View file

@ -42,6 +42,19 @@ func bdProxiedCloseFail(t *testing.T, bd, dir string, args ...string) string {
return stdout + stderr
}
// lastJSONObjectLine returns the last line of s that looks like a compact JSON
// object, or "". Partial-failure stderr is the per-id refusal prose followed by
// the machine-readable summary, so the report is the last such line.
func lastJSONObjectLine(s string) string {
lines := strings.Split(strings.TrimSpace(s), "\n")
for i := len(lines) - 1; i >= 0; i-- {
if line := strings.TrimSpace(lines[i]); strings.HasPrefix(line, "{") {
return line
}
}
return ""
}
func bdProxiedCloseJSON(t *testing.T, bd, dir string, args ...string) []*types.Issue {
t.Helper()
fullArgs := append([]string{"close", "--json"}, args...)
@ -363,6 +376,90 @@ func TestProxiedServerClose(t *testing.T) {
}
})
t.Run("close_partial_failure_exits_nonzero", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "cpf")
closable := bdProxiedCreate(t, bd, p.dir, "Closable")
blocker := bdProxiedCreate(t, bd, p.dir, "Blocker")
blocked := bdProxiedCreate(t, bd, p.dir, "Blocked", "--deps", "depends-on:"+blocker.ID)
out := bdProxiedCloseFail(t, bd, p.dir, closable.ID, blocked.ID)
if !strings.Contains(out, "1 of 2 issues failed to close") {
t.Errorf("expected partial-failure summary, got: %s", out)
}
db := openProxiedDB(t, p)
if got := readStatus(t, db, closable.ID); got != types.StatusClosed {
t.Errorf("closable issue status = %q, want closed despite the refused sibling", got)
}
if got := readStatus(t, db, blocked.ID); got == types.StatusClosed {
t.Error("blocked issue should remain open without --force")
}
})
// The machine-readable half of the #6648 contract. A JSON consumer is
// exactly the caller the issue was filed for, so exit 1 must come with a
// payload naming the failed ids instead of prose it would have to scrape —
// while stdout keeps the success-shaped closed-issues array, the way
// bd update's reportUpdateFailures already splits them.
t.Run("close_partial_failure_json_names_the_failed_ids", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "cpj")
closable := bdProxiedCreate(t, bd, p.dir, "JSON closable")
blocker := bdProxiedCreate(t, bd, p.dir, "JSON blocker")
blocked := bdProxiedCreate(t, bd, p.dir, "JSON blocked", "--deps", "depends-on:"+blocker.ID)
stdout, stderr, err := bdProxiedRunBuffers(t, bd, p.dir, "close", "--json", closable.ID, blocked.ID)
if err == nil {
t.Fatalf("expected a partial batch close to exit nonzero\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
}
// stdout keeps the success shape: just the survivor.
start := strings.Index(stdout, "[")
if start < 0 {
t.Fatalf("expected the closed-issues array on stdout, got:\n%s", stdout)
}
var closed []*types.Issue
if jsonErr := json.Unmarshal([]byte(stdout[start:]), &closed); jsonErr != nil {
t.Fatalf("parse closed array: %v\nraw: %s", jsonErr, stdout[start:])
}
if len(closed) != 1 || closed[0].ID != closable.ID {
t.Fatalf("stdout closed array = %d issue(s) %v, want only the survivor %s", len(closed), closed, closable.ID)
}
// stderr's last line is the failure report.
line := lastJSONObjectLine(stderr)
if line == "" {
t.Fatalf("expected a compact JSON failure line on stderr, got:\n%s", stderr)
}
var report struct {
Error string `json:"error"`
Failed []struct {
ID string `json:"id"`
Error string `json:"error"`
} `json:"failed"`
}
if jsonErr := json.Unmarshal([]byte(line), &report); jsonErr != nil {
t.Fatalf("parse failure report: %v\nraw: %s", jsonErr, line)
}
if report.Error != "1 of 2 issues failed to close" {
t.Errorf("failure report error = %q, want the N of M summary", report.Error)
}
if len(report.Failed) != 1 || report.Failed[0].ID != blocked.ID {
t.Fatalf("failure report named %+v, want exactly the refused id %s", report.Failed, blocked.ID)
}
if report.Failed[0].Error == "" {
t.Errorf("failure report for %s carried no reason", blocked.ID)
}
// failed[].error is the TYPED error, the same on this route as on the
// direct one — see the twin assertions in TestEmbeddedClose/
// close_partial_failure_json_names_the_failed_ids. The --force hint is
// advice for a human reader, so it belongs on the stderr line above and
// not in the field a --json consumer keys off; recording the decorated
// display line here gave the identical refusal two spellings depending
// on which route the caller was on.
assertCloseFailedErrorIsTyped(t, report.Failed[0].Error, stderr)
})
t.Run("close_pinned_refuses_without_force", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "cpr")

View file

@ -39,11 +39,22 @@ type closeProxiedInput struct {
// errors is indexed by ARGUMENT position, not by item, so a refusal reported
// here and one reported by the batch still print in the order the caller typed
// the ids.
//
// failureErrors is the same list at the same indices, but carries what a --json
// consumer reads instead of what a person reads: the TYPED error for an engine
// refusal, where errors holds closeProxiedRefusal's decorated display line. The
// direct route makes exactly this split (close.go records res.Err.Error() in
// closeIDFailure while printing closeDirectRefusal), and keeping the decorated
// line in the machine-readable field made the same refusal answer differently
// per route — which is the drift this whole close rewire exists to remove. A
// policy refusal decided here has no separate display form, so both slots hold
// the one sentence closeProxiedCheckOne returned.
type closeProxiedPreflight struct {
items []issueops.BatchCloseItem
itemArgs []int
before map[string]*types.Issue
errors []string
items []issueops.BatchCloseItem
itemArgs []int
before map[string]*types.Issue
errors []string
failureErrors []string
}
type closeProxiedOutcome struct {
@ -127,6 +138,7 @@ func runCloseProxiedServer(cmd *cobra.Command, ctx context.Context, args []strin
fmt.Fprintln(os.Stderr, e)
}
}
failures := closeProxiedFailures(&pre, args)
for _, w := range post.warnings {
fmt.Fprintf(os.Stderr, "Warning: %s\n", w)
}
@ -182,6 +194,9 @@ func runCloseProxiedServer(cmd *cobra.Command, ctx context.Context, args []strin
}
}
if len(failures) > 0 {
return reportCloseFailures(failures, len(args), closeClaimedID(claimedNextIssue), in.jsonOut)
}
if len(args) > 0 && len(outcomes) == 0 {
return SilentExit()
}
@ -223,14 +238,19 @@ func proxiedBatchCloser() (issueops.BatchCloser, error) {
// close policy to it, in one read-only unit of work.
func closeProxiedRunPreflight(ctx context.Context, args, reasons []string, in closeProxiedInput) (closeProxiedPreflight, error) {
pre := closeProxiedPreflight{
errors: make([]string, len(args)),
before: make(map[string]*types.Issue, len(args)),
errors: make([]string, len(args)),
failureErrors: make([]string, len(args)),
before: make(map[string]*types.Issue, len(args)),
}
_, err := uow.RunTxRead(ctx, uowProvider, func(ctx context.Context, uw uow.UnitOfWork) (struct{}, error) {
for i, id := range args {
refusal, current := closeProxiedCheckOne(ctx, uw, id, in)
if refusal != "" {
pre.errors[i] = refusal
// A policy refusal is already the bare sentence, so the human
// and machine fields agree; only the engine refusals below have
// a decorated display form to strip.
pre.failureErrors[i] = refusal
continue
}
pre.before[id] = current
@ -292,6 +312,10 @@ func closeProxiedOutcomes(pre *closeProxiedPreflight, result issueops.CloseBatch
item := pre.items[j]
if outcome.Err != nil {
pre.errors[pre.itemArgs[j]] = closeProxiedRefusal(item.IssueID, outcome.Err)
// The typed error, not the decorated display line: the --force hint
// closeProxiedRefusal appends is advice for a human reader, and the
// id already has its own field. Same split as the direct route.
pre.failureErrors[pre.itemArgs[j]] = closeProxiedTypedRefusal(outcome.Err)
continue
}
before := pre.before[item.IssueID]
@ -319,6 +343,82 @@ func closeProxiedOutcomes(pre *closeProxiedPreflight, result issueops.CloseBatch
return outcomes, reasons
}
// closeProxiedFailures pairs every refused argument with the id it belongs to,
// for the machine-readable half of the partial-failure report.
//
// Both slices are indexed by ARGUMENT position, so args[i] is the id that earned
// pre.errors[i], and the failures come back in the order the caller typed the
// ids. errors decides WHICH arguments failed — it is the slot the stderr print
// consults too, so the two halves of the report can never disagree about that —
// while failureErrors supplies the reason, because that is the field where the
// typed error belongs.
//
// Every writer of an errors slot fills its failureErrors twin, so the fallback
// below is unreachable today. It is here because the cost of getting that wrong
// is asymmetric: a caller that asked why an id failed is better served by the
// decorated line than by an empty string, so a future writer that forgets the
// twin degrades the wording instead of dropping the reason.
func closeProxiedFailures(pre *closeProxiedPreflight, args []string) []closeIDFailure {
var failures []closeIDFailure
for i, e := range pre.errors {
if e == "" {
continue
}
reason := pre.failureErrors[i]
if reason == "" {
reason = e
}
failures = append(failures, closeIDFailure{ID: args[i], Error: reason})
}
return failures
}
// closeProxiedTypedRefusal is the reason a --json consumer reads for one
// refused id: the typed error, spelled the way the direct route spells it.
//
// Stripping closeProxiedRefusal's decoration is not enough on its own to make
// the two routes agree, because a refusal reaching this route has also been
// wrapped by the layers it traveled through — the use case adds "close <id>: "
// (storage/domain/issue.go) and the SQL repository adds
// "db: IssueSQLRepository.CloseChecked <id>: " (storage/domain/db/issue.go) —
// while the direct route hands back the refusal exactly as the engine minted
// it. So the same blocked id reads
//
// cannot close blocked issue: x-1 is blocked by [x-2] (direct)
// close x-1: db: IssueSQLRepository.CloseChecked x-1: cannot close blocked … (proxied)
//
// For the refusal classes the CLI already names by sentinel, we report the
// outermost error that the sentinel itself explains: that is the sentence the
// engine wrote, and it is byte-identical to the direct route's. Neither wrap
// tells a caller anything it does not know — it asked to close that id — and
// one of them leaks an internal repository type name into an operator-facing
// field.
//
// Anything outside those classes keeps its whole chain. There the wrapping is
// not noise, it is the only thing that says where an unexpected failure came
// from, and there is no engine sentence to converge on.
func closeProxiedTypedRefusal(err error) string {
for _, sentinel := range []error{storage.ErrCloseBlocked, storage.ErrCloseOpenChildren} {
if !errors.Is(err, sentinel) {
continue
}
// Walk in until the next link IS the bare sentinel: that link's parent
// is the refusal with its subject filled in ("… x-1 is blocked by
// [x-2]"), where the sentinel alone would say only "cannot close
// blocked issue".
refusal := err
for {
next := errors.Unwrap(refusal)
if next == nil || next == sentinel || !errors.Is(next, sentinel) {
break
}
refusal = next
}
return refusal.Error()
}
return err.Error()
}
// closeProxiedRefusal spells one item's typed refusal the way this route has
// always spelled it. The vocabulary is matched with errors.Is rather than by
// reading the message, which is the point of the outcome carrying a typed

View file

@ -994,7 +994,11 @@ func validateStorageClassConfig(key, value string) error {
if canonical := issueType.Normalize(); canonical != issueType {
return fmt.Errorf("invalid key %q: %q is an alias of %q, and create-time lookup uses the canonical type; set storage-class.%s instead", key, suffix, canonical, canonical)
}
if !issueType.IsValidWithCustom(loadEmbeddedCustomTypes()) {
customTypes, err := resolveWorkspaceCustomTypes(rootCtx)
if err != nil {
return err
}
if !issueType.IsValidWithCustom(customTypes) {
return fmt.Errorf("invalid key %q: unknown issue type %q (use a built-in type, or add it to types.custom first)", key, suffix)
}
if _, err := types.ParseStorageClass(value); err != nil {

View file

@ -915,7 +915,7 @@ func createDepsAcceptedTypeList() string {
}
func init() {
createCmd.Flags().StringP("file", "f", "", "Create multiple issues from markdown file")
createCmd.Flags().StringP("file", "f", "", "Create one issue per ## heading (### fields attach to that issue); for title plus description-from-file, use --body-file")
createCmd.Flags().String("graph", "", "Create a graph of issues with dependencies from JSON plan file")
createCmd.Flags().String("title", "", "Issue title (alternative to positional argument)")
createCmd.Flags().Bool("silent", false, "Output only the issue ID (for scripting)")

View file

@ -171,3 +171,46 @@ func TestCreateSingleIssueAllowEmptyDescriptionRoundTrip(t *testing.T) {
t.Fatalf("expected issue %q to be created via --allow-empty-description opt-in", title)
}
}
// TestCreateFileDispatchRejectsPositionalTitle is a regression test for
// gastownhall/beads#4643: --file is a batch-import route, so a positional
// title has nowhere to go once createIssuesFromMarkdown takes over. This
// asserts gatherCreateInput's existing guard still rejects the combination
// before any issue is written, rather than silently discarding the title.
func TestCreateFileDispatchRejectsPositionalTitle(t *testing.T) {
saveAndRestoreGlobals(t)
ensureCleanGlobalState(t)
readonlyMode = false
t.Cleanup(func() { readonlyMode = false })
fileFlag := createCmd.Flags().Lookup("file")
t.Cleanup(func() {
_ = fileFlag.Value.Set("")
fileFlag.Changed = false
})
tmpDir := t.TempDir()
mdPath := filepath.Join(tmpDir, "single.md")
if err := os.WriteFile(mdPath, []byte("## My Bead\n\nBody text.\n"), 0644); err != nil {
t.Fatalf("write markdown fixture: %v", err)
}
if err := createCmd.Flags().Set("file", mdPath); err != nil {
t.Fatalf("set --file: %v", err)
}
var err error
stderr := captureStderr(t, func() {
err = createCmd.RunE(createCmd, []string{"my new bead"})
})
if err == nil {
t.Fatal("expected --file dispatch with a positional title to be rejected")
}
if !strings.Contains(stderr, "cannot specify both title and --file flag") {
t.Fatalf("expected title/--file conflict message on stderr, got: %v (err: %v)", stderr, err)
}
if !strings.Contains(stderr, "--body-file") {
t.Fatalf("expected title/--file conflict to hint at --body-file, got: %v (err: %v)", stderr, err)
}
}

View file

@ -97,7 +97,7 @@ func gatherCreateInput(cmd *cobra.Command, args []string) (createInput, error) {
}
if in.markdownFile != "" {
if len(args) > 0 {
return in, HandleError("cannot specify both title and --file flag")
return in, HandleError("cannot specify both title and --file flag; for a single issue's description from a file, use --body-file")
}
if in.dryRun {
return in, HandleError("--dry-run is not supported with --file flag")

View file

@ -40,6 +40,36 @@ func TestCreateCommandRegistersEmptyDescriptionOptIn(t *testing.T) {
}
}
func TestCreateFileFlagHelpDoesNotClaimSingleIssueGH4643(t *testing.T) {
f := createCmd.Flags().Lookup("file")
if f == nil {
t.Fatal("expected create to register --file")
}
if !strings.Contains(f.Usage, "one issue per") {
t.Fatalf("expected --file help text to name its per-heading batch behavior, got: %q", f.Usage)
}
if !strings.Contains(f.Usage, "--body-file") {
t.Fatalf("expected --file help text to point single-issue callers at --body-file, got: %q", f.Usage)
}
}
func TestGatherCreateInputRejectsTitleWithFile(t *testing.T) {
cmd := newCreateFlagsCommand(t, "--file", "issues.md")
var err error
stderr := captureStderr(t, func() {
_, err = gatherCreateInput(cmd, []string{"Some title"})
})
if err == nil {
t.Fatal("expected gatherCreateInput to reject a positional title with --file")
}
if !strings.Contains(stderr, "cannot specify both title and --file flag") {
t.Fatalf("expected title/--file conflict on stderr, got stderr=%q err=%v", stderr, err)
}
if !strings.Contains(stderr, "--body-file") {
t.Fatalf("expected title/--file conflict to hint at --body-file, got stderr=%q err=%v", stderr, err)
}
}
func TestGatherCreateInputRejectsEmptyBodyFile(t *testing.T) {
filePath := filepath.Join(t.TempDir(), "empty.md")
if err := os.WriteFile(filePath, nil, 0644); err != nil {

View file

@ -11,7 +11,6 @@ import (
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/storage/domain"
"github.com/steveyegge/beads/internal/storage/uow"
@ -21,13 +20,6 @@ import (
"github.com/steveyegge/beads/issueops"
)
func resolveProxiedCustomTypes(dbTypes []string) []string {
if len(dbTypes) > 0 {
return dbTypes
}
return config.GetCustomTypesFromYAML()
}
func runCreateProxiedServer(cmd *cobra.Command, ctx context.Context, in createInput) error {
if in.repoOverrideSet {
return HandleProxyCapabilityError(AssertProxyCapability(ProxyModeProxied, ProxyCapRepo))
@ -390,7 +382,7 @@ func runCreateProxiedGraph(_ *cobra.Command, ctx context.Context, in createInput
// The returned useWisp is the plan-wide table routing decision.
func validateProxiedGraphPlan(plan *GraphApplyPlan, in createInput, cctx domain.CreateContext, issueExists func(id string) (bool, error)) (useWisp bool, err error) {
cfg := graphPlanConfig{
customTypes: resolveProxiedCustomTypes(cctx.CustomTypes),
customTypes: cctx.CustomTypes,
// No YAML fallback for statuses — the server database is authoritative
// (that's where 'bd config set status.custom' writes) and statuses are
// store-only everywhere (single-issue create, list filters), unlike

View file

@ -3,13 +3,10 @@ package main
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"reflect"
"testing"
"time"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/issueops"
)
@ -473,55 +470,3 @@ func TestParseMarkdownDependencies_DoesNotSwapBlocks(t *testing.T) {
t.Errorf("got %#v, want %#v (no swap-direction)", got, want)
}
}
func TestResolveProxiedCustomTypes_PrefersDBTypes(t *testing.T) {
got := resolveProxiedCustomTypes([]string{"db-a", "db-b"})
if !reflect.DeepEqual(got, []string{"db-a", "db-b"}) {
t.Errorf("got %#v, want [db-a db-b] — DB types must win when non-empty", got)
}
}
func TestResolveProxiedCustomTypes_FallsBackToYAML(t *testing.T) {
restore := withTestYAMLCustomTypes(t, "molecule,gate,convoy")
defer restore()
for _, dbTypes := range [][]string{nil, {}} {
got := resolveProxiedCustomTypes(dbTypes)
if !reflect.DeepEqual(got, []string{"molecule", "gate", "convoy"}) {
t.Errorf("dbTypes=%v: got %#v, want YAML fallback [molecule gate convoy]", dbTypes, got)
}
}
}
func TestResolveProxiedCustomTypes_EmptyEverywhere(t *testing.T) {
restore := withTestYAMLCustomTypes(t, "")
defer restore()
got := resolveProxiedCustomTypes(nil)
if len(got) != 0 {
t.Errorf("expected empty result, got %#v", got)
}
}
func withTestYAMLCustomTypes(t *testing.T, customCSV string) func() {
t.Helper()
tmpDir := t.TempDir()
beadsDir := filepath.Join(tmpDir, ".beads")
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
t.Fatalf("mkdir .beads: %v", err)
}
var content string
if customCSV != "" {
content = "types:\n custom: \"" + customCSV + "\"\n"
}
if err := os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte(content), 0o644); err != nil {
t.Fatalf("write config.yaml: %v", err)
}
t.Chdir(tmpDir)
config.ResetForTesting()
if err := config.Initialize(); err != nil {
t.Fatalf("config.Initialize: %v", err)
}
return func() { config.ResetForTesting() }
}

View file

@ -65,6 +65,7 @@ dolt-server.log
dolt-server.lock
dolt-server.port
dolt-server.activity
dolt-server-config.yaml
# Debug-mode pprof artifacts (written when dolt.debug: true in config.yaml)
dolt-pprof/
@ -129,6 +130,7 @@ var requiredPatterns = []string{
"dolt-server.lock",
"dolt-server.port",
"dolt-server.activity",
"dolt-server-config.yaml",
"daemon.*",
"*.lock",
"*.corrupt.backup/",

View file

@ -1522,6 +1522,39 @@ func TestRequiredPatterns_ContainsSyncStatePatterns(t *testing.T) {
}
}
// TestGitignore_ContainsDoltServerConfig verifies that the generated Dolt
// server config is ignored like the other dolt-server.* runtime state files
// it sits beside. doltserver.Start() writes .beads/dolt-server-config.yaml
// when the resolved dolt binary supports auto_gc_behavior.archive_level, and
// it holds an absolute cfg_dir plus a per-machine port, so committing it
// would break every other clone.
//
// The hyphenated name falls outside the "dolt-server." prefix shared by the
// other five entries, so it was missed by both lists. It must be in
// requiredPatterns too, otherwise bd doctor --fix cannot heal an existing
// .beads/.gitignore.
func TestGitignore_ContainsDoltServerConfig(t *testing.T) {
// Keep this in sync with doltserver.doltServerConfigFileName. It is not
// imported here because cmd/bd/doctor must not depend on the server
// package for a string constant.
const pattern = "dolt-server-config.yaml"
if !containsGitignorePattern(GitignoreTemplate, pattern) {
t.Errorf("GitignoreTemplate should contain %q", pattern)
}
found := false
for _, p := range requiredPatterns {
if p == pattern {
found = true
break
}
}
if !found {
t.Errorf("requiredPatterns should include %q", pattern)
}
}
// TestCheckLastTouchedNotTracked_NoFile verifies that check passes when no last-touched file exists
func TestCheckLastTouchedNotTracked_NoFile(t *testing.T) {
tmpDir := t.TempDir()

View file

@ -728,26 +728,47 @@ For more options (--stdin, custom messages), see: bd vc commit`,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
st := getStore()
if st == nil {
return HandleError("no store available")
}
msg, _ := cmd.Flags().GetString("message")
if msg == "" {
msg = fmt.Sprintf("bd: dolt commit (auto-commit) by %s", getActor())
}
// CommitAll, not Commit: this command's contract is "any uncommitted
// changes in the working set", including changes made externally and
// the config table — which server-mode Commit excludes (GH#2455), so
// out-of-band config dirt used to survive this command forever. Its
// committed bool also replaces the HEAD-before/HEAD-after comparison
// this command used to detect tolerated no-ops with, which cost two
// extra HEAD reads and raced against concurrent writers.
committed, err := st.CommitAll(ctx, msg)
var (
committed bool
err error
)
if usesProxiedServer() {
// Proxied mode never opens a store — the root pre-run returns
// before newDoltStore — so getStore() is nil here and the UOW
// provider is the only handle on the server. This is the flush
// point dolt.auto-commit=batch/off defers to on that route
// (GH#4995). The message is built above so both routes name the
// same default.
committed, err = runDoltCommitProxiedServer(ctx, msg)
} else {
st := getStore()
if st == nil {
return HandleError("no store available")
}
// CommitAll, not Commit: this command's contract is "any uncommitted
// changes in the working set", including changes made externally and
// the config table — which server-mode Commit excludes (GH#2455), so
// out-of-band config dirt used to survive this command forever. Its
// committed bool also replaces the HEAD-before/HEAD-after comparison
// this command used to detect tolerated no-ops with, which cost two
// extra HEAD reads and raced against concurrent writers.
committed, err = st.CommitAll(ctx, msg)
}
if err != nil {
if isDoltNothingToCommit(err) {
switch {
case isDoltNothingToCommit(err):
committed = false
} else {
case isReportedExit(err):
// The proxied route reports provider failures itself, through
// HandleErrorRespectJSON, so the JSON envelope is already on
// stdout; re-wrapping would print a second, plain Error line.
return err
default:
return HandleError("%v", err)
}
}
@ -773,7 +794,12 @@ The server runs in the background on a per-project port derived from the
project path. PID and logs are stored in .beads/.
The server auto-starts transparently when needed, so manual start is rarely
required. Use this command for explicit control or diagnostics.`,
required. Use this command for explicit control or diagnostics.
Not available in proxied-server mode: there the proxy owns its dolt backend's
lifecycle and starts it on demand, so a server started here would be a second,
unsupervised one over the same data directory. Use 'bd dolt status' to see what
is running and 'bd dolt stop' to shut it down.`,
RunE: func(cmd *cobra.Command, args []string) error {
beadsDir := selectedDoltBeadsDir()
if beadsDir == "" {
@ -783,6 +809,26 @@ required. Use this command for explicit control or diagnostics.`,
if err != nil {
return HandleError("%v", err)
}
// A proxied workspace already has a server manager. The proxy spawns
// its dolt child on demand and reaps the whole tree when idle, so
// there is no state for bd to add here — only a second one to
// collide with. With the tree down, doltserver.Start resolves the
// proxied root's own configured port and launches an unsupervised
// sql-server directly over .beads/dolt, and the next ordinary bd
// command then fails because the relaunched proxy finds a foreign
// server on its port; with the tree up, Start instead adopts the
// proxy's child into bd's classic PID/port records, leaving two
// managers for one process. Refused rather than routed: the proxy
// owns its child's lifecycle, and an idle reaper means a "started"
// postcondition bd cannot honor for more than the idle window.
//
// Both the process-wide mode and the selected workspace's own
// metadata are consulted, and this runs before the embedded guard:
// over-refusing costs an operator one error message, under-refusing
// costs them the datastore.
if usesProxiedServer() || fileCfg.IsDoltProxiedServerMode() {
return HandleProxyCapabilityError(proxiedDoltStartRefusal())
}
if !usesSQLServer() {
return HandleError("'bd dolt start' is not supported in embedded mode (no Dolt server)")
}
@ -790,7 +836,7 @@ required. Use this command for explicit control or diagnostics.`,
// server lifecycle (GH#3545/GH#3518): starting a repo-local
// server here would write local PID/port state that shadows the
// configured remote endpoint.
if host := fileCfg.GetDoltServerHost(); !usesProxiedServer() && !configfile.IsLocalHostString(host) {
if host := fileCfg.GetDoltServerHost(); !configfile.IsLocalHostString(host) {
return HandleError("the configured Dolt server host is remote (%s); 'bd dolt start' only manages a local server.\nStart the server on that host, or clear dolt_server_host / dolt.host / BEADS_DOLT_SERVER_HOST to run one locally", host)
}
serverDir := doltserver.ResolveServerDir(beadsDir)
@ -1067,7 +1113,12 @@ PID, port, and data directory from the local PID file. For externally-
managed servers — a shared server (dolt.shared-server: true), a remote
dolt_server_host, or a local server managed outside bd (dolt.auto-start:
false, e.g. an orchestrator-shared sql-server) — pings the configured
endpoint via SQL and reports reachability, server version, and database.`,
endpoint via SQL and reports reachability, server version, and database.
In proxied-server mode, reports the proxy (the endpoint every bd command
connects through) and the dolt backend behind it separately, read from the
proxy's own process records. Reporting starts nothing: a quiesced workspace
is shown as not running, and the next bd command launches it.`,
RunE: func(cmd *cobra.Command, args []string) error {
beadsDir := selectedDoltBeadsDir()
if beadsDir == "" {
@ -1090,6 +1141,21 @@ endpoint via SQL and reports reachability, server version, and database.`,
fmt.Printf("Backend: %s (no Dolt engine)\n", cfg.GetBackend())
return nil
}
// Neither branch below describes a proxied workspace. It writes no
// classic PID file, so the bd-managed path reports "not running"
// while the proxy is serving CRUD, and shouldUseExternalDoltStatus
// deliberately excludes proxied so the SQL-probe path never sees it
// either. Keyed on the loaded config rather than the process-wide
// mode so `bd --db <proxied workspace> dolt status` describes the
// workspace it was pointed at.
if cfg.IsDoltProxiedServerMode() {
status, err := collectProxiedDoltStatus(beadsDir)
if err != nil {
return HandleError("%v", err)
}
renderProxiedDoltStatus(status)
return nil
}
if !usesSQLServer() {
showEmbeddedDoltStatus(beadsDir)
return nil

View file

@ -91,6 +91,35 @@ func issueOpsContext(ctx context.Context) (context.Context, error) {
return issueops.WithDeferredVersionCommit(ctx), nil
}
// explicitCommitPointContext clears the dolt.auto-commit deferral for a proxied
// dual whose direct-route twin is an explicit commit point.
//
// The direct route encodes two commit classes, and it encodes them by which
// wrapper a verb picks: writes whose Dolt commit is auto-commit policy go
// through transactHonoringAutoCommit or issueOpsContext above, while the
// explicit commit points go through transact and mint a Dolt commit carrying
// the caller's message whatever the policy says. The proxied route has no such
// choice to make per verb — it applies the policy ONCE, to rootCtx in the root
// pre-run (GH#4995) — so the second class has to opt back out here, or
// doltServerTx.Commit blanks the message it was given: a proxied
// `bd batch -m "release batch"` under dolt.auto-commit=batch would persist the
// rows, discard the message and mint nothing, while the identical command and
// config on the direct route commits it.
//
// Scope is the intersection of two in-tree lists: the transact() call sites,
// and the paths the proxied front door permits (proxyPermittedPaths in
// capability_registry.go). That is batch, mol bond/pour/squash, mol wisp create
// and the WISP half of mol burn; cook and migrate issues also call transact but
// are refused in proxied mode, so they have no dual to exempt.
//
// Membership is per commit site, not per command: mol burn's persistent half
// reaches deleteBatch -> issueOpsContext on the direct route, which is the
// policy-honoring class, so runMolBurnProxiedServer exempts only the wisp
// transaction. TestProxiedDualsExemptTheirExplicitCommitPoints pins both arms.
func explicitCommitPointContext(ctx context.Context) context.Context {
return issueops.WithImmediateVersionCommit(ctx)
}
type doltAutoCommitParams struct {
// Command is the top-level bd command name (e.g., "create", "update").
Command string

View file

@ -0,0 +1,238 @@
package main
import (
"context"
"errors"
"testing"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/storage/domain"
"github.com/steveyegge/beads/internal/storage/issueops"
"github.com/steveyegge/beads/internal/storage/uow"
"github.com/steveyegge/beads/internal/types"
)
// The tests below pin the WIRING half of the GH#4995 exemption. The mechanism
// half — that WithImmediateVersionCommit defeats the route-wide deferral —
// is pinned in internal/storage/uow; what is pinned here is that each proxied
// dual whose direct twin is an explicit commit point actually hands that
// exemption to its transaction, and that the duals whose twin is NOT one do
// not. Without this, deleting explicitCommitPointContext from a dual is green
// in every lane that does not have a real proxied server.
//
// The seam is uow.RunTxResult's own first act: it asks the provider for a unit
// of work, passing the caller's context. A provider that records that context
// and then refuses observes exactly "the context this dual hands its
// transaction", with no server, no store and no fixture beyond the reads the
// dual makes to decide what to write.
var errStopBeforeProbeTx = errors.New("exemption wiring probe: stop before the transaction")
// exemptionProbeProvider serves readUOW to the first `reads` NewUOW calls (the
// dual's own read phase) and refuses the rest, recording every context it was
// handed. The refusal is not a serialization error, so RunTxResult treats it as
// permanent and makes exactly one NewUOW call per transaction.
type exemptionProbeProvider struct {
readUOW uow.UnitOfWork
reads int
ctxs []context.Context
}
func (p *exemptionProbeProvider) NewUOW(ctx context.Context) (uow.UnitOfWork, error) {
p.ctxs = append(p.ctxs, ctx)
if len(p.ctxs) <= p.reads {
return p.readUOW, nil
}
return nil, errStopBeforeProbeTx
}
func (p *exemptionProbeProvider) Close(context.Context) error { return nil }
// txCtxs is the contexts handed to RunTx*, in call order: everything after the
// leading read opens.
func (p *exemptionProbeProvider) txCtxs() []context.Context {
if len(p.ctxs) <= p.reads {
return nil
}
return p.ctxs[p.reads:]
}
// installExemptionProbe points the package's proxied provider at the probe for
// the duration of one test.
func installExemptionProbe(t *testing.T, p *exemptionProbeProvider) {
t.Helper()
prev := uowProvider
uowProvider = p
t.Cleanup(func() { uowProvider = prev })
}
// exemptionProbeUOW embeds the interface without implementing it: anything a
// dual's read phase needs beyond the three use cases below panics and names
// itself, rather than being silently satisfied.
type exemptionProbeUOW struct {
uow.UnitOfWork
issues domain.IssueUseCase
labels domain.LabelUseCase
deps domain.DependencyUseCase
}
func (u exemptionProbeUOW) Close(context.Context) {}
func (u exemptionProbeUOW) IssueUseCase() domain.IssueUseCase { return u.issues }
func (u exemptionProbeUOW) LabelUseCase() domain.LabelUseCase { return u.labels }
func (u exemptionProbeUOW) DependencyUseCase() domain.DependencyUseCase { return u.deps }
// CommentUseCase is collected by workapi.NewUOWDetailSource when the read
// phase resolves an id; nothing on that path calls it.
func (u exemptionProbeUOW) CommentUseCase() domain.CommentUseCase { return nil }
type exemptionProbeIssues struct {
domain.IssueUseCase
byID map[string]*types.Issue
}
func (s exemptionProbeIssues) GetIssue(_ context.Context, id string) (*types.Issue, error) {
if issue, ok := s.byID[id]; ok && !issue.Ephemeral {
return issue, nil
}
return nil, storage.ErrNotFound
}
func (s exemptionProbeIssues) GetWisp(_ context.Context, id string) (*types.Issue, error) {
if issue, ok := s.byID[id]; ok && issue.Ephemeral {
return issue, nil
}
return nil, storage.ErrNotFound
}
func (s exemptionProbeIssues) SearchIssues(_ context.Context, _ string, filter types.IssueFilter) (domain.SearchPage, error) {
var page domain.SearchPage
for _, id := range filter.IDs {
if issue, ok := s.byID[id]; ok {
page.Items = append(page.Items, issue)
}
}
return page, nil
}
type exemptionProbeLabels struct {
domain.LabelUseCase
}
func (exemptionProbeLabels) GetLabels(context.Context, string) ([]string, error) { return nil, nil }
func (exemptionProbeLabels) GetWispLabels(context.Context, string) ([]string, error) { return nil, nil }
type exemptionProbeDeps struct {
domain.DependencyUseCase
}
func (exemptionProbeDeps) ListWithIssueMetadata(context.Context, string, domain.DepListFilter) ([]*types.IssueWithDependencyMetadata, error) {
return nil, nil
}
func (exemptionProbeDeps) GetForIssueIDs(context.Context, []string) (map[string][]*types.Dependency, error) {
return nil, nil
}
func newExemptionProbeUOW(issues ...*types.Issue) uow.UnitOfWork {
byID := make(map[string]*types.Issue, len(issues))
for _, issue := range issues {
byID[issue.ID] = issue
}
return exemptionProbeUOW{
issues: exemptionProbeIssues{byID: byID},
labels: exemptionProbeLabels{},
deps: exemptionProbeDeps{},
}
}
// deferredRouteContext is what the proxied root pre-run hands every dispatch
// under dolt.auto-commit=batch/off.
func deferredRouteContext() context.Context {
return issueops.WithDeferredVersionCommit(context.Background())
}
// TestProxiedDualsExemptTheirExplicitCommitPoints pins the duals that reach
// their transaction directly. Deleting explicitCommitPointContext from any of
// them reds its row here.
func TestProxiedDualsExemptTheirExplicitCommitPoints(t *testing.T) {
cases := []struct {
name string
call func(context.Context)
}{
{
name: "batch",
call: func(ctx context.Context) {
_, _ = runBatchProxiedServer(ctx, nil, "bd: batch probe")
},
},
{
name: "mol bond",
call: func(ctx context.Context) {
_ = runMolBondProxiedServer(ctx, molBondInput{argA: "bd-a", argB: "bd-b"})
},
},
{
name: "mol squash",
call: func(ctx context.Context) {
_ = runMolSquashProxiedServer(ctx, molSquashInput{moleculeArg: "bd-mol"})
},
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
probe := &exemptionProbeProvider{}
installExemptionProbe(t, probe)
tc.call(deferredRouteContext())
txCtxs := probe.txCtxs()
if len(txCtxs) != 1 {
t.Fatalf("%s: got %d transaction context(s), want 1 — the dual never reached RunTx*", tc.name, len(txCtxs))
}
if issueops.VersionCommitDeferred(txCtxs[0]) {
t.Errorf("%s: the context handed to RunTx* still defers the version commit; "+
"its direct twin is an explicit commit point, so this dual must clear the deferral "+
"(doltServerTx.Commit blanks the message and mints nothing)", tc.name)
}
})
}
}
// TestProxiedMolBurnExemptsOnlyTheWispHalf pins the split. bd mol burn is two
// commit classes on the direct route: wisps go through burnWisps -> `transact`
// (explicit), persistent molecules go through deleteBatch -> issueOpsContext,
// whose deferral dolt's deleter honors by returning before DOLT_COMMIT. A
// command-wide exemption mints one commit per persistent molecule under
// batch/off, where the identical direct-route command defers them all.
func TestProxiedMolBurnExemptsOnlyTheWispHalf(t *testing.T) {
wisp := &types.Issue{ID: "bd-wisp1", Ephemeral: true}
persistent := &types.Issue{ID: "bd-mol1"}
probe := &exemptionProbeProvider{
reads: 1, // runMolBurnProxiedServer's classification read
readUOW: newExemptionProbeUOW(wisp, persistent),
}
installExemptionProbe(t, probe)
// force=true skips the interactive confirmation; dryRun=false so both
// halves reach their transaction.
_ = runMolBurnProxiedServer(deferredRouteContext(), []string{wisp.ID, persistent.ID}, false, true)
txCtxs := probe.txCtxs()
if len(txCtxs) != 2 {
t.Fatalf("got %d transaction context(s), want 2 (the wisp half then the persistent half); "+
"the classification read did not produce one of each", len(txCtxs))
}
if issueops.VersionCommitDeferred(txCtxs[0]) {
t.Errorf("wisp half: the context handed to RunTxResult still defers the version commit, " +
"but its direct twin (burnWisps -> transact) commits whatever dolt.auto-commit says")
}
if !issueops.VersionCommitDeferred(txCtxs[1]) {
t.Errorf("persistent half: the context handed to RunTxResult no longer defers the version commit, " +
"so a proxied `bd mol burn` mints one Dolt commit per persistent molecule under " +
"dolt.auto-commit=batch/off — its direct twin (deleteBatch -> issueOpsContext) defers them " +
"all to `bd dolt commit`")
}
}

View file

@ -284,3 +284,37 @@ func TestTransactHonoringAutoCommitBlanksMessageInServerBatch(t *testing.T) {
})
}
}
// TestIssueOpsContextDefersByModePolicyTable pins the policy half of GH#4995:
// issueOpsContext defers the Dolt version commit for batch/off and does not for
// on/unset. It deliberately does not claim to cover the proxied-server wiring —
// issueOpsContext branches only on writesCommitNow(), never on the storage
// mode, so setting proxiedServerMode here would prove nothing. The proxied
// wiring is pinned by TestProxiedServerBatchDefersThenDoltCommitAdvancesHeadOnce
// and the deferral itself by the doltserver_tx tests.
func TestIssueOpsContextDefersByModePolicyTable(t *testing.T) {
for _, tc := range []struct {
mode string
wantDeferred bool
}{
{mode: string(doltAutoCommitOn), wantDeferred: false},
{mode: string(doltAutoCommitBatch), wantDeferred: true},
{mode: string(doltAutoCommitOff), wantDeferred: true},
{mode: "", wantDeferred: false},
} {
t.Run("mode="+tc.mode, func(t *testing.T) {
saveStorageMode(t)
serverMode = false
proxiedServerMode = false
doltAutoCommit = tc.mode
ctx, err := issueOpsContext(context.Background())
if err != nil {
t.Fatalf("issueOpsContext: %v", err)
}
if got := storageissueops.VersionCommitDeferred(ctx); got != tc.wantDeferred {
t.Fatalf("VersionCommitDeferred = %v, want %v for mode %q", got, tc.wantDeferred, tc.mode)
}
})
}
}

View file

@ -0,0 +1,191 @@
//go:build cgo
package main
import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"testing"
)
// sqlCountValue extracts a COUNT(*) cell from bdProxiedSQLJSON. sqlValueEquals
// only answers "is it this number"; the batch-flush assertions need the number
// itself so a failure can report how far HEAD actually moved.
func sqlCountValue(v any) (float64, bool) {
switch x := v.(type) {
case float64:
return x, true
case string:
f, err := strconv.ParseFloat(x, 64)
return f, err == nil
default:
return 0, false
}
}
// TestProxiedServerBatchDefersThenDoltCommitAdvancesHeadOnce pins every half of
// GH#4995 on the proxied route: dolt.auto-commit=batch must leave policy writes
// in the working set (no Dolt commit per write), `bd dolt commit` must mint
// exactly one commit for the whole batch and attribute it to the actor, and the
// explicit commit points must keep minting their own commit with the caller's
// message despite the route-wide deferral.
//
// Before the proxied flush point existed, step 3 below failed with
// "no store available": proxied mode returns from the root pre-run before
// newDoltStore runs, so getStore() is nil and `bd dolt commit` had nothing to
// commit through. batch/off therefore meant "never commit" on this route.
func TestProxiedServerBatchDefersThenDoltCommitAdvancesHeadOnce(t *testing.T) {
requireProxiedServerEnv(t)
bd := buildEmbeddedBD(t)
p := bdProxiedInit(t, bd, "batchflush")
doltLogCount := func(t *testing.T) float64 {
t.Helper()
rows := bdProxiedSQLJSON(t, bd, p.dir, "SELECT COUNT(*) AS count FROM dolt_log")
if len(rows) != 1 {
t.Fatalf("expected one row from dolt_log count, got %d: %v", len(rows), rows)
}
n, ok := sqlCountValue(rows[0]["count"])
if !ok {
t.Fatalf("dolt_log count is not numeric: %#v", rows[0]["count"])
}
return n
}
headCommit := func(t *testing.T) map[string]interface{} {
t.Helper()
rows := bdProxiedSQLJSON(t, bd, p.dir,
"SELECT message, committer, email FROM dolt_log ORDER BY date DESC LIMIT 1")
if len(rows) != 1 {
t.Fatalf("expected one dolt_log row for HEAD, got %d: %v", len(rows), rows)
}
return rows[0]
}
head0 := doltLogCount(t)
// 1. Three writes under the batch policy must not mint any Dolt commit.
for i := 1; i <= 3; i++ {
title := fmt.Sprintf("batch write %d", i)
stdout, stderr, err := bdProxiedRunBuffers(t, bd, p.dir,
"--dolt-auto-commit", "batch", "create", title, "-p", "1")
if err != nil {
t.Fatalf("bd create %q failed: %v\nstdout:\n%s\nstderr:\n%s", title, err, stdout, stderr)
}
}
if got := doltLogCount(t); got != head0 {
t.Fatalf("batch writes minted Dolt commits: dolt_log went %v -> %v (want unchanged)", head0, got)
}
// 2. The writes are in the working set, not rolled back.
listOut, listErr, err := bdProxiedRunBuffers(t, bd, p.dir, "list", "--json")
if err != nil {
t.Fatalf("bd list --json failed: %v\nstdout:\n%s\nstderr:\n%s", err, listOut, listErr)
}
for i := 1; i <= 3; i++ {
title := fmt.Sprintf("batch write %d", i)
if !strings.Contains(listOut, title) {
t.Fatalf("deferred write %q is not readable after batch create:\n%s", title, listOut)
}
}
// 3. The explicit flush point mints exactly one commit for the batch.
stdout, stderr, err := bdProxiedRunBuffers(t, bd, p.dir,
"--actor", "flush-actor", "dolt", "commit", "-m", "batch flush")
if err != nil {
t.Fatalf("bd dolt commit failed in proxied mode: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
}
if !strings.Contains(stdout, "Committed.") {
t.Fatalf("bd dolt commit did not report a commit:\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
}
if got, want := doltLogCount(t), head0+1; got != want {
t.Fatalf("bd dolt commit did not advance HEAD exactly once: dolt_log %v -> %v (want %v)", head0, got, want)
}
// 3b. The flush is attributed to the bd actor, not the SQL session user.
// Under batch mode this is the only commit a whole batch of writes leaves
// behind, so `dolt log` has to be able to say whose batch it was — the
// '--author' DoltStorage.CommitAll passes on the direct route.
head := headCommit(t)
if got := head["message"]; got != "batch flush" {
t.Fatalf("flush commit message = %v, want %q (row: %v)", got, "batch flush", head)
}
if got := head["committer"]; got != "flush-actor" {
t.Fatalf("flush commit is not attributed to the actor: committer = %v, want %q (row: %v)", got, "flush-actor", head)
}
if got := head["email"]; got != "test@test.com" {
t.Fatalf("flush commit email = %v, want the git identity %q (row: %v)", got, "test@test.com", head)
}
// 4. A second flush with nothing pending is a no-op, not a second commit.
stdout, stderr, err = bdProxiedRunBuffers(t, bd, p.dir, "dolt", "commit", "-m", "second flush")
if err != nil {
t.Fatalf("second bd dolt commit failed: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
}
if !strings.Contains(stdout, "Nothing to commit.") {
t.Fatalf("second bd dolt commit did not report an empty working set:\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
}
if got, want := doltLogCount(t), head0+1; got != want {
t.Fatalf("second bd dolt commit advanced HEAD: dolt_log = %v (want %v)", got, want)
}
// 5. The deferral is policy-driven, not unconditional: with the default
// "on" policy a single create advances dolt_log by one on its own.
before := doltLogCount(t)
stdout, stderr, err = bdProxiedRunBuffers(t, bd, p.dir,
"--dolt-auto-commit", "on", "create", "immediate write", "-p", "1")
if err != nil {
t.Fatalf("bd create with --dolt-auto-commit on failed: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
}
if got, want := doltLogCount(t), before+1; got != want {
t.Fatalf("auto-commit=on did not commit per write: dolt_log %v -> %v (want %v)", before, got, want)
}
// 6. The deferral is per commit CLASS, not per route: `bd batch -m` is an
// explicit commit point (its direct-route twin calls transact, which mints
// regardless of policy), so under batch it must still commit, carrying the
// caller's message. A plain create in the same policy is the control.
before = doltLogCount(t)
stdout, stderr, err = bdProxiedRunBuffers(t, bd, p.dir,
"--dolt-auto-commit", "batch", "create", "deferred control write", "-p", "1")
if err != nil {
t.Fatalf("control create under batch failed: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
}
if got := doltLogCount(t); got != before {
t.Fatalf("control create minted a commit under batch: dolt_log %v -> %v (want unchanged)", before, got)
}
script := filepath.Join(p.dir, "explicit-batch.txt")
if err := os.WriteFile(script, []byte("create task 1 explicit batch write\n"), 0o600); err != nil {
t.Fatalf("write batch script: %v", err)
}
stdout, stderr, err = bdProxiedRunBuffers(t, bd, p.dir,
"--dolt-auto-commit", "batch", "batch", "-f", script, "-m", "explicit batch commit")
if err != nil {
t.Fatalf("bd batch under batch policy failed: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
}
if got, want := doltLogCount(t), before+1; got != want {
t.Fatalf("explicit batch commit did not mint exactly one commit under batch: dolt_log %v -> %v (want %v)", before, got, want)
}
// The message is the half a route-wide deferral silently drops: blanking it
// selects the plain-COMMIT form, which persists the rows and records nothing.
if got := headCommit(t)["message"]; got != "explicit batch commit" {
t.Fatalf("explicit batch commit lost the caller's message: %v (want %q)", got, "explicit batch commit")
}
// 7. That commit swept the deferred control write with it (DOLT_COMMIT
// '-Am'), so the working set is clean and a flush now has nothing to do —
// the exemption does not strand the writes the policy deferred.
stdout, stderr, err = bdProxiedRunBuffers(t, bd, p.dir, "dolt", "commit", "-m", "post-batch flush")
if err != nil {
t.Fatalf("flush after explicit batch commit failed: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
}
if !strings.Contains(stdout, "Nothing to commit.") {
t.Fatalf("flush after explicit batch commit found pending work:\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
}
}

View file

@ -0,0 +1,88 @@
package main
import (
"context"
"database/sql"
"fmt"
"strings"
"github.com/steveyegge/beads/internal/storage/issueops"
)
// runDoltCommitProxiedServer is the proxied dual of `bd dolt commit`: the
// explicit commit point that discharges dolt.auto-commit=batch/off on this
// route (GH#4995). Proxied mode returns from the root pre-run before
// newDoltStore ever runs, so getStore() is nil here and the UOW provider is the
// only handle on the server — without this dual, batch/off on a proxied
// checkout meant "never commit" and writes piled up in the working set forever.
//
// It deliberately does not open a unit of work: doltServerTx.Commit blanks its
// message under a deferred context (that is the deferral this command exists to
// discharge), so routing the flush through it would make the flush itself a
// no-op. It runs DOLT_COMMIT('-Am') on a pinned maintenance connection instead,
// which is the uow-side equivalent of DoltStorage.CommitAll: "everything in the
// working set", including out-of-band and config-table dirt, attributed to the
// same actor with '--author'.
func runDoltCommitProxiedServer(ctx context.Context, message string) (bool, error) {
committed := false
// runProxiedNonTx, not an open-coded provider assertion: it is the shared
// maintenance escape hatch (backup, compact, clean-databases) and it reports
// provider failures through HandleErrorRespectJSON, so `bd --json dolt
// commit` keeps emitting the JSON error envelope the rest of the proxied
// surface emits.
err := runProxiedNonTx(ctx, func(ctx context.Context, conn *sql.Conn) error {
// The same gate doltServerTx.Commit uses, and for the same reason: an
// empty DOLT_COMMIT is rejected server-side with "nothing to commit"
// and floods the server log.
pending, err := issueops.HasPendingChanges(ctx, conn)
if err != nil {
return err
}
if !pending {
return nil
}
if _, err := conn.ExecContext(ctx, "CALL DOLT_COMMIT('-Am', ?, '--author', ?);", message, proxiedCommitAuthor()); err != nil {
if isDoltNothingToCommit(err) {
return nil
}
return err
}
committed = true
return nil
})
return committed, err
}
// proxiedCommitAuthor is the '--author' identity for the proxied flush, the
// counterpart of DoltStorage.commitAuthorString on the direct route. Without it
// the commit is attributed to the SQL session user, and under batch mode this is
// the ONE commit that survives a whole batch of writes — so on a multi-agent
// deployment `dolt log` could not say whose batch was flushed.
//
// The actor half is the same getActor() the default commit message names; the
// address half comes from git, as it does for the committer identity the store
// resolves for its own commits.
func proxiedCommitAuthor() string {
name, email := proxiedServerCommitter()
if a := strings.TrimSpace(getActor()); a != "" {
name = a
}
return renderDoltCommitAuthor(name, email)
}
// renderDoltCommitAuthor formats a Dolt '--author' argument. Dolt parses the
// git "Name <email>" grammar and rejects anything else, so the angle brackets
// and newlines an actor name could carry are stripped rather than passed
// through to fail the flush.
func renderDoltCommitAuthor(name, email string) string {
clean := strings.NewReplacer("<", "", ">", "", "\n", " ", "\r", " ")
name = strings.TrimSpace(clean.Replace(name))
email = strings.TrimSpace(clean.Replace(email))
if name == "" {
name = "beads"
}
if email == "" {
email = "beads@localhost"
}
return fmt.Sprintf("%s <%s>", name, email)
}

View file

@ -0,0 +1,29 @@
package main
import "testing"
// TestRenderDoltCommitAuthor pins the '--author' argument the proxied flush
// passes to DOLT_COMMIT (GH#4995). Dolt parses the git "Name <email>" grammar
// and rejects anything else, and the name half is an actor string the caller
// controls, so a stray bracket or newline must be stripped rather than turned
// into a failed flush — the flush is the only commit batch mode keeps.
func TestRenderDoltCommitAuthor(t *testing.T) {
for _, tc := range []struct {
name string
actor string
email string
want string
}{
{name: "actor and email", actor: "agent-7", email: "agent7@example.com", want: "agent-7 <agent7@example.com>"},
{name: "trims surrounding space", actor: " agent-7 ", email: " agent7@example.com\n", want: "agent-7 <agent7@example.com>"},
{name: "strips brackets the grammar owns", actor: "agent <7>", email: "a@b", want: "agent 7 <a@b>"},
{name: "strips embedded newline", actor: "agent\n7", email: "a@b", want: "agent 7 <a@b>"},
{name: "defaults an empty identity", actor: "", email: "", want: "beads <beads@localhost>"},
} {
t.Run(tc.name, func(t *testing.T) {
if got := renderDoltCommitAuthor(tc.actor, tc.email); got != tc.want {
t.Fatalf("renderDoltCommitAuthor(%q, %q) = %q, want %q", tc.actor, tc.email, got, tc.want)
}
})
}
}

View file

@ -0,0 +1,108 @@
//go:build cgo
package main
// The external-tcp half of the `bd dolt status` / `bd dolt start` coverage.
// It lives in the TestProxiedServer* lane, which runs on every PR, so the
// corruption guard is enforced there and not only in the path-filtered
// managed-local lane.
//
// The distinction this topology exercises: bd runs a proxy but spawns no dolt,
// so "the backend is not running" is a claim bd has no standing to make.
import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
"github.com/steveyegge/beads/internal/doltserver"
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
)
func TestProxiedServerDoltLifecycle(t *testing.T) {
bd := buildEmbeddedBD(t)
p := newSharedProxiedProject(t, bd, "extdolt")
t.Cleanup(func() {
serverDir := doltserver.ResolveServerDir(p.beadsDir)
if _, err := os.Stat(filepath.Join(serverDir, doltserver.PIDFileName)); err != nil {
return
}
t.Logf("stray classic dolt-server.pid under %s; stopping it", serverDir)
if err := doltserver.Stop(serverDir); err != nil {
t.Logf("doltserver.Stop(%s): %v", serverDir, err)
}
})
bdProxiedCreate(t, bd, p.dir, "external lifecycle sentinel")
proxyPid := readProxyPidFileOrFail(t, p)
t.Run("status reports the proxy and disclaims the backend", func(t *testing.T) {
stdout, stderr, err := bdProxiedRunBuffersWithEnv(t, bd, p.dir, []string{"BEADS_JSON=1"}, "--json", "dolt", "status")
if err != nil {
t.Fatalf("bd dolt status failed: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
}
var got struct {
Mode string `json:"mode"`
Running bool `json:"running"`
ProxyPID int `json:"proxy_pid"`
BackendManaged bool `json:"backend_managed"`
BackendRunning bool `json:"backend_running"`
BackendEndpoint string `json:"backend_endpoint"`
}
if jsonErr := json.Unmarshal([]byte(strings.TrimSpace(stdout)), &got); jsonErr != nil {
t.Fatalf("decode dolt status JSON: %v\nstdout:\n%s", jsonErr, stdout)
}
if got.Mode != "proxied-server" || !got.Running {
t.Errorf("status=%+v, want mode=proxied-server running=true", got)
}
if got.ProxyPID != proxyPid {
t.Errorf("proxy_pid=%d, want %d", got.ProxyPID, proxyPid)
}
if got.BackendManaged {
t.Error("backend_managed=true on an external topology; bd spawns no dolt there")
}
if got.BackendRunning {
t.Error("backend_running=true on an external topology; bd has no record to claim that from")
}
if !strings.HasPrefix(got.BackendEndpoint, "127.0.0.1:") {
t.Errorf("backend_endpoint=%q, want the configured external endpoint", got.BackendEndpoint)
}
})
t.Run("start is refused", func(t *testing.T) {
stdout, stderr, err := bdProxiedRunBuffersWithEnv(t, bd, p.dir, []string{"BEADS_JSON=1"}, "--json", "dolt", "start")
if err == nil {
t.Errorf("bd dolt start succeeded on an external proxied workspace:\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
}
var got struct {
Code string `json:"code"`
Mutates bool `json:"mutates"`
}
if jsonErr := json.Unmarshal([]byte(strings.TrimSpace(stdout)), &got); jsonErr != nil {
t.Fatalf("refusal is not typed JSON (%v)\nstdout:\n%s\nstderr:\n%s", jsonErr, stdout, stderr)
}
if got.Code != proxyDoltStartConflictCode || got.Mutates {
t.Errorf("refusal=%+v, want code=%q mutates=false", got, proxyDoltStartConflictCode)
}
for _, name := range []string{doltserver.PIDFileName, doltserver.PortFileName} {
if _, statErr := os.Stat(filepath.Join(p.beadsDir, name)); statErr == nil {
t.Errorf("%s exists after a refused start", name)
}
}
})
if out, err := bdProxiedRun(t, bd, p.dir, "create", "--json", "post-refusal write"); err != nil {
t.Fatalf("workspace unusable after the lifecycle probes: %v\n%s", err, out)
}
}
func readProxyPidFileOrFail(t *testing.T, p proxiedProject) int {
t.Helper()
running, pid := proxy.IsRunning(p.proxyRoot)
if !running {
t.Fatalf("expected a live proxy under %s after a create", p.proxyRoot)
}
return pid
}

View file

@ -0,0 +1,167 @@
package main
// `bd dolt start` and `bd dolt status` for proxied-server workspaces.
//
// Both commands predate proxied mode and assume bd owns the sql-server: they
// read and write .beads/dolt-server.pid. A proxied workspace never has one —
// the proxy writes proxy.pid and proxy-child.pid under the proxied root — so
// status used to report "not running" against a healthy backend, and start
// used to act on that by putting a second sql-server over the live data
// directory. This file is the proxied-aware half of both.
import (
"fmt"
"net"
"os"
"strconv"
"github.com/steveyegge/beads/internal/configfile"
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
)
// Stable identity of the `bd dolt start` refusal on a proxied workspace.
// Codes are the part of the refusal contract downstream consumers branch on,
// so this one is frozen; the message beside it is informative.
const proxyDoltStartConflictCode = "proxy.dolt_start.conflict"
const proxyDoltStartConflictMessage = "dolt start is not supported in proxied-server mode: " +
"the proxy owns its dolt backend, and a second sql-server over the same data directory risks corrupting it; " +
"the proxy starts on demand — run 'bd dolt status' to see what is running, or 'bd dolt stop' to shut it down"
// proxiedDoltStartRefusal is enforced inside the command rather than by the
// pre-provider capability gate because `bd dolt` is a noDbCommands entry: its
// subcommands skip store init and so never reach the gate in main.go. Folding
// this row into the consolidated registry is S2's job; the corruption guard
// should not wait for it.
func proxiedDoltStartRefusal() *ProxyCapabilityError {
return &ProxyCapabilityError{
Code: proxyDoltStartConflictCode,
Message: proxyDoltStartConflictMessage,
ExitCode: 1,
}
}
// proxiedDoltStatus is the `bd dolt status --json` payload for a proxied
// workspace. It reports the two processes separately because they fail
// separately and an operator's next move differs: Running says whether the
// workspace is serving (a live proxy, and on a managed topology a live dolt
// behind it), Proxy* describe the proxy every bd command connects through, and
// the Backend* fields describe the dolt server behind it. A proxy left in front
// of a dead managed backend (possible with proxies started by an older bd)
// therefore reports running=false with proxy_pid still set.
type proxiedDoltStatus struct {
Mode string `json:"mode"`
Root string `json:"root"`
Running bool `json:"running"`
ProxyPID int `json:"proxy_pid,omitempty"`
ProxyPort int `json:"proxy_port,omitempty"`
// BackendManaged is false on an external proxied topology, where the
// dolt server is somebody else's process and BackendRunning says nothing
// about it. Without this flag a caller cannot tell "the backend is down"
// from "bd never had a backend to report".
BackendManaged bool `json:"backend_managed"`
BackendRunning bool `json:"backend_running"`
BackendPID int `json:"backend_pid,omitempty"`
BackendPort int `json:"backend_port,omitempty"`
BackendEndpoint string `json:"backend_endpoint,omitempty"`
IdleTimeout string `json:"idle_timeout,omitempty"`
}
func collectProxiedDoltStatus(beadsDir string) (proxiedDoltStatus, error) {
root, err := resolveProxiedServerRootPath(beadsDir)
if err != nil {
return proxiedDoltStatus{}, err
}
live := proxy.ReadStatus(root)
status := proxiedDoltStatus{
Mode: configfile.DoltModeProxiedServer,
Root: root,
Running: live.ProxyRunning,
ProxyPID: live.ProxyPID,
ProxyPort: live.ProxyPort,
BackendManaged: true,
BackendRunning: live.BackendRunning,
BackendPID: live.BackendPID,
BackendPort: live.BackendPort,
}
info, err := configfile.LoadProxiedServerClientInfo(beadsDir)
if err != nil {
return proxiedDoltStatus{}, err
}
// A missing sidecar means the workspace predates it or was hand-edited;
// managed-local is the default topology, and the pid records already read
// above are the authority on what is actually running either way.
if info != nil {
if info.IdleTimeout > 0 {
status.IdleTimeout = info.IdleTimeout.String()
}
if info.External != nil {
status.BackendManaged = false
status.BackendEndpoint = externalDoltEndpoint(*info.External)
}
}
status.Running = proxiedStatusServing(live.ProxyRunning, status.BackendManaged, status.BackendRunning)
return status, nil
}
// proxiedStatusServing reports whether a proxied workspace is serving: its
// proxy is live and, when bd manages the backend, that dolt server is live
// too. A proxy in front of a dead managed backend serves nothing.
func proxiedStatusServing(proxyRunning, backendManaged, backendRunning bool) bool {
return proxyRunning && (!backendManaged || backendRunning)
}
func externalDoltEndpoint(cfg configfile.ExternalDoltConfig) string {
if cfg.Socket != "" {
return "unix:" + cfg.Socket
}
return net.JoinHostPort(cfg.Host, strconv.Itoa(cfg.Port))
}
func renderProxiedDoltStatus(status proxiedDoltStatus) {
if jsonOutput {
if err := outputJSON(status); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
}
return
}
// A live proxy in front of a managed backend that is gone serves nothing,
// so do not call it running. The proxy retires itself once it notices
// the backend exit; a proxy from an older bd may not.
backendDown := !status.Running && status.ProxyPID != 0 && status.BackendManaged && !status.BackendRunning
switch {
case backendDown:
fmt.Printf("Dolt server: not serving (%s): proxy is up but its dolt backend is not running\n", status.Mode)
fmt.Printf(" Proxy PID: %d\n", status.ProxyPID)
fmt.Printf(" Proxy port: %d\n", status.ProxyPort)
case status.Running:
fmt.Printf("Dolt server: running (%s)\n", status.Mode)
fmt.Printf(" Proxy PID: %d\n", status.ProxyPID)
fmt.Printf(" Proxy port: %d\n", status.ProxyPort)
default:
fmt.Printf("Dolt server: not running (%s)\n", status.Mode)
}
fmt.Printf(" Root: %s\n", status.Root)
switch {
case !status.BackendManaged:
fmt.Printf(" Backend: external at %s (not managed by bd)\n", status.BackendEndpoint)
case status.BackendRunning:
fmt.Printf(" Backend: running (dolt PID %d, port %d)\n", status.BackendPID, status.BackendPort)
default:
fmt.Println(" Backend: not running")
}
if status.IdleTimeout != "" {
fmt.Printf(" Idle timeout: %s\n", status.IdleTimeout)
}
if !status.Running && !backendDown {
fmt.Println(" The proxy starts on demand; the next bd command launches it.")
}
if backendDown {
fmt.Println(" Run 'bd dolt stop' to retire the proxy; the next bd command starts a fresh proxy and backend.")
}
if isDoltLocalOnly() {
fmt.Println(" Remote sync: disabled (dolt.local-only=true)")
}
}

View file

@ -0,0 +1,227 @@
package main
import (
"encoding/json"
"path/filepath"
"strings"
"testing"
"time"
"github.com/steveyegge/beads/internal/configfile"
)
// TestProxiedDoltStartRefusalContract pins the parts downstream consumers
// branch on. The code is frozen; the message is informative and may be
// reworded, but it has to keep naming the mode and pointing somewhere useful,
// because "start refused" with no onward path is what sends an operator
// looking for a manual workaround.
func TestProxiedDoltStartRefusalContract(t *testing.T) {
err := proxiedDoltStartRefusal()
if err.Code != "proxy.dolt_start.conflict" {
t.Errorf("code = %q, want %q", err.Code, "proxy.dolt_start.conflict")
}
if err.ExitCode != 1 {
t.Errorf("exit code = %d, want 1", err.ExitCode)
}
if err.Mutates {
t.Error("mutates = true; a refused start changes nothing")
}
for _, want := range []string{"proxied-server mode", "bd dolt status", "bd dolt stop"} {
if !strings.Contains(err.Message, want) {
t.Errorf("message does not mention %q: %q", want, err.Message)
}
}
}
func TestExternalDoltEndpoint(t *testing.T) {
for _, tc := range []struct {
name string
cfg configfile.ExternalDoltConfig
want string
}{
{"tcp", configfile.ExternalDoltConfig{Host: "127.0.0.1", Port: 3310}, "127.0.0.1:3310"},
{"ipv6", configfile.ExternalDoltConfig{Host: "::1", Port: 3310}, "[::1]:3310"},
{"socket wins", configfile.ExternalDoltConfig{Socket: "/tmp/dolt.sock"}, "unix:/tmp/dolt.sock"},
} {
t.Run(tc.name, func(t *testing.T) {
if got := externalDoltEndpoint(tc.cfg); got != tc.want {
t.Errorf("externalDoltEndpoint = %q, want %q", got, tc.want)
}
})
}
}
// TestCollectProxiedDoltStatusQuiescentRoot covers the case an operator hits
// most: nothing is running yet. The answer has to be "not running" WITHOUT
// starting anything — a status command that spawns the topology it is
// reporting on would defeat the idle reaper it is reporting about.
func TestCollectProxiedDoltStatusQuiescentRoot(t *testing.T) {
beadsDir := t.TempDir()
root := filepath.Join(beadsDir, "dolt")
t.Setenv("BEADS_PROXIED_SERVER_ROOT_PATH", root)
status, err := collectProxiedDoltStatus(beadsDir)
if err != nil {
t.Fatalf("collectProxiedDoltStatus: %v", err)
}
if status.Mode != "proxied-server" {
t.Errorf("mode = %q, want %q", status.Mode, "proxied-server")
}
if status.Root != root {
t.Errorf("root = %q, want %q", status.Root, root)
}
if status.Running || status.BackendRunning {
t.Errorf("reported something running for an empty root: %+v", status)
}
if !status.BackendManaged {
t.Error("backend_managed = false with no external sidecar; managed-local is the default topology")
}
if entries, _ := filepath.Glob(filepath.Join(root, "*")); len(entries) != 0 {
t.Errorf("reading status created %v under the proxied root", entries)
}
}
func TestCollectProxiedDoltStatusExternalTopology(t *testing.T) {
beadsDir := t.TempDir()
root := filepath.Join(beadsDir, "dolt")
t.Setenv("BEADS_PROXIED_SERVER_ROOT_PATH", root)
if err := configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{
IdleTimeout: 45 * time.Second,
External: &configfile.ExternalDoltConfig{Host: "10.0.0.5", Port: 3306},
}); err != nil {
t.Fatalf("SaveProxiedServerClientInfo: %v", err)
}
status, err := collectProxiedDoltStatus(beadsDir)
if err != nil {
t.Fatalf("collectProxiedDoltStatus: %v", err)
}
if status.BackendManaged {
t.Error("backend_managed = true for an external topology; bd spawns no dolt there")
}
if status.BackendEndpoint != "10.0.0.5:3306" {
t.Errorf("backend_endpoint = %q, want %q", status.BackendEndpoint, "10.0.0.5:3306")
}
if status.IdleTimeout != "45s" {
t.Errorf("idle_timeout = %q, want %q", status.IdleTimeout, "45s")
}
}
func TestRenderProxiedDoltStatus(t *testing.T) {
running := proxiedDoltStatus{
Mode: "proxied-server", Root: "/w/.beads/dolt", Running: true,
ProxyPID: 111, ProxyPort: 40001,
BackendManaged: true, BackendRunning: true, BackendPID: 222, BackendPort: 40002,
IdleTimeout: "30s",
}
t.Run("text reports both processes", func(t *testing.T) {
defer restoreJSONOutput(t)()
jsonOutput = false
out := captureStdout(t, func() error { renderProxiedDoltStatus(running); return nil })
for _, want := range []string{
"Dolt server: running (proxied-server)",
"Proxy PID: 111",
"Proxy port: 40001",
"Root: /w/.beads/dolt",
"Backend: running (dolt PID 222, port 40002)",
"Idle timeout: 30s",
} {
if !strings.Contains(out, want) {
t.Errorf("missing %q in:\n%s", want, out)
}
}
})
t.Run("text says how to start it when down", func(t *testing.T) {
defer restoreJSONOutput(t)()
jsonOutput = false
down := running
down.Running, down.ProxyPID, down.ProxyPort = false, 0, 0
down.BackendRunning, down.BackendPID, down.BackendPort = false, 0, 0
out := captureStdout(t, func() error { renderProxiedDoltStatus(down); return nil })
for _, want := range []string{
"Dolt server: not running (proxied-server)",
"Backend: not running",
"The proxy starts on demand",
} {
if !strings.Contains(out, want) {
t.Errorf("missing %q in:\n%s", want, out)
}
}
})
t.Run("text does not call a proxy over a dead managed backend running", func(t *testing.T) {
defer restoreJSONOutput(t)()
jsonOutput = false
stranded := running
stranded.Running = false
stranded.BackendRunning, stranded.BackendPID, stranded.BackendPort = false, 0, 0
out := captureStdout(t, func() error { renderProxiedDoltStatus(stranded); return nil })
if strings.Contains(out, "Dolt server: running") {
t.Errorf("proxy with a dead backend reported as running:\n%s", out)
}
for _, want := range []string{
"Dolt server: not serving (proxied-server)",
"Proxy PID: 111",
"Backend: not running",
"bd dolt stop",
} {
if !strings.Contains(out, want) {
t.Errorf("missing %q in:\n%s", want, out)
}
}
})
t.Run("text marks an external backend as somebody else's", func(t *testing.T) {
defer restoreJSONOutput(t)()
jsonOutput = false
external := running
external.BackendManaged, external.BackendRunning = false, false
external.BackendEndpoint = "10.0.0.5:3306"
out := captureStdout(t, func() error { renderProxiedDoltStatus(external); return nil })
if !strings.Contains(out, "Backend: external at 10.0.0.5:3306 (not managed by bd)") {
t.Errorf("external backend not described:\n%s", out)
}
if strings.Contains(out, "Backend: not running") {
t.Errorf("external backend reported as down; bd has no record to say that from:\n%s", out)
}
})
t.Run("json carries the process records", func(t *testing.T) {
defer restoreJSONOutput(t)()
jsonOutput = true
out := captureStdout(t, func() error { renderProxiedDoltStatus(running); return nil })
var got proxiedDoltStatus
if err := json.Unmarshal([]byte(strings.TrimSpace(out)), &got); err != nil {
t.Fatalf("decode %q: %v", out, err)
}
if got != running {
t.Errorf("round-trip mismatch:\ngot %+v\nwant %+v", got, running)
}
})
}
func TestProxiedStatusServing(t *testing.T) {
for _, tc := range []struct {
name string
proxyRunning, managed, backendRunning bool
want bool
}{
{"managed pair live", true, true, true, true},
{"proxy over dead managed backend", true, true, false, false},
{"external backend", true, false, false, true},
{"proxy down", false, true, true, false},
{"nothing running", false, true, false, false},
} {
if got := proxiedStatusServing(tc.proxyRunning, tc.managed, tc.backendRunning); got != tc.want {
t.Errorf("%s: proxiedStatusServing(%v, %v, %v) = %v, want %v", tc.name, tc.proxyRunning, tc.managed, tc.backendRunning, got, tc.want)
}
}
}
func restoreJSONOutput(t *testing.T) func() {
t.Helper()
orig := jsonOutput
return func() { jsonOutput = orig }
}

View file

@ -8,9 +8,9 @@ import (
"path/filepath"
"runtime"
"strconv"
"strings"
"testing"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/testutil"
)
@ -47,13 +47,21 @@ func TestDoltRemoteAddPersistsSyncRemoteToSharedWorktreeConfig(t *testing.T) {
t.Fatalf("bd dolt remote add from bare-parent worktree failed: %v\n%s", err, out)
}
// Asserted by reading it back, not by matching YAML text. The literal
// `sync.remote: "<url>"` this used to require is a key whose NAME contains
// a dot — the shape config.GetStringFromDir can never find, because it
// splits on the dot and walks nested mappings. Viper finds a dotted key
// either way, so this assertion was green while the value was invisible to
// bd's other reader; it passed BECAUSE bd-zj95 was present. What the remote
// add owes its caller is a remote that reads back, so that is what this
// checks.
configPath := filepath.Join(bareBeadsDir, "config.yaml")
content, err := os.ReadFile(configPath)
if err != nil {
t.Fatalf("failed to read shared config.yaml: %v", err)
}
if !strings.Contains(string(content), `sync.remote: "`+remoteURL+`"`) {
t.Fatalf("expected shared config.yaml to contain sync.remote, got:\n%s", string(content))
if got := config.GetStringFromDir(bareBeadsDir, "sync.remote"); got != remoteURL {
t.Fatalf("shared config.yaml sync.remote = %q, want %q; contents:\n%s", got, remoteURL, content)
}
if _, err := os.Stat(filepath.Join(worktreeDir, ".beads")); !os.IsNotExist(err) {

View file

@ -30,6 +30,15 @@ func exitCodeFromError(err error) (int, bool) {
return 0, false
}
// isReportedExit reports whether err is an already-rendered failure — the
// *exitError every Handle*Error returns after writing the message (or the JSON
// error envelope) itself. A caller that re-wraps one prints a second Error line
// and, in --json mode, a plain line after the envelope.
func isReportedExit(err error) bool {
_, reported := exitCodeFromError(err)
return reported
}
func activeWorkspaceNotFoundError() string {
return "no active beads workspace found"
}
@ -76,8 +85,16 @@ func buildJSONError(message, hint string) interface{} {
return inner
}
// buildJSONCapabilityError renders a typed refusal. {code, error, mutates} is a
// frozen contract that downstream consumers parse; `reason` is additive and
// appears only on refusals that came from the capability registry, which is why
// it is omitted rather than emitted empty — a consumer that keys on its presence
// must not be told "" by a runtime state error that has no policy reason.
func buildJSONCapabilityError(e *ProxyCapabilityError) interface{} {
inner := map[string]interface{}{"error": e.Message, "code": e.Code, "mutates": e.Mutates}
if e.Reason != "" {
inner["reason"] = string(e.Reason)
}
if jsonEnvelopeEnabled() {
return map[string]interface{}{"schema_version": JSONSchemaVersion, "data": inner}
}

View file

@ -58,6 +58,7 @@ var storeConstructors = map[string]map[string]bool{
"OpenForReadOnlyCommand": true,
"OpenForPreviewCommand": true,
"OpenForWorkingSetReconcile": true,
"OpenForRemoteSync": true,
},
"github.com/steveyegge/beads/internal/storage/uow": {
"NewDoltServerUOWProvider": true,

View file

@ -12,6 +12,7 @@ import (
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/metrics"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/internal/ui"
)
@ -33,9 +34,9 @@ Gate types:
gh:pr - Waits for PR merge (Phase 3)
bead - Waits for another bead to close (Phase 4)
For bead gates, await_id is a bead ID in this rig's database (e.g., "bd-abc123").
The historical cross-rig form <rig>:<bead-id> can no longer be evaluated
(multi-rig routing removed) and stays pending until resolved manually.
For bead gates, await_id may be a bead ID in this rig's database (e.g.,
"bd-abc123") or the historical cross-rig form <rig>:<bead-id>. Cross-rig
targets resolve through the bead ID's prefix route in routes.jsonl.
Examples:
bd gate list # Show all open gates
@ -669,7 +670,7 @@ Examples:
}
}
results := evaluateGates(ctx, filteredGates, time.Now(), store, persistAwaitID)
results := evaluateGates(ctx, filteredGates, time.Now(), routedBeadGateGetter{localStore: store}, persistAwaitID)
resolvedCount, escalatedCount, errorCount := applyGateCheckResults(
results, dryRun, escalateFlag,
@ -1182,27 +1183,48 @@ type issueGetter interface {
GetIssue(ctx context.Context, id string) (*types.Issue, error)
}
// routedBeadGateGetter gives direct-mode gate checks the same local -> prefix
// route -> contributor fallback used by other read commands. Routed stores are
// opened read-only and closed before the result is returned.
type routedBeadGateGetter struct {
localStore storage.DoltStorage
}
func (g routedBeadGateGetter) GetIssue(ctx context.Context, id string) (*types.Issue, error) {
if g.localStore == nil {
return nil, fmt.Errorf("no local store available")
}
result, err := getIssueWithRouting(ctx, g.localStore, id)
if err != nil {
return nil, err
}
defer result.Close()
return result.Issue, nil
}
// checkBeadGate checks if a bead gate is satisfied.
// Returns (satisfied, reason).
//
// A plain await_id (no colon) names a bead in THIS rig's database: the gate
// resolves once that bead closes — the common case, an agent idle-waiting on
// local work (wy-hgms2; the old unconditional cross-rig refusal left every
// local bead gate permanently pending and its waiters asleep).
//
// The historical cross-rig form <rig>:<bead-id> cannot be evaluated since
// multi-rig routing was removed; it stays pending with a descriptive message.
// A plain await_id names a bead in this rig. The historical
// <rig>:<bead-id> form uses the bead ID as the routed lookup key; the rig
// component is retained for compatibility while routes.jsonl remains keyed by
// bead prefix. The supplied getter owns local-versus-routed lookup policy.
func checkBeadGate(ctx context.Context, st issueGetter, awaitID string) (bool, string) {
if awaitID == "" {
return false, "bead gate has no await_id"
}
targetID := awaitID
if strings.Contains(awaitID, ":") {
return false, fmt.Sprintf("cross-rig bead gate %q cannot be checked (multi-rig routing removed)", awaitID)
parts := strings.SplitN(awaitID, ":", 2)
if parts[0] == "" || parts[1] == "" {
return false, fmt.Sprintf("invalid cross-rig bead gate %q: expected <rig>:<bead-id>", awaitID)
}
targetID = parts[1]
}
if st == nil {
return false, fmt.Sprintf("bead gate %q: no local store available", awaitID)
}
issue, err := st.GetIssue(ctx, awaitID)
issue, err := st.GetIssue(ctx, targetID)
if err != nil {
return false, fmt.Sprintf("bead gate %q: %v", awaitID, err)
}
@ -1210,9 +1232,9 @@ func checkBeadGate(ctx context.Context, st issueGetter, awaitID string) (bool, s
return false, fmt.Sprintf("bead gate %q: bead not found", awaitID)
}
if issue.Status == types.StatusClosed {
return true, fmt.Sprintf("bead %s closed", awaitID)
return true, fmt.Sprintf("bead %s closed", targetID)
}
return false, fmt.Sprintf("bead %s is %s", awaitID, issue.Status)
return false, fmt.Sprintf("bead %s is %s", targetID, issue.Status)
}
// closeGate closes a gate issue with the given reason

View file

@ -39,8 +39,21 @@ func (proxiedFreshReadGetter) GetIssue(ctx context.Context, id string) (*types.I
if err != nil {
return nil, err
}
defer uw.Close(ctx)
return uw.IssueUseCase().GetIssue(ctx, id)
issue, localErr := uw.IssueUseCase().GetIssue(ctx, id)
uw.Close(ctx)
if localErr == nil {
return issue, nil
}
if !gateProxiedNotFound(localErr) {
return nil, localErr
}
result, routeErr := resolveViaPrefixRouting(ctx, id)
if routeErr != nil {
return nil, localErr
}
defer result.Close()
return result.Issue, nil
}
func runGateCheckProxiedServer(cmd *cobra.Command, ctx context.Context) error {

View file

@ -0,0 +1,77 @@
//go:build cgo
package main
import (
"context"
"os"
"path/filepath"
"testing"
"github.com/steveyegge/beads/internal/types"
)
// TestCheckBeadGateCrossRigPrefixRoute proves the full evaluator seam: the
// historical rig:id value is reduced to the target bead ID, the current
// routes.jsonl prefix router opens the foreign store read-only, and target
// lifecycle state determines whether the gate resolves.
//
// NOTE: This test uses os.Chdir and cannot run in parallel with other tests.
func TestCheckBeadGateCrossRigPrefixRoute(t *testing.T) {
ctx := context.Background()
townRoot := t.TempDir()
townBeadsDir := filepath.Join(townRoot, ".beads")
rigBeadsDir := filepath.Join(townRoot, "rig", ".beads")
if err := os.MkdirAll(townBeadsDir, 0o755); err != nil {
t.Fatalf("create town beads dir: %v", err)
}
if err := os.MkdirAll(rigBeadsDir, 0o755); err != nil {
t.Fatalf("create rig beads dir: %v", err)
}
townDBPath := filepath.Join(townBeadsDir, "dolt")
townStore := newTestStoreIsolatedDB(t, townDBPath, "hq")
rigStore := newTestStoreIsolatedDB(t, filepath.Join(rigBeadsDir, "dolt"), "gt")
for _, issue := range []*types.Issue{
{ID: "gt-closed", Title: "Closed routed target", Status: types.StatusClosed, Priority: 2, IssueType: types.TypeTask},
{ID: "gt-open", Title: "Open routed target", Status: types.StatusOpen, Priority: 2, IssueType: types.TypeTask},
} {
if err := rigStore.CreateIssue(ctx, issue, "test"); err != nil {
t.Fatalf("create routed issue %s: %v", issue.ID, err)
}
}
if err := rigStore.Close(); err != nil {
t.Fatalf("close rig store: %v", err)
}
routesPath := filepath.Join(townBeadsDir, "routes.jsonl")
if err := os.WriteFile(routesPath, []byte(`{"prefix":"gt-","path":"rig"}`), 0o644); err != nil {
t.Fatalf("write routes.jsonl: %v", err)
}
oldDBPath := dbPath
dbPath = townDBPath
t.Cleanup(func() { dbPath = oldDBPath })
oldWD, err := os.Getwd()
if err != nil {
t.Fatalf("get working directory: %v", err)
}
if err := os.Chdir(townRoot); err != nil {
t.Fatalf("change to town root: %v", err)
}
t.Cleanup(func() { _ = os.Chdir(oldWD) })
getter := routedBeadGateGetter{localStore: townStore}
resolved, reason := checkBeadGate(ctx, getter, "rig:gt-closed")
if !resolved {
t.Fatalf("closed cross-rig target did not resolve gate: %s", reason)
}
resolved, reason = checkBeadGate(ctx, getter, "rig:gt-open")
if resolved {
t.Fatalf("open cross-rig target unexpectedly resolved gate: %s", reason)
}
if !gateTestContainsIgnoreCase(reason, "open") {
t.Fatalf("pending reason %q does not report target status", reason)
}
}

View file

@ -3,10 +3,12 @@ package main
import (
"bytes"
"context"
"database/sql"
"encoding/json"
"errors"
"io"
"os"
"path/filepath"
"slices"
"sync"
"testing"
@ -154,28 +156,53 @@ func TestShouldCheckGate(t *testing.T) {
type fakeBeadGateGetter struct {
issues map[string]*types.Issue
err error
gotID string
}
func (f *fakeBeadGateGetter) GetIssue(_ context.Context, id string) (*types.Issue, error) {
f.gotID = id
if f.err != nil {
return nil, f.err
}
return f.issues[id], nil
}
func TestCheckBeadGate_CrossRigStaysPending(t *testing.T) {
func TestCheckBeadGate_CrossRigUsesBeadIDForRoutedLookup(t *testing.T) {
ctx := context.Background()
st := &fakeBeadGateGetter{issues: map[string]*types.Issue{
"gt-abc": {ID: "gt-abc", Status: types.StatusClosed},
}}
// The cross-rig <rig>:<bead-id> form cannot be evaluated since multi-rig
// routing was removed; it must stay pending with the explanatory message,
// never consult the store, and never resolve.
satisfied, reason := checkBeadGate(ctx, st, "gastown:gt-abc")
if !satisfied {
t.Fatalf("expected closed routed bead to satisfy gate, got reason %q", reason)
}
if st.gotID != "gt-abc" {
t.Fatalf("routed lookup ID = %q, want %q", st.gotID, "gt-abc")
}
}
func TestProxiedFreshReadGetterPreservesLocalNotFoundWhenRoutingUnavailable(t *testing.T) {
withStubbedProxiedLookup(t, nil)
oldDBPath := dbPath
dbPath = filepath.Join(t.TempDir(), ".beads", "dolt")
t.Cleanup(func() { dbPath = oldDBPath })
_, err := (proxiedFreshReadGetter{}).GetIssue(context.Background(), "bd-missing")
if !errors.Is(err, sql.ErrNoRows) {
t.Fatalf("GetIssue error = %v, want original local not-found", err)
}
}
func TestCheckBeadGate_InvalidCrossRigFormat(t *testing.T) {
ctx := context.Background()
tests := []struct {
name string
awaitID string
}{
{name: "missing rig", awaitID: ":gt-abc"},
{name: "missing bead", awaitID: "my-project:"},
{name: "well-formed cross-rig", awaitID: "nonexistent:some-id"},
}
for _, tt := range tests {
@ -184,8 +211,8 @@ func TestCheckBeadGate_CrossRigStaysPending(t *testing.T) {
if satisfied {
t.Errorf("expected not satisfied for %q", tt.awaitID)
}
if !gateTestContainsIgnoreCase(reason, "multi-rig routing removed") {
t.Errorf("reason %q does not contain %q", reason, "multi-rig routing removed")
if !gateTestContainsIgnoreCase(reason, "expected <rig>:<bead-id>") {
t.Errorf("reason %q does not describe the expected format", reason)
}
})
}

View file

@ -12,7 +12,6 @@ import (
"strings"
"time"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/internal/validation"
@ -305,15 +304,6 @@ func warnUnknownGraphFields(w io.Writer, unknown map[string][]string) []string {
return hintFields
}
func loadEmbeddedCustomTypes() []string {
if store != nil {
if ct, err := store.GetCustomTypes(rootCtx); err == nil && len(ct) > 0 {
return ct
}
}
return config.GetCustomTypesFromYAML()
}
// loadEmbeddedCustomStatuses reads custom statuses from the store only — no
// YAML fallback, matching single-issue create and loadListFilterConfig
// (custom types fall back to YAML; custom statuses deliberately do not).
@ -348,9 +338,13 @@ func createIssuesFromGraph(planFile string, dryRun bool, opts GraphApplyOptions)
return HandleErrorRespectJSON("parsing graph plan: %v", err)
}
customTypes, err := resolveWorkspaceCustomTypes(rootCtx)
if err != nil {
return HandleErrorRespectJSON("%v", err)
}
dbPrefix, allowedPrefixes := loadEmbeddedIDPrefixes()
cfg := graphPlanConfig{
customTypes: loadEmbeddedCustomTypes(),
customTypes: customTypes,
customStatuses: loadEmbeddedCustomStatuses(),
dbPrefix: dbPrefix,
allowedPrefixes: allowedPrefixes,

View file

@ -1,28 +0,0 @@
package main
// HistoryCapabilityClass classifies history/version-control commands on the
// proxied topology without coupling them to a particular backend engine.
type HistoryCapabilityClass string
const (
HistoryProxySupported HistoryCapabilityClass = "proxy-supported"
HistoryProxyAPI HistoryCapabilityClass = "proxy-api"
HistoryDirectOnly HistoryCapabilityClass = "direct-only"
)
var historyCapabilityMatrix = map[string]HistoryCapabilityClass{
"history": HistoryProxySupported,
"branch": HistoryDirectOnly, "conflicts": HistoryDirectOnly, "repo": HistoryDirectOnly,
"federation": HistoryDirectOnly, "vc": HistoryDirectOnly, "flatten": HistoryDirectOnly,
"dolt push": HistoryDirectOnly, "dolt pull": HistoryDirectOnly, "dolt commit": HistoryDirectOnly,
"dolt remote": HistoryDirectOnly, "dolt remote add": HistoryDirectOnly, "dolt remote list": HistoryDirectOnly,
"dolt remote reset-data": HistoryDirectOnly, "dolt remote remove": HistoryProxySupported,
"sync": HistoryDirectOnly,
}
// LookupHistoryCapability classifies an exact command path. Unknown paths are
// intentionally absent so callers cannot accidentally advertise support.
func LookupHistoryCapability(commandPath string) (HistoryCapabilityClass, bool) {
c, ok := historyCapabilityMatrix[commandPath]
return c, ok
}

View file

@ -61,7 +61,6 @@ func TestHistoryRemoteRefusalFrontDoorMatrix(t *testing.T) {
{"flatten", "proxy.flatten.unsupported", "flatten is not supported in proxied-server mode", []string{"flatten"}},
{"dolt push", "proxy.dolt_push.unsupported", "dolt push is not supported in proxied-server mode", []string{"dolt", "push"}},
{"dolt pull", "proxy.dolt_pull.unsupported", "dolt pull is not supported in proxied-server mode", []string{"dolt", "pull"}},
{"dolt commit", "proxy.dolt_commit.unsupported", "dolt commit is not supported in proxied-server mode", []string{"dolt", "commit"}},
{"dolt remote add", "proxy.dolt_remote.unsupported", "dolt remote add is not supported in proxied-server mode", []string{"dolt", "remote", "add", "backup", "https://example.invalid/backup"}},
{"dolt remote list", "proxy.dolt_remote.unsupported", "dolt remote list is not supported in proxied-server mode", []string{"dolt", "remote", "list"}},
{"dolt remote reset-data", "proxy.dolt_remote.unsupported", "dolt remote reset-data is not supported in proxied-server mode", []string{"dolt", "remote", "reset-data", "backup"}},
@ -126,8 +125,10 @@ func snapshotHistoryArtifacts(t *testing.T, p proxiedProject) []byte {
return out
}
// TestHistoryRemoteSupportedFrontDoorParity checks the two operations that
// are intentionally shared by direct and proxied providers.
// TestHistoryRemoteSupportedFrontDoorParity checks the operations that are
// intentionally shared by direct and proxied providers: history --events,
// dolt remote remove, and dolt commit (the flush point dolt.auto-commit=batch/off
// defers to, GH#4995).
func TestHistoryRemoteSupportedFrontDoorParity(t *testing.T) {
if os.Getenv("BEADS_TEST_PROXIED_SERVER") != "1" && os.Getenv(managedLocalProxiedEnvVar) != "1" {
t.Skip("set a proxied test lane to run history parity")
@ -162,6 +163,13 @@ func TestHistoryRemoteSupportedFrontDoorParity(t *testing.T) {
if err != nil || !strings.Contains(string(out), "backup") {
t.Fatalf("remote remove failed: %v\n%s", err, out)
}
// dolt commit must pass the front door rather than be refused. Exact
// commit semantics are pinned by
// TestProxiedServerBatchDefersThenDoltCommitAdvancesHeadOnce.
out, err = bdProxiedRun(t, bd, p.dir, "--json", "dolt", "commit")
if err != nil || strings.Contains(string(out), "proxy.dolt_commit.unsupported") {
t.Fatalf("dolt commit refused or failed: %v\n%s", err, out)
}
})
}
}

View file

@ -220,6 +220,60 @@ type VersionChange struct {
// versionChanges contains agent-actionable changes for recent versions
var versionChanges = []VersionChange{
{
Version: "1.3.2-rc.1",
Date: "2026-10-05",
Changes: []string{
"RC: first candidate for 1.3.2, a patch on top of 1.3.1 with no schema migration, so upgrading from 1.3.1 is a binary swap.",
"UPGRADE: after upgrading from bd <=1.3.0, run 'bd recompute-blocked' once per workspace (#7037). Migration 0059 (first shipped in 1.3.0) recomputes is_blocked with a recursive query whose parent-child filter is dropped by a Dolt query-planner bug on Dolt servers older than 2.4.0 and on the embedded engine (dolthub/dolt#11886). Blockedness then spreads across relates-to, discovered-from, tracks and other edges, and unblocked beads silently vanish from 'bd ready'. The flag is stored, so the damage persists until recomputed. This includes a workspace now on 1.3.1 that was first created by 1.2.x or earlier. The command is idempotent and reports rows_corrected.",
"FIX: 'bd purge' keeps every closed bead in a chain above a live bead, not just the one a live bead points at directly (#7031). A closed root over a closed child over an open grandchild used to lose its root, orphaning the rest; --wisps-plane retention sweeps hit this.",
"FIX: auto-backup records the Dolt commit read before the sync as its watermark (#7032). A commit landing during the sync used to be recorded as backed up although the snapshot lacked it, and auto-backup then reported 'no changes' until HEAD moved again.",
},
},
{
Version: "1.3.1",
Date: "2026-09-30",
Changes: []string{
"STABLE: first stable 1.3.1 release. Same code as 1.3.1-rc.2; only the version stamp changed. No schema migration, so upgrading from 1.3.0 or any 1.3.1 RC is a binary swap. Coming from 1.3.0, the 1.3.1-rc.2 and 1.3.1-rc.1 entries below both apply; read the [1.3.1-rc.2] upgrade notes in CHANGELOG.md.",
},
},
{
Version: "1.3.1-rc.2",
Date: "2026-09-29",
Changes: []string{
"RC: second candidate for the 1.3.1 patch line. Still no schema migration, so upgrading from 1.3.0 or 1.3.1-rc.1 is a binary swap. The 1.3.1-rc.1 entry below still applies.",
"NEW: on a proxied-server workspace whose Dolt server bd runs (managed-local, the default), 'bd backup init/sync/status/restore/remove' now work, and 'backup.enabled=true' turns on auto-backup (default stays OFF). On an external or team-server proxied topology the family stays refused with 'proxy.backup.unsupported' and \"reason\": \"design\". Proxied refusals now carry a 'reason' field ('design' or 'unimplemented'). A per-workspace '.beads/backup.lock' serializes backups: 'bd backup sync' fails after 5s if another backup is running.",
"NEW: 'bd purge --wisps-plane --older-than <age> --force [--limit N] --json' can replace a raw DELETE FROM wisps retention step. With --limit it purges oldest-closed first and reports 'remaining' and 'has_more'; loop while has_more is true.",
"CHANGE: 'bd purge' ALWAYS keeps a closed bead that a not-done bead depends on through parent-child, tracks or blocks, and reports the count as 'live_dependent_skipped'. There is no flag to disable it.",
"CHANGE: '--older-than' on 'bd purge' and 'bd prune' takes hour values exactly: '12h' no longer rounds up to a day and '36h' no longer floors to one, so 'bd prune --older-than 12h' now deletes rows closed 12-24 hours ago. Day values (7, 7d, 2w) are unchanged; a value too large to represent is refused.",
"CHANGE: 'bd show --watch <id>' works under --proxied-server, and on both routes a watch whose id cannot be found exits 1 instead of 0.",
"CHANGE: 'bd sql' classifies statements with the SQL parser. Proxied CTE queries ('WITH ... AS (...) SELECT') return their rows instead of 'OK, 0 rows affected', and CALL result sets are printed. In direct server mode a multi-statement write, or a write the parser cannot classify, prints 'OK' / {\"status\":\"ok\"} instead of 'OK, N rows affected' / {\"rows_affected\":N}. 'bd sql --readonly' refuses statements it cannot parse (e.g. PRAGMA).",
"CHANGE: 'bd types' lists exactly what 'bd create --type' accepts, with a new 'System types' section and an additive 'system_types' JSON field. A failure to read custom types now fails 'bd types', 'bd create --graph' and 'bd config set storage-class.*' instead of meaning 'no custom types'.",
"CHANGE: an explicit BEADS_DIR is authoritative. Point it at the .beads directory itself: a BEADS_DIR naming a project root, or a .beads that does not exist yet, now fails with 'no beads database found' instead of resolving to the nearest workspace above the current directory. 'bd init' initializes the named directory.",
"CHANGE: 'bd close' with several ids exits non-zero when any id fails to close (the rest still close). With --json, a summary naming the failed ids goes to stderr.",
"CHANGE: an unflagged piped 'bd query' is no longer capped at 50 rows; it follows the 'bd list' limit policy.",
"CHANGE: on a proxied workspace, dolt.auto-commit=batch/off now defers Dolt history commits and 'bd dolt commit' is supported as the flush point. Explicit commit points ('bd batch', 'bd mol bond/pour/squash', 'bd mol wisp create') still commit. The default 'on' is unchanged.",
"CHANGE: 'bd ready' and 'bd list --ready' include issues whose custom status is in the 'active' category; 'bd list --status <s> --ready' honors --status; bare 'bd list --wisp-type' is refused (use --include-ephemeral); 'bd doctor' warns about a missing .beads/dolt-server-config.yaml gitignore pattern until 'bd doctor --fix'.",
"CHANGE: on a proxied-server workspace or under 'bd serve', opening a store against an unreachable Dolt server retries for up to ~40s before failing, instead of failing at once.",
"FIX: two blockers of one dependent removed at the same time (parallel closes, a close racing 'bd dep remove' or a delete) no longer leave the dependent stuck blocked and hidden from 'bd ready' (#6716), on every store route including --proxied-server.",
"FIX: a proxy whose Dolt backend exits cleanly now retires, so the next command starts a fresh one; 'bd dolt status' reports it as not serving.",
"FIX: a server workspace with an empty .beads/dolt is no longer refused as a legacy workspace; 'bd init' writes the version marker.",
"FIX: the smart migrate gate no longer auto-migrates a clone whose data is behind its remote. It stops with 'run bd dolt pull, then retry', and 'bd dolt pull' works from that state.",
"FIX: deleting or purging a wisp no longer orphans wisp_dependencies, wisp_labels, wisp_events, wisp_comments or wisp_child_counters rows on stores without the wisp foreign keys (existing orphans are not cleaned). A clone missing its dolt-ignored events tables recreates them on open.",
},
},
{
Version: "1.3.1-rc.1",
Date: "2026-09-16",
Changes: []string{
"RC: first candidate for the 1.3.1 patch line, on top of 1.3.0. It carries fixes only — no schema migration, so upgrading from 1.3.0 is a binary swap. If you are coming from 1.2.2 or earlier, the [1.3.0] entry below still describes everything you meet, including the migration and backup notes; read it first.",
"CHANGE: 'bd dolt start' on a PROXIED workspace is now a typed refusal with code 'proxy.dolt_start.conflict' instead of starting a second sql-server over the proxy's own data directory. It previously either stranded ordinary bd commands on 'invalid connection' or adopted the proxy's dolt child into bd's classic PID/port records, leaving two managers for one process. The proxy owns its backend's lifecycle: it starts on demand, and 'bd dolt stop' shuts it down. Direct-server and embedded workspaces are unaffected.",
"CHANGE: 'bd dolt status --json' changes shape on a proxied workspace. It now reports the proxy and its dolt backend separately — {\"mode\": \"proxied-server\", \"running\": <proxy up>, \"proxy_pid\", \"proxy_port\", \"backend_managed\", \"backend_running\", \"backend_pid\", \"backend_port\", \"backend_endpoint\", \"idle_timeout\", \"root\"} — instead of the always-false {\"running\": false, \"pid\": 0, \"port\": 0} it emitted by reading a PID file proxied mode never writes. 'pid' and 'port' are gone, replaced by the proxy_*/backend_* pairs. 'running' now describes the proxy, the endpoint every bd command connects through, so it is usually true where it used to be always false; 'backend_managed' is false on external proxied topologies, where 'backend_endpoint' names the server bd does not manage. A script parsing the old payload changes behavior on upgrade.",
"FIX: a dotted config key now round-trips — what 'bd config set' writes is what 'bd config get' and bd's own readers find. Setting a key like 'sync.remote' or 'dolt.host' into a config.yaml with no matching section used to append a top-level key whose NAME contained the dot, which Viper finds and the direct reader GetStringFromDir does not; 'bd init --remote' in a fresh workspace was the ordinary way in, recording a remote no reader could locate. Dotted keys are written nested now, an existing flat spelling is migrated, and 'bd config unset' removes the nested form (it only ever matched the flat one, so unsetting 'sync.remote' silently left the remote live).",
"CHANGE: writing a dotted key nested has a consequence outside bd — 'bd config set <dotted.key>' DELETES a flat top-level key of the same literal name. Writing 'dolt.host' into a file that already carries a top-level 'dolt.host: \"10.0.0.1\"' removes that entry and re-emits the value under 'dolt:'; only the key being written is touched. .beads/config.yaml is not exclusively bd's, so an external tool that both writes AND reads flat dotted keys there stops seeing any value bd migrates this way. Realistic collisions are 'dolt.*', 'export.auto', and 'backup.enabled'. If that tool re-adds its flat key the file carries both spellings and bd's own readers disagree: Viper-backed reads ('bd config get', and the dolt.auto-start lookup on store open) return the FLAT value while GetStringFromDir returns the NESTED one, so a 'bd config set' can be shadowed by a stale flat entry. Tracked as #6594; until it lands, let the other tool own its keys, or check .beads/config.yaml for a duplicated key after running 'bd config set'.",
"CHANGE: two config writes that used to exit 0 now exit 1, because both produced a value no reader could see — setting a dotted key under a parent that already holds a scalar ('sync: enabled', then 'bd config set sync.remote'), and setting one in a file whose top level is not a mapping.",
},
},
{
Version: "1.3.0",
Date: "2026-09-15",

View file

@ -0,0 +1,146 @@
//go:build cgo
package main
import (
"bytes"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"github.com/steveyegge/beads/internal/configfile"
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
)
// explicitBeadsDirMode describes how a storage mode's bd subprocesses are
// initialized and run for the explicit-BEADS_DIR regression tests.
type explicitBeadsDirMode struct {
initArgs []string
env func(home string) []string
proxied bool
}
// runExplicitBeadsDirBD runs bd in dir with the mode's isolated environment.
// beadsDir, when non-empty, is passed as an explicit BEADS_DIR.
func runExplicitBeadsDirBD(t *testing.T, bd string, mode explicitBeadsDirMode, home, dir, beadsDir string, args ...string) (string, string, error) {
t.Helper()
cmd := exec.Command(bd, args...)
cmd.Dir = dir
env := append(mode.env(home), "XDG_CONFIG_HOME="+filepath.Join(home, ".config"))
if beadsDir != "" {
env = append(env, "BEADS_DIR="+beadsDir)
}
cmd.Env = env
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
return stdout.String(), stderr.String(), err
}
// testExplicitBeadsDirIsAuthoritative covers the regression where an explicit
// BEADS_DIR without project files was ignored during discovery: bd walked up
// from CWD, bound the parent workspace, and `bd init` then refused ("already
// initialized") while data commands read and wrote the parent's store.
func testExplicitBeadsDirIsAuthoritative(t *testing.T, bd string, mode explicitBeadsDirMode) {
t.Helper()
home := t.TempDir()
parent := t.TempDir()
initGitRepoAt(t, parent)
parentBeadsDir := filepath.Join(parent, ".beads")
child := filepath.Join(parent, "child")
explicit := filepath.Join(child, ".beads")
if err := os.MkdirAll(child, 0o755); err != nil {
t.Fatal(err)
}
if mode.proxied {
for _, root := range []string{filepath.Join(parentBeadsDir, "dolt"), filepath.Join(explicit, "dolt")} {
root := root
t.Cleanup(func() {
if _, err := os.Stat(root); err != nil {
return
}
if err := proxy.Shutdown(root); err != nil {
t.Logf("proxy.Shutdown(%s): %v", root, err)
}
})
shutdownProxyOnInterrupt(t, root)
}
}
initArgs := append([]string{"init", "--quiet", "--non-interactive", "--skip-agents", "--skip-hooks"}, mode.initArgs...)
if stdout, stderr, err := runExplicitBeadsDirBD(t, bd, mode, home, parent, "", append(initArgs, "--prefix", "par")...); err != nil {
t.Fatalf("parent bd init: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
}
parentID, stderr, err := runExplicitBeadsDirBD(t, bd, mode, home, parent, "", "create", "--silent", "parent issue")
if err != nil {
t.Fatalf("parent bd create: %v\nstderr:\n%s", err, stderr)
}
parentID = strings.TrimSpace(parentID)
// A data command against the uninitialized explicit dir must not fall
// back to the parent workspace.
stdout, stderr, err := runExplicitBeadsDirBD(t, bd, mode, home, child, explicit, "list", "--json")
if err == nil || strings.Contains(stdout, parentID) {
t.Errorf("bd list with BEADS_DIR=%s (no workspace yet) should fail without reading the parent store; err=%v\nstdout:\n%s\nstderr:\n%s", explicit, err, stdout, stderr)
} else if !strings.Contains(stderr, "no beads database found") {
t.Errorf("bd list with an uninitialized BEADS_DIR: want \"no beads database found\", got stderr:\n%s", stderr)
}
// bd init must initialize the explicit dir (existing but empty, as a
// caller that pre-creates it would leave it), not refuse because of the
// parent workspace.
if err := os.MkdirAll(explicit, 0o755); err != nil {
t.Fatal(err)
}
if stdout, stderr, err := runExplicitBeadsDirBD(t, bd, mode, home, child, explicit, append(initArgs, "--prefix", "kid")...); err != nil {
t.Fatalf("bd init with BEADS_DIR=%s: %v\nstdout:\n%s\nstderr:\n%s", explicit, err, stdout, stderr)
}
childCfg, err := configfile.Load(explicit)
if err != nil || childCfg == nil {
t.Fatalf("load %s metadata: cfg=%v err=%v", explicit, childCfg, err)
}
if childCfg.DoltDatabase != "kid" {
t.Fatalf("explicit BEADS_DIR dolt_database = %q, want %q", childCfg.DoltDatabase, "kid")
}
parentCfg, err := configfile.Load(parentBeadsDir)
if err != nil || parentCfg == nil || parentCfg.DoltDatabase != "par" {
t.Fatalf("parent metadata changed: cfg=%+v err=%v", parentCfg, err)
}
// Writes through the explicit dir land in the new workspace only.
childID, stderr, err := runExplicitBeadsDirBD(t, bd, mode, home, child, explicit, "create", "--silent", "child issue")
if err != nil {
t.Fatalf("bd create with BEADS_DIR=%s: %v\nstderr:\n%s", explicit, err, stderr)
}
childID = strings.TrimSpace(childID)
if !strings.HasPrefix(childID, "kid-") {
t.Fatalf("bd create with BEADS_DIR=%s minted %q, want a kid- ID", explicit, childID)
}
parentList, stderr, err := runExplicitBeadsDirBD(t, bd, mode, home, parent, "", "list", "--json")
if err != nil {
t.Fatalf("parent bd list: %v\nstderr:\n%s", err, stderr)
}
if strings.Contains(parentList, childID) || !strings.Contains(parentList, parentID) {
t.Fatalf("parent store should hold only %s, got:\n%s", parentID, parentList)
}
}
func TestEmbeddedInitExplicitBeadsDirIsAuthoritative(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt init tests")
}
t.Parallel()
testExplicitBeadsDirIsAuthoritative(t, buildEmbeddedBD(t), explicitBeadsDirMode{env: bdEnv})
}
func TestProxiedServerInitExplicitBeadsDirIsAuthoritative(t *testing.T) {
requireProxiedServerEnv(t)
testExplicitBeadsDirIsAuthoritative(t, buildEmbeddedBD(t), explicitBeadsDirMode{
initArgs: []string{"--proxied-server"},
env: bdProxiedEnv,
proxied: true,
})
}

View file

@ -6,6 +6,7 @@ import (
"strings"
"testing"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/configfile"
)
@ -125,9 +126,8 @@ func TestPersistInitSyncRemoteExplicitRemoteWritesTargetDir(t *testing.T) {
}
callerConfig := filepath.Join(callerBeadsDir, "config.yaml")
if err := os.WriteFile(callerConfig, []byte("sync.remote: git+ssh://git@example.com/wrong/repo.git\n"), 0o600); err != nil {
t.Fatal(err)
}
const callerRemote = "git+ssh://git@example.com/wrong/repo.git"
seedSyncRemote(t, callerBeadsDir, callerRemote)
targetConfig := filepath.Join(targetBeadsDir, "config.yaml")
if err := os.WriteFile(targetConfig, []byte("# Beads Config\n"), 0o600); err != nil {
t.Fatal(err)
@ -162,6 +162,56 @@ func TestPersistInitSyncRemoteExplicitRemoteWritesTargetDir(t *testing.T) {
if strings.Contains(string(callerBytes), remote) {
t.Fatalf("caller config.yaml was modified instead of target:\n%s", callerBytes)
}
// Stronger than the absence above: the caller still resolves to what it had.
// A write that landed somewhere unreadable would satisfy "does not contain
// the new remote" while having quietly destroyed the old one.
if got := config.GetStringFromDir(callerBeadsDir, "sync.remote"); got != callerRemote {
t.Fatalf("caller sync.remote = %q, want it untouched at %q:\n%s", got, callerRemote, callerBytes)
}
}
// `bd init --remote` runs createConfigYaml and then immediately writes
// sync.remote into what it just created. That template is comments and nothing
// else, which is the one document shape yaml.v3 parses to no nodes at all — so a
// writer that round-trips a node tree has nothing to write back but the key it
// added, and the operator's first commit after init carries a config.yaml with
// its entire documentation deleted. It is git-tracked, so they see it.
//
// This runs the real pair in the real order rather than asserting on a replica
// of the template, so it stays true if either side moves.
func TestInitPersistingSyncRemoteKeepsTheConfigTemplate(t *testing.T) {
beadsDir := filepath.Join(t.TempDir(), ".beads")
if err := os.MkdirAll(beadsDir, 0o750); err != nil {
t.Fatal(err)
}
if err := createConfigYaml(beadsDir, false, ""); err != nil {
t.Fatalf("createConfigYaml: %v", err)
}
template, err := os.ReadFile(filepath.Join(beadsDir, "config.yaml"))
if err != nil {
t.Fatal(err)
}
const remote = "git+ssh://git@example.com/right/repo.git"
if err := persistInitSyncRemote(beadsDir, remote, remote, false, true, false); err != nil {
t.Fatalf("persistInitSyncRemote: %v", err)
}
body, err := os.ReadFile(filepath.Join(beadsDir, "config.yaml"))
if err != nil {
t.Fatal(err)
}
for _, line := range strings.Split(string(template), "\n") {
if strings.TrimSpace(line) == "" {
continue
}
if !strings.Contains(string(body), line) {
t.Errorf("init dropped a line of its own config template: %q\ngot:\n%s", line, body)
}
}
if got := config.GetStringFromDir(beadsDir, "sync.remote"); got != remote {
t.Errorf("sync.remote = %q, want %q\n%s", got, remote, body)
}
}
func TestInitTimeCloneConfigExternalDefaultsAreSelfContained(t *testing.T) {

View file

@ -75,6 +75,20 @@ func guardLegacyUpgradeWorkspace(beadsDir string) error {
return nil
}
if serverMode {
if !present && isEmptyDirectory(filepath.Join(beadsDir, "dolt")) {
// An empty .beads/dolt holds no Dolt data, so no legacy release
// could have left anything in it to protect: it carries no more
// evidence than a server workspace without that directory, which
// is admitted above. bd creates exactly this shape itself — the
// local Dolt root is made on use even when the data lives on an
// external server — so refusing it made `bd init --server
// --external` fail over a provisioner's empty root, and made a
// workspace that lost its gitignored witness unusable with no bd
// command able to repair it. Admitting it lets the command re-seed
// the witness. A present pre-1.0 witness was refused above, and a
// root holding anything at all still refuses below.
return nil
}
if present && classifyVersionWitness(version) == witnessEraUnknown {
// A witness that is present but unreadable — including one left
// blank or whitespace-only by an interrupted or disk-full
@ -265,6 +279,22 @@ func hasLegacyDoltRoot(beadsDir string) bool {
return err == nil && info.IsDir() && info.Mode()&os.ModeSymlink == 0
}
// isEmptyDirectory reports whether path is a real (non-symlink) directory with
// no entries. Any error reading it answers false, so callers fail closed.
func isEmptyDirectory(path string) bool {
info, err := os.Lstat(path)
if err != nil || !info.IsDir() || info.Mode()&os.ModeSymlink != 0 {
return false
}
dir, err := os.Open(path) // #nosec G304 -- bounded probe beneath selected workspace
if err != nil {
return false
}
defer func() { _ = dir.Close() }()
names, err := dir.Readdirnames(1)
return len(names) == 0 && err == io.EOF
}
func isNonEmptyRegularFile(path string) bool {
info, err := os.Lstat(path)
return err == nil && info.Mode().IsRegular() && info.Size() > 0

View file

@ -31,7 +31,7 @@ func bindSelectedWorkspaceConfig(t *testing.T, beadsDir string) {
}
// writeDoltRootWorkspace lays down the ambiguous shape the guard classifies: a
// .beads directory that owns a local Dolt root, plus whatever metadata.json,
// .beads directory that owns a populated local Dolt root, plus whatever metadata.json,
// config.yaml and version witness the case needs. An empty string means "do not
// write this file at all".
func writeDoltRootWorkspace(t *testing.T, metadata, configYaml, version string) string {
@ -52,9 +52,7 @@ func writeDoltRootWorkspace(t *testing.T, metadata, configYaml, version string)
t.Fatal(err)
}
}
if err := os.Mkdir(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
t.Fatal(err)
}
populateLegacyDoltRoot(t, beadsDir)
bindSelectedWorkspaceConfig(t, beadsDir)
return beadsDir
}

View file

@ -490,7 +490,7 @@ func TestLegacyGuardUsesSelectedTargetSharedServerConfig(t *testing.T) {
// TestLegacyGuardAdmitsConfigYamlServerWorkspace runs the real binary against
// the workspace shape gc provisions — `dolt.mode: server` in
// .beads/config.yaml, a local .beads/dolt root, a metadata.json that names no
// .beads/config.yaml, a populated local .beads/dolt root, a metadata.json that names no
// dolt_mode — and pins that the guard no longer calls it legacy. The in-process
// guard tests bind the workspace config themselves; only a subprocess proves
// that PersistentPreRunE's own binding puts the selected workspace's
@ -518,9 +518,7 @@ func TestLegacyGuardAdmitsConfigYamlServerWorkspace(t *testing.T) {
repoDir := t.TempDir()
initGitRepo(t, repoDir)
beadsDir := filepath.Join(repoDir, ".beads")
if err := os.MkdirAll(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
t.Fatal(err)
}
populateLegacyDoltRoot(t, beadsDir)
writeFile(t, filepath.Join(beadsDir, "metadata.json"), []byte(`{"backend":"dolt","dolt_database":"hq"}`))
writeFile(t, filepath.Join(beadsDir, "config.yaml"), []byte("dolt:\n mode: server\n auto-start: false\n"))
if tt.version != "" {

View file

@ -0,0 +1,143 @@
package main
import (
"os"
"path/filepath"
"testing"
)
// populateLegacyDoltRoot lays down a .beads/dolt root that holds a Dolt
// database, the shape a historical local sql-server left behind. The guard has
// to treat such a root as evidence worth protecting.
func populateLegacyDoltRoot(t *testing.T, beadsDir string) {
t.Helper()
if err := os.MkdirAll(filepath.Join(beadsDir, "dolt", "beads", ".dolt"), 0o700); err != nil {
t.Fatal(err)
}
}
// writeEmptyDoltRootServerWorkspace lays down the shape a current bd leaves
// behind after `bd init --server --external`: server mode selected, a
// .beads/dolt directory that bd created on use but that holds nothing because
// the data lives on the external server, and — once the gitignored witness has
// been lost, or when a provisioner created the empty root before bd init —
// no .local_version.
func writeEmptyDoltRootServerWorkspace(t *testing.T, metadata, configYaml, version string) string {
t.Helper()
beadsDir := t.TempDir()
for name, contents := range map[string]string{
"metadata.json": metadata,
"config.yaml": configYaml,
} {
if contents == "" {
continue
}
if err := os.WriteFile(filepath.Join(beadsDir, name), []byte(contents), 0o600); err != nil {
t.Fatal(err)
}
}
if version != "" {
if err := writeLocalVersion(filepath.Join(beadsDir, localVersionFile), version); err != nil {
t.Fatal(err)
}
}
if err := os.Mkdir(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
t.Fatal(err)
}
bindSelectedWorkspaceConfig(t, beadsDir)
return beadsDir
}
const externalServerMetadata = `{"backend":"dolt","dolt_mode":"server","dolt_server_host":"db.example.test","dolt_database":"ext_db"}`
// TestLegacyUpgradeGuardAdmitsServerWorkspaceWithEmptyDoltRoot pins the
// external-host recovery: a server-mode workspace whose .beads/dolt is empty
// and whose witness is missing holds no local Dolt data a legacy release could
// have left there, so it carries no more evidence than a workspace with no
// .beads/dolt at all — which the guard already admits. Refusing it made the
// workspace unusable after `bd init --server --external` whenever the witness
// was absent, with no bd command able to repair it.
func TestLegacyUpgradeGuardAdmitsServerWorkspaceWithEmptyDoltRoot(t *testing.T) {
cases := []struct {
name string
metadata string
configYaml string
}{
{name: "metadata.json external server", metadata: externalServerMetadata},
{name: "metadata.json server", metadata: `{"backend":"dolt","dolt_mode":"server"}`},
{name: "config.yaml server mode", configYaml: configYamlServerMode},
// Proxied-server does not select server mode, so it never reaches the
// empty-root branch; it is admitted by the final non-embedded arm. Pin
// that so a later change to either arm cannot start refusing it.
{name: "metadata.json proxied server", metadata: `{"backend":"dolt","dolt_mode":"proxied-server"}`},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
warnings := captureLegacyUpgradeWarnings(t)
beadsDir := writeEmptyDoltRootServerWorkspace(t, tc.metadata, tc.configYaml, "")
if err := guardLegacyUpgradeWorkspace(beadsDir); err != nil {
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want nil", err)
}
if warnings.Len() != 0 {
t.Fatalf("guard warned about an absent witness: %q", warnings.String())
}
})
}
}
// TestLegacyUpgradeGuardEmptyDoltRootAdmissionStaysNarrow proves the empty-root
// admission relaxes nothing else: pre-1.0 evidence still refuses, a root that
// holds anything still refuses, and outside server mode an empty root is still
// the legacy embedded shape.
func TestLegacyUpgradeGuardEmptyDoltRootAdmissionStaysNarrow(t *testing.T) {
t.Run("historical server witness", func(t *testing.T) {
captureLegacyUpgradeWarnings(t)
beadsDir := writeEmptyDoltRootServerWorkspace(t, externalServerMetadata, "", "0.62.0")
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
}
})
t.Run("historical embedded witness", func(t *testing.T) {
captureLegacyUpgradeWarnings(t)
beadsDir := writeEmptyDoltRootServerWorkspace(t, externalServerMetadata, "", "0.49.6")
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
}
})
for _, entry := range []string{"beads", ".dolt", "stray-file"} {
t.Run("root holding "+entry, func(t *testing.T) {
captureLegacyUpgradeWarnings(t)
beadsDir := writeEmptyDoltRootServerWorkspace(t, externalServerMetadata, "", "")
path := filepath.Join(beadsDir, "dolt", entry)
var err error
if entry == "stray-file" {
err = os.WriteFile(path, nil, 0o600)
} else {
err = os.Mkdir(path, 0o700)
}
if err != nil {
t.Fatal(err)
}
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
}
})
}
for _, metadata := range []string{`{"backend":"dolt"}`, `{"backend":"dolt","dolt_mode":"embedded"}`} {
t.Run("embedded "+metadata, func(t *testing.T) {
captureLegacyUpgradeWarnings(t)
beadsDir := writeEmptyDoltRootServerWorkspace(t, metadata, "", "")
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
}
})
}
}

View file

@ -0,0 +1,141 @@
//go:build cgo
package main
import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"
)
// runExternalServerBD runs the bd binary under test in repoDir with env and
// returns its combined output.
func runExternalServerBD(t *testing.T, repoDir string, env []string, args ...string) (string, error) {
t.Helper()
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, buildBDUnderTest(t), args...)
cmd.Dir = repoDir
cmd.Env = env
out, err := cmd.CombinedOutput()
if ctxErr := ctx.Err(); ctxErr != nil {
t.Fatalf("bd %s did not finish before the deadline: %v\n%s", strings.Join(args, " "), ctxErr, out)
}
return string(out), err
}
// externalServerTestEnv isolates a bd child from the developer's home and
// config (a real ~/.beads may select a shared server) and from the ambient
// BEADS_DOLT_* endpoint this package's TestMain exports, so only the flags and
// files under test choose the target.
func externalServerTestEnv(t *testing.T) []string {
t.Helper()
home := t.TempDir()
return append(envWithoutBeadsStorageSettings(),
"HOME="+home,
"XDG_CONFIG_HOME="+filepath.Join(home, ".config"),
"BEADS_TEST_IGNORE_REPO_CONFIG=1",
"BD_DISABLE_METRICS=1",
"BEADS_DOLT_AUTO_START=0",
)
}
func externalServerInitArgs(database string, extra ...string) []string {
args := []string{
"init", "--quiet", "--server", "--external",
"--server-host", "127.0.0.1",
"--server-port", fmt.Sprintf("%d", testDoltServerPort),
"--database", database,
"--prefix", "ext",
"--skip-hooks", "--skip-agents",
}
return append(args, extra...)
}
func assertCurrentVersionWitness(t *testing.T, beadsDir string) {
t.Helper()
data, err := os.ReadFile(filepath.Join(beadsDir, localVersionFile))
if err != nil {
t.Fatalf("expected %s after the command: %v", localVersionFile, err)
}
if got := strings.TrimSpace(string(data)); got != Version {
t.Fatalf("%s = %q, want %q", localVersionFile, got, Version)
}
}
// TestExternalServerInitWritesWitnessOverEmptyDoltRoot reproduces the
// provisioner shape: config.yaml already selects server mode and an empty
// .beads/dolt exists before `bd init --server --external` runs. The legacy
// guard used to refuse that init as a "legacy Dolt server workspace", so the
// scope never got a witness and every later command was refused too.
func TestExternalServerInitWritesWitnessOverEmptyDoltRoot(t *testing.T) {
skipIfNoDolt(t)
env := externalServerTestEnv(t)
repoDir := t.TempDir()
initGitRepo(t, repoDir)
beadsDir := filepath.Join(repoDir, ".beads")
if err := os.MkdirAll(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
t.Fatal(err)
}
writeFile(t, filepath.Join(beadsDir, "config.yaml"), []byte("dolt.mode: server\n"))
database := uniqueTestDBName(t)
t.Cleanup(func() { dropTestDatabase(database, testDoltServerPort) })
out, err := runExternalServerBD(t, repoDir, append(env, "BEADS_DIR="+beadsDir),
externalServerInitArgs(database, "--init-if-missing")...)
if err != nil {
t.Fatalf("bd init --server --external over an empty .beads/dolt failed: %v\n%s", err, out)
}
assertCurrentVersionWitness(t, beadsDir)
}
// TestExternalServerWorkspaceRecoversMissingWitness covers a workspace already
// in the broken state: initialized against an external server, then left
// without .local_version (it is gitignored, so a fresh checkout or a cleanup
// drops it) while bd's own empty .beads/dolt remains. The next ordinary
// command must open the workspace and re-seed the witness with no manual
// steps.
func TestExternalServerWorkspaceRecoversMissingWitness(t *testing.T) {
skipIfNoDolt(t)
env := externalServerTestEnv(t)
repoDir := t.TempDir()
initGitRepo(t, repoDir)
beadsDir := filepath.Join(repoDir, ".beads")
database := uniqueTestDBName(t)
t.Cleanup(func() { dropTestDatabase(database, testDoltServerPort) })
out, err := runExternalServerBD(t, repoDir, env, externalServerInitArgs(database)...)
if err != nil {
t.Fatalf("bd init --server --external failed: %v\n%s", err, out)
}
assertCurrentVersionWitness(t, beadsDir)
entries, err := os.ReadDir(filepath.Join(beadsDir, "dolt"))
if err != nil {
t.Fatalf("precondition: expected bd init to leave a .beads/dolt directory: %v", err)
}
if len(entries) != 0 {
t.Fatalf("precondition: expected an empty .beads/dolt for an external server, found %d entries", len(entries))
}
if err := os.Remove(filepath.Join(beadsDir, localVersionFile)); err != nil {
t.Fatal(err)
}
out, err = runExternalServerBD(t, repoDir, env, "list", "--json", "--all")
if err != nil {
t.Fatalf("bd list on an external-server workspace without a witness failed: %v\n%s", err, out)
}
if strings.Contains(out, "explicit migration is required") {
t.Fatalf("bd list reported a legacy-upgrade refusal:\n%s", out)
}
assertCurrentVersionWitness(t, beadsDir)
}

View file

@ -206,14 +206,12 @@ func TestLegacyUpgradeGuardMetadataLessSQLiteAndCurrentEmbeddedPrecedence(t *tes
}
})
t.Run("explicit server metadata with missing version witness and local Dolt root is refused", func(t *testing.T) {
t.Run("explicit server metadata with missing version witness and populated local Dolt root is refused", func(t *testing.T) {
beadsDir := t.TempDir()
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), []byte(`{"backend":"dolt","dolt_mode":"server"}`), 0o600); err != nil {
t.Fatal(err)
}
if err := os.Mkdir(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
t.Fatal(err)
}
populateLegacyDoltRoot(t, beadsDir)
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
}
@ -290,9 +288,7 @@ func TestLegacyUpgradeGuardServerSelectionBeatsStaleEmbeddedRepository(t *testin
t.Fatal(err)
}
}
if err := os.Mkdir(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
t.Fatal(err)
}
populateLegacyDoltRoot(t, beadsDir)
staleRepo := filepath.Join(beadsDir, "embeddeddolt", "stale", ".dolt")
if err := os.MkdirAll(staleRepo, 0o700); err != nil {
t.Fatal(err)

View file

@ -84,7 +84,8 @@ func TestLegacyServerVersionSpansHistoricalServerEra(t *testing.T) {
}
// writeSelectedServerWorkspace lays down the ambiguous shape the guard has to
// classify: a selected Dolt server workspace that still owns a local Dolt root.
// classify: a selected Dolt server workspace that still owns a populated local
// Dolt root.
func writeSelectedServerWorkspace(t *testing.T, version string) string {
t.Helper()
beadsDir := t.TempDir()
@ -97,9 +98,7 @@ func writeSelectedServerWorkspace(t *testing.T, version string) string {
t.Fatal(err)
}
}
if err := os.Mkdir(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
t.Fatal(err)
}
populateLegacyDoltRoot(t, beadsDir)
return beadsDir
}

View file

@ -240,7 +240,7 @@ func runListCore(cmd *cobra.Command, _ []string) error {
}
if in.watchMode {
if err := watchIssues(ctx, activeStore, filter, in.ReadyFlag, in.ParentID, in.SortBy, in.Reverse, in.effectiveLimit); err != nil {
if err := watchIssues(ctx, activeStore, filter, in.ReadyFlag, in.ParentID, in.SortBy, in.Reverse, in.effectiveLimit, in.Status); err != nil {
if capErr := handleMaxRowsError(err); capErr != nil {
return capErr
}
@ -315,7 +315,7 @@ func runListCore(cmd *cobra.Command, _ []string) error {
return HandleError("loading dependencies for --deps: %v", depErr)
}
// Hierarchical --parent walks use an unlimited per-level query, so the tree is never page-truncated.
displayPrettyListWithDepsMode(treeIssues, false, allDeps, in.depsMode, false, in.ReadyFlag)
displayPrettyListWithDepsMode(treeIssues, false, allDeps, in.depsMode, false, in.ReadyFlag, in.Status)
printSkipLabelsFooter(in.SkipLabels)
return nil
}
@ -324,7 +324,7 @@ func runListCore(cmd *cobra.Command, _ []string) error {
if depErr != nil && in.depsMode != "" {
return HandleError("loading dependencies for --deps: %v", depErr)
}
displayPrettyListWithDepsMode(issues, false, allDeps, in.depsMode, truncated, in.ReadyFlag)
displayPrettyListWithDepsMode(issues, false, allDeps, in.depsMode, truncated, in.ReadyFlag, in.Status)
printTruncationHint(truncated, in.effectiveLimit)
printSkipLabelsFooter(in.SkipLabels)
return nil
@ -470,6 +470,14 @@ func init() {
// Infra type filtering: exclude agent/role/message by default
listCmd.Flags().Bool("include-infra", false, "Include infrastructure beads (agent/role/message) in output")
// Ephemeral plane: the wisps table is suppressed by default. This is the
// PLANE knob on its own — ListRequest.IncludeEphemeral — as distinct from
// --include-infra, which admits the plane AND lifts the infra-type
// exclusions above. Without it the plane is reachable from the CLI only
// through --include-infra's wider bundle, which leaves --wisp-type below
// with no narrow way to match anything.
listCmd.Flags().Bool("include-ephemeral", false, "Include ephemeral wisp-plane rows in output (normally hidden)")
// Explicit type exclusion
listCmd.Flags().StringSlice("exclude-type", nil, "Exclude issue types from results (comma-separated or repeatable, e.g., --exclude-type=convoy,epic)")

View file

@ -58,6 +58,7 @@ func TestListFooterLineCountsAreJustified(t *testing.T) {
name string
total, open, inProgress int
truncated, readyFiltered bool
statusSelector string
facts footerFacts
}{
{
@ -90,11 +91,19 @@ func TestListFooterLineCountsAreJustified(t *testing.T) {
total: 0, open: 0, inProgress: 0,
facts: footerFacts{"total": 0, "open": 0, "in_progress": 0},
},
{
// Explicit --status under --ready is a different pin. The footer
// names that selector and must not reuse the default-open sentence.
name: "ready-filtered, explicit in_progress",
total: 3, open: 0, inProgress: 3, readyFiltered: true,
statusSelector: "in_progress",
facts: footerFacts{"total": 3},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
line := listFooterLine(tt.total, tt.open, tt.inProgress, tt.truncated, tt.readyFiltered)
line := listFooterLine(tt.total, tt.open, tt.inProgress, tt.truncated, tt.readyFiltered, tt.statusSelector)
assertEveryNumberIsJustified(t, line, tt.facts)
// The headline count always describes the rows actually rendered.
@ -110,7 +119,7 @@ func TestListFooterLineCountsAreJustified(t *testing.T) {
// reader cannot distinguish "none exist" from "none survived the filter".
func TestListFooterLineReadyOmitsVacuousInProgressCount(t *testing.T) {
// 40 in-progress issues match the same query; --ready removed them all.
line := listFooterLine(6, 6, 0, false, true)
line := listFooterLine(6, 6, 0, false, true, "")
if strings.Contains(line, "in progress)") {
t.Errorf("--ready summary asserts an in-progress count that the filter forced to zero: %q", line)
@ -126,7 +135,7 @@ func TestListFooterLineReadyOmitsVacuousInProgressCount(t *testing.T) {
// Without --ready the breakdown is a genuine finding and must survive: this is
// the half of the behaviour the fix must not regress.
func TestListFooterLineUnfilteredKeepsBreakdown(t *testing.T) {
line := listFooterLine(9, 6, 3, false, false)
line := listFooterLine(9, 6, 3, false, false, "")
for _, want := range []string{"Total: 9 issues", "6 open", "3 in progress"} {
if !strings.Contains(line, want) {
t.Errorf("unfiltered summary lost %q, got: %q", want, line)
@ -157,7 +166,7 @@ func TestDisplayWatchedIssueListReadyFooterDisclosesFilter(t *testing.T) {
// for; the footer is what is under test, and this keeps the file free of
// the cgo-tagged stub so it still compiles under CGO_ENABLED=0.
out := captureStdout(t, func() error {
displayWatchedIssueList(context.Background(), nil, issues, false, true)
displayWatchedIssueList(context.Background(), nil, issues, false, true, "")
return nil
})
@ -177,7 +186,7 @@ func TestDisplayPrettyListWithDepsReadyFooterDisclosesFilter(t *testing.T) {
}
out := captureStdout(t, func() error {
displayPrettyListWithDeps(issues, false, nil, false, true)
displayPrettyListWithDeps(issues, false, nil, false, true, "")
return nil
})
if strings.Contains(out, "in progress)") {
@ -190,7 +199,7 @@ func TestDisplayPrettyListWithDepsReadyFooterDisclosesFilter(t *testing.T) {
// The other half: without --ready the same wrapper must keep the breakdown,
// so the fix cannot be "never print counts".
plain := captureStdout(t, func() error {
displayPrettyListWithDeps(issues, false, nil, false, false)
displayPrettyListWithDeps(issues, false, nil, false, false, "")
return nil
})
if !strings.Contains(plain, "in progress)") {
@ -201,7 +210,7 @@ func TestDisplayPrettyListWithDepsReadyFooterDisclosesFilter(t *testing.T) {
// Truncation and readiness are independent scopes and both must be disclosed
// when both apply — neither may silently mask the other.
func TestListFooterLineTruncationDisclosedAlongsideReady(t *testing.T) {
line := listFooterLine(5, 5, 0, true, true)
line := listFooterLine(5, 5, 0, true, true, "")
if !strings.Contains(line, "truncated by --limit") {
t.Errorf("truncated page must say so even under --ready, got: %q", line)
}
@ -212,3 +221,65 @@ func TestListFooterLineTruncationDisclosedAlongsideReady(t *testing.T) {
t.Errorf("a truncated page must never be labelled Total: %q", line)
}
}
// GH#5832: an explicit --status under --ready is a different pin. The default
// "open only — --ready excludes in_progress" sentence must not be reused.
func TestListFooterLineReadyExplicitStatusNamesSelector(t *testing.T) {
line := listFooterLine(3, 0, 3, false, true, "in_progress")
if strings.Contains(line, "open only") || strings.Contains(line, "excludes in_progress") {
t.Errorf("explicit --status must not reuse the default-open sentence: %q", line)
}
if !strings.Contains(line, "in_progress only") {
t.Errorf("explicit --status footer must name the selected status, got: %q", line)
}
if strings.Contains(line, "in progress)") {
t.Errorf("--ready summary must still omit the vacuous in-progress count: %q", line)
}
}
// --pretty/--tree/--deps share displayPrettyListWithDepsMode; --watch uses
// displayWatchedIssueList. Both must thread the explicit selector so the
// default-open sentence cannot leak through a wrapper.
func TestDisplayPrettyListWithDepsReadyExplicitStatusFooter(t *testing.T) {
issues := []*types.Issue{
{ID: "bd-1", Title: "A", Status: types.StatusInProgress, Priority: 1, IssueType: types.TypeTask},
}
out := captureStdout(t, func() error {
displayPrettyListWithDeps(issues, false, nil, false, true, "in_progress")
return nil
})
if strings.Contains(out, "open only") || strings.Contains(out, "excludes in_progress") {
t.Errorf("--status in_progress --ready --pretty reused the default-open sentence: %q", out)
}
if !strings.Contains(out, "in_progress only") {
t.Errorf("--status in_progress --ready --pretty must name the selected status, got: %q", out)
}
depsOut := captureStdout(t, func() error {
displayPrettyListWithDepsMode(issues, false, nil, "scheduling", false, true, "in_progress")
return nil
})
if strings.Contains(depsOut, "open only") || strings.Contains(depsOut, "excludes in_progress") {
t.Errorf("--status in_progress --ready --deps reused the default-open sentence: %q", depsOut)
}
if !strings.Contains(depsOut, "in_progress only") {
t.Errorf("--status in_progress --ready --deps must name the selected status, got: %q", depsOut)
}
}
func TestDisplayWatchedIssueListReadyExplicitStatusFooter(t *testing.T) {
issues := []*types.Issue{
{ID: "bd-1", Title: "A", Status: types.StatusInProgress, Priority: 1, IssueType: types.TypeTask},
}
out := captureStdout(t, func() error {
displayWatchedIssueList(context.Background(), nil, issues, false, true, "in_progress")
return nil
})
if strings.Contains(out, "open only") || strings.Contains(out, "excludes in_progress") {
t.Errorf("--status in_progress --ready --watch reused the default-open sentence: %q", out)
}
if !strings.Contains(out, "in_progress only") {
t.Errorf("--status in_progress --ready --watch must name the selected status, got: %q", out)
}
}

View file

@ -317,7 +317,7 @@ func TestListDisplayPrettyList_TruncatedSummary(t *testing.T) {
}
out := captureStdout(t, func() error {
displayPrettyListWithDepsMode(issues, false, nil, "", true, false)
displayPrettyListWithDepsMode(issues, false, nil, "", true, false, "")
return nil
})
if !strings.Contains(out, "Showing 2 issues") {
@ -343,7 +343,7 @@ func TestDisplayWatchedIssueList_UsesDependencyHierarchy(t *testing.T) {
}
out := captureStdout(t, func() error {
displayWatchedIssueList(context.Background(), store, []*types.Issue{child, parent}, false, false)
displayWatchedIssueList(context.Background(), store, []*types.Issue{child, parent}, false, false, "")
return nil
})

View file

@ -134,6 +134,7 @@ func gatherListInput(cmd *cobra.Command) (listInput, error) {
in.IncludeTemplates, _ = cmd.Flags().GetBool("include-templates")
in.IncludeGates, _ = cmd.Flags().GetBool("include-gates")
in.IncludeInfra, _ = cmd.Flags().GetBool("include-infra")
in.IncludeEphemeral, _ = cmd.Flags().GetBool("include-ephemeral")
in.ExcludeTypes, _ = cmd.Flags().GetStringSlice("exclude-type")
in.ParentID, _ = cmd.Flags().GetString("parent")
@ -158,6 +159,28 @@ func gatherListInput(cmd *cobra.Command) (listInput, error) {
return in, HandleError("invalid wisp-type %q (must be %s)", s, types.ValidWispTypeNames())
}
in.WispType = &wt
// wisp_type is a PREDICATE, not a plane selector (see
// issueops.ListRequest.WispType): it narrows whatever the rest of the
// request admitted. On a default listing that is the durable rows,
// which carry no classification — so this request cannot match a row
// for ANY input, and would report an empty listing rather than the
// unread plane that actually holds the answer.
//
// The request stays LAWFUL at the API layer, where composing to empty
// is the pinned contract. Refusing it belongs HERE, at the CLI, where
// the only thing a human can have meant is the combination that
// answers with rows.
//
// An explicit --type is left alone: an infra type routes to the plane
// by itself, so the request may be satisfiable and this cannot tell
// without the workspace's infra vocabulary, which this layer does not
// load.
if !in.IncludeEphemeral && !in.IncludeInfra && in.IssueType == "" {
return in, HandleErrorWithHint(
fmt.Sprintf("--wisp-type %s cannot match anything here: it filters the wisp_type column, and this listing admits only durable rows, which never carry one", s),
"add --include-ephemeral to admit the ephemeral plane (or --include-infra, which admits it as part of a wider bundle)")
}
}
in.DeferredFlag, _ = cmd.Flags().GetBool("deferred")
@ -308,10 +331,8 @@ func gatherListInput(cmd *cobra.Command) (listInput, error) {
in.effectiveLimit = 0
case listLimitConfigured:
in.effectiveLimit = limit
case !ui.IsTerminal():
in.effectiveLimit = 0 // Piped stdout should not truncate (GH#4094)
case ui.IsAgentMode():
in.effectiveLimit = 20
default:
in.effectiveLimit = unflaggedLimit(limit)
}
// The request carries the limit the caller receives. Which row limit that
// implies for the query - a sort SQL cannot express fetches everything and
@ -366,3 +387,28 @@ func parseListTimeFlag(cmd *cobra.Command, name string) (*time.Time, error) {
}
return &t, nil
}
// agentModeLimit is the page size an unflagged listing gets in agent mode on a
// terminal: ultra-compact output for an LLM context window.
const agentModeLimit = 20
// unflaggedLimit is the limit a listing command uses when the caller named
// none: the part of the policy `bd list` and `bd query` share, so the two
// cannot drift (GH#6229). Each command resolves its own earlier branches first
// (an explicit --limit, `bd list`'s --all and list.limit) and hands its own
// default here as fallback.
func unflaggedLimit(fallback int) int {
return resolveUnflaggedLimit(fallback, ui.IsTerminal(), ui.IsAgentMode())
}
// resolveUnflaggedLimit is unflaggedLimit with the environment passed in, so
// the terminal and agent-mode branches are testable from a piped `go test`.
func resolveUnflaggedLimit(fallback int, stdoutIsTerminal, agentMode bool) int {
switch {
case !stdoutIsTerminal:
return 0 // Piped stdout should not truncate (GH#4094)
case agentMode:
return agentModeLimit
}
return fallback
}

View file

@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"strings"
"text/template"
"github.com/steveyegge/beads/internal/types"
@ -18,8 +19,23 @@ func printTruncationHint(truncated bool, effectiveLimit int) {
if !truncated || effectiveLimit <= 0 || !ui.IsStderrTerminal() {
return
}
msg := fmt.Sprintf("\nShowing %d issues; more results matched but were hidden by --limit. Use --limit 0 for all, or --limit N to raise the cap.\n", effectiveLimit)
fmt.Fprint(os.Stderr, ui.RenderWarn(msg))
fmt.Fprint(os.Stderr, formatTruncationHint(effectiveLimit))
}
func truncationHintText(effectiveLimit int) string {
return fmt.Sprintf("Showing %d issues; more results matched but were hidden by --limit. Use --limit 0 for all, or --limit N to raise the cap.", effectiveLimit)
}
func formatTruncationHint(effectiveLimit int) string {
return composeTruncationHint(ui.RenderWarn, truncationHintText(effectiveLimit))
}
// composeTruncationHint keeps newlines outside the renderer. lipgloss pads
// blank lines to the widest-line width (alignTextHorizontal shortAmount =
// widestLine - lineWidth) and drops the trailing newline (GH#5685).
func composeTruncationHint(render func(string) string, text string) string {
rendered := strings.TrimRight(render(text), " \t\r\n")
return "\n" + rendered + "\n"
}
func outputDotFormat(out io.Writer, issues []*types.Issue, depsByIssueID map[string][]*types.Dependency) error {

View file

@ -4,9 +4,11 @@ import (
"bytes"
"errors"
"io"
"regexp"
"strings"
"testing"
lipgloss "charm.land/lipgloss/v2"
"github.com/steveyegge/beads/internal/types"
)
@ -167,3 +169,103 @@ func TestOutputFormattedListWithNoEdgesDoesNotWrite(t *testing.T) {
t.Fatalf("zero-edge output made %d writes, want 0", writer.writes)
}
}
func TestFormatTruncationHintExactBytes(t *testing.T) {
t.Parallel()
got := formatTruncationHint(2)
plain := stripANSIForTest(got)
const want = "\nShowing 2 issues; more results matched but were hidden by --limit. Use --limit 0 for all, or --limit N to raise the cap.\n"
if plain != want {
t.Fatalf("truncation hint bytes differ\ngot:\n%q\nwant:\n%q", plain, want)
}
if !strings.HasSuffix(got, "\n") {
t.Fatal("truncation hint missing trailing newline")
}
if strings.HasSuffix(got, "\n\n") {
t.Fatal("truncation hint ended with a double newline")
}
assertNoWhitespaceOnlyLine(t, plain)
got10 := stripANSIForTest(formatTruncationHint(10))
if !strings.Contains(got10, "Showing 10 issues;") {
t.Fatalf("limit interpolation missing: %q", got10)
}
if strings.HasPrefix(got10, "\n\n") {
t.Fatalf("leading double newline: %q", got10)
}
}
func TestComposeTruncationHintRejectsLipglossBlankLinePadding(t *testing.T) {
t.Parallel()
// Empty lipgloss Style (props==0) is identity — the colorless test
// default, and why RenderWarn("\n"+text+"\n") did not catch GH#5685.
// Foreground sets props so alignTextHorizontal pads blank lines to
// the widest-line width (not terminal width; no PTY required).
style := lipgloss.NewStyle().Foreground(lipgloss.Color("3"))
render := func(s string) string { return style.Render(s) }
text := truncationHintText(2)
buggy := render("\n" + text + "\n")
got := composeTruncationHint(render, text)
buggyPlain := stripANSIForTest(buggy)
gotPlain := stripANSIForTest(got)
padWidth := whitespaceOnlyLineWidth(buggyPlain)
if padWidth == 0 {
t.Fatalf("fixture: styled Render of newline-wrapped text should pad a blank line; got %q", buggyPlain)
}
if padWidth != len(text) {
t.Fatalf("lipgloss pad width = %d, want hint length %d (widest-line width, not terminal width)\nbuggy=%q", padWidth, len(text), buggyPlain)
}
widest := widestNonBlankLineWidth(buggyPlain)
if padWidth != widest {
t.Fatalf("lipgloss pad width = %d, want widest-line width %d\nbuggy=%q", padWidth, widest, buggyPlain)
}
assertNoWhitespaceOnlyLine(t, gotPlain)
if !strings.HasSuffix(got, "\n") {
t.Fatalf("composeTruncationHint missing trailing newline: %q", got)
}
if strings.HasSuffix(got, "\n\n") {
t.Fatal("composeTruncationHint ended with a double newline")
}
if got == buggy {
t.Fatalf("composeTruncationHint still uses newline-inside-Render bytes:\n%q", got)
}
}
func stripANSIForTest(s string) string {
return regexp.MustCompile(`\x1b\[[0-9;]*m`).ReplaceAllString(s, "")
}
func whitespaceOnlyLineWidth(s string) int {
width := 0
for _, line := range strings.Split(s, "\n") {
if line != "" && strings.TrimSpace(line) == "" && len(line) > width {
width = len(line)
}
}
return width
}
func widestNonBlankLineWidth(s string) int {
width := 0
for _, line := range strings.Split(s, "\n") {
if strings.TrimSpace(line) != "" && len(line) > width {
width = len(line)
}
}
return width
}
func assertNoWhitespaceOnlyLine(t *testing.T, s string) {
t.Helper()
for i, line := range strings.Split(s, "\n") {
if line != "" && strings.TrimSpace(line) == "" {
t.Fatalf("whitespace-only line at index %d (len=%d): %q", i, len(line), line)
}
}
}

View file

@ -156,7 +156,7 @@ func runListProxiedWatch(_ *cobra.Command, ctx context.Context, in listInput) er
if err != nil {
return fmt.Errorf("initial query: %w", err)
}
displayPrettyListWithDeps(issues, true, deps, hasMore, in.ReadyFlag)
displayPrettyListWithDeps(issues, true, deps, hasMore, in.ReadyFlag, in.Status)
printTruncationHint(hasMore, in.effectiveLimit)
lastSnapshot := issueSnapshot(issues)
@ -183,7 +183,7 @@ func runListProxiedWatch(_ *cobra.Command, ctx context.Context, in listInput) er
snap := issueSnapshot(issues)
if snap != lastSnapshot {
lastSnapshot = snap
displayPrettyListWithDeps(issues, true, deps, hasMore, in.ReadyFlag)
displayPrettyListWithDeps(issues, true, deps, hasMore, in.ReadyFlag, in.Status)
printTruncationHint(hasMore, in.effectiveLimit)
fmt.Fprintf(os.Stderr, "\nWatching for changes... (Press Ctrl+C to exit)\n")
}
@ -239,7 +239,7 @@ func renderProxiedListText(ctx context.Context, out io.Writer, issues []*types.I
printTruncationHint(truncated, in.effectiveLimit)
return nil
}
displayPrettyListWithDepsMode(issues, false, depsByIssueID, in.depsMode, truncated, in.ReadyFlag)
displayPrettyListWithDepsMode(issues, false, depsByIssueID, in.depsMode, truncated, in.ReadyFlag, in.Status)
printTruncationHint(truncated, in.effectiveLimit)
printSkipLabelsFooter(in.SkipLabels)
return nil

View file

@ -156,7 +156,7 @@ func loadWatchedIssues(ctx context.Context, store storage.DoltStorage, filter ty
// names its scope instead of asserting an in-progress count the ready filter
// forced to zero. A watch loop is where a stale "0 in progress" is most likely
// to be read as a live fact, so this is the path that most needs it.
func displayWatchedIssueList(ctx context.Context, store watchListDependencyStore, issues []*types.Issue, truncated, readyFiltered bool) {
func displayWatchedIssueList(ctx context.Context, store watchListDependencyStore, issues []*types.Issue, truncated, readyFiltered bool, statusSelector string) {
var allDeps map[string][]*types.Dependency
if store != nil {
deps, err := store.GetAllDependencyRecords(ctx)
@ -164,7 +164,7 @@ func displayWatchedIssueList(ctx context.Context, store watchListDependencyStore
allDeps = deps
}
}
displayPrettyListWithDeps(issues, true, allDeps, truncated, readyFiltered)
displayPrettyListWithDeps(issues, true, allDeps, truncated, readyFiltered, statusSelector)
}
// watchIssues returns an error only for the initial query — a failure there
@ -174,7 +174,7 @@ func displayWatchedIssueList(ctx context.Context, store watchListDependencyStore
// runListCore route a MaxRows cap violation through handleMaxRowsError for
// exit-code-2 semantics instead of watchIssues swallowing it and exiting 0
// (be-x42v.4 follow-up, review MUST-FIX 5).
func watchIssues(ctx context.Context, store storage.DoltStorage, filter types.IssueFilter, ready bool, parentID string, sortBy string, reverse bool, effectiveLimit int) error {
func watchIssues(ctx context.Context, store storage.DoltStorage, filter types.IssueFilter, ready bool, parentID string, sortBy string, reverse bool, effectiveLimit int, statusSelector string) error {
// Initial display
issues, err := loadWatchedIssues(ctx, store, filter, ready, parentID, sortBy, reverse)
if err != nil {
@ -184,7 +184,7 @@ func watchIssues(ctx context.Context, store storage.DoltStorage, filter types.Is
// below depends on; what is left is the cut and its verdict, and those are
// the shared epilogue's on every other listing this command has.
issues, truncated := workapi.FinishPage(issues, "", false, effectiveLimit, false)
displayWatchedIssueList(ctx, store, issues, truncated, ready)
displayWatchedIssueList(ctx, store, issues, truncated, ready, statusSelector)
printTruncationHint(truncated, effectiveLimit)
lastSnapshot := issueSnapshot(issues)
@ -214,7 +214,7 @@ func watchIssues(ctx context.Context, store storage.DoltStorage, filter types.Is
snap := issueSnapshot(issues)
if snap != lastSnapshot {
lastSnapshot = snap
displayWatchedIssueList(ctx, store, issues, truncated, ready)
displayWatchedIssueList(ctx, store, issues, truncated, ready, statusSelector)
printTruncationHint(truncated, effectiveLimit)
fmt.Fprintf(os.Stderr, "\nWatching for changes... (Press Ctrl+C to exit)\n")
}
@ -256,7 +256,7 @@ func runListProxiedHierarchicalParent(ctx context.Context, uw uow.UnitOfWork, in
}
// Hierarchical --parent walks use an unlimited per-level query; never page-truncated.
displayPrettyListWithDepsMode(treeIssues, false, depsByIssueID, in.depsMode, false, in.ReadyFlag)
displayPrettyListWithDepsMode(treeIssues, false, depsByIssueID, in.depsMode, false, in.ReadyFlag, in.Status)
printSkipLabelsFooter(in.SkipLabels)
return nil
}

View file

@ -147,26 +147,28 @@ func printPrettyTree(childrenMap map[string][]*types.Issue, parentID string, pre
// There is no --ready arm behind this one: it is the plain tree, so the
// summary keeps its status breakdown.
func displayPrettyList(issues []*types.Issue, showHeader bool) {
displayPrettyListWithDeps(issues, showHeader, nil, false, false)
displayPrettyListWithDeps(issues, showHeader, nil, false, false, "")
}
// displayPrettyListWithDeps displays issues in tree format using dependency data.
// readyFiltered must be threaded from the caller's --ready state rather than
// defaulted here: the watch paths reach the summary through this wrapper, and a
// hardcoded false silently restores the vacuous "(N open, 0 in progress)" that
// listFooterLine exists to suppress.
func displayPrettyListWithDeps(issues []*types.Issue, showHeader bool, allDeps map[string][]*types.Dependency, truncated, readyFiltered bool) {
displayPrettyListWithDepsMode(issues, showHeader, allDeps, "", truncated, readyFiltered)
// readyFiltered and statusSelector must be threaded from the caller's --ready
// / --status state rather than defaulted here: the watch paths reach the
// summary through this wrapper, and a hardcoded false silently restores the
// vacuous "(N open, 0 in progress)" that listFooterLine exists to suppress.
func displayPrettyListWithDeps(issues []*types.Issue, showHeader bool, allDeps map[string][]*types.Dependency, truncated, readyFiltered bool, statusSelector string) {
displayPrettyListWithDepsMode(issues, showHeader, allDeps, "", truncated, readyFiltered, statusSelector)
}
// listFooterLine renders the one-line summary under a text listing.
//
// The status breakdown is only meaningful when the query could have returned
// more than one status. Under --ready it cannot: BuildListFilter pins
// filter.Status to open (internal/workapi/list.go), so every row is open by
// construction and the breakdown degenerates to a tautology — "(N open, 0 in
// progress)" is what it prints for ANY database, including one with a thousand
// in-progress issues matching the same label.
// more than one status. Under --ready the query is status-pinned: the default
// (no --status, or --status all) is still open, so "(N open, 0 in progress)"
// is a tautology for ANY database, including one with a thousand in-progress
// issues matching the same label. An explicit --status is the intersection
// (GH#5832), and the same tautology applies to whatever selector was asked
// for — the footer must name that selector rather than reuse the default-open
// sentence.
//
// Printed next to a real count that number reads as a finding rather than an
// artifact of the flag: "0 in progress" answers the question "is anything in
@ -175,13 +177,14 @@ func displayPrettyListWithDeps(issues []*types.Issue, showHeader bool, allDeps m
// construction, say what was excluded instead of asserting a count for it. This
// is the same principle as the truncation arm below, which refuses to label a
// cut-off page "Total" (GH#5362): a count is only honest alongside its scope.
func listFooterLine(total, open, inProgress int, truncated, readyFiltered bool) string {
func listFooterLine(total, open, inProgress int, truncated, readyFiltered bool, statusSelector string) string {
if readyFiltered {
// No status breakdown: --ready makes it vacuous. Name the scope instead.
scope := readyFooterScope(statusSelector)
if truncated {
return fmt.Sprintf("Showing %d ready issues (open only — --ready excludes in_progress); more match (truncated by --limit). Use --limit 0 for all.", total)
return fmt.Sprintf("Showing %d ready issues (%s); more match (truncated by --limit). Use --limit 0 for all.", total, scope)
}
return fmt.Sprintf("Ready: %d issues with no active blockers (open only — --ready excludes in_progress)", total)
return fmt.Sprintf("Ready: %d issues with no active blockers (%s)", total, scope)
}
if truncated {
return fmt.Sprintf("Showing %d issues (%d open, %d in progress); more match (truncated by --limit). Use --limit 0 for all.",
@ -190,14 +193,31 @@ func listFooterLine(total, open, inProgress int, truncated, readyFiltered bool)
return fmt.Sprintf("Total: %d issues (%d open, %d in progress)", total, open, inProgress)
}
// readyFooterScope names the status pin a --ready listing actually used.
// Empty / "all" still take the open default; an explicit selector is the
// intersection and must not reuse "excludes in_progress" (GH#5832).
func readyFooterScope(statusSelector string) string {
var parts []string
for _, part := range strings.Split(statusSelector, ",") {
part = strings.TrimSpace(part)
if part != "" {
parts = append(parts, part)
}
}
if len(parts) == 0 || (len(parts) == 1 && parts[0] == "all") {
return "open only — --ready excludes in_progress"
}
return strings.Join(parts, ",") + " only"
}
// displayPrettyListWithDepsMode displays issues in tree format. When depsMode is
// "scheduling" or "all", the tree also annotates each node's dependency edges and
// orders siblings by their scheduling dependencies (see orderSiblingsByDeps). An
// empty depsMode is the plain parent-child tree. truncated means the page was cut
// by --limit; the summary then says "Showing N" instead of "Total: N" (GH#5362).
// readyFiltered means --ready was in force, which pins the query to open issues —
// see listFooterLine for why the summary must say so.
func displayPrettyListWithDepsMode(issues []*types.Issue, showHeader bool, allDeps map[string][]*types.Dependency, depsMode string, truncated, readyFiltered bool) {
// readyFiltered means --ready was in force; statusSelector is the --status value
// so the summary names the pin that actually applied — see listFooterLine.
func displayPrettyListWithDepsMode(issues []*types.Issue, showHeader bool, allDeps map[string][]*types.Dependency, depsMode string, truncated, readyFiltered bool, statusSelector string) {
if showHeader {
// Clear screen and show header
fmt.Print("\033[2J\033[H")
@ -243,7 +263,7 @@ func displayPrettyListWithDepsMode(issues []*types.Issue, showHeader bool, allDe
inProgressCount++
}
}
fmt.Println(listFooterLine(len(issues), openCount, inProgressCount, truncated, readyFiltered))
fmt.Println(listFooterLine(len(issues), openCount, inProgressCount, truncated, readyFiltered, statusSelector))
fmt.Println()
fmt.Println("Status: ○ open ◐ in_progress ● blocked ✓ closed ❄ deferred")
fmt.Println("Priority: P0–P4 (label only; not a status icon)")

View file

@ -0,0 +1,130 @@
package main
import (
"strings"
"testing"
"github.com/spf13/cobra"
)
// newWispTypeInputCmd carries only the flags the --wisp-type reachability
// check reads. gatherListInput reads many others, but GetString / GetBool on
// an unregistered flag return zero values, so this stays minimal — the same
// shape as newListInputTestCmd.
func newWispTypeInputCmd() *cobra.Command {
cmd := &cobra.Command{Use: "list"}
f := cmd.Flags()
f.String("wisp-type", "", "")
f.Bool("include-ephemeral", false, "")
f.Bool("include-infra", false, "")
f.StringP("type", "t", "", "")
return cmd
}
// TestListRegistersIncludeEphemeral pins the flag the guard below points at.
//
// It is the load-bearing half of this change: ListRequest.IncludeEphemeral is
// the plane knob its own doc names as the combination that answers with rows,
// and `bd list` did not register a flag for it. Without this the advice the
// guard prints names a flag that does not exist, which is worse than the
// silence it replaces.
func TestListRegistersIncludeEphemeral(t *testing.T) {
if listCmd.Flags().Lookup("include-ephemeral") == nil {
t.Fatal("bd list must register --include-ephemeral: it is the only narrow way to admit the wisp plane, and --wisp-type's error message tells callers to use it")
}
}
// TestGatherListInput_WispTypeWithoutAPlaneIsRefused covers the request that
// cannot match a row for ANY input: wisp_type narrows whatever the rest of the
// request admitted, and a default listing admits only durable rows, which
// carry no classification.
//
// The API layer keeps composing this to an empty page — that is its pinned
// contract, and this does not touch it. The refusal is here, where the only
// thing a human can have meant is the combination that returns rows.
func TestGatherListInput_WispTypeWithoutAPlaneIsRefused(t *testing.T) {
defer func(prev bool) { jsonOutput = prev }(jsonOutput)
jsonOutput = false
cmd := newWispTypeInputCmd()
if err := cmd.Flags().Set("wisp-type", "heartbeat"); err != nil {
t.Fatalf("set wisp-type: %v", err)
}
var err error
stderr := captureStderr(t, func() { _, err = gatherListInput(cmd) })
if err == nil {
t.Fatal("--wisp-type with no plane knob cannot match any row and must be refused, got nil error")
}
// The message has to carry the way out, or it is just a different silence.
if !strings.Contains(stderr, "--include-ephemeral") {
t.Errorf("the refusal must name the flag that makes the request answerable; got:\n%s", stderr)
}
}
// TestGatherListInput_WispTypeWithAPlaneIsAccepted is the discriminating half:
// a guard that refused everything would pass the test above on its own. Each
// case here admits the plane by a different route, and all must survive.
func TestGatherListInput_WispTypeWithAPlaneIsAccepted(t *testing.T) {
defer func(prev bool) { jsonOutput = prev }(jsonOutput)
jsonOutput = false
for _, tc := range []struct {
name string
flag string
val string
}{
{"the narrow plane knob", "include-ephemeral", "true"},
{"the wider bundle that also admits it", "include-infra", "true"},
// An explicit type is left alone: an infra type routes to the plane by
// itself, and this layer cannot tell which types those are without the
// workspace's infra vocabulary. Refusing here would reject a lawful,
// answerable request.
{"an explicit type, which may itself be infra", "type", "agent"},
} {
t.Run(tc.name, func(t *testing.T) {
cmd := newWispTypeInputCmd()
if err := cmd.Flags().Set("wisp-type", "heartbeat"); err != nil {
t.Fatalf("set wisp-type: %v", err)
}
if err := cmd.Flags().Set(tc.flag, tc.val); err != nil {
t.Fatalf("set %s: %v", tc.flag, err)
}
in, err := gatherListInput(cmd)
if err != nil {
t.Fatalf("--wisp-type with --%s must be accepted, got: %v", tc.flag, err)
}
if in.WispType == nil || string(*in.WispType) != "heartbeat" {
t.Errorf("WispType must survive onto the request, got %v", in.WispType)
}
})
}
}
// TestGatherListInput_IncludeEphemeralReachesTheRequest confirms the new flag
// is wired through rather than merely registered — a flag that parses but is
// never read would leave the plane just as unreachable.
func TestGatherListInput_IncludeEphemeralReachesTheRequest(t *testing.T) {
defer func(prev bool) { jsonOutput = prev }(jsonOutput)
jsonOutput = false
cmd := newWispTypeInputCmd()
if err := cmd.Flags().Set("include-ephemeral", "true"); err != nil {
t.Fatalf("set include-ephemeral: %v", err)
}
in, err := gatherListInput(cmd)
if err != nil {
t.Fatalf("gatherListInput: %v", err)
}
if !in.IncludeEphemeral {
t.Error("--include-ephemeral must set ListRequest.IncludeEphemeral, got false")
}
// And the default stays off, so the durable-only listing is unchanged.
bare, err := gatherListInput(newWispTypeInputCmd())
if err != nil {
t.Fatalf("gatherListInput (bare): %v", err)
}
if bare.IncludeEphemeral {
t.Error("IncludeEphemeral must default to false; the default listing is durable-only")
}
}

View file

@ -229,13 +229,6 @@ func effectiveRootStorePolicy(cmdName string, strictReadonly bool) rootStorePoli
}
}
// backendSupportsStrictReadonly reports whether the live backend path can open
// without provisioning or lifecycle changes. Unsupported SQL backends are
// rejected earlier by validateConfiguredBackend; proxied Dolt remains writable-only.
func backendSupportsStrictReadonly(cfg *configfile.Config) bool {
return cfg == nil || !cfg.IsDoltProxiedServerMode()
}
// runsPostCommandMaintenance reports whether PersistentPostRunE should run the
// post-command maintenance net — Dolt auto-commit, the tip-metadata commit,
// auto-backup, auto-export and auto-push.
@ -324,6 +317,30 @@ func isWorkingSetReconcileCommand(cmd *cobra.Command) bool {
return parent.Name() == "dolt" || parent.Name() == "vc"
}
// isRemoteSyncCommand reports whether cmd is `bd dolt pull`: the one command
// the #6575 data-behind migrate-gate refusal tells the operator to run.
//
// It is the same deadlock isWorkingSetReconcileCommand breaks for #4566, one
// refusal over. The gate stops a data-behind clone from migrating and names
// `bd dolt pull` as the remedy — but the pull opens the store too, so it hit
// that refusal before it could clear its cause. On an embedded clone there is
// no external `dolt` binary to fall back to, which left the refused clone with
// exactly one exit: BD_ALLOW_REMOTE_MIGRATE=1, i.e. performing the migration
// the refusal exists to prevent. Opening via embeddeddolt.OpenForRemoteSync /
// dolt.Config.RemoteSyncOpen tolerates that ONE gate reason and nothing else.
//
// Deliberately just the pull, not `bd sync`: sync also pushes and can write
// issue rows, and a write against a stale schema is the hazard the gate is
// about. The pull only moves the commit graph, which is precisely the
// precondition the refusal is waiting on.
func isRemoteSyncCommand(cmd *cobra.Command) bool {
if cmd.Name() != "pull" {
return false
}
parent := cmd.Parent()
return parent != nil && parent.Name() == "dolt"
}
// isForcedMigrate reports whether cmd is `bd migrate` or `bd migrate schema`
// invoked with --force: the operator confirming they are the single designated
// migrator, so the remote-migrate gate (#4259) must not block this run's store
@ -343,15 +360,27 @@ func isForcedMigrate(cmd *cobra.Command) bool {
// open targets `beads_global`, so the block's `bd migrate schema` would
// migrate the PROJECT database and leave the refusal in place — the working
// remedy is the same verb with the same flag.
func printGlobalDatabaseConsentHint(w io.Writer) {
//
// It takes the refusal because "the same verb" is not the same verb on every
// arm: the #6575 data-behind stop on a shared store is remote-backed by
// construction, and there the bare verb's consent is never read (see
// schema.SharedConsentCommandForced), so retargeting the bare form would hand
// the operator a global-scoped command that still cannot succeed. This mirrors
// the retarget in handleRemoteMigrateGateJSON. A nil error keeps the
// pre-existing bare-verb wording.
func printGlobalDatabaseConsentHint(w io.Writer, e *schema.RemoteMigrateGateError) {
if !globalFlag {
return
}
consent := schema.SharedConsentCommandGlobal
if e != nil && e.IsDataBehind() && e.Shared {
consent = schema.SharedConsentCommandForcedGlobal
}
fmt.Fprintf(w,
"\n This command targeted the global database (--global), so run the\n"+
" migrate step with the same flag:\n"+
" %s\n",
schema.SharedConsentCommandGlobal)
consent)
}
// renderTypedOpenError prints the actionable block for the store-open failures
@ -381,7 +410,7 @@ func renderTypedOpenError(err error) bool {
handleRemoteMigrateGateJSON(gateErr)
} else {
fmt.Fprint(os.Stderr, gateErr.UserMessage())
printGlobalDatabaseConsentHint(os.Stderr)
printGlobalDatabaseConsentHint(os.Stderr, gateErr)
}
return true
}
@ -850,7 +879,7 @@ func init() {
rootCmd.PersistentFlags().BoolVar(&sandboxMode, "sandbox", false, "Sandbox mode: disables Dolt auto-push")
rootCmd.PersistentFlags().BoolVar(&readonlyMode, "readonly", false, "Read-only mode: block write operations (for worker sandboxes)")
rootCmd.PersistentFlags().BoolVar(&globalFlag, "global", false, "Use the global shared-server database (beads_global)")
rootCmd.PersistentFlags().StringVar(&doltAutoCommit, "dolt-auto-commit", "", "Dolt auto-commit policy (off|on|batch). 'on': commit after each write. 'batch': defer commits to bd dolt commit; uncommitted changes persist in the working set until then (a live batch-mode bd process also flushes on SIGTERM/SIGHUP). Applies to embedded and direct SQL-server modes; proxied-server routes are unaffected. Default: on. Override via config key dolt.auto-commit")
rootCmd.PersistentFlags().StringVar(&doltAutoCommit, "dolt-auto-commit", "", "Dolt auto-commit policy (off|on|batch). 'on': commit after each write. 'batch': defer commits to bd dolt commit; uncommitted changes persist in the working set until then (a live batch-mode bd process also flushes on SIGTERM/SIGHUP, except in proxied-server mode, where bd dolt commit is the only flush point). In proxied-server mode the deferral covers the writes the CLI makes on that route, including config and version metadata; explicit commit points (bd batch, bd mol bond/pour/squash, bd mol wisp create, and the wisp half of bd mol burn) still commit, and a bd serve process on the same database is unaffected. Default: on. Override via config key dolt.auto-commit")
rootCmd.PersistentFlags().BoolVar(&cpuProfileEnabled, "cpu-profile", false, "Generate CPU profile for performance analysis")
rootCmd.PersistentFlags().StringVar(&memProfilePath, "mem-profile", "", "Write heap profile to FILE on exit (also respects BEADS_MEM_PROFILE)")
rootCmd.PersistentFlags().BoolVarP(&verboseFlag, "verbose", "v", false, "Enable verbose/debug output")
@ -1256,18 +1285,18 @@ var rootCmd = &cobra.Command{
fmt.Fprintf(os.Stderr, "warning: %v\n", err)
}
}
if beadsDir == "" {
beadsDir = beads.FindBeadsDir()
}
if cmdName == "doctor" && usesProxiedServer() {
// Refuse only on a real refusal. validateProxyMaintenance...
// Refuse only on a real refusal. The registry validator
// returns nil for doctor subcommands, and returning early on
// that would skip the legacy-store guard and autocommit-mode
// resolution every other skipsStoreInit command still runs.
if err := validateProxyMaintenanceBeforeProvider(cmd); err != nil {
if err := validateProxyRegistryBeforeProvider(cmd, resolveProxiedTopology(beadsDir)); err != nil {
return err
}
}
if beadsDir == "" {
beadsDir = beads.FindBeadsDir()
}
if err := guardLegacyNoStoreCommand(cmd, beadsDir); err != nil {
isMigrationCommand := false
for current := cmd; current != nil; current = current.Parent() {
@ -1414,6 +1443,11 @@ var rootCmd = &cobra.Command{
// would create a local database instead of using the redirect target.
// (GH#bd-0qel)
targetBeadsDir := beads.FindBeadsDir()
if targetBeadsDir == "" {
// An explicit BEADS_DIR is authoritative even
// before it holds project files.
targetBeadsDir = beads.ExplicitBeadsDir()
}
if targetBeadsDir == "" {
targetBeadsDir = ".beads"
}
@ -1468,14 +1502,13 @@ var rootCmd = &cobra.Command{
}
// Reject proxy capability combinations before any workspace side effect
// (version tracking, migration, auto-start, or provider construction).
// Two validators, one for each half of the policy: flag-keyed rules and
// the path-keyed capability registry.
if cfg != nil && cfg.IsDoltProxiedServerMode() {
if err := validateProxyCapabilitiesBeforeProvider(cmd); err != nil {
return err
}
if err := validateProxyMaintenanceBeforeProvider(cmd); err != nil {
return err
}
if err := validateProxyTransformBeforeProvider(cmd); err != nil {
if err := validateProxyRegistryBeforeProvider(cmd, resolveProxiedTopology(beadsDir)); err != nil {
return err
}
}
@ -1486,9 +1519,6 @@ var rootCmd = &cobra.Command{
if readonlyMode && cfg != nil && cfg.IsDoltProxiedServerMode() {
return HandleProxyCapabilityError(AssertProxyCapability(ProxyModeProxied, ProxyCapReadonly))
}
if readonlyMode && !backendSupportsStrictReadonly(cfg) {
return HandleError("strict readonly is unavailable for dolt proxied-server backend; refusing to open a store that cannot guarantee mutation-free access")
}
// Set actor for audit trail
actor = getActorWithGit()
@ -1622,6 +1652,7 @@ var rootCmd = &cobra.Command{
DisableAutoStart: policy.disableAutoStart,
BeadsDir: beadsDir,
LenientOpen: isWorkingSetReconcileCommand(cmd),
RemoteSyncOpen: isRemoteSyncCommand(cmd),
}
// Load config to get database name and server connection settings.
@ -1781,6 +1812,16 @@ var rootCmd = &cobra.Command{
}
uowProvider = uow.NewNotifyingProvider(p, uowSinks)
// Honor dolt.auto-commit for proxied writes the same way
// issueOpsContext already does for the direct/SQL-server routes
// (bd-4wamg): batch/off defer the Dolt version commit rather than
// minting one per write (GH#4995). uow.issueOperations reads this
// off the context for every Create/Update/Close/Reopen it runs.
rootCtx, err = issueOpsContext(rootCtx)
if err != nil {
return HandleError("failed to resolve dolt auto-commit policy: %v", err)
}
if !previewMode {
reconcileVersionProxiedServer(rootCtx)
}
@ -1964,6 +2005,15 @@ var rootCmd = &cobra.Command{
if shouldAutoPruneEventsJournal(cmd) {
maybeAutoPruneEventsJournal(rootCtx, beads.FindBeadsDir())
}
// Auto-backup, through the provider this command opened. Same
// gate as the direct arm's maintenance net below (strict
// --readonly, `bd serve` and a migration freeze all skip it),
// plus previews: a --dry-run must not register a backup remote
// or write backup state. proxiedAutoBackupBackend decides the
// topology, so this stays inert off managed-local.
if runsPostCommandMaintenance(cmd.Name(), readonlyMode) && !isPreviewCommand(cmd) && !commandFreeze.Frozen() {
runPostRunAutoBackup(rootCtx)
}
if uowProvider != nil {
_ = uowProvider.Close(rootCtx)
uowProvider = nil

View file

@ -154,6 +154,38 @@ Just a title and description.
},
},
},
{
name: "GH-4643 H2-per-section briefing file parses as three issues",
content: `## Problem
Something is broken.
## Context
Extra background.
## Acceptance Criteria
It should work.
`,
expected: []*IssueTemplate{
{
Title: "Problem",
Description: "Something is broken.",
Priority: 2,
IssueType: "task",
},
{
Title: "Context",
Description: "Extra background.",
Priority: 2,
IssueType: "task",
},
{
Title: "Acceptance Criteria",
Description: "It should work.",
Priority: 2,
IssueType: "task",
},
},
},
}
for _, tt := range tests {

View file

@ -199,12 +199,17 @@ func migrateFault(phase migratePhase) error {
return nil
}
// externalMigrationRefusal is a policy refusal rather than a registry row: it
// depends on the workspace's endpoint, not on which command was typed. The
// reason is design because someone else owns that endpoint and its schema —
// no amount of plumbing on this side makes migrating it bd's business.
func externalMigrationRefusal(message string) error {
return HandleProxyCapabilityError(&ProxyCapabilityError{
Code: "proxy.migrate.external_endpoint",
Message: message,
ExitCode: 1,
Mutates: false,
Reason: ProxyReasonDesign,
})
}

View file

@ -27,6 +27,9 @@ func runPourProxiedServer(ctx context.Context, in pourInput) error {
if uowProvider == nil {
return HandleError("proxied-server UOW provider not initialized")
}
// Explicit commit point, like the `transact` in cloneSubgraph the direct
// route reaches through spawnMolecule (GH#4995).
ctx = explicitCommitPointContext(ctx)
vars, err := parseVarFlags(in.varFlags)
if err != nil {
@ -372,6 +375,9 @@ func runMolBondProxiedServer(ctx context.Context, in molBondInput) error {
if uowProvider == nil {
return HandleErrorRespectJSON("proxied-server UOW provider not initialized")
}
// Explicit commit point, like `transact` in bondProtoMol/bondMolecules on
// the direct route (GH#4995).
ctx = explicitCommitPointContext(ctx)
if in.dryRun {
uw, err := proxiedOpenReadUOW(ctx)
@ -446,6 +452,9 @@ func runMolSquashProxiedServer(ctx context.Context, in molSquashInput) error {
if uowProvider == nil {
return HandleErrorRespectJSON("proxied-server UOW provider not initialized")
}
// Explicit commit point, like `transact` in runMolSquash on the direct
// route (GH#4995).
ctx = explicitCommitPointContext(ctx)
if in.dryRun {
uw, err := proxiedOpenReadUOW(ctx)
@ -516,6 +525,15 @@ func runMolBurnProxiedServer(ctx context.Context, args []string, dryRun, force b
if uowProvider == nil {
return HandleErrorRespectJSON("proxied-server UOW provider not initialized")
}
// Only the wisp half is an explicit commit point, so the exemption is
// applied per commit site below rather than to this ctx (GH#4995).
// runMolBurn splits on the direct route: wisps go through burnWisps ->
// `transact`, which mints the commit whatever dolt.auto-commit says, while
// persistent molecules go through deleteBatch -> issueOpsContext, the
// policy-honoring class — dolt's deleter returns before DOLT_COMMIT when
// that context defers. Exempting the whole command would mint one commit
// per persistent molecule under batch/off, on a destructive verb, where the
// identical direct-route command defers them all to `bd dolt commit`.
uw, err := proxiedOpenReadUOW(ctx)
if err != nil {
@ -617,7 +635,8 @@ func runMolBurnProxiedServer(ctx context.Context, args []string, dryRun, force b
}
if len(wispIDs) > 0 {
result, err := uow.RunTxResult(ctx, uowProvider, func(ctx context.Context, uw uow.UnitOfWork) (*BurnResult, string, error) {
// The wisp half's direct twin is burnWisps -> `transact`.
result, err := uow.RunTxResult(explicitCommitPointContext(ctx), uowProvider, func(ctx context.Context, uw uow.UnitOfWork) (*BurnResult, string, error) {
r, err := burnWispsInto(ctx, newUOWMolWriter(uw), wispIDs, actor)
if err != nil {
return nil, "", err
@ -635,6 +654,10 @@ func runMolBurnProxiedServer(ctx context.Context, args []string, dryRun, force b
}
for _, id := range persistentIDs {
// No exemption: the persistent half's direct twin is deleteBatch ->
// issueOpsContext, so this stays on the inherited policy context and
// the message is blanked under batch/off, exactly as the direct route
// leaves these deletions in the working set for `bd dolt commit`.
result, err := uow.RunTxResult(ctx, uowProvider, func(ctx context.Context, uw uow.UnitOfWork) (BurnResult, string, error) {
subgraph, err := loadTemplateSubgraph(ctx, newUOWMolWriter(uw), id)
if err != nil {

Some files were not shown because too many files have changed in this diff Show more