Commit graph

3,572 commits

Author SHA1 Message Date
Julian Knutsen
dba70de281
fix(federation): actionable error when peer credentials cannot be decrypted (#6995)
* fix(embeddeddolt): use stored peer credentials for federation sync

bd federation add-peer promises stored credentials are used automatically
when syncing, but the embedded Fetch/PushTo/PullFrom paths read only the
DOLT_REMOTE_USER environment variable, so first sync against any
authenticated Dolt server presented the wrong identity. This is the
peer-path remainder of the class fixed for default remotes in #2543.

withPeerAuth mirrors server mode's withPeerCredentials: peer-store lookup
first, environment fallback for unknown remotes and credential-free peers
(federation sync iterates every dolt remote, so non-peer remotes must
keep their behavior). Stored credentials override the process-wide
DOLT_REMOTE_USER/DOLT_REMOTE_PASSWORD pair as a unit under a
federationEnvMutex, mirroring package dolt: the in-process Dolt engine
reads them from the process environment, so the override is serialized
and both variables are restored (or re-unset) afterward, including on
callback failure. A stored empty field unsets its variable rather than
inheriting an ambient value.

Fixes #5080

Agent-Signature: claude-code-claude-fable-5-unknown-reasoning on behalf of Michael Pursifull

* docs(embeddeddolt): clarify federationEnvMutex is separate from package dolt's lock

Review nit on #5085: the 'mirroring' phrasing read as if the two
packages shared one mutex. State explicitly that they are separate
locks and why per-package serialization suffices.

* fix(federation): actionable error when peer credentials cannot be decrypted

A database pulled to a second machine carries federation_peers rows
its local .beads-credential-key cannot decrypt, and every peer
operation died with a raw cipher error while bd federation status
blamed the network (Unreachable:). The failure semantics were right
(fail closed, matching server mode); the message said nothing about
the machine-local key or the fix.

Add storage.ErrCredentialKeyMismatch plus a shared wording helper
CredentialKeyMismatchError naming the key file as context and the
remediation (re-run bd federation add-peer on this machine). Both
backends wrap their decrypt failures with it: embeddeddolt at its
single decrypt funnel, dolt at its two read paths. GetFederationPeer
wraps now name the peer. bd federation status classifies the sentinel
with errors.Is and prints Local credential error instead of
Unreachable; the --json shape is unchanged and now pinned by test.

When the error fires is unchanged: same call sites, same fail-closed
semantics, no fallback to ambient credentials.

Tests pin the decrypt-failure branch in both backends (embeddeddolt
against a real store with a rotated key, dolt via sqlmock) and the
status classification end to end in the gated CLI harness.

Refs #5080

* fix(embeddeddolt): classify short ciphertext as credential-key mismatch

A stored peer password blob shorter than the GCM nonce returned a bare
'ciphertext too short' error, bypassing CredentialKeyMismatchError, so
federation status read that local corruption as an unreachable peer.
Route the branch through the same sentinel as a failed GCM open; the
remediation (re-add the peer on this machine) is identical.

Adds a short-ciphertext regression at the decrypt funnel.

Refs: gastownhall/beads#5214 (review, gap 1)

* fix(embeddeddolt): bind stored credentials to the remote URL; serialize env fallbacks

Two fixes to the shared withPeerAuth seam from the consolidation review:

- Stored peer credentials are now bound to the peer's canonical remote
  URL, not only to a matching remote name. AddRemoteIfNotExists keeps
  an existing same-name remote regardless of its URL, so a redirected
  remote could receive the stored password. withPeerAuth now verifies
  the live dolt_remotes URL against the peer row before any credential
  is installed, failing closed on divergence and on a missing remote.

- The plain-remote and empty-credential fallback callbacks now run
  under federationEnvMutex too. They previously called remoteAuthUser()
  and the operation itself outside the lock, so a fallback operation
  could observe a concurrent stored-peer operation's temporarily
  installed DOLT_REMOTE_USER/DOLT_REMOTE_PASSWORD pair.

Adds three regressions: diverged-URL fail-closed, missing-remote
fail-closed, and env-fallback-does-not-observe-peer-credentials.

Refs: gastownhall/beads#5085 (review)

* style(dolt): use US spelling in the decrypt-funnel comments

The repo's misspell linter rejects 'Labelling' and 'labelled'. Comment
text only; no behavior change.

Refs: gastownhall/beads#5214 (CI)

* review: name the resolved credential-key path in the mismatch error

Maintainer review fixup for PR #5214 (adopt-pr iteration 1). Addresses the one
minor and the one nit from the review synthesis; both reviewers found 0 blockers
and 0 majors and the quality scorecard is approve (898/850).

Minor (Debuggability & Operability). All three CredentialKeyMismatchError call
sites passed the bare const credentialKeyFile, so the message claimed "the key
file .beads-credential-key is machine-local" without saying where it is. On the
dolt backend that basename is genuinely ambiguous: initCredentialKey resolves it
against s.beadsDir and falls back to the legacy s.dbPath as a transparent
migration, so during the migration window two files with that name can exist
carrying different keys. Pass filepath.Join(s.beadsDir, credentialKeyFile)
instead, at dolt/credentials.go and both embeddeddolt/federation.go sites. No
signature change: the parameter was already named keyFile and its doc comment
already describes it as machine-local.

beadsDir is provably non-empty at all three sites in production, verified in
source rather than assumed: dolt only reaches the funnel with a non-nil key, and
initCredentialKey leaves the key nil when beadsDir is empty; embeddeddolt's
ensureCredentialKey errors out when it is empty.

This lengthens a message the author pre-declared as a judgment call. The
synthesis adjudicated that carve-out deliberately: it covers the message's
wording and its single-line form, not which file the text identifies.

Nit (Test Evidence Quality). dolt's withPeerCredentials is the seam that carries
the sentinel into `bd federation status` on the default backend and had no
fails-closed pin, unlike its embedded twin TestWithPeerAuth_KeyMismatchFailsClosed.
Added one subtest on the existing sqlmock harness asserting the callback does not
run and the sentinel survives the seam's own wrap.

Both pins were proven non-vacuous by mutation, not assumed:
- Reverting the three call sites to the bare const reds all three dolt subtests
  and all three embeddeddolt tests, with the original bare-basename text in the
  diff output.
- Making withPeerCredentials swallow the decrypt error reds only the new subtest,
  on exactly the two properties the nit named (callback ran; no failure).

The dolt test needed beadsDir set on its hand-built store: filepath.Join("",
credentialKeyFile) is the bare basename, so with beadsDir left empty the
resolved-path assertion would have passed vacuously. The embeddeddolt pin's
package-level const became a function of the store for the same reason — its
store has a real temp beadsDir, so the clause now pins the resolved path.

Validation: go vet rc=0 on all three packages; internal/storage, dolt
(3 tests incl. both negative/narrowing tests) and embeddeddolt (3 credential
tests) green; cmd/bd TestEmbeddedFederation 12/12 green including the PR's own
status_credential_key_mismatch e2e subtest. make bazel-sync-check rc=0 with zero
tracked drift — no new files and zero import changes, so no BUILD srcs or deps
can move.

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

---------

Co-authored-by: Michael Pursifull <mike@arcaven.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.com>
2026-09-30 20:29:57 -07:00
Jim Wordelman
9407cba7ee
feat(schema): soft watchdog warning for long-running schema migrations (#5997)
* test(feat): red — Add soft watchdog warning for long-running schema migrations (refs be-yyzzs)

* feat: green — Add soft watchdog warning for long-running schema migrations (refs be-yyzzs)

* fix(schema): address review follow-ups on migration watchdog doc citation (refs be-yyzzs, review be-sogif)

Round 1 review (be-sogif) flagged criterion 7: the soft-watchdog comment
at schema.go cited engdocs/plans/be-m65rs-migration-watchdog-scoping.md,
which was never landed to any reachable ref (only exists on PM's own
unmerged worktree branch). Replace the dangling file citation with an
inline summary of the rationale plus reachable citations: the existing
initSchema comment in store.go (migration 0047 as a concrete long-runner
example) and `bd show be-m65rs` for the full scoping decision. Comment-only
change; no functional/behavioral diff. gofmt/build/vet clean; full package
suite reconfirmed 132 PASS, 0 FAIL, 0 SKIP.

* test(schema): red — watchdog is silent off a tty, and ignores bare seconds

Both from review #5997.

TestRunMigrationsWatchdogSurvivesNonTTY drives runMigrations end to end
with a deliberately slow first migration body and a 10ms interval, with
the progress writer put in the state a non-tty caller really sees. It
fails with an empty buffer: runMigrations hands the watchdog the package
stderr var, which is io.Discard whenever os.Stderr is not a terminal, so
the warning is discarded under bd serve, systemd, CI and any piped
invocation — the exact cases where a migration running for twenty minutes
needs to be visible. On a tty it works, which is why this went unnoticed.
Asserting on the wiring rather than on a package variable, so the fix has
to actually reach the call site.

The interval table gains bare-seconds cases. store.go's parseTimeout — the
convention migrationWatchdogIntervalDuration's own doc comment claims to
follow — documents "bare numbers treated as seconds (e.g. \"90\")", and
this one does not, so an operator setting the value to 90 silently gets
5m.

Note the review's own example value, 300, cannot serve as the test input:
300s IS the 5m default, so it passes whether the value was parsed or
discarded. Using 90 and 600 instead, which distinguish.

watchdogStderr exists here but is not yet wired, so the red is behavioural
rather than a compile error.

Refs be-lotba.

* fix(schema): point the watchdog's last dangling citation at bd show be-m65rs

Review #5997 point 1. Round 2 replaced the citation on the call-site
comment but missed the one in runMigrationWithWatchdog's own doc comment,
which still named engdocs/plans/be-m65rs-migration-watchdog-scoping.md.
That path does not exist, and neither does engdocs/plans/ — so the comment
sent a reader after a file that was never committed.

Points it at bd show be-m65rs, matching what the call site already says.
This was the last engdocs/plans reference in the repo; a repo-wide grep for
that prefix is now empty, so the two comments can no longer disagree.

Refs be-lotba.

* fix(schema): send the migration watchdog WARN somewhere a non-tty caller sees

Review #5997 point 2. The package's stderr var is io.Discard whenever
os.Stderr is not a terminal (schema.go:26-37) — it was introduced for
routine per-migration progress lines, where discarding off a tty is
correct. Wiring the watchdog to it inherited that gating, so the WARN was
emitted only on an interactive terminal and silently dropped under bd
serve, systemd, CI and any piped invocation: precisely the situations
where a migration still running after twenty minutes is worth knowing
about. On a tty it worked, which is why it was not caught earlier.

Routes the watchdog through its own writer instead. This is not a new
convention for the package — remote_migrate_gate.go, smart_remote_migrate
_gate.go and both schema-skew notices in this file already write operator
warnings straight to os.Stderr, ungated, for the same reason. stderr keeps
its terminal gating and its progress lines.

Chose the writer over the alternative the review offered (scoping the doc
comment to "interactive runs"), since the feature's stated purpose in
be-m65rs is telling an operator reading logs that a migration is still
working — and logs are the non-tty case.

Turns TestRunMigrationsWatchdogSurvivesNonTTY green; it asserts through
runMigrations rather than on the package var, so the wiring at the call
site is what is under test.

Refs be-lotba.

* fix(schema): accept a bare-seconds watchdog interval, matching parseTimeout

Review #5997 nit. BEADS_MIGRATION_WATCHDOG_INTERVAL=300 fell back to the
5m default instead of meaning 300s, so an operator changing the value got
the number they were trying to change and no diagnostic.

The doc comment claimed to follow internal/storage/dolt/store.go's
timeoutFromEnv, but only its unset/invalid-falls-back shape. timeoutFromEnv
is a one-line wrapper; the contract lives in parseTimeout below it, which
retries an unparsable value as raw+"s" so bare numbers mean seconds. This
function skipped that half, so the comment promised a convention the code
did not implement. Now mirrors parseTimeout's full shape — including its
non-positive handling on both branches — and cites parseTimeout by name,
since that is where the behavior being mirrored actually is.

On the review's related note that d > 0 is the only floor: that is
deliberate and is also parseTimeout's only floor. Diverging here would
make the two disagree again, which is what produced this nit. Happy to add
a minimum on both together if you want one.

Not reused directly because parseTimeout is unexported in another package.

The interval table gains bare-seconds cases; 90 and 600 rather than the
review's 300, since 300s is the 5m default and so cannot distinguish
"parsed as seconds" from "fell back".

Refs be-lotba.

* docs(changelog): add the migration watchdog to Unreleased

Review #5997 nit: a new user-facing env var and a new WARN line earn an

Deliberately CHANGELOG only, not docs/reference/configuration.md — even
though BEADS_FSCK_TIMEOUT, the sibling this env var's parsing mirrors, has
a row in that page's table. docs/ describes the pinned release
(docs/cli-docs.pin is v1.2.2, which does not contain this feature) rather
than main, per engdocs/decisions/2026-07-17-docs-release-pin.md. The table
row belongs with the pin bump at release time; adding it now would
document a flag no released bd accepts.

Refs be-lotba.

* fix(bazel): list migration_watchdog_test.go in the schema go_test srcs

Base added internal/storage/schema/BUILD.bazel after this PR's merge base,
enumerating go_test srcs file by file. The PR's new migration_watchdog_test.go
was therefore absent from it, so under Bazel the target reported
"Executed 1 out of 1 test: 1 test passes" while running NONE of the new tests
("testing: warning: no tests to run") -- a silent green.

Measured both ways on the adopted head: without this entry 0 watchdog tests
run; with it, all 7 tests and 8 subtests execute and pass
(bazel test //internal/storage/schema:schema_test). The enumeration is
maintained at 100% repo-wide -- all 56 unlisted test files are
//go:build-tagged -- so this file would have been the only untagged omission.

Maintainer fixup applied during PR adoption's rebase gate. No contributor
code changed; the contributor could not have seen this file, which did not
exist at the merge base.

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

* fix(schema): scope the watchdog promise to the migration body, stop the warner on panic

Maintainer fixup applied during PR adoption's review loop (iteration 1),
addressing the one major plus the three non-gating findings in the review
synthesis. No contributor commit was rewritten.

Major -- Change Impact / Blast Radius (scope). The watchdog wraps only
execMigrationBody, while a migration step also runs the dirty-table snapshot,
preMigrationRepair, the cursor INSERT and commitMigrationStep -- and this file
already says the per-step DOLT_ADD/DOLT_COMMIT is "the expensive, fallible part
of this step on the production embedded path". The CHANGELOG therefore
over-promised: it told users a wedged migration no longer "looked identical from
outside", which is false for a wedge in that commit. The synthesis offered two
arms and said explicitly not to do both. Taking the minimal-sufficient arm:
CHANGELOG.md now scopes the guarantee to the migration body and states that a
stall in the per-step commit is still quiet, and a comment at the call site
records that the narrow boundary is deliberate, and why. The extension arm was
declined on cost: widening the wrap means moving the snapshot/commit ordering
that carries this loop's atomic-commit contract (#4566, #4690), under a
strict-ordered sqlmock expectation set and the cross-package
migrateStepFaultHook tests -- more risk than an observability-only change should
carry. Measured: this fix leaves runMigrations at gocyclo 16 / gocognit 29,
byte-identical to before, whereas nesting the whole step in a closure would have
driven the cognitive score well past its current band.

Minor -- Resource Lifecycle & Cleanup. close(done)/wg.Wait() moved into a defer.
A panic out of fn skipped the straight-line close and orphaned the ticker
goroutine, which then went on warning about a migration that was no longer
running, for the life of the process, on the deliberately un-gated
watchdogStderr. Reachability is open rather than proven
(internal/httpapi/server.go:1406 recovers everything but http.ErrAbortHandler
and keeps serving), which is the argument for taking the one-keyword fix. Pinned
by a new test: against the pre-fix schema.go it reds with "3 WARN lines when the
panic unwound, 8 after a further 50ms"; with the defer it passes under -race.

Minor -- Test Evidence Quality. TestMigrationWatchdogIntervalDuration's
"unset_defaults_to_5m" arm never unset anything, so the ambient environment flowed
straight into the call. Two-arm control: with BEADS_MIGRATION_WATCHDOG_INTERVAL=600
exported the old arm reds ("= 10m0s; want 5m0s") and the fixed arm passes, with the
subtest confirmed to have actually run rather than being filtered out.

Nit -- Contract & Interface Fidelity. BEADS_MIGRATION_WATCHDOG_INTERVAL added to
docs/reference/configuration.md's env table, beside the BEADS_FSCK_TIMEOUT row
whose duration contract it mirrors.

Validation: go test ./internal/storage/schema/ -count=1 green (41s); 8 watchdog
tests + 8 subtests PASS, 0 SKIP, 0 FAIL; gofmt clean; go vet clean; git diff
--check clean; ./scripts/check-doc-freshness.sh PASSED.

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

* fix(bazel): list golang.org/x/term in the schema go_test deps

migration_watchdog_test.go imports golang.org/x/term directly. Under Bazel
it compiled only through embed = [":schema"], but gazelle lists a test
file's own imports in the go_test's deps, so `bazel run //:gazelle`
rewrites this BUILD file. Since the base now gates PRs on the Bazel lanes,
BAZEL_TEST's "BUILD files in sync (gazelle, go_srcs, MODULE.bazel)" step
would fail on exactly this one line. This is the line gazelle produces.

Measured on the adopted head refreshed onto current main: the whole CI sync
step run locally (go_srcs.py --check, bazel run //:gazelle, go_srcs.py,
bazel mod tidy) leaves this line as the only drift in the repository.
With it, bazel test //internal/storage/schema:schema_test --config=ci
passes: 433 test cases, 0 failures, all 16 watchdog cases run (0 skipped),
and tools/bazel/check_testcases.py plus equivalence.py report no schema
divergence.

Maintainer fixup applied during PR adoption's pre-approval CI repair. No
contributor code changed.

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

---------

Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-30 20:23:14 -07:00
Alex
1764637093
perf(ready): recurse the --parent descendant walk off indexed base tables (#6130)
* perf(ready): recurse the descendant walk off indexed base tables (be-qfm)

`bd ready --parent` and `bd blocked --parent` compute the parent's
transitive descendants with a recursive CTE whose edge relation was a
non-recursive `parent_edges` CTE over `dependencies UNION ALL
wisp_dependencies` with the typed target columns COALESCE'd into one.
Dolt cannot index through that wrapper: it materializes the relation and
re-scans it once per recursion row, so the walk costs (parent-child rows)
x (descendants) — 7.46 s for 483 descendants on a 4.6k-edge database,
about 14 ms per descendant, and past the shared pool's read deadline on
a busy server.

Build the walk in sqlbuild.DescendantWalkQuery instead: one anchor and
one recursive member per (dependency table x typed target column), each
joining the base table on a bare indexed column, with per-column IS NULL
guards reproducing the COALESCE precedence and the LOCATE cycle guard,
depth guard and parent-child filter carried onto every member. The
recursive members carry JOIN_ORDER(d,e) LOOKUP_JOIN(d,e): the cycle guard
references both join sides, and without the hints Dolt's planner keeps
the recursive working table on the inner side and scans the edge table
per iteration, which measured no faster than the wrapper shape and
flipped plans between runs. With them the frontier is the outer side and
every member is an index probe.

issueops.GetDescendantIDsInTx and domain/db.getDescendantIDs call the
builder; they had carried the same query text separately.

Measured on a local Dolt 2.2.4 sql-server with a generated forest of
4,541 issues, 4,500 parent-child rows and 500 descendants under the
probed parent (BenchmarkDescendantWalk, new): 1.26–2.28 s/op on main,
32–36 ms/op with this change. Same rows on every target kind, cycle
and depth limit (TestDescendantWalkReachesEveryTargetKindAndStopsOnCycles,
new; the conformance ReadyParentScopesToItsTransitiveDescendants cases on
all three backends).

Refs #6128

Co-authored-by: qcore/syl <q@withq.ai>
Agent-Signature: claude-code-claude-fable-5-max on behalf of a3ackerman

* test(embeddeddolt): gate the descendant-walk reference test on cgo (be-qfm)

The embedded-Dolt test tier is cgo-only and every sibling file carries
the build tag; this one did not, so the CGO_ENABLED=0 boundary job
compiled it against a package whose helpers were excluded and failed on
an undefined newTestEnv.

Refs #6128

Agent-Signature: claude-code-claude-fable-5-max on behalf of a3ackerman

* fix(review): sync BUILD.bazel srcs and resolve every dep target column in the descendants CTE

Maintainer fixup from the PR #6130 adoption review, iterations 1 and 2.

Bazel srcs gap (major, claude+codex). The four new .go files were absent from
the gazelle-managed go_library/go_test srcs lists, so
//internal/storage/sqlbuild did not contain DescendantWalkQuery and both
consumers failed to compile under Bazel:

    internal/storage/issueops/blocked.go:170:13: undefined: sqlbuild.DescendantWalkQuery
    internal/storage/issueops/blocked.go:171:13: undefined: sqlbuild.DescendantWalkArgs

`make bazel-sync` adds exactly the four srcs rows the review measured; the
fifth BUILD.bazel row is a deps entry this commit's own new test requires.
A second sync leaves the tree clean. Note that `make bazel-sync-check` and
tools/bazel/go_srcs.py --check pass falsely on a srcs gap -- they manage only
the go_srcs glob filegroups -- and bazel-autofix cannot absorb this one
because bazel.yml:313 guards the sync step on steps.bazel.outcome ==
'success', which a compile break never reaches.

buildDescendantsCTE target columns (major, codex). GetDescendants' walk
resolved a row's parent through COALESCE(depends_on_issue_id,
depends_on_wisp_id), omitting depends_on_external, while the classic ParentID
filter it mirrors resolves all three and the reference test this PR adds makes
a cross-prefix parent a pinned contract for the sibling walk. ck_dep_one_target
(migration 0041) leaves exactly one target column set, so an external-target
row coalesced to NULL and could never match an edge: adding the column is
strictly additive, and it closes a gap where the proxied-server
bd list --parent tree (and --watch) could not see a cross-prefix child or
its subtree, while the direct route's per-level ParentID filter listed them.
TestBuildDescendantsCTEResolvesEveryDepTargetColumn derives the expected
column set from sqlbuild.DepTargetExpr, so the two cannot drift again.

That finding's other half -- migrating these members to the per-(table,
column) shape -- is deliberately deferred to bd-tztam and recorded at the
site. buildDescendantsCTE is a different query ((id, src, via) projection, a
dotted-ID fallback recursion, hoisted per-level filter predicates, no depth
cap, no path cycle guard), sqlbuild exports no member-fragment API, and
per-column members would triple its branch count, which the predBundle
comment above it records as tripping the dolt 2.1.6 analyzer.

nullGuards precedence and column binding (minor, claude+codex; minor, codex).
TestDescendantWalkQueryReproducesDepTargetPrecedence pins the per-column
IS NULL guards, which no existing test could see: the shape test never asserts
on a guard and the reference test seeds exactly one target column per edge, so
emptying nullGuards left both new test files green. The expected counts are
derived from DepTargetExpr's column list rather than restated, so the same
test binds descendantWalkTargetCols to it. The review's prescribed
`DepTargetExpr = "COALESCE(" + strings.Join(descendantWalkTargetCols, ", ")
+ ")"` does not compile -- issueops/dependencies.go:58 and
domain/db/dependency.go:35,:37 consume it in const declarations -- so this
takes the unit-assertion arm the same finding offers.

LOOKUP_JOIN warning multiplicity (nit, codex). The doc comment now records
that the ignored-hint warning is raised once per hint comment, six per
includeWisps=true query.

Iteration 2 (two minors, gate impact none, on a 981/850 approve).
TestGetDescendantsCrossPrefixParent pins the widened COALESCE against real
rows, where the test above pins only query text. Its edges go through the
repository's own classifier, which routes any cross-prefix target to
depends_on_external even when both ends are local, and each of its four
edges is matched by a different edge member (issues and wisps, anchor and
recursive): reverting the column at any one member reds the case with a
different set of children missing. CHANGELOG.md gains a Fixed bullet for
the user-visible half of this change, the proxied-server bd list --parent
tree.

Validation: sqlbuild 31 PASS / 0 FAIL / 0 SKIP; full domain/db package green
against the real Dolt container (915 PASS / 0 FAIL / 0 SKIP, 49s),
including TestGetDescendantsCrossPrefixParent,
TestGetDescendantsDottedOrphans, TestGetDescendantsFilteredByStatus and
TestParityReadyBlockedDescendants; golangci-lint 2.10.1 reports 0 issues on
the three changed packages; go test -run Bazel ./scripts/ is 13 PASS / 0 FAIL,
including TestBazelTestTagsFollowTaxonomy; bazel test
//internal/storage/sqlbuild:sqlbuild_test PASSED and bazel build
//internal/storage/domain/db:db_test succeeds; a final make bazel-sync
leaves the tree unchanged.

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

---------

Co-authored-by: qcore/syl <q@withq.ai>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 20:22:43 -07:00
Stephanie Jarmak
12b19a6df7
feat(dep): detect cycles through tracks edges (#6148)
* feat(dep): teach bd dep cycles to traverse tracks edges (gc-818bx)

Adds DetectCyclesRequest.IncludeTracks and a CanonicalMixedCyclePaths
walk so a molecule-root deadlock closing through a tracks edge (root
--blocks--> its own entry step, step --tracks--> root) is detectable,
while a cycle made entirely of tracks edges stays silent by
construction (guards against the PR #4933 false-positive regression).

Wired end to end: public issueops.DetectCyclesRequest -> pure
CanonicalMixedCyclePaths/AppendMixedCycleGraphInTx ->
DetectCycleReportInTx -> dolt/embeddeddolt/uow-domain transactional
wrappers -> `bd dep cycles --include-tracks`. Default request behavior
is unchanged (byte-identical code path when IncludeTracks is false).

Tests: pure-function unit tests for the new DFS variant (rotation,
parallel-edge dedup, self-loops, map-order determinism); conformance
cases against both dolt and embeddeddolt real backends plus the uow
provider (RunCycleDetectorIncludeTracksIgnoresAPureTracksLoop,
RunCycleDetectorIncludeTracksFindsTheMoleculeRootShape, and an added
DepTracks case in RunCycleDetectorFollowsOnlyBlockingEdges pinning the
default's exclusion); CLI-level flag registration and threading tests.

Scope: fix candidate 3 only, per gascity-pl's 2026-08-10 scope-narrowing
comment on gc-818bx (candidates 1/2 addressed upstream by gastownhall/
gascity PR #5202).

* fix(dep): find mixed cycles by SCC instead of single-pass DFS (gc-818bx)

CanonicalMixedCyclePaths could report no cycle for a graph that has a
qualifying one. A single global visited/onPath set only detects a back
edge to a node still on the active recursion stack, so a tracks-only
loop that fully closes and unwinds first (a->b->a) leaves b marked
visited-but-off-path by the time a scheduling edge into the same
component (a->c->b) is examined, and the c->b return edge is invisible
to the DFS.

Every internal edge of a strongly connected component lies on some
cycle within it, so replace the DFS with Tarjan's algorithm: find each
SCC, and for any SCC containing a scheduling edge, walk a deterministic
BFS return path back to that edge's source. Nodes, adjacency, SCC
membership, the chosen edge, and the return path are all sorted so the
result stays a pure function of the graph, matching the existing
determinism guarantee.

Adds the counterexample from exact-head review: a--tracks-->b,
b--tracks-->a, a--blocks-->c, c--tracks-->b, which the prior
implementation reported as acyclic despite the qualifying a->c->b->a
cycle.

* fix(dep): fail loudly if SCC path invariant breaks (gc-zo8a7)

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of sjarmak

* fix(dep): keep every default cycle in the --include-tracks report

CanonicalMixedCyclePaths emitted one cycle per strongly connected
component, so a tracks edge joining two separate blocks-only deadlocks
collapsed them into one reported cycle and --include-tracks could report
fewer cycles than the default walk.

The widened report is now the union of the default depth-first walk on the
scheduling-only subgraph and, for each blocks/conditional-blocks edge
inside a component of the widened graph, that edge closed by its shortest
return path over either edge type. The first set is the default report by
construction; the second adds cycles that close through tracks edges. Every
reported cycle still contains a scheduling edge, so tracks-only loops stay
out. The report holds at most one cycle per internal scheduling edge plus
the default cycles.

A missing return path inside a component is an invariant breach; it now
returns an error through DetectCycles instead of panicking.

* test(dep): pin tracks edge direction in the cycle detector contract

A two-node cycle reads the same under edge reversal, so the existing
IncludeTracks cases could not tell a walk that follows issue_id ->
depends_on_id from one that follows the reverse. The new three-node case
seeds a -> c (tracks), c -> b (blocks), b -> a (tracks), whose reported
path is a, c, b and becomes a, b, c if the edges are reversed.

Also refresh the cycledetector.go line citations this branch shifted.

* perf(dep): share one return-path search per target in the --include-tracks report

CanonicalMixedCyclePaths ran one breadth-first search per scheduling edge
inside a component, O(E(V+E)). On a dense tangle E grows with the square of
V, so the report grew with the fourth power of the component size.

Group the component's scheduling edges by target and close every edge into a
target from one shortestPathTree rooted there, confined to the component.
closeMixedCycle now reads the return path out of that tree and still returns
an error, never loops, when the tree does not reach the edge's source.

TestShortestPathTreeClosesEachEdgeAsAPerEdgeSearchDid checks over generated
graphs that each edge closes to the cycle reachPath produced for it alone,
ties included. BenchmarkCanonicalMixedCyclePathsDenseTangle (80 issues, a
blocks edge for every ordered pair, one tracks edge back): 26.3 ms and
27.8 MB per call before, 5.4 ms and 2.8 MB after.

* fix(dep): scope the --include-tracks guarantee and bound its output

Review iteration 1 (maintainer fixup) for the one gating major. The
IncludeTracks doc claimed that requiring "at least one blocks/
conditional-blocks edge" on every reported cycle is what keeps out the
`bd doctor` regression that "produced thousands of cycles". That rule is
NECESSARY, NOT SUFFICIENT. One tracks-only loop fuses everything it
touches into a single strongly connected component, after which every
scheduling edge inside that component lies on a cycle and is reported --
even where those scheduling edges alone are strictly acyclic and the
default walk reports nothing. A 10-step molecule whose entry step tracks
back to its root yields 9 reports against the default walk's 0.

The doc's own BOUND paragraph conceded the volume ("never more than twice
the distinct scheduling edges") while the paragraph above it claimed the
guard prevented it. The algorithm is correct and is unchanged; what was
wrong is the contract written over it, plus the absence of any cap on a
diagnostic that can now be edge-count sized.

A census found the claim in 5 sites, not the 2 the review cited:
  issueops/cycledetector.go                       IncludeTracks field doc
  internal/storage/issueops/cycle_report.go       the BOUND paragraph
  internal/storage/issueops/cycles.go             AppendMixedCycleGraphInTx
  cmd/bd/dep.go                                   flag registration comment
  internal/storage/issueops/cycle_report_test.go  section header
backend/conformance/cycle_detector_contract.go:246 already scoped it
correctly ("a loop made entirely of tracks edges stays silent") and is
left alone. The PR body and the contributor's commit messages assert only
the true narrow rule, so neither needed correcting.

--limit caps the RENDERED list (default 50, 0 = no limit), matching the
idiom in list/search/stale/find_duplicates. It is a rendering cap and not
a narrower request because CycleReport.Cycles promises to omit no cycle:
the printed total stays the whole report's, the truncation says how much
it held back, and --json is never capped.

TestCanonicalMixedCyclePathsBoundsAFusedMoleculeByItsSchedulingEdges pins
the manufacture direction ...KeepsDeadlocksATracksEdgeFuses left open --
that one fuses two real deadlocks and checks neither is lost; this one
fuses none at all and still gets 9 reports.

Also taken, both non-gating: dropped the dormant
`json:"include_tracks,omitempty"` tag, since no serializer of
DetectCyclesRequest exists in the tree and handleDependencyCycles calls
requireNoQuery, so the tag advertised a wire contract the server refuses;
and added a comment naming the backend conformance cases as the only pin
on the row->edge admission switch.

Declined this iteration: factoring appendDependencyGraphInTx and
AppendMixedCycleGraphInTx onto one shared row loop (nit, gate impact
none). It restructures the SQL read path that, per the finding directly
above it, is pinned only at the conformance layer, and
appendDependencyGraphInTx also backs AppendSchedulingGraphInTx -- the
write-time gate behind every `bd dep add`. That is a wider blast radius
than a zero-gate-impact nit earns inside a fixup whose subject is a doc
overclaim; it belongs in its own change.

Validation: go build ./... clean; go vet clean on the 4 touched packages;
golangci-lint v2.10.1 reports 0 issues on issueops/...,
internal/storage/issueops/... and cmd/bd/...; internal/storage/issueops
full package 749 PASS / 0 FAIL / 0 SKIP (748 before, +1 new); cmd/bd
dep-cycles selector 9 PASS / 0 FAIL / 0 SKIP; internal/httpapi
Cycle|SpecParity 6 PASS / 0 FAIL. Mutation: making tracks edges unable to
fuse a component reds the new pin plus 5 incumbents (the feature dies);
reporting only one cycle per component reds the new pin ALONE (1 of 14),
so it covers a degradation no existing test catches.

Review iteration 2: the remedy above re-entered its own finding class. Both
iteration-2 items indict text THIS fixup wrote, not the contributor's.

The --limit cap is UNCONDITIONAL -- `if limit > 0 && len(shown) > limit` never
consults includeTracks -- yet every rationale iteration 1 wrote for it was
scoped to the widened walk, and the IncludeTracks field doc still closed with
"the base walk this type's doc above describes is unchanged". True of the walk;
false of its rendering, since plain `bd dep cycles` printed every cycle at base
and now prints at most 50. That is the same defect class as the major this
commit exists to fix: a doc claiming a scope the mechanism does not honor.

Of the two arms the review offered, only documenting the true scope is
available. Gating the cap on includeTracks reds this PR's own incumbent test:
printCycleReportForTest calls runDepCycles(false, limit), so
TestDepCyclesTruncatesTheRenderedListButNotTheCount/capped asserts the DEFAULT
walk truncates. Measured, not assumed -- that arm fails capped and
registered_default while no_limit passes. The implementation, the flag's help
string and the tests already agreed the cap is unconditional; only the prose
disagreed, so the prose moved:
  cmd/bd/dep_cycles.go      runDepCycles doc: the cap is unconditional, bounds
                            both walks, and names the behavior change vs base
  cmd/bd/dep.go             flag comment: caps both walks; the widened walk is
                            what makes the cap necessary, not what scopes it
  issueops/cycledetector.go the "Default false" closer: the walk is unchanged,
                            its RENDERING is not
Also the nit: the opening paragraph argued no flag can narrow either question
while --limit had no carve-out, where IncludeTracks had one. It now says no flag
narrows the ANSWER, and that --limit caps only what is PRINTED.

New renderer arm "registered default" closes the gap the minor named: every
existing arm drove an explicit limit, so the shipped 50 was pinned only by
TestDepCyclesLimitFlagRegistration's DefValue != "0". It reads the default off
the command and renders past it, so it tracks whatever ships; ids are
fixed-width so "past the cap" cannot match as a prefix of one inside it.

Mutation (3 arms, control restored byte-identical by cp -- the fixset was
uncommitted): gate the cap on includeTracks => capped + registered_default RED;
default 50 -> 0 => LimitFlagRegistration + registered_default RED (the new arm
independently catches an unbounded default); shown[:limit+1] => capped +
registered_default RED, so the arm pins the boundary and not merely "some
truncation". no_limit stays green under all three by design.

Validation: gofmt clean, git diff --check clean, go build ./... rc=0, go vet
clean on cmd/bd and issueops, cmd/bd dep-cycles selector 9 PASS / 0 FAIL / 0
SKIP (same top-level roster, +1 subtest). No production behavior changed this
iteration -- doc text plus one test arm.

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

---------

Co-authored-by: sjarmak <t@t.co>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-30 20:20:17 -07:00
Jim Wordelman
7d545486e5
fix(init): refuse to silently recreate a missing server-side database as empty (#5791)
* test(init): red — existing project with missing server DB must refuse init

be-5up5: server mode never has a local dolt/ directory, whether this is a
genuine fresh clone or an existing project whose database was lost from the
server — doltDirExists==false alone (GH#2433's signal) can't distinguish
them. Adds TestInitGuard_ExistingProjectMissingServerDB_Refuses, which spins
up a real dolt sql-server with no database and a metadata.json carrying a
non-empty project_id (proof of a prior real init). Currently fails: the
guard returns nil and lets init silently recreate the database as empty,
which is the 2026-08-11 fleet-wide data loss.

RED only — checkExistingBeadsDataAt is not yet fixed.

* fix(init): refuse to recreate a missing server-mode database (be-5up5)

bd init's server-mode "already initialized" check treated a missing or
unreachable database the same as a genuine fresh clone, silently
returning nil and letting init proceed to create an empty database —
even when metadata.json's project_id proved this was an existing
project whose database had gone missing (the 2026-08-11 fleet-wide
data loss).

Guard on cfg.ProjectID != "" to distinguish the two cases. An existing
project now gets a refusal (initGuardMissingServerDBMessage) that
names bd doctor / bd dolt status / bd backup restore as the recovery
path and explicitly does not recommend bd bootstrap, since bootstrap
has its own related mode-blind create bug (tracked separately). A new
--recreate-missing flag is required to opt into creating fresh in this
case — never implied by --force, config, or env. Genuine fresh clones
(empty project_id) are unaffected.

Also:
- doctor/gitignore.go: drop the "bd init (safe to re-run)" fix hint,
  since re-running bd init is exactly the unsafe action this fix
  prevents in the case that matters.
- storage/dolt/errors.go: the general "database not found" hint no
  longer claims bd bootstrap is a safe first step for "an existing
  project" — only for genuine fresh-clone / shared-server-recovery,
  which is what the existing tests actually cover.

* test(init): pin exit_contract's bootstrap-not-recommended requirement (be-5up5)

TestInitGuard_ExistingProjectMissingServerDB_Refuses checked the refusal
and the absence of --force, but not the exit_contract's explicit "does
not recommend bd bootstrap for a server-mode workspace" requirement —
that was only verified by hand during self-review. Pin it directly, and
assert the message names an actual recovery path.

* test(init): cover --recreate-missing positive path (be-ab3b)

be-5up5's guard already correctly permits init to proceed when
--recreate-missing is set; only the negative path (flag absent -> refuse)
had test coverage. Adds TestInitGuard_ExistingProjectMissingServerDB_
RecreateMissingAllows, covering both guard sites the flag gates:
init.go:2566 (server reachable, database confirmed missing) and
init.go:2578 (server unreachable / errored during the check).

refs be-3mvz (review round 1 request-changes), closes be-ab3b

* chore: release gate PASS for bd init missing-server-DB guard fix (be-udx2)

* chore: record full pre-PR contributor check results for be-udx2 gate

* test(init): red — bd init --force recreates a missing server DB as empty

--force is a deprecated alias for --reinit-local (init.go ~395), and the
existing-data guard is gated on !reinitLocal (~763), so --force skips
checkExistingBeadsData — and with it the be-5up5 missing-database refusal
this PR added. The reinit path's own typed confirmation does not cover the
gap either: it keys on countExistingIssues, which returns 0 or an error in
exactly the case where the server-side database is missing, so no prompt
and no destroy token are ever required.

Net effect at this commit, measured against a real dolt sql-server
(2.2.3) holding no "myproject" database, with metadata.json carrying a
project_id:

    $ bd init --force --prefix myproject --skip-hooks
    ...
      Database: myproject
      Issue prefix: myproject
    Run bd quickstart to get started.
    $ echo $?
    0
    $ ls <server data-dir>
    config.yaml  .dolt  .doltcfg  myproject      <-- created, empty

An empty database at the name the real one used to occupy, exit 0, no
prompt. That is the 2026-08-11 fleet-wide data-loss reflex, reached
through the flag an operator in a panic is most likely to reach for.

This test drives the real binary because that is the only way to exercise
the --force -> reinitLocal -> "skip the guard" path end to end; a unit
test on the guard function cannot see that the caller never runs it.
Both subtests fail at this commit.

Reported in review of PR #5791 by bee-ghosttrack, item 1.

* fix(init): green — --reinit-local/--force cannot bypass the missing-DB guard

Add guardMissingServerDatabaseAt, a narrowed form of the be-5up5 refusal
that answers only one question — is this an already-initialized
server-mode project whose configured database is missing or
unconfirmable? — and run it on the reinitLocal path, which
checkExistingBeadsData never reaches.

The distinction the guard encodes: --reinit-local/--force authorize
destroying a database that EXISTS. They do not authorize inventing an
empty one where the configured database has gone missing. Only the
explicit, per-invocation --recreate-missing does that, which is what makes
that flag's "never implied by --force" help text an honest guarantee
rather than an aspiration. The review suggested softening that help text
instead; making the claim true seemed better than documenting that it
isn't.

Deliberately narrow. It returns nil for every state except the missing
database — no metadata, non-Dolt backend, non-server mode, empty
project_id, or a local dolt/ directory all fall through — so it never
resurrects the "already initialized" refusal that --reinit-local is
legitimately meant to bypass. The "stays silent on a fresh clone with no
project_id" subtest pins that boundary.

Same scenario as the previous commit, now:

    $ bd init --force --prefix myproject --skip-hooks
    Error:
    (warn) Database "myproject" not found on server at 127.0.0.1:34813 ...
    bd init will NOT create an empty database here — that would strand any
    existing issue data behind a new, empty database of the same name.
    $ echo $?
    1
    $ ls <server data-dir>
    config.yaml  .dolt  .doltcfg            <-- nothing created

Addresses review of PR #5791 by bee-ghosttrack, item 1.

* test(init): cover the unreachable-server refuse branch

Review of PR #5791, item 2. The PR claimed
TestInitGuard_ExistingProjectMissingServerDB_Refuses covered both guard
sites — server reachable with the database missing, and server unreachable
or errored while checking. It does not: that test starts a live dolt
sql-server, so it only ever exercises the first. The unreachable site had
coverage on the PERMIT side only (the BEADS_DOLT_SERVER_PORT=1 subtest of
_RecreateMissingAllows), which would not notice if its refusal were
dropped.

TestInitGuard_UnreachableServerRefuses closes that: port 1 is unreachable
by construction, so it needs no dolt binary and runs in the fast lane.

Also drops a comment reference to scripts/repro-bd-init-recreates-empty-db.sh,
which is not in the repo or in this diff (item 3, third bullet), and
describes the state the test sets up instead.

Addresses review of PR #5791 by bee-ghosttrack, item 2.

* docs(init-safety): document --recreate-missing and its known limits

Review of PR #5791, item 3 (doc drift), plus the non-blocking note.

The flag's own help pointed users at `bd help init-safety`, whose FLAG
SURFACE section did not list it — so the one place the help sends you was
the one place it was missing. Added there, stating plainly that it is
per-invocation only and never implied by --force/--reinit-local, config,
or env.

docs/recovery/init-safety.md gains an init-missing-server-db section (and
a TOC entry) covering the refusal users will actually hit: why the
fresh-clone and lost-database cases are indistinguishable from the local
filesystem in server mode, why the old "assume fresh clone" answer caused
the 2026-08-11 loss, and the three ways out in the order they should be
tried — diagnose the server first (a stopped server or wrong --data-dir
presents identically and needs no re-init), then restore from an export,
then --recreate-missing as the deliberate last resort.

Both limits the review flagged as non-blocking are recorded there and in
the guard comment rather than left as folklore:

- The guard keys on project_id, minted by GH#2372. A pre-GH#2372 workspace
  carries none and is indistinguishable from a fresh clone, so it FAILS
  OPEN. Accepted deliberately — failing closed would block legitimate
  first inits on every such clone, and this guard's job is to stop a
  silent recreate where prior initialization can be PROVEN, not to guess
  where it cannot.
- Server mode only. Proxied-server mode returns early on a missing root
  and never reaches the guard, and bd bootstrap has its own separate
  mode-blind create path.

Addresses review of PR #5791 by bee-ghosttrack, item 3 and the
non-blocking notes.

* docs(changelog): record the --force missing-database bypass fix

Under Unreleased/Fixed. This is a behavior change to bd init --force on
every server-mode workspace whose database has gone missing, and it was
not recorded anywhere users read.

* fix(init): make the missing-server-database guard fire in shared-server mode

Review round 2, item 1 (blocking): the guard was a no-op in shared-server mode
— the topology of the 2026-08-11 data loss, and so the primary case.

guardMissingServerDatabaseAt statted doltserver.ResolveDoltDir(beadsDir) and
returned early when it was a directory, reading that as "there is local data to
protect". In shared mode ResolveDoltDir returns the machine-global
~/.beads/shared-server/dolt, and SharedDoltDir() MkdirAlls it
(internal/doltserver/doltserver.go:281). The stat therefore always succeeded and
checkDatabaseOnServer was never reached, while every per-project test kept
passing.

Fix per the reviewer's first option: test for THIS project's database directory
rather than the data directory that holds it. A Dolt data dir contains one
subdirectory per database, each with its own .dolt — verified on disk — so
<doltDir>/<dbName>/.dolt is the correct probe in BOTH modes, and it is strictly
more precise in per-project mode too: a data dir that exists but holds no
database for this project no longer counts as local data to protect.

Two new tests, both against a real dolt sql-server rather than an unreachable
port, covering the two cases the reviewer noted were uncovered:

  TestInitGuard_SharedServerMode_MissingServerDB_Refuses
      reachable server, database absent -> must refuse.  This is the actual
      loss shape. Reverting the one-line guard change turns it red with
      "got nil error"; the pre-existing per-project tests stay green, so it
      pins the shared-mode gap specifically.
  TestInitGuard_SharedServerMode_PresentServerDB_Allows
      reachable server, database present -> must NOT refuse, so --reinit-local
      and ordinary reinit keep working. The reviewer verified this by hand and
      flagged it as untested.

Also from the same review:
- docs/recovery/init-safety.md overstated the proxied limit. The proxied path
  does not reach THIS guard (dispatch at init.go:619 precedes the
  initAllowRecreateMissing assignment at :767), but it does reach the older
  checkExistingBeadsData (init_proxied_server.go:89) — and because the flag is
  never assigned there, --recreate-missing is inert under --proxied-server.
  Documented as pre-existing rather than silently fixed.
- Shared-server mode now named explicitly in the same Limits section.
- checkExistingBeedsData typo corrected.
- The "### 3." heading wrapped onto a second line and rendered broken.

Verified: full TestInitGuard suite 15/15 PASS, 0 SKIP (12.1s), including all
pre-existing guard tests. go build ./... clean, gofmt clean, go vet clean.

Refs be-ok1tt, be-udx2.

* test(init): redirect the shared-mode fixtures with BEADS_SHARED_SERVER_DIR

Round-3 MINOR-2, unaddressed through round 4. The two shared-server tests
redirected HOME so SharedDoltDir() would resolve inside the test tree, but
SharedServerPath() reads BEADS_SHARED_SERVER_DIR first and only then falls
back to os.UserHomeDir(). An ambient BEADS_SHARED_SERVER_DIR — the override
that function's own comment advertises for testing — silently won, and the
pair then wrote into and asserted against the developer's real
~/.beads/shared-server/dolt, failing spuriously if a real "myproject" lived
there. HOME is also a no-op on Windows, where os.UserHomeDir() reads
%USERPROFILE%.

Set the variable the resolver actually consults first. No behavior change.

* test(init): make the present-database control pin the early return

Round-3 NIT-4, unaddressed through round 4, and demonstrated there: with the
local-database probe reverted, _SharedServerMode_PresentServerDB_Allows stayed
green, so it pinned nothing of the early return that commit rewrote. It
returned nil via the server check alone, because the fixture never gave this
project a database directory under the shared data dir.

Create that directory, the way a real shared-mode install has one, and then
assert the early return specifically: with the server made unreachable, the
local database directory alone must still satisfy the guard. Removing the
early return now turns this test red.

* test(init): red — the documented --recreate-missing recovery cannot reach its opt-in

Round-3 MAJOR-1 / round-4 finding 1. checkExistingBeadsDataAt derives "is this
project's database here?" from os.Stat(ResolveDoltDir(beadsDir)) — the DATA
directory, which exists on every initialized workspace (shared-server mode
MkdirAlls the machine-global one in SharedDoltDir; per-project mode MkdirAlls
it in ensureDoltInit). So the FR-010 missing-vs-present branch never runs and
both --recreate-missing opt-ins inside it are unreachable.

Four surfaces tell the operator to run `bd init --recreate-missing --prefix
<p>`: the flag help, `bd help init-safety`, docs/recovery/init-safety.md, and
the guard's own refusal text. That command exits 1 with a false "already
initialized" message pointing back at --reinit-local, which is the destructive
path. The documented recovery is a dead end and the only thing that works,
--reinit-local --recreate-missing, is named nowhere.

The existing _Refuses/_RecreateMissingAllows fixtures cannot see this: they
omit the data directory entirely, so their branch condition is true for the
wrong reason. These two add it, which is the state of every real workspace
whose server-side database was dropped.

Both fail at this commit.

* fix(init): green — probe this project's database directory, not the data dir holding it

Round-3 MAJOR-1 / round-4 finding 1. Test for <dolt-data-dir>/<database>/.dolt
instead of the data directory itself, so the FR-010 missing-vs-present branch
is reachable on an initialized workspace and `bd init --recreate-missing`
reaches its own opt-in. This is the same probe, for the same reason, that
guardMissingServerDatabaseAt already uses on the reinit path.

Making that branch reachable also exposes states the data-dir stat used to
shadow, and permitting them would be a new fail-open policy rather than a fix.
The clearest is a workspace that predates GH#2372: it carries no project_id,
so `existingProject` is false, and the branch would permit a silent empty
recreate on exactly the installed base this guard exists to protect. The
data-dir stat therefore stays — it stops being the gate and becomes the permit
condition, admitting only what the old probe already admitted, plus the
explicit per-invocation opt-in. Net behavior change is the opt-in becoming
reachable, and the false "already initialized" message being replaced by the
accurate missing-database refusal where the database is genuinely gone.

Choosing a better proof of prior local init is deliberately NOT done here.
project_id comes from git-tracked .beads/metadata.json, so a fresh clone
inherits one (round-4 finding 2); the replacement signal needs a different
answer in per-project and shared-server mode, and is tracked as its own
architecture decision on be-5pjhd. The known limit is now recorded in the
guard comment and in docs/recovery/init-safety.md rather than left implicit.

Tests: the two red tests from the previous commit now pass, and two more pin
the narrowing — a pre-project_id workspace with a local data dir stays blocked,
and --recreate-missing still opens it.

* docs: record the --recreate-missing fix and the fresh-clone project_id limit

Round-3 NIT-3 / round-4 finding 4: the round-3 probe change (data dir to
<dolt-data-dir>/<database>/.dolt) was never written down, and it is
user-visible wherever the data dir exists but the database is gone. Both that
and this round's --recreate-missing fix are now under [Unreleased] / ### Fixed.
The stray double blank line is gone with the section's move.

Also records, in docs/recovery/init-safety.md's "Limits worth knowing", that
project_id is inherited by a fresh clone because .beads/metadata.json is
git-tracked by default — the round-4 finding-2 gap this series deliberately
does not close. It fails in the safe direction and --recreate-missing is the
supported way through it; the replacement signal is tracked separately.

* docs(adr): ADR-0004 — proof-of-prior-init signal for the missing-database guards

Round-4 finding 2 asked what should replace project_id as the proof that a
workspace was initialized locally, and what the fail-open/fail-closed policy
should be per server mode. It needed a design decision rather than a
mechanical fix, so it was escalated; this records the answer.

The decision is to formalize what the code already does for local hosts and
keep project_id where nothing local can ever help. Presence of this project's
own <dolt-data-dir>/<database>/.dolt is unconditional proof, because the path
is gitignored and only a real local process creates it. Its ABSENCE, however,
cannot be promoted to proof in either direction: it looks identical whether
the workspace was never initialized here or was initialized here and lost its
storage — and the second is the shape of the 2026-08-11 incident. For a
genuinely remote host the probe is not merely silent today, it is structurally
silent forever, since the only code that creates that directory runs on local
server-management paths.

So project_id stays as the tier-2 fallback with its git-inheritance weakness
accepted, and --recreate-missing is the permanent resolution UX rather than a
stopgap. A local-only init marker and repurposing .local_version are recorded
as rejected, with reasons, so neither is re-proposed each review round.

Extends ADR 0002, which set the init safety invariants but left the evidence
question open.

* test(init): red — the reinit guard waves through a pre-project_id workspace

ADR-0004 follow-up 1. guardMissingServerDatabaseAt is the safety net for
--reinit-local and --force, which bypass checkExistingBeadsDataAt entirely. It
returns nil the moment cfg.ProjectID is empty, BEFORE it ever reaches the
per-database .dolt probe eighteen lines below.

checkExistingBeadsDataAt does the opposite: it probes first, and only falls
back to project_id — narrowed by the coarse-directory permit condition — when
that probe comes up empty. So a workspace initialized before GH#2372 minted
project_id, whose local Dolt storage has since been lost, is protected under
plain `bd init` and waved straight through under the two flags an operator
reaches for in a panic. The weaker path is the one behind --force.

Three tests through guardMissingServerDatabaseAt, mirroring the plain-init
trio: no project_id with a local data dir present must refuse; no project_id
with nothing local at all is a genuine fresh clone and must be allowed; and
--recreate-missing must still open the refused case.

The first fails at this commit. The other two pass, and pin the directions the
fix must not break.

* fix(init): green — probe the local database before consulting project_id

ADR-0004 follow-up 1. Move the per-database <dolt-data-dir>/<database>/.dolt
probe above the project_id check in guardMissingServerDatabaseAt, and run it
unconditionally, so this guard reasons in the same order as the plain-init
guard it backstops.

When the probe comes up empty and project_id is also absent, apply the same
coarse-directory permit condition checkExistingBeadsDataAt uses: allow only
when there is no local Dolt data directory either. A data directory with no
database in it still says this workspace has touched local Dolt storage, and
that is exactly the pre-GH#2372 lost-storage case the old early return waved
through under --reinit-local and --force.

One cell of the behavior matrix changes: no project_id, no local database, but
a local data directory present now refuses instead of returning nil.
Everything else is untouched, --recreate-missing still returns nil at the top
of the function, and a workspace with nothing local at all is still treated as
a fresh clone.

The comment records the shared-server asymmetry ADR-0004 accepts — there the
coarse directory is machine-global, so that cell is more conservative — as
settled rather than as an open defect, since it fails toward refuse and its
population only shrinks.

* docs: cite ADR-0004 from the plain-init guard, the recovery doc and CHANGELOG

The comment at checkExistingBeadsDataAt's project_id check said the limit was
"OPEN and tracked by be-5pjhd" and that the replacement signal was
"deliberately not made here". It is made now, so the comment says settled
instead of open, and points at the ADR rather than at a bead — with a note to
read it before reopening, since the two obvious alternatives are recorded
there as rejected rather than unconsidered.

docs/recovery/init-safety.md said the same thing in operator language and is
updated the same way, plus a new bullet stating that the guard now applies
equally to bd init, --reinit-local and --force. That equality is the
user-visible half of the fix and was not previously stated anywhere.

Its "Last reviewed" marker moves to today. The doc is freshness-tracked
against cmd/bd/init.go, which this series changes, and leaving the marker at
2026-09-08 would claim text written today had been reviewed eight days before
it existed.

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

  release-gates/be-udx2-init-missing-db-guard-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

* chore(bazel): enumerate init_guard_force_e2e_test.go in cmd/bd srcs

The PR adds cmd/bd/init_guard_force_e2e_test.go under a plain '//go:build cgo'
tag, which is the tag class cmd/bd/BUILD.bazel enumerates (the 23 unenumerated
test files in this package are all 'cgo && integration', 'scripttests' or
'chaos'). cmd/bd/BUILD.bazel is base-added, so the contributor's branch could
not have carried this row. Generated by 'make bazel-sync'; no hand edits.

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

* fix(init): honor --recreate-missing on the proxied route; scope the refusal's evidence claim

Maintainer review fixes for PR #5791 (iteration 1). Five review minors; the
three substantive ones:

1. --recreate-missing was inert under --proxied-server. runInit dispatches to
   runInitProxiedServer and returns before the assignment site, while
   runInitProxiedServer calls checkExistingBeadsData, which reads the global —
   so converting a server-mode workspace with a missing database to proxied
   mode was refused despite the explicit opt-in, and the refusal named the
   exact flag the operator had just passed. It failed closed, so there was no
   data hazard, only a recovery dead-end. The assignment now sits beside its
   flag read, upstream of every dispatch in runInit.

   The PR's recovery runbook documented this inertness as "pre-existing
   behaviour, not introduced here". The early dispatch is pre-existing, but
   --recreate-missing is introduced by this PR, so the flag could not have had
   pre-existing inertness. That paragraph is rewritten to the new behaviour.

2. initGuardMissingServerDBMessage asserted "metadata.json has a project_id"
   unconditionally, but the --reinit-local/--force guard also emits it for a
   workspace predating GH#2372 where only local Dolt storage proves prior use —
   the population the CHANGELOG bullet names. The evidence sentence is now
   selected by the caller, so the message never cites an artifact its caller
   does not have. Pinned from both sides: the project_id cell must cite that
   evidence, the no-project_id cell must not.

3. The new doc comment claimed initGuardServerMessage is "used when there is no
   evidence either way". It has no production caller, so the contrast was
   asserted as two live code paths. Reworded to intent. The dead message's
   surviving "existing project -> bd bootstrap" sentence is pre-existing, is
   pinned by four tests, and is left for a follow-up.

Also re-cited two stale path:line references by symbol and branch (the recovery
runbook's three, and a test comment's two), and expanded the else-branch comment
in checkExistingBeadsDataAt to cover the reachable-but-missing fall-through that
lands there — the branch's guards are correct for both cases only because their
conditions do not mention reachability.

Declined, with reasons, as out of scope for opportunistic cleanup: restructuring
the fall-through itself (a control-flow change in the diff's most complex
function, which both review lanes agree is behaviourally correct today);
rewording the caller-less message's bootstrap sentence (four pinned tests,
pre-existing); and adding --recreate-missing to the generated CLI reference
(the required check-doc-flags job passes at this head and seven other registered
initCmd flags are equally absent, so that page is not a flag enumeration).

Validation: go build ./... and go vet ./cmd/bd/ clean; gofmt clean;
go test ./cmd/bd/ -run 'TestInitGuard|TestCheckExistingBeadsData' ok (26 tests,
real Dolt servers); scripts/check-doc-freshness.sh PASSED; git diff --check
clean. The evidence pin was proved non-vacuous by mutation: forcing the reinit
call site back to an unconditional project_id claim reddens exactly the
no-project_id test and nothing else.

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

* fix(doctor): drop the bd init hint from #5634's permissions warning

1d7629213b on this branch removed "bd init (safe to re-run)" from the
.beads/.gitignore fix hints, because re-running bd init is the unsafe
action be-5up5 guards against. #5634 (c33738d209) reached main while
this PR was open. It added a CheckGitignore warning for unexpected file
permissions that still carries the old hint, so after the merge it was
the only gitignore check that suggested bd init.

Give it the same "Run: bd doctor --fix" hint as the four other
gitignore warnings. That is a complete repair here: FixGitignore
restores mode 0600, and #5634's test already checks that the warning
clears after it runs.

TestCheckGitignore_WarnsOnLoosePermsWhenPatternComplete only checked
that Fix was non-empty. It now pins the exact hint. With the old
gitignore.go line put back, the test fails.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(init): name the real gitignore template in ADR-0004 and init.go

ADR-0004 and the matching comment in init.go both cite
`defaultGitignoreContent` in cmd/bd/doctor/gitignore.go as the place
that says .beads/metadata.json is git-tracked by default. No symbol by
that name exists, in this branch or in main's history. The constant
that says it is GitignoreTemplate. Its closing lines read "Config files
(metadata.json, config.yaml) are tracked by git by default since no
pattern above ignores them".

Rename the reference in both places. The claim itself is unchanged.
Neither file changes outside that one identifier.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
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 <noreply@anthropic.com>
2026-09-30 20:07:49 -07:00
Jim Wordelman
96949bc290
test(storage/dolt): give each cold store its own context budget in setupTwoProjectStores (#6256)
* test(dolt): red — setupTwoProjectStores shares one testTimeout across two cold store opens (refs be-gvnsq)

* feat: green — setupTwoProjectStores shares one testTimeout across two cold store opens (refs be-gvnsq)

* chore: release gate PASS for be-5fap7

* test(storage/dolt): give every cold store open its own budget, and drop the test that proved nothing

Review findings 1-4 on PR #6256. All four are upheld; two of them are fixed by
deleting what this PR added.

Finding 1 (blocking) — TestStoreOpenContext_FreshBudgetPerCall did not exercise
the property it claimed. It asserted that two context.WithTimeout calls return
different deadlines, which is a property of the standard library. It never
named setupTwoProjectStores, New or DoltStore, so reverting setupTwoProjectStores
outright could not have turned it red. The gate record's "TDD red" was a compile
failure (storeOpenContext undefined pre-fix), not a behavioural one.

Deleted rather than replaced. The real property — a cold open must not inherit
a budget already spent by a previous open — is not observable from a unit test
without an injectable clock or injectable load, and writing a second test that
merely looks like it checks this would repeat the original mistake. The guard
is now structural instead: every two-open site routes through one helper.

Finding 2 (blocking) — the fix covered one site of five. Enumerating every
New(ctx, ...) in the package found SEVEN unfixed siblings, three more than the
review reported:

  cross_project_test.go:307,320  PortCollision_SameDatabase          (reported)
  cross_project_test.go:812,829  IdentityCheck_..._ForeignRejected   (reported)
  cross_project_test.go:856,866  IdentityCheck_..._MatchingSucceeds  (reported)
  create_guard_test.go:273,291   CreateGuard_ExistingDB_WithData     (reported)
  cross_project_test.go:903,914  IdentityCheck_SoftSkip_NoLocalMetadata
  cross_project_test.go:938,945  IdentityCheck_SoftSkip_EmptyDBProjectID
  cross_project_test.go:976,996  IdentityCheck_Gateway_SkipsVerification

All extended rather than deferred; the shape is gone from the package.

Findings 3 and 4 (nits) — storeOpenContext() was byte-identical to
testContext(t) (dolt_test.go:59-62) minus t.Helper(), and the unconditional
500ms time.Sleep existed only to exercise it. Both removed with the test.

openStoreWithOwnBudget(t, cfg) replaces them. It does not duplicate
testContext: it composes it with the New call and the cancel, which is the
invariant all 14 call sites need. Cancelling the open context when the open
returns is safe for the reason the review already established — the context
bounds the open, not the returned store.

testTimeout's doc comment claimed "some tests set up two stores under one
context"; no longer true, corrected.

Net effect is a smaller diff than the reviewed version: -90/+44 across three
files, against +78/-7 in one.

Verified against a real dolthub/dolt-sql-server:2.2.0 container with ambient
BEADS_DOLT_SERVER_PORT unset: TestCrossProject 11/11 PASS 0 SKIP (193.4s),
TestCreateGuard 9/9 PASS 0 SKIP (35.3s). Zero SKIPs matters — these suites skip
rather than fail when the container cannot start.

Refs be-6sszs, be-gvnsq.

* docs(release-gates): correct the be-5fap7 "TDD red" claim and record the review response

The gate record called c2e896373 a TDD red with the new regression test
"confirmed failing pre-fix". The reviewer showed that failure was a compile
error — storeOpenContext did not exist before the fix commit — not a
behavioural red. A compile error is not evidence that a test guards a
behaviour, and that mislabel is what let a vacuous test through the gate.

Corrects the commit annotation and the scope paragraph, and adds an addendum
recording all four findings, the seven sibling sites (three more than the
review reported), and the container-verified test evidence.

Refs be-6sszs.

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

  release-gates/be-5fap7-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(test/dolt): give the cheap calls their own budget too, not just the opens

Review of PR #6256 found the per-open budget conversion incomplete at its own
headline function. In setupTwoProjectStores the shared ctx was created BEFORE
both cold opens and still guarded storeB.SetConfig after the second, and
context deadlines are absolute — so the own-budget opens drained it anyway.
Base failed iff d(openA)+d(SetA)+d(openB) > 45s; head failed iff the same sum
plus a millisecond SetConfig > 45s. The same runs failed either way: be-gvnsq
was relocated onto a cheaper call with a more misleading message, not fixed.

Changes:

- Add setConfigWithOwnBudget, the SetConfig twin of openStoreWithOwnBudget,
  and route both setupTwoProjectStores writes through it. The shared ctx is
  gone entirely, which is the shape the PR already demonstrates at
  ...SoftSkip_EmptyDBProjectID. Taking this arm over "move the ctx below the
  storeB open" keeps the call order and every error-cleanup arm verbatim, and
  leaves no residual shared deadline at all.
- Convert cross_project_test.go:783 (New(ctx, initCfg), landed by base commit
  7a81e297d9 inside a function this PR had already converted) to
  openStoreWithOwnBudget.
- Reword the testTimeout comment: the PR replaced a hedged claim with the
  absolute "no test shares one deadline across two", which is false in 8
  functions across 8 files at this head. It now states the helper's policy and
  what a raw New(ctx, ...) still means. Converting the other 8 is follow-up
  work, not this PR's obligation (65 raw sites repo-wide; this PR converted 16).
- Document on openStoreWithOwnBudget that per-open budgets do not by themselves
  decouple the caller — the gap this review found — pointing at setupTestStore's
  pre-existing note, which already stated the ordering rule the change missed.

Measured, two arms, same mutations (testTimeout 8s + a 9s sleep standing in for
a slow cold open, injected between the storeB open and the SetConfig after it):

  pre-fix code  FAIL  "failed to set prefix for project B: begin write tx:
                       context deadline exceeded"  <- the predicted relocation
  post-fix code PASS

The load-dependent flake itself still has no deterministic pin; that remains an
accepted trade-off, as the contributor's dropped regression test found.

Not addressed here: the two create_guard_test.go conversions ADD a 45s bound
where ctx was context.Background(), rather than removing a coupling. That is a
framing note for the PR description, which this workflow edits at finalize.

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

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-30 18:40:10 -07:00
ecuthiell
4e804885dd
test(credentials): make remaining credential-command fixtures native-Windows portable (#5748) (#5749)
* test(credentials): make command fixtures Windows-portable (#5748)

Replace POSIX-only credential test commands with a shared shell-portable protocol, exercise their intended failure and non-invocation semantics on native Windows, and add the focused required CI selector.

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* test(ci): require each Windows credential fixture to pass

Include the standalone credentialcmd protocol test in the existing Windows
step. One package/test map drives both selection and exact terminal checks,
so missing, skipped, failed, or duplicate tests cannot report success.
Resolve native Go once and reuse it for the test invocation.

Bead: saa-cgh.66
Agent-Signature: unknown-model/unknown-reasoning

* test(ci): select the first Go application on PATH

Hosted Windows images can expose more than one Go application. Preserve
setup-go's PATH precedence, select one absolute application and reuse it.

Bead: saa-cgh.66
Agent-Signature: unknown-model/unknown-reasoning

* chore(bazel): sync BUILD.bazel srcs for the new credentialcmd test helper

Base landed the Bazel PR gates (#6881/#6887) after this PR was authored, so
the PR's new internal/testutil/credentialcmd package and internal/creds
testmain_test.go were never enumerated in any BUILD.bazel. Two already
enumerated test srcs (internal/creds/command_test.go and
internal/storage/dolt/gateway_credential_test.go) import the new package, so
`bazel build //internal/creds:all` fails GoCompilePkg without this.

Generated by `make bazel-sync` (gazelle); a second sync is a no-op. The
internal/storage/dolt version_staging_completeness_test.go srcs row is
pre-existing base drift that gazelle corrects in the same pass, not PR content.

* test(credentialcmd): pin the Windows gate's assertions and stop claiming foreign helpers

Maintainer review fixes for PR #5749, adoption iteration 1. The synthesis is
`approve` with no required changes; all four findings are minor or nit. A
maintainer bazel commit already exists on this branch, so the push was owed
regardless and none of these cost anything extra. No production code changes.

F1 — the new required Windows gate pinned its own wiring but almost none of its
assertions. The guard checked three package paths and one test name, so it
stayed green if someone dropped six of the nine test names from $expected,
deleted the `Action -in 'fail', 'skip'` throw, or deleted the exactly-one-PASS
loop -- leaving a required gate whose only real guarantee was "go test exited
0", which a fully skipped suite also satisfies. The pinned slice now carries all
nine test names plus both load-bearing guard tokens, keeping the file's existing
substring idiom.

F2 — the property the fixture exists for was unassertable end to end. Emit is
written to produce byte-exact stdout across sh and the Windows .cmd trampoline,
but parseCredential runs bytes.TrimSpace before every comparison, so every
existing assertion is blind to a trailing newline: a trampoline changed to
`echo %OUT%` would keep the whole suite green. TestCommandSourceRealShell now
wraps the existing credRunner package seam to capture the helper's stdout as the
shell produced it, and asserts it byte-exact. The real shell stays in the loop,
so this remains end-to-end rather than becoming a second in-process test.

F3 — Dispatch claimed any process where BEADS_TEST_CREDENTIAL_COMMAND_HELPER=1,
on the env alone and before inspecting argv, exiting 97 when the sentinel was
absent. command() arms that variable in the *parent* process and BEADS_-prefixed
variables reach every re-exec'd child through the integration allowlist, so the
first composition with a package that re-execs its own test binary -- which
internal/storage/dolt already does -- would have died with a wrong-subsystem
"missing protocol sentinel". Both gates are now required, and an env-armed
process without the sentinel falls through to its own TestMain.

The second half of that finding's prescription is deliberately NOT applied.
Adding BEADS_TEST_CREDENTIAL_COMMAND_HELPER to helperSubprocessSentinels reds
TestHelperSubprocessSentinelsAreComplete: that guard has a reverse-direction
control, and its regex looks for a literal os.Getenv("BEADS_..._HELPER") in
internal/storage/dolt's own test sources. This sentinel is read in
internal/testutil/credentialcmd, so the entry registers as a stale one. Measured,
not assumed -- the failure is "helperSubprocessSentinels lists
BEADS_TEST_CREDENTIAL_COMMAND_HELPER, but no test source reads it". With the
Dispatch gate fixed the entry also buys nothing: a dolt helper child already
carries its own sentinel, so isHelperSubprocess is true for it either way.

F4 — the exported constructors documented themselves as "returns a unique shell
command" while replacing PATH for the rest of the calling test, setting env vars
via t.Setenv (which bans t.Parallel), and silently rejecting an empty payload.
The shared contract is now stated once above the three of them, and Emit fails
fast with an explanation instead of letting the shell drop the empty payload
word and the helper exit 97. No caller passes an empty payload today.

Each fix was checked by reverting it and confirming its own pin reddens: the
dropped test name reds the guard by name; the trailing-newline wrong
implementation reds the new raw-stdout assertion while the sibling end-to-end
test stays green, which is the blindness the finding described; and reverting
the Dispatch gate reproduces `(97, true)`. `make bazel-sync` is a no-op -- every
edit landed in a file already enumerated in srcs.

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 18:30:25 -07:00
Harry Miller
d0743f89d7
fix(formula): substitute vars in step assignee, labels, and metadata (#5758)
* fix(formula): substitute vars in step assignee, labels, and metadata

Cook and pour substituted title/description/notes/gate but copied
assignee, labels, and metadata through raw, so a poured bead carried
literal `{{var}}` text in all three.

- labels: every label-based query, filter, and automation silently stops
  matching, and nothing errors (GH#5110).
- metadata: general keys came through literal; only a top-level "repo"
  key on a gh:* gate was substituted (GH#5110).
- assignee: worse than cosmetic - close refuses when the actor doesn't
  match the assignee, so every step of a poured molecule is unclosable
  and the molecule can never advance (GH#5754).

internal/formula/expand.go already substituted assignee and labels on
the inline-expansion path, so the two paths disagreed on the same
fields; Step.Assignee is documented as "supports substitution" and
ExtractVariables already scanned it, meaning pour hard-failed demanding
a variable it then refused to resolve.

Both call sites are fixed together: runtime-mode cook feeds the proto
that pour clones, so a field left literal in either path ships a
placeholder onto the bead. Fixing cloneSubgraphInto covers pour, wisp,
bond, and the proxied-server paths, which all funnel through it.

substituteMetadataRepo is generalized to substituteMetadataVars, which
resolves every string leaf of the metadata JSON at any depth. This drops
the earlier gh:*-gate-only restriction (SF2/SF4): reading a `repo` key
AS a GitHub selector is only correct on a gh:* gate, but resolving a
{{var}} in it interprets the key not at all. The walk still decodes into
json.RawMessage, so untouched values stay byte-identical, and object
keys are never rewritten (a rewritten key could collide with a sibling).

The variable scan is widened to match: extractAllVariables (pour) and
ExtractVariables (cook) now cover assignee, labels, metadata strings,
notes, and await ID, so pour demands exactly the variables it resolves.
Undeclared handlebars are still filtered out by VarDefs.

Regression coverage asserts on a poured bead, and checks the assignee
via validation.AssigneeMatches rather than a string compare - a
substitution-only assertion would pass while the unclosable symptom
persisted.

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

* chore(formula): regenerate schema_gen.go after the types.go doc edits

TestSchemaGenIsCurrent holds schema_gen.go to a byte-for-byte rerun of
the generator over types.go, and the field docs are part of the
generated output — so the Labels/Metadata comment updates made it stale.

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

* fix(mol bond): resolve vars like pour instead of demanding every handlebar

buildAttachCloneOpts demanded every variable extractAllVariables found in
the proto subgraph and applied no declared defaults, unlike pour
(cmd/bd/pour.go) and wisp (cmd/bd/wisp.go). Widening the scanned field set
to assignee, labels and metadata therefore widened bond's hard refusal
along with it: a proto whose label or metadata carried an undeclared
documentation handlebar, or a declared var carrying only a default, made
`bd mol bond` fail with "missing required variables" where it previously
succeeded.

Run applyVariableDefaults + extractRequiredVariables there, matching the
sibling call sites. extractRequiredVariables returns the unfiltered list
when VarDefs is nil, so a legacy template still requires every var it
mentions; the change is strictly a reduction in false failures. Applying
the defaults also puts them in opts.Vars, which is the map
cloneSubgraphInto actually substitutes from.

Also from review:

- docs/workflows/gates.md no longer enumerates a stale three-field list for
  where `{{var}}` substitution applies.
- maxMetadataSubstitutionDepth's doc names walkJSONStrings (not the
  long-gone substituteJSONVars) and says plainly that hitting the bound
  deliberately ships a literal placeholder rather than erroring.

Reported-by: bee-ghosttrack
Agent-Signature: claude-code-opus-5-unknown-reasoning on behalf of Harry Miller

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

* build(bazel): add the validation dep to the bd_test go_test (make bazel-sync)

mol_embedded_test.go and template_test.go now import internal/validation
directly (validation.AssigneeMatches, to check the substituted step
assignee), so gazelle emits //internal/validation on bd_test. bd_lib
already carries the dep, so bd_test compiles through embed, but gazelle
lists every direct test import on the go_test itself. cmd/bd/BUILD.bazel
landed on main after this PR branched, so the PR could not carry the
line; without it, bazel.yml's "BUILD files in sync" step fails in the
required Bazel / test lane. Generated by `make bazel-sync`.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.local>
2026-09-30 18:08:44 -07:00
Alex
916887c5a1
fix(dolt): apply the pool read/write deadline knobs on every open path (#6145)
* fix(dolt): apply the pool read/write deadline knobs on every open path (be-4at)

BEADS_DOLT_POOL_READ_TIMEOUT / dolt.pool-read-timeout (and the write
twins) shipped in #5089 as the relief valve for overloaded shared
servers, but their env/config ladder lived only in applyResolvedConfig,
which runs for callers of NewFromConfig*. The CLI's own store open and
bd serve's provider hand-build their Config (resolveDoltServerConnection,
whose comment says it bypasses applyResolvedConfig) and go straight to
New, so every bd command in server mode kept the built-in 10s deadline
whatever the knob said: on a 31k-issue hub that is what made every
bd close of a bead with dependents die in its recompute with
"i/o timeout" while the documented knob did nothing.

Move the ladder into ApplyPoolTimeouts and run it from
applyConfigDefaults, the constructor step every open path shares;
applyResolvedConfig calls the same helper, so the two ladders cannot
drift again. Idempotent: a caller-set deadline still wins.

Reproduced on stock main against a scratch server-mode store:
bd sql "SELECT SLEEP(15)" died at ~10s with the env set to 60s and with
dolt.pool-read-timeout=60s in config. The new test pins the ladder at the
seam New calls (applyConfigDefaults) and the DSN it produces; it fails on
main with PoolReadTimeout = 0s.

Fixes #6144

Agent-Signature: claude-code-claude-fable-5-max on behalf of a3ackerman
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YFPUYZEQjsBK2nBjsSQTij

* fix(dolt): narrow the pool-deadline claim to DoltStore opens, disclose the import precedence (be-4at)

Review round:
- CHANGELOG: the ladder covers every DoltStore open (the CLI's store, bd
  serve's store provider, library callers of New/NewFromConfig*); bd serve's
  HTTP data path builds its own DSN without pool deadlines and is unchanged.
  Operators of loaded servers are told the documented precedence now reaches
  bd import too, which used to inherit the 5m long-read fallback
  unconditionally because the CLI's knob value was always 0.
- applyPoolTimeouts is unexported (no out-of-package caller).
- The config.yaml rung falls back to config.GetStringFromDir(cfg.BeadsDir, …)
  for library consumers, like the auto-start ladder above it.
- The "unset knobs" subtest resets the config package state, not only env.
- The "every open path" wording in the code comments narrowed to match.

Agent-Signature: claude-code-claude-fable-5-1-max on behalf of A3Ackerman
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LrzRcJhWSUH6SnU64gtFE

* fix(dolt): retarget base's poolCfg comment, drop the false serve-provider claim, cover the config.yaml rung

Maintainer fixup for the #6145 adoption. Two parts.

Rebase compose (original): base's comment above poolCfg said it was "shared by
the pool knobs below", which the deadline compose falsified -- after this PR
poolCfg has exactly one call site (dolt.max-conns). Retargeted to match.

Review fixes (iteration 1, all three non-gating minors; the nit is declined
below):

- The PR claimed `bd serve`'s store provider as a beneficiary of the relocated
  ladder. It is not one: `grep -c -F 'dolt.New' cmd/bd/uow_factory.go` is 0, and
  the tree says so itself at uow_factory.go:365-367 ("the DoltStore serve never
  touches"). Dropped that clause from all three sites that carried it -- the
  CHANGELOG bullet (both of its clauses), applyPoolTimeouts's doc comment, and
  this test file's header. The surviving beneficiaries are verified rather than
  merely shortened: cmd/bd/store_factory.go:76 does reach dolt.New, as do the
  doctor paths, alongside library callers of New/NewFromConfig*. The separate
  "`bd serve`'s HTTP data path ... is unchanged" sentence is true and is kept.

- Added a fourth subtest covering the config.yaml rung on the constructor path.
  The three existing subtests only reach the env rung, so poolTimeoutFromConfig's
  directory fallback -- the rung a library consumer that never called
  config.Initialize depends on -- was pinned only for applyResolvedConfig
  (TestApplyResolvedConfig in open_test.go). The new subtest mirrors that one
  through applyConfigDefaults, which reads the directory off cfg.BeadsDir rather
  than a parameter, and asserts the no-global-viper premise first so it cannot
  pass vacuously. Proven load-bearing: disabling the GetStringFromDir rung fails
  exactly two subtests, base's and this new one.

- Listed pool_timeouts_test.go in internal/storage/dolt/BUILD.bazel's go_test
  srcs. At origin/main that list is an exact 223/223 match with the package's
  test files, so it is gazelle-maintained and the PR's new file was the only
  drift in the merged tree (223 srcs vs 224 on disk) -- which is what
  .github/workflows/bazel.yml's `make bazel-sync` + git-status check reds on.
  Added the single entry by hand rather than running a full sync, so no
  base-owned rows come along.

Declined, deliberately: the nit proposing a `beadsDir string` parameter for
poolTimeoutFromConfig. The claude lane names that exact shape as the refactor
that silently re-opens #6144 while every existing pin stays green, and the two
items are coupled through their remedies. The coverage subtest above is the
precondition for it, so the ordering is recorded for a future change rather than
taken here; it is optional and out of scope for a non-gating nit.

Validation on this head: go build ./... and go vet ./internal/storage/dolt/
clean, gofmt clean, and -run
'^(TestApplyConfigDefaultsAppliesPoolTimeoutLadder|TestApplyResolvedConfig)$'
gives 2 top-level PASS / 17 subtests / 0 FAIL.

* fix(dolt): drop the last false serve-provider claim in applyConfigDefaults

d0f0b013fe removed "bd serve's store provider" from the list of
DoltStore opens that reach New in four places, but a fifth copy in
store.go's applyConfigDefaults comment survived: there the phrase wraps
across two comment lines, so a single-line grep for it misses it.

bd serve's HTTP data path builds its own ExternalDoltConfig and never
calls dolt.New (cmd/bd/uow_factory.go), so it does not get the pool
deadlines. Keep only what is true: the CLI's store and library callers
of New/NewFromConfig* all reach New, which is the only non-test caller
of newServerMode (the sole DoltStore constructor). This matches the
CHANGELOG entry's wording. Comment-only; no behavior change.

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

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-30 18:06:57 -07:00
Ben Younes
e8839c4f0a
fix(import): normalize optional timestamps to UTC on insert (#5771)
* fix(import): normalize optional timestamps to UTC on insert

On JSONL import, an optional timestamp carrying a non-UTC offset (e.g. a
closed_at of `...-04:00` from an older SQLite-era export) kept its local
wall-clock digits: created_at/updated_at were normalized to UTC on insert
but closed_at and the other optional pointer timestamps were not, so the
stored instant shifted by the host's UTC offset while every other field
round-tripped cleanly.

Add Issue.NormalizeOptionalTimestampsToUTC and call it from both insert
paths (embedded PrepareIssueForInsert and proxied-server
normalizeIssueTimestamps) so started_at, closed_at, compacted_at, due_at,
defer_until, lease_expires_at and heartbeat_at are converted to true UTC,
exactly as created_at/updated_at already are.

Fixes #5765

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

* chore(bazel): enumerate the two new UTC-normalization test files in go_test srcs

gazelle-generated, one line per package, both packages owned by this PR.
Each file is untagged so its go_test target owes the enumeration; the
in-package census showed the gap was exactly these two with zero
pre-existing untagged gaps (59 vs 58, 61 vs 60).

* review: correct the domain/db mechanism claim and pin the full timestamp set

Applies the two optional in-PR minors from the bd-s0msb iteration-1 review
synthesis (both Gate impact: none; the synthesis and scorecard both decided
approve with zero blockers and zero majors).

- normalize_timestamps_utc_test.go header claimed this route covers "the
  proxied-server insert path share of #5765". It does not: domain/db runs on
  go-sql-driver, whose DSN Loc defaults to time.UTC and which converts bound
  time.Time values into that location on both the interpolate and prepared
  paths, and no production DSN sets loc=. The embedded route is the one that
  discards offsets, formatting in the value own zone via vitess
  BuildBindVariable. Reworded to state the call is defense-in-depth for parity
  with the embedded path. The test body is unchanged and still passes.

- NormalizeOptionalTimestampsToUTC hand-enumerates its 7 *time.Time fields to
  keep the insert path free of reflection, but the two new tests assert only 5
  of them, leaving LeaseExpiresAt and HeartbeatAt normalized yet unasserted, so
  an 8th field added later would be skipped silently. Adds a reflection-driven
  drift tripwire that walks Issue, sets every *time.Time to a fixed non-UTC
  zone, and fails on any field left off UTC. Dropping &i.HeartbeatAt from the
  helper reds it naming HeartbeatAt while both pre-existing tests stay green.

No production code changes. The tripwire went into the existing types_test.go,
so no new go_test src is owed in internal/types/BUILD.bazel.

---------

Co-authored-by: Ben Younes <2910651+ousamabenyounes@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-30 16:00:03 -07:00
Rongjun GENG
8da2ae4328
fix(embeddeddolt): commit pending changes before push (#5433) (#5795)
* fix(embeddeddolt): commit pending changes before push (#5433)

Every Pull variant (Pull, PullWithStrategy, PullRemoteWithStrategy,
PullRemote, PullFrom) auto-commits pending working-set changes first
(GH#2474, so a crashed command's leftovers don't make the merge
refuse to start), but no Push variant (Push, ForcePush, PushRemote,
PushTo) did. A write that landed in the working set but was never
explicitly committed -- auto-commit configured off, or a session that
ended right after a write with no intervening commit -- silently
pushed nothing new while `bd dolt push` still printed "Push
complete." and exited 0.

This is the half of #5433's silent-stall report the maintainer traced
and confirmed in code (issue comment, quoting exact line numbers this
matches on current main): "every Pull variant calls CommitPending
before pulling... no Push variant does... push never flushes the
working set, then prints 'Push complete.' on nil error with no
remote-ref or working-set check. Strongest hook for a narrow
push-honesty PR." Reporter confirmed: "Yes, please open the
push-honesty PR. That is the surface that actually cost us."

Scoped to exactly this half -- the confirmed, traced, mechanical gap
matching an already-established pattern (copy Pull's own guard to
Push). Did NOT attempt the harder half discussed in the same thread:
verifying the remote ref actually advanced and reporting honestly
when it didn't. That needs a deliberate design call the maintainer
themselves treated as separate (distinguishing a legitimate no-op
push, already in sync, from one that had something to send but
transferred nothing) and risks false positives if done carelessly --
a bigger change than this issue's narrowed scope asked for. Flagging
in the relay rather than guessing at that design.

Also confirmed the server-mode backend (internal/storage/dolt) has
the identical asymmetry -- Push/ForcePush/PushRemote all route through
pushToRemote, which likewise never calls CommitPending -- but the
issue's repro and the maintainer's trace are both embedded-mode
specific, so left server-mode untouched pending its own verification.

Does not claim to fix the mysterious full stall itself (bd dolt
commit also returning "Nothing to commit" while HEAD stays frozen,
even when called directly) -- the reporter and maintainer both
independently concluded that has no known deterministic trigger.
This closes one real, confirmed contributing gap: push not flushing
pending changes the way pull always has.

RED: added TestPushCommitsPendingChangesFirst, table-driven over all
four Push variants. Creates an issue (a genuinely pending, uncommitted
change -- verified via GetCurrentCommit before/after CreateIssue, so
the test would fail loudly if CreateIssue ever started auto-committing
on its own), then calls each Push variant and asserts HEAD moved.
Push/ForcePush/PushRemote route through the swappable vcPush/
vcForcePush vars (remote_peer_auth_test.go's existing
captureRemoteEntryPoints seam) so the test stops with errStopRemote
before any network IO; PushTo calls versioncontrolops.Push directly
with no equivalent seam, so it actually attempts the push and fails on
"remote not found" in this remote-less test store -- still proves
CommitPending ran first, since that failure only happens after this
fix's guard clause. All four failed pre-fix (HEAD did not move).
GREEN: all four pass after the fix.

Verified: full remote-verb/peer-auth suite (TestWithPeerAuth and its
variants, TestRemoteVerbsPresentStoredPeerCredentials,
TestRemoteVerbPlainRemote*) still green -- confirms this fix doesn't
disturb credential resolution or the swappable-seam test
infrastructure it shares. go vet clean, go build ./... clean across
the repo.

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

* chore(bazel): enumerate push_commit_pending_test.go in embeddeddolt go_test srcs

Generated by `bazel run //:gazelle`. The PR predates base's addition of
internal/storage/embeddeddolt/BUILD.bazel, so its new test file was not in
the explicit go_test srcs list; bazel would have silently run zero of its
cases. Base parity at the rebase base was 118/118 enumerated.

* fix(autopush): record post-push HEAD, and cover the clean-store push path

Maintainer review fixup for #5795 (adopt-pr review iteration 1).

Push now commits pending changes before pushing (GH#5433), so HEAD can move
across the call. maybeAutoPush read HEAD only before the push and recorded that
hash as LastCommit, which is now the parent of what was actually pushed, so the
next tick saw a mismatch and pushed once redundantly before re-latching. Route
the recorded hash through pushedCommitForState, which re-reads HEAD after a
successful push and falls back to the pre-push value if the re-read fails (the
push itself already succeeded, so dropping LastCommit would lose change
detection entirely).

Also:

- Add a clean-store arm to TestPushCommitsPendingChangesFirst. The guard relies
  on commitAll(tolerateEmpty=true) mapping Dolt's "nothing to commit" to
  (false, nil) for every push against an already-committed store, and nothing
  in this package asserted it. Flipping that flag reds the new arm alone, with
  the four pending-change arms still green.

- Correct the `bd dolt remote reset-data` confirmation, which promised the
  remote is "rebuilt from local HEAD" while the push now adds a commit created
  after the operator types y.

Not taken here, tracked separately: extending auto-push change detection to also
fire on a dirty working set (that gate predates this PR, so skipping it is an
incompleteness rather than a regression this PR introduces), and the PR-body
disclosure that push now commits on the auto-push and `bd sync` cadences.

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

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-30 15:58:51 -07:00
Jim Wordelman
9d646fc887
fix(dolt): server-mode bd ready never wakes expired defers (re-proposes #6082) (#6424)
* test(dolt): red — defer auto-wake must run for classified-read-only server-mode opens (be-vbhpf)

TestServerModeDeferAutoWake exercises the same defer/wake contract as the
embedded and proxied-server variants, against a real dolt sql-server. Today
the sweep (DoltStore.wakeExpiredDefers) unconditionally skips whenever the
store is opened read-only — including when that read-only-ness comes purely
from command classification (bd ready/bd list are read-only for the CURRENT
project), which is indistinguishable, before the fix, from a strict
--readonly or foreign-project open that must never sweep.

RED: expired_dated_defer_wakes_on_ready and expired_dated_defer_wakes_on_list_ready
fail (issue never returns to open). dateless_defer_never_wakes and
future_dated_defer_stays_hidden pass today too, trivially (no sweep runs at
all pre-fix) — kept as regression guards for the GREEN step, which is where a
unit test proving classifiedRead=false still does NOT sweep belongs, since
that distinction doesn't exist yet at RED.

* feat: green — defer auto-wake runs for classified-read-only server-mode opens (refs be-vbhpf)

bd ready/bd list on a dolt-sql-server-backed store open with the store
classified read-only for command purposes; the lazy defer-wake sweep
silently early-returned before ever running, so expired defers never
woke unless something else opened the store writable first.

Threads a new ClassifiedRead flag through dolt.Config -> DoltStore,
set at the call site to exactly "read-only because of command
classification, not strict --readonly/preview/foreign-project"
(policy.readOnly && !readonlyMode && !previewMode in main.go).
wakeExpiredDefers's guard now delegates to a small extracted
predicate, deferWakeSweepEligible(readOnly, classifiedRead), so the
truth table can be unit-tested without a live store.

* chore: release gate PASS for be-6iglh-gate

* docs(release-gates): record the be-5fjqh rebase onto current main

origin/main advanced 6 commits past this branch's base and PR #6082 went
CONFLICTING; hourly pr-audit filed be-5fjqh. The branch is now rebased onto
0efe0adf5.

The only conflict was cmd/bd/main.go: this branch and e05000d64 (wy-sbgucn)
each append a field to the same dolt.Config literal at the same anchor line.
Resolved keep-both -- PoolReadTimeoutFallback and ClassifiedRead drive
disjoint code paths.

The addendum records the new base and SHAs, patch-id equivalence for the five
files that did not conflict, what was re-verified at the new base (build plus
the diff-owned tests, container-backed), and what was NOT re-run (the
full-suite and ci-pr-policy lanes still refer to the old base).

Agent-Signature: claude-code-claude-opus-5[1m]-unknown-reasoning on behalf of Jim Wordelman

* docs(release-gates): record the be-qjern re-propose rebase and full re-gate

PR #6082 was closed and its branch deleted 2026-09-01 by an unknown actor
under the shared quad341 identity. Operator ruling 2026-09-08: accidental,
not a rejection — re-proposing. This addendum records a second self-rebase
onto current origin/main (zero conflicts this time), the full-suite and
ci-pr-policy re-gate the 09-01 addendum left outstanding (0 FAIL, policy
FAIL attributed to pre-existing be-mrl6j), and re-verification of both
diff-owned container-backed tests at the new HEAD.

refs be-qjern

* test(feat): red — add strict --readonly server-mode subtest to TestServerModeDeferAutoWake (refs be-acsyx)

* docs(release-gates): green — reword container-backed evidence claims, add nit-3 comment (refs be-acsyx)

bee-ghosttrack nit 2: TestDeferWakeSweepEligibleHonorsClassifiedRead is a
pure-function table test, not container-backed like TestServerModeDeferAutoWake
— reworded release-gates/be-6iglh-gate.md criteria 2(4) and 3 accordingly, and
attributed the preview/foreign-project claim to code structure at
cmd/bd/main.go:1485 rather than to that test. PR #6424 body reworded to match
(not part of this commit; edited via gh pr edit).

bee-ghosttrack nit 3 (optional): one-line comment on the unreachable
"classifiedRead without readOnly" table case explaining it documents totality,
not a reachable state.

Full suite: 0 FAIL. Targeted re-verification (TESTCONTAINERS_RYUK_DISABLED=true
to dodge host-load reaper flakiness): TestServerModeDeferAutoWake 5/5 subtests
PASS (12.427s), TestDeferWakeSweepEligibleHonorsClassifiedRead 4/4 subtests
PASS (5.957s).

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

  release-gates/be-6iglh-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

* ci(proxied-shard): discover TestServerMode* entry points

Review finding (major, Test Evidence Quality): TestServerModeDeferAutoWake —
this PR's only end-to-end guard for the classified-read defer-wake fix — was
selected by no CI lane. The two lanes that set BEADS_TEST_PROXIED_SERVER=1
both shard through proxied-test-shard.sh, whose discovery grep matched only
`^func TestProxiedServer`, so the wiring lines at cmd/bd/main.go:1675 and
internal/storage/dolt/store.go:2136 had zero CI-executed coverage: the one
CI-reachable new test pins the pure predicate and cannot catch a mis-wired
flag.

Widen discovery to `^func Test(ProxiedServer|ServerMode)` in the shard script
and in scripts/ci/gen_proxied_shard_manifest.py so the two discovery patterns
stay in step, and widen the shard script's manifest-name validation to match.
That last part is load-bearing, not cosmetic: without it a regenerated
manifest containing a TestServerMode* row is rejected outright ("Invalid
shard manifest line") and the whole lane exits 1.

This also rescues the two pre-existing TestServerModeServe* suites, which
share the identical requireSharedProxiedServer gate and the same shared dolt
sql-server harness and were equally invisible — the unclosed class this PR
was following.

Verified: discovery goes 151 -> 154; a 15-shard BEADS_TEST_SHARD_LIST_ONLY=1
dry run assigns each of the 154 to exactly one shard with no pre-existing
test moved (the three land on shards 4/13/15 via hash fallback); the
pre-change script selects none of the three.

Also clarifies the reviewers' nit: the "foreign-project" exclusion named in
the new comments is not tested at the guard or in the policy expression —
those opens build their own dolt.Config and leave ClassifiedRead false, so
the guarantee is fail-closed by default.

Iteration-2 review (two minors, both non-gating): the fixup's own new prose
asserted two universals that measurement falsifies — the same class as the
nit above, reintroduced in the CI files this fixup added.

  * proxied-test-shard.sh claimed "Both families gate on
    requireSharedProxiedServer", contradicted two lines earlier by its own
    mention of the TestProxiedServerPathHelpers unit test. Transitive gate
    census over the 154 discovered entry points: 143 reach
    requireSharedProxiedServer, 10 reach the different helper
    requireProxiedServerEnv, and TestProxiedServerPathHelpers
    (cmd/bd/proxied_server_test.go, bare `package main`, three assert.Equal
    calls on path helpers) has no gate and no build tag, so it also runs in
    every ordinary `go test ./cmd/bd/` lane. Now scoped to the
    TestServerMode* family, which does gate uniformly (3/3), and the
    TestProxiedServer* side is described as mixed rather than generalized
    over.

  * main.yml claimed TestServerMode* discovery means "neither family can be
    silently left out of CI". Discovery is a non-recursive cmd/bd/*_test.go
    glob: 154 top-level matches versus 156 recursive, the difference being
    cmd/bd/doctor/database_test.go:60 and cmd/bd/doctor/dolt_test.go:126.
    Now scoped to the top-level entry points, and the comment names the
    residual hazard (a container-gated suite added under cmd/bd/<subpkg>/ is
    still never selected here) instead of implying it cannot happen.

Both edits are comment-only and behaviorally inert: non-comment lines are
byte-identical in both files, and the 15-shard BEADS_TEST_SHARD_LIST_ONLY=1
sweep is byte-identical before and after (154 assignments, 0 duplicates,
assigned set == discovered set, the three TestServerMode* still at 4/13/15).

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

* ci(bazel): add defer_wake_server_test.go to cmd/bd go_test srcs

Maintainer CI repair, generated by `make bazel-sync` (gazelle).

`cmd/bd/BUILD.bazel`'s `go_test` srcs is an explicit list, not a glob, so the
new `cmd/bd/defer_wake_server_test.go` was never compiled or run by the Bazel
lane. `Bazel / test` failed two required steps on the pushed head
`0a3f5e0047`:

  Go test equivalence:
    go test:  105 packages, 8988 top-level tests
    bazel:    107 go_test targets, 106 tested; 8987 top-level tests seen
    tests go test runs that Bazel did not (1):
      cmd/bd  TestServerModeDeferAutoWake
    EQUIVALENCE: FAIL

  BUILD files in sync (gazelle, go_srcs, MODULE.bazel): out of sync

`BAZEL_TEST` is listed in `CI_GATE_REQUIRED` for `CI Gate / Required`
(.github/workflows/pr.yml), so this is a required-lane red, not advisory.

That the missing test is this PR's own headline guard makes the repair squarely
in scope: the PR exists to close exactly this "no CI lane runs it" gap, and its
review fixup closed it for the proxied shard lane. The Bazel lane had the same
gap for a different reason.

Attribution: main's Bazel run at this PR's exact base 43a526b828 concluded
success, so the red is this branch's, not inherited.

Validation:
- `make bazel-sync` produces exactly this one line; a second run is a no-op
  (gazelle idempotent, md5 7d1d0549fcd466159451c02181661c78).
- Byte-identical to CI's own `bazel-sync-patch` artifact for this head
  (blob pair efec974..6dd76e3).
- srcs-only change: gazelle added no deps entry, so every import the new file
  needs was already declared.
- `bazel build //cmd/bd:bd_test` succeeds, and the generated
  `bd_test_/testmain.go` now enumerates TestServerModeDeferAutoWake, which is
  the row the equivalence check reported missing.
- `tools/bazel/go_srcs.py --check` was already clean, and `bazel mod tidy`
  produced no MODULE.bazel drift, so this single line is the whole repair.

No contributor commit is modified and no Go source changes.

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-30 15:53:22 -07:00
Harry Miller
dfdedf5dfb
fix(status): disclose the counted rows bd list will not show (#5763)
* feat(stats): count the rows the default listing suppresses

bd status counts the issues table; bd list hides gates and templates on
account of what they are. The two therefore disagree, and nothing
reconciles them: a teardown driven by bd list leaves a gate behind and
status reports a total the operator cannot account for from any listing.

Break the suppressed rows out as their own counts. TotalIssues keeps
counting the database, which is what a command titled "Issue Database
Status" should report; these say how much of that total no default
listing will show. Every backend's statistics path funnels through
ScanIssueCountsInTx, so one query serves all of them.

Infra types need no counterpart here: they live on the wisp plane, which
this query does not read.

* fix(status): disclose the counted rows bd list will not show

bd status reported "Total Issues: 2" for a workspace whose every listing
showed one, because gates and templates are suppressed from a default
bd list. Nothing connected the two numbers, so the remainder read as a
phantom -- most visibly after a teardown driven by bd list, which leaves
its gates behind and then cannot see them.

Report the suppressed rows under the summary they qualify, naming the
flag that reveals each kind. The breakdown is printed rather than a
single hidden-total, since a template gate would otherwise be counted
twice. Nothing is printed when there is nothing suppressed.

Stacked on the statistics counts that make this reportable.

* docs(api): put gate_issues and template_issues on the Statistics schema

The Statistics schema is pinned to types.Statistics, so the two new
counts were on the wire the moment the struct grew them, and
TestWireTagBijection fails the openapi gate until the spec says so:

    Go fields with no spec property: [gate_issues template_issues]

Document both as a breakdown of total_issues rather than an addition to
it — they count rows the default `bd list` suppresses, which
total_issues already includes — and warn against summing them, since a
row can be both a gate and a template.

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

* fix(status): give --assigned the same disclosure, and test the behavior

Three points from review.

1. `bd status --assigned` never printed the line. AssigneeStats does not
   go through ScanIssueCountsInTx - it folds one actor's rows through
   workapi.FoldStatsAssigneeSummary, which left both new fields zero. That
   route's filter sets only Assignee, so IsTemplate stays nil and the
   actor's gates and protos really ARE in those rows while
   `bd list --assignee` suppresses both: the same reconciliation gap, one
   scope down. The fold now counts them, and its doc says they are set
   deliberately rather than borrowed from a workspace-wide answer.

2. The infra-type suppression is now explained rather than asserted away,
   and the answer is that a durable infra row is NOT unreachable, so the
   third breakdown is filed as GH#6439 rather than dismissed. Both the
   plane routing and the listing's exclusions read the workspace-configured
   types.infra set, and writing that key only invalidates a cache
   (dolt/config.go) - it never moves rows already written. So durable rows
   created while a type was not infra stay durable once it becomes one, and
   a type evicted from the set creates durable rows outright, which the
   create contract already pins ("evicted infra type",
   issue_operations_contract.go). Counting them needs that configured set,
   which ScanIssueCountsInTx - portable SQL with no config seam, called
   from six backend sites - cannot reach; guessing with the built-in names
   would be wrong in exactly the workspaces where it matters.
   suppressedTypeSummary's doc now carries that reasoning.

3. The behavior itself had no test - both existing cases exercised a pure
   string formatter, and would pass with the render call site deleted. Now:

   - TestRenderStatusEmitsTheSuppressedRowsLine captures renderStatus's
     stdout, asserts the line and both parts, and asserts it sits after the
     totals it reconciles rather than in the extended block. It fails with
     the call site removed ("renderStatus did not emit the disclosure
     line"), plus a companion asserting the line is absent when there is
     nothing to disclose.
   - Three conformance cases in stats_reporter_contract.go, wired into all
     three role wirings (dolt, embeddeddolt, uow), so the new SQL is
     checked cross-backend rather than at one call site:
     BreaksOutTheRowsTheDefaultListingSuppresses (with the negative rows a
     loose predicate would also move), BreaksOutAGateThatIsAlsoATemplate
     (the two suppressions are independent, so a proto's gate step counts
     in both), and AssigneeStatsBreaksOutTheSuppressedRows for the fold.
     statsReporterCounts and assertStatsReporterDelta carry the two fields.
     All three are behavioral reds against zeroed counts, not compile
     errors:

         GateIssues moved by 0 (0 -> 0), want 1
         TemplateIssues moved by 0 (0 -> 0), want 1
         GateIssues = 0, want 1 - the actor's gate is in this answer but
           not in `bd list --assignee`

4. Nit: pluralCount takes both spellings instead of appending "s", so a
   caller with an irregular plural is not silently mis-served.

Also adds the CHANGELOG entry the behavior change was missing, including
the GH#6439 gap.

Reported-by: bee-ghosttrack
Agent-Signature: claude-code-opus-5-unknown-reasoning on behalf of Harry Miller

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

* fix(conformance): declare the new stats cases in the order the table runs them

TestRoleContractCasesCoverEveryContractCase checks more than coverage: the
roleContractCases table has to list cases in the order their contract file
DECLARES them, because that is the order the unit-of-work leg's runners use
and the order its config-writing cases depend on.

I declared all three new cases together, then registered the assignee one
with the other assignee cases in the table, so the two orders disagreed:

    roleContractCases is out of declaration order at position 449: table
    has RunStatsReporterAStatusOutsideTheTalliesIsCountedOnlyInTotal,
    source has RunStatsReporterAssigneeStatsBreaksOutTheSuppressedRows

Fixed by moving the declaration rather than the table entry, since the
assignee case belongs beside the other assignee-scoped ones anyway - the
grouping the table already had was the correct one. Caught by CI because I
ran go vet over backend/conformance but not its tests; both now pass.

Agent-Signature: claude-code-opus-5-unknown-reasoning on behalf of Harry Miller

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

* docs(changelog): move this PR's entry under [Unreleased]

The 1.3.0 cut renamed the old [Unreleased] block, so the entry this branch
added there now merges cleanly into the released [1.3.0] section (#6643).

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>

* fix(status): complete the disclosure's remedy and pin its population

Maintainer review fixes for PR #5763 (adopt-pr iteration 1). Four of the
five review findings taken; the nit is declined with its measurement.

Finding 2 (minor, gate impact minor) - the printed remedy was incomplete.
The two counters come from the same scan as TotalIssues and are status-blind
with it, but the flags they named lift only the TYPE exclusion, so a CLOSED
gate was counted while `bd list --include-gates` still would not show it.
Gates are closed as the work they guard completes, so that is the ordinary
case rather than an edge.

Took the "complete the hint" arm over the "scope the counters" arm. Every
other field ScanIssueCountsInTx fills is workspace-wide; the disclosure
exists to account for TotalIssues, a database number printed three lines
above it; and scoping these two to the listing's population would leave them
explaining nothing about the total they are broken out of. `--all` "replaces
the status exclusions only" and lifts no type exclusion of its own
(backend/conformance/reader_contract.go:487), so the two flags together are
exactly the remedy. Recorded the population in the types.go field comment,
the status.go doc, and the CHANGELOG, which printed the old example verbatim.

Finding 3 (minor) - the three new conformance cases seeded only open rows,
so a backend counting over every status and one counting only the listing's
population returned identical numbers on all of them. Added a closed gate and
a closed proto to the first case. Proved it now decides the question: scoping
both SQL SUMs with `AND status <> 'closed'` reds exactly that case
("GateIssues moved by 1 (0 -> 1), want 2") while the all-open sibling
BreaksOutAGateThatIsAlsoATemplate stays green.

Finding 4 (minor) - the normative role doc in issueops/statsreporter.go
enumerated only the six prior counts. Added the two to that scan's bullet and
corrected two statements this PR had falsified: the headline "six counts of
one set", and the AssigneeStats bullet's "the fold ... tallies the five
statuses and nothing else", which stopped being true when the fold gained the
two increments.

Finding 1 (minor, gate impact minor) - ran `make bazel-sync`. It proposed
exactly one line, `+ "status_suppressed_test.go"` in cmd/bd/BUILD.bazel, and
nothing else, confirmed by porcelain rather than by bazel-sync-check.
Generator-owned, not hand-edited.

Finding 5 (nit) - declined. The three helpers already in package main
(pluralIssue, pluralize, plural) all DERIVE the "s" and cannot render a
caller-chosen pair; the tree's one two-form helper, pluralWord, is unexported
in internal/storage/issueops, and exporting it so a CLI string could reach it
would add exported surface to a storage role for a cosmetic. Recorded that
trade in pluralCount's doc comment instead.

Validation: `go build ./...` and `go vet` (6 pkgs) clean, gofmt clean,
`git diff --check` clean; cmd/bd 4/4 named PASS, internal/httpapi
TestWireTagBijection|TestSpec* PASS, internal/workapi PASS,
internal/storage/uow TestStatsReporterContract 18/18 subtests PASS. Both new
pins are mutation-proved: reverting `--all` reds all four table cases, both
flag subtests and the render-path pin, while the absence assertion stays
green.

Not done here: the PR body carries the same stale example line
("1 gate (--include-gates)"). Review iterations do not touch the PR surface,
so that correction is stamped for finalize.

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

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-30 15:44:40 -07:00
Julian Knutsen
a7fe6aea50
feat(httpapi): PATCH /v0/beads/issues/{id} accepts claim, the wire spelling of bd update --claim (#6890)
The update operation had no way to express a claim, so an HTTP client of
`bd serve` had to refuse `bd update <id> --claim` outright. The request now
carries a `claim` boolean that passes straight through to
issueops.UpdateRequest.Claim on the same lifecycle role the direct route
uses, so the claim and the patch land in one transaction with the direct
route's semantics: same-actor re-claim is idempotent (changed: false), a
foreign holder is 409 already_claimed and an unclaimable status 409
not_claimable, both naming `claim` and carrying {id}:claim's extension
members (shared through claimRefusal), and a refused claim writes none of
the patch.

With claim: true the patch may be empty (the claim is the whole write).
claim beside expected_assignee, expected_status or force_assignee_transfer
is refused at the edge as a 400 naming `claim` rather than surfacing the
role's ErrValidation as the generic patch 400. No capability token: per the
document's version-skew rules, member presence is probed, and an older
server refuses `claim` as unknown_parameter before any database work.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.local>
2026-09-30 15:42:37 -07:00
ecuthiell
ae4a04c12b
fix(config): name profile variables in path error (#5671) (#5676)
Identify HOME and USERPROFILE in unsafe user-home diagnostics without changing path resolution or filesystem behavior.

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell

Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com>
Co-authored-by: Bee <bee@ghosttrack.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 15:40:49 -07:00
Jim Wordelman
9fec68dcfc
fix(schema): retry a fresh-bootstrap heal reset that the server aborts (#5895)
MigrateUpWithLock consumes the one-shot FreshBootstrapHealCapability before
issuing CALL DOLT_RESET('--hard'), deliberately, so that no later pass can
re-arm a second destructive reset. The consequence is that whatever that one
reset returns is final for the database: if it fails, the interrupted bootstrap
refuses every later migration with DirtyTablesError and the only way back is a
human running 'bd dolt commit'. The outer retry cannot help — isRetryableError
excludes a 1105 that is not one of two named startup recoveries, and the
capability is spent either way.

That is only safe if a reset can fail for reasons that would persist. Dolt can
also abort the statement from inside the server. Its own debug log shows the
reset starting and failing under a millisecond later with a bare "context
canceled", on a healthy pinned session with no other session on the server, no
GC running, and the statements either side of it succeeding:

    m=2.6865 cid=35 Starting query        SELECT COUNT(*) FROM dolt_log WHERE commit_hash = '...'
    m=2.6871 cid=35 Query finished in 0 ms
    m=2.6873 cid=35 Starting query        CALL DOLT_RESET('--hard')
    m=2.6881 cid=35 error running query   ERR=context canceled  CALL DOLT_RESET('--hard')
    m=2.6883 cid=35 Starting query        SELECT RELEASE_LOCK('bd_schema_init:heal_exact_creator')
    m=2.6893 cid=35 Query finished in 1 ms

The caller's context has minutes left at that point and the next statement on
that same context and connection succeeds, so this is not our own cancellation
being reported back. It is what makes
TestFreshBootstrapHealIncarnation/exact_creator_heals_its_interrupted_bootstrap
fail on shard 12 of the Server Dolt Full Suite.

Retry the reset up to three times, 50ms apart, stopping early when ctx.Err() is
set — the caller's own cancellation is not transient and must not spend the
attempts that remain. This does not weaken the one-shot invariant:
DOLT_RESET('--hard') is idempotent and the retries stay inside a single
authorized heal, on the same locked session, for the same incarnation, against
one consumed capability. A reset that keeps failing still fails the migration
with both the original refusal and the reset error.

Refs: be-v3ms8

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-30 07:15:59 -07:00
Jim Wordelman
0950db0658
Fix ResolveServerMode ambient port-var handling and the KillStaleServers regression it introduced (#5934)
* test(doltserver): red — ResolveServerMode ignores BEADS_DOLT_SERVER_PORT/BEADS_DOLT_PORT (refs be-9i0yq.1)

* feat(doltserver): green — ResolveServerMode honors BEADS_DOLT_SERVER_PORT/BEADS_DOLT_PORT (refs be-9i0yq.1)

* test(doltserver): isolate BEADS_DOLT_SERVER_PORT/BEADS_DOLT_PORT in ambient-blind tests (refs be-lbnk8)

TestResolveServerMode_Default, _EmbeddedMode, and _EmbeddedHonoredWithoutServerEnv
cleared BEADS_DOLT_SHARED_SERVER/BEADS_DOLT_SERVER_MODE via t.Setenv but never
cleared BEADS_DOLT_SERVER_PORT/BEADS_DOLT_PORT, so they silently depended on
ambient absence of those two vars. That held in clean CI but not in this rig
(BEADS_DOLT_SERVER_PORT=28231 ambient), where round-1's new env-port-aware
step 2c in ResolveServerMode correctly fired and these three regressed.

servermode.go is unchanged: its precedence logic was already correct, and the
round-1 tests (EnvPortImpliesExternal, EnvPortOverridesStaleEmbedded) already
prove it. This is a test-hermeticity fix matching the isolation pattern those
two tests already follow.

* fix(doltserver): green — killStaleServersForDir ignores ambient BEADS_DOLT_SERVER_PORT (refs be-lbnk8)

killStaleServersForDir's orphan-cleanup guard (GH#2430) called the public
ResolveServerMode, which treats an ambient BEADS_DOLT_SERVER_PORT/
BEADS_DOLT_PORT (set fleet-wide on multi-agent rigs purely to route bd's
own client connections) the same as a genuine "not my server" declaration
(explicit shared-server/host/port config). That collapsed connection-
routing into lifecycle-ownership, so the guard silently skipped orphan
cleanup for directories beads still owns whenever the ambient var was set.

Split ResolveServerMode into a shared resolveServerMode(dir, honorPortEnv)
implementation:
- ResolveServerMode(dir) = resolveServerMode(dir, true) — unchanged
  behavior for all existing callers.
- resolveServerModeIgnoringPortEnv(dir) = resolveServerMode(dir, false) —
  skips only the ambient-port-var check, used solely by
  killStaleServersForDir's guard.

Audited the other three production ResolveServerMode call sites
(internal/storage/dolt/open.go:47+182, cmd/bd/bootstrap.go:914); all three
correctly want the ambient port var included (auto-start suppression and
clone-strategy selection both need to route to an already-running server),
so they are left calling the public ResolveServerMode unchanged. A fourth
call site (internal/storage/dolt/store.go:1602) already independently
short-circuits on the same env vars before it would ever reach
ResolveServerMode, so it was unaffected by construction. Audit findings
recorded in be-lbnk8's notes.

TestKillStaleServersPreservesOtherRepoServers (added in the prior round)
now passes; TestResolveServerMode_HostInferredExternal and
TestResolveServerMode_EnvHostBeatsEmbeddedMetadata remain the same two
pre-existing/unrelated failures confirmed at the parent commit (tracked
as be-wbyau).

* docs(release-gates): record be-lbnk8 gate PASS (ambient serverport scoping fix)

Deploy gate for be-mob5e (source review be-lbnk8, deploy commit
f5328d863153ecef94df9713ca2e3ed5e0ab0a95). 7/7 criteria PASS, with
two named non-blocking exceptions in the policy/lint lane (stale
.githooks/commit-msg marker check, and a stale golangci-lint
result-cache artifact referencing a deleted worktree) — both
environmental, independently verified, unrelated to the diff.

* fix(doltserver): exempt proxied-server from the port-env check, gate the carve-out

Check 2c classified any workspace with BEADS_DOLT_SERVER_PORT set as external
without either guard HostImpliesServerMode applies. The proxied-server
exemption is the one that bites: a proxied workspace reaches its server through
the proxy, so an ambient port does not describe its lifecycle, and our own
constellation runs dolt_mode: proxied-server with that variable set. 2c now
mirrors 2b's exemption.

The second HostImpliesServerMode guard -- any explicit non-empty DoltMode
suppresses inference -- is deliberately NOT mirrored, because
TestResolveServerMode_EnvPortOverridesStaleEmbedded pins the opposite for
dolt_mode=embedded on GH#2949 grounds. configfile.IsDoltServerMode has no port
check at all, so for that one combination the storage-mode and lifecycle
resolvers still disagree. That is a precedence question above this change, not
something to settle by picking whichever makes the tests green; the code says
so and it is tracked separately.

Adds TestKillStaleServersReapsOrphanUnderAmbientServerPort, the missing gate on
the resolveServerModeIgnoringPortEnv carve-out: it sets the port variable
itself rather than relying on the host exporting one, so it catches a
re-disabled GH#2430 anywhere. Red/green confirmed -- pointing the guard back at
the naive ResolveServerMode gives killed=[], want [222].

Two mode tests also stopped inheriting an ambient Dolt port.
TestResolveServerMode_EnvHostBeatsEmbeddedMetadata and
TestResolveServerMode_HostInferredExternal neutralize SHARED_SERVER,
SERVER_MODE and SERVER_HOST but never the port vars, so on a host that exports
one they asserted against it. The latter fails that way on origin/main too. The
whole internal/doltserver package now passes under this rig's real ambient
BEADS_DOLT_SERVER_PORT, which the previous body claimed and did not do.

Adds the CHANGELOG entry this user-visible auto-start change was missing.
(refs be-lbnk8)

* refactor(configfile): centralize the port-implies-server-mode rule

doltserver kept a private doltServerPortFromEnv plus an inline proxied-server
exemption -- a second copy of a rule that belongs beside HostImpliesServerMode.
Extract Config.PortImpliesServerMode with the same shape (proxied exemption,
then BEADS_DOLT_SERVER_PORT and the legacy BEADS_DOLT_PORT) and have
resolveServerMode's check 2c call it. No resolver changes behaviour.

Also corrects check 2c's doc comment, which was the actual defect the review
found rather than the code. It claimed the "explicit non-empty DoltMode
suppresses inference" guard was deliberately unmirrored and called that an
unresolved precedence question. HostImpliesServerMode does not work that way:
it reads BEADS_DOLT_SERVER_HOST at configfile.go:421-423 and can return there,
before the DoltMode suppression at :424-426 is ever reached. Real precedence is
env > explicit dolt_mode > persisted host, and 2c already mirrors every tier
with a port-side counterpart -- there is no persisted-port tier to guard,
because an explicit dolt_mode=embedded returns at check 3 before check 4 reads
metadata.json's dolt_server_port. Settled as be-yb2ai;
TestResolveServerMode_EnvPortOverridesStaleEmbedded keeps pinning it.

IsDoltServerMode deliberately does NOT consult the new predicate: it selects the
storage backend for every data command, a far wider blast radius than this
lifecycle-only change, and extending it needs its own call-site audit. The two
resolvers therefore still disagree for an unset/embedded dolt_mode plus a bare
port env var and no other server signal. That gap is documented at both sites
and owned by be-2nolj.

TestPortImpliesServerMode covers the new predicate directly: 14 cases over env
precedence, invalid/zero/negative ports, env-beats-explicit-dolt_mode, and the
proxied-server exemption including case-insensitivity. (refs be-lbnk8)

* docs(changelog): say the ambient port marks external, not "no longer suppresses auto-start"

The headline claimed an ambient BEADS_DOLT_SERVER_PORT "no longer suppresses
auto-start". This PR does the opposite: check 2c yields ServerModeExternal for
that var, resolveAutoStart (internal/storage/dolt/open.go:223) returns false on
External, and ensureServerRunning (internal/doltserver/doltserver.go:969-985)
refuses to start with "auto-start is suppressed because the server is
externally managed".

Only the reap clause was true. The headline now states both halves as they
behave, matching the entry's own body text.

Review round 3 blocking point 1 (bee-ghosttrack).

* docs(dolt): note that an ambient server port marks the workspace external

docs/architecture/dolt.md presented BEADS_DOLT_SERVER_PORT purely as the port
knob, in both the server-mode connection table and the environment-variable
table. Since check 2c it is also a lifecycle assertion: on a plain
non-shared, non-proxied workspace it resolves ServerModeExternal, so
auto-start is suppressed and PortSourceEnv -- documented at
internal/doltserver/doltserver.go:630 as an authoritative user assertion --
is unreachable for a bd-owned auto-start. A user setting it to pick a port
gets the "externally managed" refusal instead of a server.

Both sites now say so. proxied-server is called out as exempt; shared-server
already resolves external at check 2, before 2c is reached.

Review round 3 non-blocking point 2 (bee-ghosttrack).

* docs(servermode): cite GH#6181 for the IsDoltServerMode gap, not an invisible bead

Both cross-references for the deferred resolver-precedence gap pointed at
be-2nolj, an internal bead id maintainers cannot see -- the reason review
round 3 asked for a GitHub issue. bee-ghosttrack opened GH#6181
("doltserver: ResolveServerMode and configfile.IsDoltServerMode must share
one inference gate") from this review, which is exactly that tracker, so the
comments now name it.

Comment-only; no behavior change.

Review round 3 point 2 follow-up (bee-ghosttrack).

* feat: green — Fix: PR #5934's env-port check reclassifies bd's own server as shared, so it refuses to migrate (refs be-4yy5e)

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

  release-gates/be-lbnk8-serverport-ambient-scope-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

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 07:13:57 -07:00
ecuthiell
e766da5ed0
fix(worktree): preserve CRLF gitignore appends (#5677)
* fix(worktree): preserve CRLF gitignore appends (#5670)

Choose CRLF only when the user repository's existing .gitignore delimiters are consistently CRLF. Preserve existing bytes and retain LF as the default for every other convention.

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell
Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com>

* fix(worktree): complete trailing CR before a CRLF gitignore append

Append only LF when the last existing byte already supplies the CR in the
file's unambiguous CRLF convention. Preserve all existing bytes and cover the
exact output and repeated-add behavior.

Refs gastownhall/beads#5677
Agent: unknown-model/unknown-reasoning

* docs(worktree): clarify LF trailing CR completion (saa-cgh.83)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* refactor(worktree): reuse the shared gitignore line-ending detector (saa-cgh.83)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(gitignore): keep line ending coverage with its shared owner (saa-cgh.83)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* build(bazel): enumerate worktree_gitignore_eol_test.go in cmd/bd go_test srcs

cmd/bd/BUILD.bazel lists go_test srcs explicitly (647 entries), so the new
untagged test file added by this PR is not compiled into //cmd/bd:bd_test.
`make bazel-sync-check` cannot see this: it only runs tools/bazel/go_srcs.py,
which manages the go_srcs filegroup glob, not the go_library/go_test srcs
lists. The bazel.yml "BUILD files in sync" step runs `make bazel-sync` and
fails on any resulting porcelain drift, so gazelle adding this entry would
red that job; the lane is armed for this fork PR via
`github.event.pull_request.head.repo.fork == true`.

This line is gazelle's own output: re-running `make bazel-sync` after it
leaves the file unchanged. With it, both of the PR's new tests execute under
bazel (TestAddToGitignoreCompletesTrailingCR PASS in shard 3/16,
TestAddToGitignorePreservesCRLFWhenAppending PASS in shard 4/16;
//cmd/bd:bd_test 8 PASS / 0 FAIL / 0 SKIP) instead of being silently
excluded from every bazel target.

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

* test(worktree): cover the CRLF append arm that uses the detected line ending

Maintainer review fix for PR #5677, adoption iteration 1. The synthesis is
`approve` with no required changes; the one actionable finding is a minor, and it
is taken because the PR already owes a push (the rebase needed a repair and a
maintainer bazel commit is already on the branch).

addToGitignore's `separator := lineEnding` is guarded twice: the block is only
entered when the file does not end in "\n", and inside it a trailing "\r" is
completed with a bare "\n" instead. So the detected "\r\n" is used for exactly one
shape -- a CRLF file whose final byte is neither, i.e. an unterminated final line.
Neither existing fixture reaches it: "a/\r\nb/\r" ends in CR and takes the
completion branch, and "node_modules/\r\n" ends in LF so the block is never
entered. internal/gitignore's own table already covers this input for the
detector; the call site that consumes it did not.

The new case asserts the exact bytes for initial "node_modules/\r\nbuild/", and
appends twice so idempotence is covered as well as CRLF correctness.

Mutation-proved: replacing `separator := lineEnding` with a hardcoded "\n" --
which would write the mixed-terminator .gitignore this PR exists to prevent --
reds ONLY this new test; all three pre-existing tests stay green. That is the
surviving mutant the review reported, and it is now dead.

The remaining nit asked for no change ("None required": the inline duplication of
the append policy is byte-for-byte nil today, deliberate because the O_APPEND
stream cannot take a whole-buffer API, and locked by exact-byte tests), so none
was made.

Not included: `make bazel-sync` also wants an `upgrade_smoke_loop_test.go` row in
scripts/BUILD.bazel. That is base drift, not PR content -- the row is absent at
this branch's rebase base (147047e153) but origin/main already carries it, 33
commits ahead -- so it heals on the next base refresh, and adding it here would
duplicate main's own fix on a file this PR does not touch.

---------

Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-30 01:46:12 -07:00
Jim Wordelman
25a54a73ab
test: restore migration 0052 round-trip coverage (up/down/up, ~2K rows) (#5796)
* test(feat): red — Restore migration_0033_test.go round-trip test (up/down/up, 2K rows) (refs be-auu.5)

* feat: green — Restore migration_0033_test.go round-trip test (up/down/up, 2K rows) (refs be-auu.5)

No production code change: migration 0052 (D4v2 composite status/updated_at
index + defer_until index, renumbered from 0033) already shipped correctly
via 0268ba894 (PR #3662). This bead restores test coverage only; there is no
implementation gap for TestMigration0052_RoundTrip /
TestMigration0052_ExplainCapture to expose. Verification: go build ./... and
go vet ./internal/storage/dolt/... both clean; go test ./... exits 1
repo-wide via the pre-existing baseline documented in be-m0cy (91 distinct
failures across 9 unrelated packages) -- no new failures beyond that
baseline. The two new tests skip cleanly (no local Docker/Dolt server in
this sandbox), consistent with sibling be-auu.1/.2/.3 verification notes.

* chore(release-gate): PASS record for be-s424 (migration 0052 round-trip test)

All 7 criteria pass. Restores test coverage for migration 0052 (renumbered
from 0033), a composite-index migration already live in production via
PR #3662. Independently re-verified: 4/4 diff-owned tests PASS with real
podman/Dolt containers, build/vet/gofmt clean, single-file diff, clean
divergence from origin/main.

* fix(test): gate migration 0052 EXPLAIN capture on an env var, not short mode

scripts/check-testing-short.sh reserves testing.Short() for true
runtime/stress/large-fixture skips and fails the PR-policy lane on any
other use. TestMigration0052_ExplainCapture used it for a
diagnostic-artifact boundary, so "check testing.Short boundaries" failed
and took the CI Gate / Required aggregator down with it.

Switch to the environment-check idiom the policy message itself
recommends, matching the BEADS_RUN_DOLT_UPSTREAM_REPRO gate on the
sibling repro test in this package.

This also makes the test do what its doc comment already claimed --
"skipped unless explicitly opted in". The short-mode guard did the
opposite: it ran the test by default and skipped it only in the -short
lanes.

Verified locally:
- scripts/check-testing-short.sh passes (was the failing gate)
- gofmt, go vet, go build all clean
- default path skips in 0.00s, no container started
- opt-in path (BEADS_RUN_EXPLAIN_CAPTURE=1) passes against a real Dolt
  container and captures both plans, confirming IndexedTableAccess on
  [issues.status,issues.updated_at] and [issues.defer_until]
- TestMigration0052_RoundTrip still passes (16.15s)

Refs be-s424, be-wlv5.

* test(dolt): make the migration 0052 EXPLAIN capture a real regression gate

The PR body advertised "EXPLAIN-verified query-plan assertions", but
TestMigration0052_ExplainCapture only t.Logf'd the plan and could not
fail. Since the right index names demonstrably do appear, asserting on
them costs nothing and converts a one-shot diagnostic into a standing
planner-regression gate: if a schema change or Dolt upgrade silently
stops using idx_issues_status_updated_at — an index whose entire
justification is that these two queries use it — this now fails instead
of printing a plan nobody reads.

Each case gains a wantIndex substring, checked against the accumulated
plan text. Matching the column list rather than the index identifier is
deliberate: EXPLAIN FORMAT=TREE names columns, not the index name, so
that is the strongest claim the output actually supports.

Verified against a real Dolt container (dolthub/dolt-sql-server:2.2.0),
BEADS_RUN_EXPLAIN_CAPTURE=1, both subtests pass:

  IndexedTableAccess(issues)
    index: [issues.status,issues.updated_at]
    filters: [{[in_progress, in_progress], (NULL, 2020-01-01 ...)}, ...]

  IndexedTableAccess(issues)
    index: [issues.defer_until]
    filters: [{(2026-09-03 07:36:36 +0000 UTC, ∞)}]

and confirmed non-vacuous: substituting a bogus wantIndex fails the
corresponding subtest.

The plan is still logged unconditionally — it is the be-eei §8 guardrail 4
artifact, and on failure it reports what the planner actually chose rather
than only that it was not what we wanted. The test remains opt-in, so the
gate only bites when someone runs it; that is the same bargain the fixture
cost already forced, and an assertion is strictly better than the t.Logf
it replaces.

Addresses review of PR #5796 by bee-ghosttrack.

* test(dolt): make the 0052 helpers' comments match what they do

Four review nits, all cases of a comment promising more than the code
delivered. Three are fixed by correcting the code, one by correcting the
comment.

sortedKeys did not sort. Go randomizes map iteration, so the index names
in a failure message reordered between runs and two reports of the same
failure could not be compared. Now sorts.

verifySampleIssues said it checked title, status and type; it read the ID
and a title prefix. It now checks status and issue type too, recomputing
the expected values from the ordinal encoded in the id rather than from a
"before" snapshot — so the assertion cannot be satisfied by a value the
round-trip corrupted symmetrically. Confirmed non-vacuous: permuting the
expected status cycle fails with

    sample verify date-idx-000000: status mutated to "open", want "closed"

sampleIssueIDs claimed an evenly-spaced sample but takes the first N by
id. Here the comment was the wrong half — determinism is what the
round-trip check needs, and ORDER BY id ASC LIMIT N already provides it,
so a spread would add cost for no coverage. Comment corrected to say what
it does, and why that is sufficient.

The RoundTrip header now records that its up→down→up DDL is only safe
because setupTestStore puts each test on its own Dolt branch
(testutil.StartTestBranch, dolt_test.go:173). Dropping
idx_issues_status_updated_at mid-run on the shared testSharedDB would be
a package-wide hazard rather than a local one, so the note names it as
load-bearing and warns against adding t.Parallel() or removing the branch.

Addresses the nits from review of PR #5796 by bee-ghosttrack.

* test(dolt): anchor the 0052 EXPLAIN assertions to the index node, not the predicate

Review round 2, blocking: the second assertion was vacuous. wantIndex
"issues.defer_until" matched the plan's Filter node, which echoes the query's
own predicate, so it passed on a full table scan — the exact regression this
gate exists to catch.

Mutation-tested against a real dolthub/dolt-sql-server:2.2.0 container by
dropping idx_issues_defer_until after the fixture seed:

  index dropped + old bare "issues.defer_until"      -> PASS  (vacuous)
  index dropped + new "index: [issues.defer_until]"  -> FAIL  (gate bites)
  index present + new "index: [issues.defer_until]"  -> PASS

The degraded plan is:

  └─ Filter
      ├─ ((NOT(issues.defer_until IS NULL)) AND (issues.defer_until > ...))
      └─ Table
          ├─ name: issues

Table, not IndexedTableAccess — and the Filter line still contains the bare
substring, which is why the old form could never fail. Both cases now match
the "index: [...]" wrapper, which appears only on an IndexedTableAccess node.
Case 1 was already anchored (its column list is comma-joined and does not
appear in its Filter), but it takes the same form for consistency.

The field comment now records why the wrapper is load-bearing, so the "match
the column list, not the index name" rationale is not read as license to drop
it again.

Also from the same review:
- The header told readers not to add t.Parallel() while setupTestStore calls
  it itself (dolt_test.go:140) — every run prints "=== PAUSE". Replaced with
  what is actually load-bearing: the per-test Dolt branch.
- Citation dolt_test.go:173 -> :174 (the StartTestBranch line).
- sampleIssueIDs scopes its query with WHERE id LIKE 'date-idx-%', so the
  caller's strconv.Atoi cannot hard-fail on a foreign id sorting ahead of the
  fixture.

Verified with a real container, ambient BEADS_DOLT_SERVER_PORT unset:
BEADS_RUN_EXPLAIN_CAPTURE=1 -> ExplainCapture PASS (7.82s, both subtests),
RoundTrip PASS (16.23s); default path -> ExplainCapture SKIP, RoundTrip PASS.

Refs be-n2y2o.

* docs(release-gates): correct the be-s424 gate accounting and record round 2

Review round 2, nit: the gate record still claimed "352 lines / 1 file" and
4/4 PASS. It is 439 lines across 2 files at the current head, and 3 PASS /
1 SKIP on the default path now that ExplainCapture is env-gated.

The per-criterion numbers were accurate for the commit the gate evaluated
(961aa8cdd), so they are scoped to it rather than rewritten, matching how the
same correction was made on PR #6221. The 4/4 count is labelled as the
BEADS_RUN_EXPLAIN_CAPTURE=1 count.

Adds a round-2 addendum with the mutation-test table proving the old
assertion vacuous and the new one load-bearing, plus the current accounting.

Refs be-n2y2o.

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

  release-gates/be-s424-migration-0052-roundtrip-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

* chore(bazel): add migration_0052_test.go to internal/storage/dolt go_test srcs

The PR adds an untagged internal/storage/dolt/migration_0052_test.go. That
package's BUILD.bazel is base-added since this branch's merge base and its
go_test srcs is an explicit 207-entry list, not a glob, so the new file was
silently omitted: //internal/storage/dolt:dolt_test would never compile the
PR's 439-line regression test.

Neither check tool can see this -- tools/bazel/go_srcs.py --check and
make bazel-sync-check both exit 0 on the unrepaired head, because they only
validate the go_srcs filegroup glob, never go_library/go_test srcs.

Base parity decides it is PR-introduced: at the upstream base the same census
shows a gap of exactly 15 files and all 15 carry //go:build integration
(0 untagged), so the enumeration is exhaustive for untagged tests. Repair is
make bazel-sync, which inserted the one srcs line alphabetically. No deps line
is owed: //internal/storage and //internal/types are already in go_test deps.

* test(dolt): assert the 0052 index composition and give the plan probes rows

Maintainer review fixes for PR #5796, adoption iteration 1. The synthesis is
`approve` with no required changes; all four findings are minor or nit, and the
Pre-Merge Checklist orders them by value if the file is being touched anyway.
It is, so all four are taken. No production code; the payload stays one test
file.

F1 — index assertions were name-only. The entire D4v2 justification for
idx_issues_status_updated_at is column ORDER (status as the equality prefix,
updated_at as the range suffix), but SHOW INDEX was reduced to a name set, so a
migration that created the composite as (updated_at, status), or restored the
legacy idx_issues_status on another column, produced an identical name set and
satisfied every assertion while leaving the index useless for the two queries it
exists for. indexNames becomes indexColumns and returns name -> columns in
key-part order; Seq_in_index and Column_name were already being scanned and
discarded one line before use, so this costs no extra query. The round-trip now
pins (status, updated_at), (defer_until), and the post-down legacy (status).
Renaming the helper rather than keeping a name that no longer describes it is
the one deviation from the prescription.

F2 — both EXPLAIN probes matched zero rows. seedDateIndexFixture deliberately
leaves date columns NULL, so defer_until IS NOT NULL was false everywhere and no
row was older than the stale cutoff: the plans were asserted over an empty match
set, which is the same output an empty table gives, so the 1K seed bought no
signal. shapeDatePredicateMinority backdates updated_at and sets defer_until on
10% of the fixture, and each probe now asserts a non-zero match count next to its
plan so a PASS cannot mean "matched nothing". A minority and not the whole
fixture, because a predicate matching every row is not a range scan the planner
has reason to serve from an index. updated_at is assigned in the same statement
as defer_until: the column is ON UPDATE CURRENT_TIMESTAMP, so an UPDATE that did
not name it would bump the rows back to now and re-empty the match set.

Measured: 67 of 1000 rows for the stale probe, 100 of 1000 for the deferred
probe, and the planner still picks both indexes under the row-bearing fixture.
That last point settles the open uncertainty the review disclosed rather than
asserted -- whether a non-empty match set would make Dolt switch away from the
index. It does not.

F3 — a comment claimed the ORDER BY needed "no sort step". The test's own
captured plan contains TopN(Limit: [50]; issues.updated_at ASC). Dolt runs
status IN (...) as two index range scans and merges them, so the composite buys
access, not global ordering. Reworded to say that; no assertion changes, since
the assertion (index use) was always true.

F4 — cited line numbers had drifted across the 278-commit base advance:
StartTestBranch is at :180 not :174, t.Parallel() at :146 not :140, testTimeout
is 45s not the "30s" quoted. The getChildrenOfDeferredParentsInTx citation named
internal/storage/dolt/ready_work.go, a file that does not exist -- it is
internal/storage/issueops/ready_work.go. Every citation is now a symbol plus a
package path, which is what stops this drifting again; none is a line number.

Each fix carries its own evidence. The column-order assertion was checked by
flipping the expectation to (updated_at, status): it fails with "column 1 is
\"status\"; want \"updated_at\"", which is the regression the name-only form
passed. Both tests run live against Dolt 2.2.0 -- RoundTrip 27.0s,
ExplainCapture 14.4s with BEADS_RUN_EXPLAIN_CAPTURE=1, all PASS.

---------

Co-authored-by: Gas City Adopt-PR <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-29 17:27:18 -07:00
Jim Wordelman
a1ac9f4dcb
fix(testutil): wait for database visibility in SetupSharedTestDB (#5788)
* test(storage): be-s9d setup-shared-db visibility tests for dolt.New / initSharedSchema

Adds five tests pinning the behavioral contract that
testutil.SetupSharedTestDB must result in a database that is fully
visible to fresh MySQL sessions on the same Dolt server. The bug
under be-s9d (originally observed in the BEADS_TEST_EXTERNAL_DOLT_PORT
TestMain branch added in cfd38cda) is that CREATE DATABASE in
SetupSharedTestDB is left in the working set without an explicit
DOLT_COMMIT, so fresh connections that open their own session do not
see the new database. The reviewer's diagnosis (be-nx7 reconciliation
notes) calls out adding CALL DOLT_COMMIT after CREATE DATABASE, or
retry-with-USE in the external-port branch, as the fix surface.

State today (validator's failing tests, written before the fix):

  PASS  TestSetupSharedTestDB_FreshRawConnSeesDatabase
        SHOW DATABASES on a fresh raw mysql conn does list the new db
        (regression-guard for the existing-good behavior).
  FAIL  TestSetupSharedTestDB_NewStoreOpens
        dolt.New() fails with "database not found" against a freshly
        SetupSharedTestDB-created db, even though the prior test shows
        SHOW DATABASES does see it. This is the literal failure mode
        — the difference is dolt.New's initDB connection shape (empty
        ServerUser, internal-built DSN) hits a stricter visibility
        boundary than my User=root probe. Captures the bug.
  PASS  TestSetupSharedTestDB_FreshConnAfterSecondSetupCall
        Idempotent CREATE-IF-NOT-EXISTS path stays visible across two
        setup calls. Regression-guard for any DOLT_COMMIT side effect
        the fix introduces.
  PASS  TestSetupSharedTestDB_RefusesProductionPort
        FIREWALL guard against port 3307 (DefaultSQLPort) intact.
        Defensive contract — must not regress through the be-s9d fix.
  FAIL  TestInitSharedSchema_AfterFreshDatabase
        After initSharedSchema completes (all migrations apply,
        DOLT_ADD + DOLT_COMMIT runs), a fresh connection's SHOW
        TABLES returns zero rows. Schema commits on the
        initSharedSchema session do not surface to other sessions —
        the deeper invariant the fix must restore.

Both failing tests pass on the testcontainer path that masks the bug
in CreateIfMissing=true mode, which is why TestMain external-port is
the only place the suite-wide runtime hits it; my tests pin the
contract at the dolt.New / SHOW TABLES level so the fix is verifiable
without a second host-resident dolt sql-server. The benchstat-geomean
write-bench measurement that be-s9d also requests is a downstream
measurement task, not a test, and is not in this commit.

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

* fix(testutil): wait for database visibility in SetupSharedTestDB (be-s9d)

The BEADS_TEST_EXTERNAL_DOLT_PORT branch added in cfd38cda was supposed to
let CI/dev runs target a host-resident dolt sql-server, but the polecat
tests added in 295b4552 surfaced a startup race: SetupSharedTestDB returns
right after CREATE DATABASE, and a sibling pool opened by dolt.New() inside
initSharedSchema can outrace the Dolt server's catalog refresh and fail
with "Error 1049 (HY000): database not found: <name>" — Dolt's own wording
from go-mysql-server, distinct from MySQL's "Unknown database" handled in
isRetryableError since GH-1851.

Three load-bearing changes:

1. testutil.SetupSharedTestDB now polls USE <dbName> on the same handle
   with bounded exponential backoff (50ms → 1s, 10s deadline) before
   returning. The catalog race is what 295b4552's
   TestSetupSharedTestDB_NewStoreOpens / TestInitSharedSchema_AfterFreshDatabase
   were pinning; both flip from RED → GREEN with this poll.

2. dolt.isRetryableError now also retries "database not found", same
   reason as the existing "unknown database" branch (GH-1851). Defensive
   backstop in case any code path opens a fresh pool against the new
   database without first going through SetupSharedTestDB's poll.

3. testmain_test.go now sets BOTH BEADS_DOLT_SERVER_PORT and
   BEADS_DOLT_PORT (and unsets both at end). applyConfigDefaults reads
   BEADS_DOLT_SERVER_PORT first and only falls through to the legacy
   BEADS_DOLT_PORT, so a pre-existing BEADS_DOLT_SERVER_PORT in the
   surrounding agent shell (gc-beads-bd exports the rig's gc.endpoint
   port) silently won over the testmain-set BEADS_DOLT_PORT and routed
   the bench to the wrong server. Both branches (external-port +
   testcontainer) pin both vars.

Tests exercising these paths (added in 295b4552):
  PASS  TestSetupSharedTestDB_FreshRawConnSeesDatabase
  PASS  TestSetupSharedTestDB_NewStoreOpens         (was FAIL at baseline)
  PASS  TestSetupSharedTestDB_FreshConnAfterSecondSetupCall
  PASS  TestSetupSharedTestDB_RefusesProductionPort
  PASS  TestInitSharedSchema_AfterFreshDatabase     (was FAIL at baseline)

Run with TESTCONTAINERS_RYUK_DISABLED=true BEADS_TEST_EXTERNAL_DOLT_PORT=33400.

Unblocks the 10K write-bench measurement called for in be-eei §8 guardrail 5
(CreateIssue/UpdateIssue regression vs pre-D4v2). Bench results to follow
in a separate be-s9d note.

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

* chore: release gate PASS for shared-test-DB-visibility-waits theme (be-pow0)

* fix(testutil): narrow to test-only per review — drop retry-classifier change, reword visibility-wait comments

bee-ghosttrack's review (2026-09-03) on #5788 flagged that the
isRetryableError "database not found" case was a real production
behaviour change riding along in a PR described as test infrastructure:
it turns a genuinely-missing-database failure from immediate into a full
~30s backoff (serverRetryMaxElapsed) across six withRetryClassified call
sites. Dropping it entirely — SetupSharedTestDB's own visibility poll in
testdoltbranch.go already resolves the catalog race the classifier case
was meant to backstop, so it was never load-bearing for this fix.

Also rewords waitForDatabaseVisible's doc comment to describe what USE on
a pooled connection actually proves — that one connection observed the
catalog refresh, not a pool-wide guarantee, and that USE mutates that
connection's session default database as a side effect — and notes as a
comment (not a behaviour change) that the backoff cap can let delay reach
~1.6s before capping, which is harmless inside the 10s bound.

testmain_test.go's teardown also unset BEADS_DOLT_SERVER_PORT, the other
half of the same port-pin hunk the rebase already dropped in favour of
main's ambient-port FATAL guard (#5837); that half merged cleanly instead
of conflicting, so it survived silently until now. Removed — main never
sets that var, so unsetting it was dead code.

TestSetupSharedTestDB_NewStoreOpens and the rest of the visibility suite
still pass without the classifier change (podman testcontainer run: 5
PASS / 0 FAIL / 0 SKIP).

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

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

  release-gates/be-pow0-shared-test-db-visibility-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(testutil): poll SHOW DATABASES exact-match for visibility, not USE (be-2wf6u)

waitForDatabaseVisible was polling USE <dbName>, which Dolt can satisfy by
auto-attaching a database to the session before the server's catalog (what
SHOW DATABASES and dolt.New() actually check) has registered it — a no-op
wait in exactly the racy just-created case it exists to guard against
(bee-ghosttrack PR #5788 R2 item 1).

Switch to the same SHOW DATABASES exact-match iteration
databaseExistsOnServer (internal/storage/dolt/store.go) already uses, via a
small local helper (databaseVisibleNow) rather than a cross-package import,
to avoid coupling internal/testutil to internal/storage/dolt for one
10-line check. Preserves the existing backoff/deadline/ctx-cancellation
shape and the "not visible after" bounded error.

Update the call-site and function-doc comments to stop claiming the wait
proves visibility "to a fresh connection" — success only guarantees the
polling connection's own view is current, not a guarantee for every
connection in db's pool. R1 already corrected the function doc to this
wording; the call site had drifted from it (R2 item 2... no, R1 nit,
flagged again in R2 follow-up).

TestWaitForDatabaseVisible_ReturnsBoundedErrorWhenNeverCreated pins the
bounded-failure contract as a falsifiability/regression guard, not an
old-vs-new discriminator: a name that is never created is a permanent
absence the old USE-based poll's retry branch already handled correctly by
coincidence. R2 itself found the real race too flaky to assert on directly
("a mutation probe... did not discriminate either, because the
fresh-connection test is flaky against its own 45s deadline"), so this test
is exactly what R2 prescribed instead. Its doc comment is corrected to say
so accurately.

Verified against a real Dolt container (TESTCONTAINERS_RYUK_DISABLED=true —
without it, Ryuk's reaper handshake times out on this host and produces a
container-setup failure that looks like a test failure but isn't):
internal/testutil full package green (25.9s), internal/storage/dolt's 5/5
visibility suite green (17.1s).

refs be-2wf6u

* chore(bazel): sync gazelle srcs/deps for PR #5788 test files

Maintainer fixup during adoption. `make bazel-sync` output only:
- internal/storage/dolt: enumerate the PR's new untagged setup_shared_db_test.go
  in go_test srcs (without it Bazel silently runs 0 of the PR's 5 new tests).
- internal/testutil: gazelle-canonical deps for the two non-stdlib imports the
  PR adds to the already-enumerated testdoltbranch_test.go.

Base parity at 4e4ebdb44 is 0 untagged gaps / 100 of 100 packages, so the
omission is PR-introduced. Idempotent on re-run.

* fix(testutil): review fixes for PR #5788 — firewall pin + doc accuracy

Maintainer fixup applying the iteration-1 review synthesis (4 of its 5
findings; all minor/nit, no blockers or majors).

- setup_shared_db_test.go: narrow TestSetupSharedTestDB_RefusesProductionPort
  to the one token only the firewall emits ("production") and add a "dial tcp"
  negative control. The old containsAny(err, "refused", "production", "3307")
  was vacuous: the test carries no skipIfNoServer guard, so it also runs where
  nothing listens on 3307, and there a deleted firewall falls through to
  CREATE DATABASE and fails with "dial tcp 127.0.0.1:3307: connect: connection
  refused" — a string matching both "refused" and "3307". Measured: the old
  assertion is true for the firewall message AND that dial error; the new one
  is true only for the firewall message. Same single-specific-needle pattern
  as the sibling TestSetupSharedTestDB_RefusesAmbientPortMismatch.
- setup_shared_db_test.go: mark the be-nx7 DOLT_COMMIT diagnosis in the file
  header as superseded by the catalog-refresh-race diagnosis — the wait
  succeeds before any DOLT_COMMIT runs (initSharedSchema commits only after
  SetupSharedTestDB returns), so a redundant post-CREATE DOLT_COMMIT is not
  the completion of this fix.
- testdoltbranch.go: state the real bound. The deadline is checked before the
  sleep, so the final capped delay lands past it — probes at
  0/50/150/350/750/1550/3150/4750/6350/7950/9550/11150ms, i.e. ~11.2s
  worst-case return over 12 probes, not the "~10s" the doc claimed. The cap
  comment no longer asserts the total stays inside 10s.
- store.go: comment-only back-reference marking databaseExistsOnServer and
  internal/testutil.databaseVisibleNow as a coupled mirror, so a future edit
  to the consumer's predicate cannot silently diverge the fixture's probe.
  The synthesis prescribed this arm over hoisting into doltutil precisely to
  keep the PR's upstream-requested test-only narrowing (eea022b6e) intact; it
  adds no production behavior.

Synthesis finding 3 (deleting the visibility wait is invisible to the
deterministic suite) carries "Required fix: None" — disclosed in-code and not
fixable without an injectable probe; left as recorded residual.

Validation: gofmt clean; go build + go vet on both packages; focused tests
green with the ambient BEADS_DOLT_* env scrubbed — internal/storage/dolt
5 PASS / 0 FAIL / 0 SKIP, internal/testutil 2 PASS / 0 FAIL / 0 SKIP.
make bazel-sync is a no-op (the added import is stdlib).

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-29 17:22:06 -07:00
Cherub Kumar
ab88b20517
fix(utils): refuse a bare jq/JS sentinel (null, undefined, empty) as an issue ID (#6215)
* fix(utils): refuse a bare jq/JS sentinel as an issue ID

`jq -r` prints the literal string "null" when a selector misses, and JS
tooling prints "undefined". Both are a valid partial-ID shape, so
ResolvePartialID accepted them and resolved them through its leading-prefix
abbreviation branch: any issue whose hash began with the token became the
target, and the write reported success naming an issue the caller never
mentioned.

Reproduced on stock beads at a07794015, embedded Dolt, scratch workspace,
no orchestrator:

    bd init --prefix bd
    bd create --id bd-null3t0 "decoy: must not be touched"
    bd update null --status closed
    ✓ Updated issue: bd-null3t0 — decoy: must not be touched   (exit 0)

HasPrefix), so this needs a hash that begins with the token — the same case

The guard sits in ResolvePartialID rather than in a command because
internal/utils/id_parser.go is the only ID-resolution entry point in the
repository: 52 non-test call sites across 29 files, plus 2 through the
ResolvePartialIDs wrapper, and the four cmd/bd/*_proxied_server.go twins
resolve through the same function. One guard covers the direct, embedded and
proxied-server paths uniformly.

The riskiest thing this does is add a refusal to the resolver every command
shares. An ID that merely contains a token (bd-null, null3t0,
undefined-behavior) is unaffected, abbreviation matching is otherwise
unchanged, and the empty string already failed — it now says why.

Case folding is deliberate: NULL is what SQL-shaped tooling prints.
Whitespace is trimmed for the comparison only, never for resolution.

The tests use a nil store so the ordering is observable: reaching the
"storage is nil" error proves the guard did not fire. Mutation-tested — with
the guard reverted all eight refused inputs fail and the seven accepted
inputs still pass.

Fixes #6214
Refs #5393

Agent-Signature: claude-code-opus-5-unknown-reasoning on behalf of Cherub Kumar
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SDrKFyrfKTKM5J9yFbW7uA

* fix(utils): refuse none/nil too, and list the new test in the Bazel srcs

Maintainer review fixes for #6215, review iteration 1. Both lanes and the
scorecard returned approve with no required changes; this commit takes the two
actionable minors, both of which land inside the PR's own change.

Taken:

- Behavioral Correctness (minor). `bd update None --status closed` still reached
  the leading-prefix abbreviation branch: strings.ToLower("None") is "none" and
  every character passes looksLikePartialIDHash, so it could silently write to
  whichever issue's hash begins "none" and exit 0. `nil` is the same class. That
  is the identical silent-wrong-write harm this PR exists to prevent, and the
  remedy lands in the switch the PR just added, so "none" and "nil" join the
  same case arm and the refused-inputs table.

  The error text is generalized with them: "none" is Python and "nil" is
  Go/Ruby, so the previous jq/JS-only wording would have mis-described the two
  new tokens.

- Change Impact / Blast Radius (minor). The PR adds two TestX functions that
  `go list` selects for internal/utils but that Bazel's utils_test target could
  not compile or run -- exactly what tools/bazel/equivalence.py reports as
  `missing`. Gazelle's verdict, not a hand-guess: `make bazel-sync` produced
  exactly `+ "id_parser_sentinel_test.go",` for internal/utils/BUILD.bazel. It
  also rewrote 13 other BUILD.bazel files (pre-existing base drift), which is out
  of scope here, so that output was reverted and only this PR's row re-applied at
  gazelle's chosen slot. utils_test is 10 entries, sorted, no duplicates, all on
  disk.

  Note the review predicted the regen would also add `+ "//internal/debug",` to
  this file's go_library deps "once rebased on main". It did not at this base,
  because the import that needs it is not present here -- that dep is
  base-owned drift and is already tracked separately.

Over-refusal is guarded, not assumed: the pre-existing accepted-inputs test
(nullos, null3t0) and the whole ResolvePartialID suite -- cross-prefix,
allowed-prefixes, wisp, title-false-positive -- all still pass.

Validation: gofmt clean, go build ./... and CGO_ENABLED=1 go vet ./internal/utils/
clean; 42 PASS / 0 FAIL / 0 SKIP over -run "Sentinel|ResolvePartialID". The new
rows are mutation-proved: dropping "none" from the case arm reds
TestResolvePartialIDRefusesSentinelTokens, and restoring returns rc=0.

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

---------

Co-authored-by: Cherub Kumar <5449665+ckumar1@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-29 17:15:45 -07:00
Harry Miller
fe5b9d1e0f
fix(formula): reject a waits_for gate with no spawner, and stop reporting invalid formulas as not found (#5761)
* fix(formula): reject a waits_for gate that has no spawner to wait for

waits_for = "all-children" (or "any-children") names no spawner, so
collectDependencies infers one from needs[0] and emits no dependency at
all when the step has no needs. Validation accepted that step, cooking
gave it a gate:all-children label, and the result was a step with zero
dependencies that is ready immediately — a fan-in that silently never
fans in. Only the label survived to suggest otherwise.

Reject it where the intent is still visible, naming both repairs: add
needs, or name the spawner with children-of(step-id), which carries its
own spawner and stays valid without needs. depends_on is deliberately not
accepted as a substitute, because the inference does not read it.

The fan-in example in docs/workflows/gates.md taught exactly the broken
shape — a summarize step with waits_for and no needs — so it is corrected
here alongside, with the spawner step it was missing.

* fix(formula): make a validation failure distinguishable from "not a formula"

Callers that resolve a name as a formula and fall back to a proto/issue
lookup have no way to tell the two apart, so a formula that exists and
does not validate is reported as not found and its real error is thrown
away. The spawnerless waits_for gate rejected above lands in exactly that
path.

ErrVarValidation already exists for the same reason, covering bad --var
values. Give Validate the matching sentinel; the message it produces is
unchanged. Wiring the fallbacks to it is a separate change.

* fix(mol): report an invalid formula instead of calling it not found

pour, wisp, bond and seed resolve a name as a formula first and fall back
to a proto/issue lookup. Any error from the formula path was treated as
"this is not a formula", so a formula that exists and fails validation
came back as "'<name>' not found as formula or proto ID" — with bd
formula list happily showing it. The real error was never printed, and
the advice to run bd formula list confirmed the wrong diagnosis.

Each fallback now reports a validation failure directly, the way it
already does for the bad --var values ErrVarValidation covers. A name
that really is not a formula is unaffected.

* fix(mol bond): make --dry-run validate the formula the real bond validates

resolveOrDescribe resolved a formula name with parser.LoadByName, which
never calls Formula.Validate - LoadByName -> loadFormula -> ParseFile does
not, and only parser.Resolve does. The real bond path
(resolveAndCookFormulaWithVars) calls Resolve, so the dry-run previewed
"will cook as proto" for every formula the real bond rejects, including
for the waits_for-without-a-spawner rule this branch adds. The function's
own comment already promised the opposite.

resolveOrDescribe now resolves before it validates provided vars, which
also means the --var check runs against the merged formula rather than the
unmerged one, so a var declared only in a parent is checked too. The two
error wrappings match the real path's, so the routes produce the same
message rather than merely the same exit code.

TestBdMolBondDryRun_RejectsInvalidFormulaLikeTheRealBond runs both routes
against the same invalid formula and asserts they agree - both fail, both
name waits_for, neither reports it as "not found as issue or formula". It
reproduces the gap against the old code:

    dry-run previewed a bond the real bond rejects:
      A: dryrun-invalid-gate (formula -> will cook as proto)

Also from review:

- validation_sentinel_test.go uses strings.HasPrefix instead of a slice
  that would panic with index-out-of-range rather than failing cleanly if
  the message ever shortened.
- Step.WaitsFor's field doc now states the needs requirement, and
  schema_gen.go is regenerated from it, so the generated schema documents
  the rule the validator enforces. docs/workflows/gates.md already said it.

The condition-filtering follow-up is filed as GH#6437: Validate runs
inside parser.Resolve, before FilterStepsByCondition, so a spawner dropped
by a false condition still reaches collectDependencies as a dangling
reference and is skipped silently - the same zero-dependency gate, past
the new check.

Reported-by: bee-ghosttrack
Agent-Signature: claude-code-opus-5-unknown-reasoning on behalf of Harry Miller

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

* test(mol bond): assert the dry-run gap in process, not through a subprocess

The regression test spawned an embedded bd and ran two CLI invocations,
which is the most expensive shape of test in cmd/bd - and cmd/bd already
runs 477s of its 600s budget on the macos runner, so the addition timed
the package out.

The process boundary was never what the test was about. resolveOrDescribe
and resolveOrCookToSubgraph are both reachable directly with a molReader
that answers "no such issue", and GT_ROOT puts a temp formula dir on
formula.DefaultSearchPaths without touching HOME or the working directory.
Same assertion - the two routes agree, both name waits_for, neither
reports an invalid formula as not found - in 0.03s instead of 18s.

Asserting the routes against each other rather than against a literal
message is deliberate: it is what stops a validation rule added later from
re-opening the same gap. The LoadByName control is now explicit too, since
that call still accepting the formula is the reason the bug existed; if it
ever starts validating, the comparison stops distinguishing anything and
the test says so instead of passing quietly.

Second case added while here: the dry-run validated --var values against
the UNMERGED formula, so a constraint declared only in a parent went
unchecked. Resolving first fixes that as well, and an extends chain with
the enum in the parent pins it:

    dry-run accepted a var value the real bond rejects; the enum is
    declared only in the parent (real bond said: formula "dryrun-child":
    variable validation failed:
      - variable "env": value "staging" not in allowed values [dev prod])

Agent-Signature: claude-code-opus-5-unknown-reasoning on behalf of Harry Miller

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

* docs(changelog): move this PR's entry under [Unreleased]

The 1.3.0 cut renamed the old [Unreleased] block, so the entry this branch
added there now merges cleanly into the released [1.3.0] section (#6643).

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>

* chore(bazel): enumerate the PR's two new test files in go_test srcs

Base added cmd/bd/BUILD.bazel and internal/formula/BUILD.bazel after this
branch's merge base, so the two untagged _test.go files this PR adds were
absent from their go_test srcs lists. Generated by 'make bazel-sync'
(bazel run //:gazelle); no hand edits. A second sync is a no-op.

* docs(formula): correct the waits_for spawner doc and the dry-run parity claim

Maintainer review fixup for the adoption of #5761 (review iteration 1
pre-merge checklist). Wording only -- no control flow changes.

internal/formula/types.go: the new Step.WaitsFor doc said "Requires needs
(or depends_on)", but Formula.Validate receives only step.Needs and cook
infers the spawner solely from Needs[0] (cmd/bd/cook.go:961-962) -- the
DependsOn loop never feeds waitsForSpawnerStepID, and the struct doc's
"merged during cooking" happens after Validate. A depends_on-only bare gate
is therefore correctly rejected: the code and the error message are right,
only the comment was wrong, and it shipped into the generated schema surface
agents read. docs/workflows/gates.md already states it correctly.
Regenerated schema_gen.go with `go generate ./internal/formula/`.

CHANGELOG.md: "so it fails on exactly what the real bond fails on" was an
overclaim. The dry-run now resolves and validates the way the real bond
does, but five later real-path failure surfaces (inline expansions,
expansions, aspect load/type, condition filtering) stay outside the preview.
Named that boundary rather than claiming total parity.

Contributor commits untouched.

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-29 17:09:59 -07:00
Marco Del Pin
63d8cc2522
cmd/bd: bd label rename <old> <new> (stacked on #6007) (#6009)
* storage: add RenameLabel primitive with merge semantics

Add a storage primitive that renames a label across every issue and
wisp that carries it, in one transaction per store. An issue that
already carries the new label is a merge - the stale old-label row is
dropped rather than raising a duplicate-key error - and the call
reports renamed/merged counts plus every touched id.

- internal/storage/issueops/labels.go: RenameLabelInTx sweeps the
  labels and wisp_labels tables (INSERT IGNORE then DELETE, so the
  merge never errors), emitting one EventLabelRenamed plus the usual
  full-snapshot journal row per touched issue/wisp, matching
  AddLabelInTx/RemoveLabelInTx's journal shape. A single batch event
  was considered and rejected: the journal-completeness guard requires
  every touched row to carry its own journal entry.
- internal/storage/storage.go: RenameLabel added to the Storage
  interface, next to AddLabel/RemoveLabel/GetIssuesByLabel.
- internal/storage/dolt, internal/storage/embeddeddolt: direct
  implementations. The dolt commit targets the fixed events/labels
  table pair; doltAddAndCommit's own HasStagedChanges guard skips it
  when the rename touched wisps only (wisp tables are dolt-ignored,
  same as AddLabel/RemoveLabel).
- internal/storage/hook_decorator.go: HookFiringStore.RenameLabel
  fires on_update per touched issue, matching AddLabel/RemoveLabel.
- internal/types/types.go: new EventLabelRenamed event type. Unlike
  EventLabelAdded/EventLabelRemoved, one rename produces exactly one
  of these per touched row, never a paired add+remove.
- internal/jira/tracker_test.go: mock stub for the new interface
  method.

Tests: internal/storage/dolt/label_rename_test.go, against a real
dolt-sql-server container - basic rename, merge, wisp sweep,
zero-carrier no-op, over-length refusal, event assertion. All green.
Also verified TestEveryBeadMutatorJournalsOrIsExempt still passes.

Gates: gofmt clean, go vet ./... clean, CGO_ENABLED=0 go test -tags
gms_pure_go -c -o /dev/null ./cmd/bd clean, go build ./... clean.

* storage: refuse RenameLabel(x, x) instead of wiping the label

RenameLabelInTx's merge branch treats every carrier of oldLabel as
already carrying newLabel when the two names collide (they are the
same string): the batched INSERT IGNORE no-ops on every row, and the
unconditional DELETE FROM <table> WHERE label = ? that follows then
removes every row for that label plane. A self-rename silently wiped
the label instead of leaving it untouched.

Reject oldLabel == newLabel (compared after trimming, case-sensitive)
before any write, returning the new ErrRenameLabelSameName. Verified
red->green: TestRenameLabel_SameNameRefused and
TestRenameLabel_SameNameAfterTrimRefused both fail (GetLabels returns
[] on both the labels and wisp_labels planes) against the pre-fix
code, and pass against the fix. Full TestRenameLabel* suite in
internal/storage/dolt still green.

* telemetry: instrument InstrumentedStorage.RenameLabel

AddLabel and RemoveLabel already get OTel spans/metrics through
InstrumentedStorage; RenameLabel had no override and so fell through
to the embedded storage.DoltStorage passthrough, invisible to
storage.* tracing. Add the override, mirroring the AddLabel/RemoveLabel
shape: span attributes for the old/new label pair (bd.label.old,
bd.label.new, matching the existing bd.dep.from/bd.dep.to pairing
convention), and on success a bd.result.count / bd.merged.count pair
following the SearchIssues-style "set result attributes after a
successful call" pattern already used elsewhere in this file.

* storage: document the O(N) round-trip cost of RenameLabelInTx's event loop

renameLabelInPlane's per-issue loop (InsertDerivedEvent + RecordEventInTx)
is O(len(oldIDs)) SQL round trips inside one transaction, up to four per
touched issue. On a huge label population that lengthens the transaction
and raises the odds an optimistic-concurrency retry has to redo the whole
rename from scratch.

No batching added: InsertDerivedEvent's dedup SELECT is a real
cross-replica convergence check (Protocol v0.1 C2.3), not a redundant one
this transaction could skip, and no batch primitive for this shape exists
anywhere in this package - building one here would be new shared
infrastructure grown for a single caller. AddLabelInTx/RemoveLabelInTx
already pay the identical per-call cost for their one issue; this loop is
that cost repeated once per touched issue. Documented inline as a
disclosed limitation rather than silently left unremarked.

* bda-lbjv: derive rename merge count from rows-affected, not a prior read

renameLabelInPlane computed merged from a snapshot SELECT of newLabel's
carriers taken before the INSERT IGNORE - a check-then-insert whose
result is used. A concurrent AddLabel(issue, newLabel) committing between
snapshot and insert made the reported count schedule-dependent while the
stored data stayed correct (cross-model finding: the Opus panel cleared
A1, codex flipped it to NOT-SAFE on exactly this line).

Now the count is a measurement: INSERT IGNORE reports one affected row
per id actually inserted, so merged = len(oldIDs) - inserted, and the
newLabel pre-read is gone entirely.

Tests: sqlmock scripts the racing schedule (insert sees a row the
snapshot read could not); mutation control confirms the old
implementation fails the new test. Full issueops package + live-store
TestRenameLabel_* green.

* bda-c77s: first-party coverage for EmbeddedDoltStore.RenameLabel

The embedded impl had zero tests while DoltStore.RenameLabel carries a
dedicated suite; AddLabel/RemoveLabel both have parallel embedded
coverage by convention. Four wiring cases (basic, merge, zero-carrier
no-op, same-name refusal) - the deep semantics stay pinned by the shared
issueops suite and the dolt-side tests against the same implementation.

BEADS_TEST_EMBEDDED_DOLT=1: 5 RUN, all green, 2.8s.

* storage: scope the rename delete to the ids the sweep captured

An unrestricted DELETE ... WHERE label = ? makes the sweep's blast radius
engine-dependent: under current-read DELETE semantics a row a concurrent
AddLabel(oldLabel) committed after this transaction's snapshot would be
removed without ever being renamed, counted or journaled. Restricting the
delete to the captured ids touches exactly the rows the INSERT IGNORE above
accounted for on every engine; a concurrent add outside the snapshot now
deterministically SURVIVES the rename - the same observable state as that
add landing after the rename committed, which is the only order-independent
reading of the race.

sqlmock WithArgs pins the id-scoped statement shape; the embedded-Dolt
lifecycle set stays green (5/5).

* cmd/bd: add `bd label rename <old> <new>` with dry-run preview

Wire the storage.RenameLabel primitive (previous commit) into a CLI
command that renames a label everywhere it appears in one call instead
of a per-issue add-then-remove loop.

- cmd/bd/label.go: `bd label rename <old> <new> [--dry-run]`.
  validateLabelRename refuses empty/identical labels and the
  'provides:' reserved prefix before any store call - it is a pure
  function so those rules are testable without a store. --dry-run
  previews the blast radius (count plus the first issues) read-only,
  via a path kept separate from the write path so it can never reach a
  transaction.
- cmd/bd/label_proxied_server.go: the proxied-server route composes
  the existing per-issue LabelUseCase.AddLabel/RemoveLabel (and wisp
  twins) in one uow.RunTx, the same fan-out shape label propagate
  already uses on this route. It journals as an add/remove pair per
  issue rather than the direct route's single EventLabelRenamed,
  because LabelUseCase has no rename-shaped event; the rename
  semantics (merge-on-collision, honest zero-carrier no-op, dry-run
  preview) are identical on both routes.
- docs/core-concepts/labels.md: documents rename, dry-run, and merge
  semantics under Label Management.

Tests: cmd/bd/label_rename_test.go (pure argument-validation table
test, no store needed) plus new subtests in
cmd/bd/label_embedded_test.go covering the full CLI path - basic
rename, merge, dry-run writes nothing, zero-carrier no-op,
identical/empty/reserved-prefix refusals. All green.

Gates: gofmt clean, go vet ./... clean, CGO_ENABLED=0 go test -tags
gms_pure_go -c -o /dev/null ./cmd/bd clean, go build ./... clean.

* cmd/bd,domain: emit label_renamed on the proxied route, not add+remove

runLabelRenameProxiedServer used to fan a rename out into a per-issue
AddLabel-then-RemoveLabel pair, journaling label_added/label_removed
instead of one EventLabelRenamed - a divergence from the direct
DoltStore/EmbeddedDoltStore route the upstream reviewer has already
rejected for another PR touching the same class of proxied/direct
split.

Add domain.LabelUseCase.RenameLabel and domain.LabelSQLRepository.
RenameLabel. The repository method delegates straight to
issueops.RenameLabelInTx (r.runner satisfies issueops.DBTX
structurally), so the proxied route is not merely the same SQL SHAPE
as the direct one, it is the same function: identical merge semantics,
the same ErrRenameLabelSameName refusal, and one EventLabelRenamed per
touched issue. runLabelRenameProxiedServer now just calls
uw.LabelUseCase().RenameLabel(...) inside its existing uow.RunTx.

Declare recordingLabelUC.RenameLabel so the notifying unit of work
records one update per touched issue/wisp (mirroring
HookFiringStore.RenameLabel on the direct route) instead of silently
recording nothing through the embedded interface - caught by the
existing structural parity guard, TestRecordingLabelUseCaseCoversItsSurface,
which fails on any domain.LabelUseCase method neither declared on
recordingLabelUC nor exempted with a reason.

Tests, verified red->green:
  - internal/storage/domain/db: TestLabelUseCase/RenameLabel adds 5
    subtests. EmitsOneRenamedEventPerIssue is the direct regression
    test - reverting RenameLabel to a simulated add-then-remove
    fan-out reproduces exactly the pre-fix event counts (renamed=0,
    added=2, removed=1) it now asserts against (renamed=1, added=1,
    removed=0).
  - cmd/bd/label_proxied_integration_test.go: new "rename" subtest
    exercises `bd label rename` end to end through the real proxied
    server and asserts the same label_renamed/added/removed counts
    directly against the events table.
  - internal/storage/uow: TestRecordingLabelUseCaseCoversItsSurface
    goes red (RenameLabel inherited, records nothing) without the
    recordingLabelUC override and green with it.

Full internal/storage/uow suite (287s) and the new domain/db and
cmd/bd tests all pass.

* cmd/bd: record commandDidWrite before the rename error return

runLabelRename read renamed>0 into commandDidWrite only after the
`if err != nil` early return, so a rename whose SQL side committed but
whose store call also returned an error - the Dolt publication step
failing after the working-set write landed - never marked the command
as having written. The caller's deferred auto-commit would then skip
creating a Dolt commit for a write that, on disk, actually happened.

Move the commandDidWrite.Store(true) check ahead of the error check,
matching applyLabelEdit's existing per-issue marking a few lines above
in the same file.

New test: TestRunLabelRename_CommandDidWriteSetBeforeErrorReturn wraps
a real *dolt.DoltStore in a spy whose RenameLabel reports a publish
failure (renamed>0, err!=nil) after delegating to the real rename, and
asserts commandDidWrite is set despite the returned error. Verified
red->green: reverting the ordering reproduces the exact failure this
guards against.

* bda-bnid: nolint:forbidigo on proxied bulk rename call

The route delegates to domain.LabelUseCase.RenameLabel deliberately: one
EventLabelRenamed per issue with identical merge semantics to the direct
route. Patch.Labels (the lint's suggested remedy) would reintroduce the
per-issue add/remove event divergence this delegation replaced. Matches
the file's own convention (4 sibling nolints, same shape).

Negative control: without the nolint golangci-lint forbidigo reports
exactly this line; with it, 0 issues.

* cmd/bd: address review on label rename (CHANGELOG entry, dry-run caveat, partial-failure count)

Two blocking items from review (bee-ghosttrack, PR #6009):

- Add the CHANGELOG entry for `bd label rename`, in the house voice used
  by the neighboring bd-label entries (bold lead sentence, PR link, dense
  explanatory prose on the merge/dry-run/partial-failure contract).
- The `--dry-run` merged count is a plain snapshot intersection of two
  independent reads - exactly the check-then-count shape
  renameLabelInPlane's own comment documents rejecting for the write
  path, because it is schedule-dependent under a concurrent
  AddLabel/RemoveLabel. That is an acceptable estimate for a preview, but
  nothing said so: the command's Long text, the --dry-run flag help, and
  an inline comment at the computation site now all say the number is
  not authoritative.

One non-blocking nit fixed (the other - hydrating full issue rows in the
direct dry-run just to print 10 titles - is left alone; see below):

- On a partial rename failure (renamed>0, err!=nil - e.g. a Dolt
  publication failure after the SQL side already committed) the command
  now reports how many issues were renamed and merged before the
  failure, instead of only the error. Mirrors the existing shape in
  conflicts.go's ResolveConflictRows handling ("resolved %d of %d
  conflict(s) before failing").

Left alone, and why: the GetIssuesByIDs-hydration nit. GetIssuesByLabel
hydrates every matching issue via GetIssuesByIDs on both the old-label
and new-label reads, which is wasteful on a label carrying 10k issues
when the text-mode preview only prints 10. But the JSON-mode contract
already returns every matching issue's id+title (not capped at the
preview limit), so avoiding hydration only helps the text-mode path and
would branch the two output modes apart for a marginal win on an
uncommon case (a rename dry-run over a 10k-issue label). Not clean
enough to do inline without its own test coverage and a decision about
whether the JSON contract should change too - flagged in the review as
skippable, so skipping it here.

Verification:
- go build ./... - clean
- go vet ./cmd/bd/... - clean
- gofmt -l cmd/bd/label.go - clean
- go test ./cmd/bd/... -run 'Label|LabelRename' - all pass
- BEADS_TEST_EMBEDDED_DOLT=1 go test ./cmd/bd/... -run 'TestEmbeddedLabel$' -v
  - all pass, including label_rename_basic/merge/dry_run_writes_nothing
- BEADS_TEST_PROXIED_SERVER=1 BEADS_TEST_EMBEDDED_DOLT=1 go test ./cmd/bd/...
  -run TestProxiedServerLabel -v - all pass, including the "rename" subtest
- BEADS_TEST_EMBEDDED_DOLT=1 go test ./internal/storage/issueops/... -run Rename -v
- BEADS_TEST_EMBEDDED_DOLT=1 go test ./internal/storage/dolt/... -run Rename -v (live dolt-sql-server)
- BEADS_TEST_EMBEDDED_DOLT=1 go test ./internal/storage/embeddeddolt/... -run Rename -v

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

* cmd/bd: report an upper bound on a failed rename, not a landed count

The partial-failure message asserted that renamed>0 means the SQL side committed. On both routes the counts are assigned inside the transaction closure (label_proxied_server.go RunTx, dolt/labels.go withRetryTx), so a Commit failure or retry exhaustion returns them holding the rolled-back attempt numbers - nothing landed, and the user read 'renamed 6 issue(s) before failing'. Retry exhaustion under a busy server is the likely failure for a bulk rename, so it misreported exactly when it fired. Now reports an upper bound. commandDidWrite keeps the same premise deliberately: it is fail-safe in the other direction.

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

* cmd/bd: pin the partial-failure wording, and hedge the merged count too

Round-3 review: the r2 correction rode unpinned. Nothing in the suite drives
a failing rename with renamed > 0, so the whole TestEmbeddedLabel suite passed
with the hunk reverted - the fix was unfalsifiable, which is the same defect
class the correction itself was about.

Extracts the sentence into labelRenamePartialFailureMessage, a pure function a
test can assert on without inducing a mid-transaction failure, and pins it:
the hedged phrasings must be present AND the two pre-correction phrasings must
be absent. Mutation-checked - restoring the old wording turns it red on three
assertions.

Also the round-3 nit: (%d merged) was the one unhedged clause in a hedged
sentence. It now reads (of which up to %d merged), so no number in the message
asserts a write that may never have landed.

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

* docs: retire the landed-count premise from the CHANGELOG too

Round-4 review, MAJOR: the code retracted a premise and the CHANGELOG kept
publishing it. The entry still said a partway failure 'reports how many issues
were renamed and merged before the failure' - a landed count - while
labelRenamePartialFailureMessage had already become an upper bound.

The sentence carried the premise TWICE and the review named one: besides the
count, its parenthetical offered 'a Dolt publication failure after the SQL side
already committed' as the case, when the whole point of the correction is that
renamed > 0 cannot distinguish that from a rollback. Rewrote both halves: the
bound is explicit, and the two failure shapes are named as indistinguishable
from the count alone.

Also round-4 MINOR: the helper had been inserted between reportLabelRename's
doc comment and its func, so the comment headed the wrong function and
reportLabelRename was left undocumented. Moved back down.

Not done, deliberately: the round-4 NIT that the pin covers the helper and not
the call site. It is marked 'noting, not asking', and an unrequested fix is the
one that ships a defect - this PR already demonstrated that.

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

* CHANGELOG: move this PR's entry under [Unreleased]

The 1.3.0 cut renamed the old [Unreleased] block, so these lines
merged cleanly into a released section (gastownhall/beads#6643).
Moved 31 line(s); the code is unchanged.

* cmd/bd: register label rename in the proxied capability registry

TestProxyCapabilityRegistryCoversCommandTree requires every command path to
carry a proxied-server row. label rename has a proxied route (RunE hands the
rename to runLabelRenameProxiedServer and the --dry-run preview to a proxied
read UOW), so it joins its label siblings in proxyPermittedPaths.

* storage: mint a version for every bead a label rename touches

TestEveryBeadMutatorMintsOrIsExempt (added with #6650) fails on this PR:
RenameLabelInTx writes the labels table but never reached
RecordVersionInTx. A rename changes the label set - part of the durable
snapshot - of every issue that carried oldLabel, whether it gained
newLabel or already had it (merge), so each touched issue now mints one
version row, the same gate AddLabelInTx/RemoveLabelInTx draw on a row
that landed. RecordVersionInTx is already a no-op for wisps and when
versioned history is disabled, and a rename nobody carries touches no
id, so the no-op shape mints nothing.

TestRenameLabelMintsOneVersionPerTouchedBead is the runtime twin of the
static guard: plain rename +1, merge +1, untouched bead +0, a second
rename with no carriers +0, current_revision equal to the row count.

* build(bazel): list this PR's six new test files in their go_test srcs

Generated-artifact drift repair, produced by the repository's own command
(`make bazel-sync`) and inspected before committing, not hand-written.

The PR adds six `_test.go` files and none were listed in their package's
`go_test` srcs, so Bazel compiled each of those packages' test targets without
them - green by omission. That was invisible on the pre-merge head because its
CI predates the Bazel lanes entirely (zero `Bazel /` rows). This merge brings in
e1b2e79484 (#6941), which makes those lanes feed the required gate, so the
omission would now surface as a real red.

Purely additive: 6 insertions, 0 deletions, `go_test` srcs only. No `go_library`
srcs change is needed because every added file is a test, which is also why this
cannot break the build the way a missing production source would.

Verified: `make bazel-sync` is now a no-op against this tree (empty porcelain),
and `bazel build //cmd/bd/... //internal/storage/... //internal/types/...
//internal/telemetry/...` completes successfully - 3429 actions, 0 errors.

---------

Co-authored-by: Marco Del Pin <marco@omniaevo.it>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-29 17:02:35 -07:00
Jim Wordelman
73c9944cdb
test(dolt): document contention-vs-bug verdict for 2 federation tests (#5996)
* test(dolt): document contention-vs-bug verdict for 2 federation tests (be-72xld)

Triaged 3 singleton real-server test failures flagged from PR #5836's
test-server-storage-full job:

- TestClaimerReclaimsAcrossSpellingWithoutWriting: already fixed upstream
  by PR #5856 (canonicalActor --/__ collapse). Passes in isolation on
  current main; no code change needed.
- TestFederationListRemotes: resource-contention/timeout, not a bug.
  Passes in 0.11s isolated; this package serializes all tests through a
  size-2 shared-server slot semaphore (acquireTestSlot), which can exceed
  a test's context deadline under full-suite concurrent load without any
  assertion failing. Documented in place rather than masked with a
  timeout/semaphore workaround.
- TestFederationSyncCommitsPendingPeerMetadataBeforeFetch: same verdict,
  same mechanism, same evidence class (0.16s isolated pass).

Refs be-72xld.

* docs(dolt): name the context that actually expires in these two tests

Review #5996: the mechanism the comments named cannot produce the symptom.
Both tests build their own context AFTER setupTestStore returns
(federation_test.go), so the size-2 test-slot queue wait is already over and
that context starts with a fresh minute. dolt_test.go's setupTestStore doc
comment prescribes exactly that ordering to prevent the failure the comments
were blaming.

Verified on origin/main c0d8da42d: setupTestStore acquires its slot, then
builds ctx via testContext(t) (the package testTimeout), then calls New() and
initSchemaOnDB under it. A genuine deadline expiry in these tests therefore
comes from that bound and surfaces as "failed to create Dolt store" or
"failed to initialize branch-local ignored schema" attributed to the test --
not from the minute-long context in the test body.

Rewords both blocks to name that context instead, and starts the second block
with TestFederationSyncCommitsPendingPeerMetadataBeforeFetch so it reads
correctly as that function's doc comment (reviewer nit).

Comment-only; no behavior change. gofmt and go vet -tags integration clean.

Refs be-vlg2c.

---------

Co-authored-by: Gas City Merge Queue <noreply@gastownhall.dev>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-29 17:00:24 -07:00
Karel Bourgois
e8f318316f
feat(count): --include-ephemeral, the plane knob bd count never had (#6240)
* feat(count): --include-ephemeral, the plane knob `bd count` never had

`bd count` can admit the wisps table only through `--include-infra`, which
makes four changes at once. This adds the flag that makes just the first one,
mirroring the `--include-ephemeral` that `bd list` gained in #6098.

## Why the plane is unreachable on its own

The write path routes on STORAGE CLASS, not type — dolt's `useWispsTable` is
`Ephemeral || NoHistory || WispType != "" || IsInfraType`. So a `no_history`
task lives in the wisps TABLE while remaining ordinary durable work, and a
default `bd count` never sees it.

Recovering it today means `--include-infra`, which this repo's own doc calls
"FOUR changes at once and not one": it admits the plane, drops the infra-type
exclusions, changes the template treatment, and reconciles cardinality with
`bd list --all`. Its template exclusion then silently drops template rows of
the named type — so a caller who wanted the plane trades one silent undercount
for another.

`ListRequest.IncludeEphemeral` has been the narrow answer on the listing side
since #5476, and #6098 gave it a CLI flag. `CountRequest` had no equivalent
field at all. This is the missing half of that pair.

## The change

- `issueops.CountRequest.IncludeEphemeral` — the plane knob alone: exactly the
  first of `IncludeInfra`'s four changes, with none of the other three.
- `internal/workapi/count.go` — one line, `} else if !in.IncludeEphemeral {`.
- `cmd/bd/count.go` — flag registration, matching `bd list`'s wording.
- `internal/httpapi` — `include_ephemeral` on `countIssues`, in the spec; the
  generated `types.gen.go` is `make api-gen` output, not hand-edited.

Unset, the count is durable-plane only: the historical answer, unchanged. Every
default is untouched.

It does NOT promise a count and a listing agree. They already differ on
TEMPLATES without this flag and still do with it — a count includes template
rows unless `IncludeInfra` excludes them, a listing excludes them unless
`IncludeTemplates` admits them. That predates this and is unchanged by it; only
`IncludeInfra` sets out to reconcile cardinality, and it pays with three
changes beyond the plane.

## Verification

    ok  github.com/steveyegge/beads/internal/workapi
    ok  github.com/steveyegge/beads/internal/httpapi
    ok  github.com/steveyegge/beads/issueops
    --- PASS: TestEmbeddedCountIncludeEphemeral (39.71s)
    --- PASS: TestCountIncludeInfraFlagShape
    --- PASS: TestParseCountRequestCarriesEveryFilterFlag

`TestEmbeddedCountIncludeEphemeral` was run with `BEADS_TEST_EMBEDDED_DOLT=1`
and really executed — 39.71s, not a skip. The default fast tier would have
skipped it and reported `ok`.

`make api-gen` reproduces `types.gen.go` byte-for-byte from the spec hunk, so
the two cannot drift apart in review. `go build ./...`, `go vet` and `gofmt`
clean.

Claude-Session: https://claude.ai/code/session_01X1jMLQTSrCwtzFRS1xeUC6

* count: reframe the comments for this repo, not the fork they came from

Review on #6240 (bee-ghosttrack): five comment blocks were written from the
fork's point of view and become false once merged here — "belongs upstream",
"the half that still has to go upstream", "the fork's old wide default",
and "upstream's default" meaning the current default.

Find-and-replace, as asked: the reasoning is kept, only the frame of reference
changes. "upstream's default" -> "the default before this change"; the bd
list sibling "landed in #6098"; the infra-type divergence is "pinned, not
fixed, here" with the reason; the embedded test's fork-maintenance history is
replaced by what it actually pins. No code changes.

* build(bazel): list the two test files this PR adds in their go_test srcs

Maintainer review fixes for #6240, review iteration 1. The synthesis and the
quality scorecard both returned approve with no required changes; this commit
takes the one minor whose subject is the PR's own added files.

Taken:

- Change Impact / Blast Radius (minor, gate impact minor). The PR adds
  cmd/bd/count_include_ephemeral_embedded_test.go and
  internal/workapi/count_skipwisps_test.go, but neither was listed in its
  package's explicit go_test srcs, so the PR's own assertions were invisible to
  `bazel test`. Both rows are now listed.

  Gazelle's verdict, not a hand-guess: `make bazel-sync` was run (bazel 9.2.0 is
  available here) and it produced exactly these two entries. Its full output
  also rewrote 12 other BUILD.bazel files -- pre-existing base drift from other
  PRs' files, plus dep/select churn -- which is out of scope for this PR, so the
  generated result was reverted and only the two rows this PR is responsible for
  were re-applied, at the slots gazelle chose. Both srcs lists remain sorted
  with no duplicates (cmd/bd bd_test 637 entries, internal/workapi workapi_test
  24 entries).

  The cgo build tag on count_include_ephemeral_embedded_test.go does not exempt
  it: the repo lists tag-gated *_embedded_test.go files anyway (99 of the 101 in
  cmd/bd are listed, and the sampled ones are simultaneously listed and tagged).

Declined:

- Test Evidence Quality (nit, gate impact none). The filing lane itself marked
  it optional and explicitly said not to gate on it, and its own reasoning holds:
  internal/storage/dolt/counts.go and internal/storage/embeddeddolt/counts.go
  both delegate to the same issueops.CountIssuesInTx, differing only in
  transaction acquisition.

Validation: go build ./... and CGO_ENABLED=1 go vet on cmd/bd, internal/workapi
and issueops all clean; go test ./internal/workapi/ ./issueops/ ok. No
production code changed -- the commit is two generated-list rows.

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

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-29 16:56:23 -07:00
ecuthiell
beed11c7f4
fix(init): use selected hook context in embedded initialization (#6464)
* fix(worktree): scrub inherited Git routing state

Establish CWD as the worktree repository boundary before discovery can consume inherited Git routing. Fence the startup config probe, clear routing in-process before root pre-run discovery, and retain command-owned subprocess scrubbing as defense in depth without changing PID or signal semantics.

Fixes #5531

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell

* refactor(worktree): explain owned filtering and remove an unused shim

Document why filtering the fresh routing slice in place is safe and call
the shared routing-key classifier directly from tests. Retain the two
forwarders used by production worktree subprocess/removal paths.

Review: https://github.com/gastownhall/beads/pull/5623#pullrequestreview-5098421671
Bead: saa-cgh.23
Agent-Signature: unknown-model/unknown-reasoning

* fix(config): isolate identity and tracked-file Git probes from routing

Reuse the worktree routing owner for GetIdentity and isGitTracked so
explicit cwd/path selection is not displaced by inherited repository,
index or injected config state. Preserve identity precedence and the
tracked-secret refusal contract, with real target/decoy regressions.

Follow-up: https://github.com/gastownhall/beads/issues/6222
Dependency: https://github.com/gastownhall/beads/pull/5623
Reported-by: bee-ghosttrack
Bead: saa-cgh.93
Agent-Signature: unknown-model/unknown-reasoning

* fix(config): share subprocess key identity for Git routing (saa-cgh.93)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(exec): match Windows environment key identity (#5618)

Centralize os/exec-compatible environment-key comparison and use it for credential, metrics, Git-hook, trace, and repro subprocess filters. Preserve exact Unix semantics and Unicode near-collisions.

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell
Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com>

* test(execenv): exercise every environment operation under both host rules

Thread the host choice through narrow private helpers behind the existing
exported functions. Keep one normalization owner and retain native wrapper
tests; the additional table covers both host branches for equality, prefix
matching, last-wins lookup, filtering and input preservation.

Review: https://github.com/gastownhall/beads/pull/5672#pullrequestreview-5096948965
Bead: saa-cgh.78
Agent-Signature: unknown-model/unknown-reasoning

* test(execenv): exercise exported host policy wiring (saa-cgh.78)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* docs(worktree): explain startup Git environment scope (saa-cgh.23)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(config): isolate role commands from Git routing (saa-cgh.99)

Follow-up to bee-ghosttrack's review of gastownhall/beads#6322; refs #6357.

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(env): exercise shared key helpers on native Windows (saa-cgh.78)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* refactor(gitenv): share key parsing and normalize routing membership once (saa-cgh.93)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* docs(config): explain role command routing policy (saa-cgh.99)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): isolate role configuration from inherited Git routing (saa-cgh.109.3)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): use the selected origin in contributor setup (saa-cgh.109.7)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): isolate Git writes in planning repositories (saa-cgh.109.9)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(init): retain inherited planning commit author (saa-cgh.109.9)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): align embedded role gates with selected Git context (saa-cgh.109.12)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): scope embedded artifact Git operations to selected directory (saa-cgh.109.15)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(init): cover selected optional artifacts and explain refused commits (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* Honor role-probe cancellation and exercise actual fork planning (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): warn when automatic contributor role write fails (saa-cgh.109.3)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(init): cover successful nonquiet contributor role writes (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* Assert the automatic contributor setup banner alongside warnings (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* test(init): read persisted role routing from the store (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* fix(git): isolate domain role configuration from inherited routing (saa-cgh.109.5)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): probe the selected repository before configuring roles (saa-cgh.109.8)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* docs(init): explain role probe discovery ceiling behavior (saa-cgh.109.8)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): bind proxied tail Git operations to selected directory (saa-cgh.109.14)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(gitignore): preserve CRLF when appending project rules (saa-cgh.96)

Reported by bee-ghosttrack in gastownhall/beads#6343.

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(gitignore): pin detector edge cases and clarify append behavior (saa-cgh.96)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(gitignore): preserve line endings in Git exclude appends (saa-cgh.104)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(gitignore): clarify exclude fixture path variable (saa-cgh.104)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(gitignore): refuse exclude writes after read errors (saa-cgh.110)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* refactor(gitignore): share append byte composition (saa-cgh.105)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* docs(gitignore): explain append aliasing and trailing CR completion (saa-cgh.105)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* refactor(gitignore): use shared composition for exclude rules (saa-cgh.111)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(gitignore): omit the empty exclude leading separator (saa-cgh.112)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): bind exclude writers to the selected Git directory (saa-cgh.109.16)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(hooks): isolate tracked-file guard from Git routing (saa-cgh.98)

Follow-up to bee-ghosttrack's review of gastownhall/beads#6322; refs #6356.

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(hooks): retain legitimate inherited tracking context (saa-cgh.98)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(hooks): isolate trusted global configuration fixture (saa-cgh.98)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* docs(hooks): explain conservative tracked-file guard (saa-cgh.98)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* refactor(git): resolve hooks paths in an explicit read-only context (saa-cgh.109.17.1)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* Bind init hook operations to the selected repository (saa-cgh.109.17)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* Give the hooks tail fixture an explicit remote context (saa-cgh.109.17)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(git): canonicalize the hooks fixture repository root (saa-cgh.109.17.1)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): complete selected hook options and alias handling (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* Clarify hooks resolver ownership and preserve work-tree diagnostics (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* Explain restoration of absent routing variables in selected exclude tests (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* Keep init role operations on the captured selected Git context (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* Align selected-tail fixtures with captured role authority (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): keep embedded hook setup in the selected project (saa-cgh.120.12)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(init,config): maintainer fixup for #6464

Pre-review CI repair:
- Annotate #nosec G702 on the selected hooks-path git invocation. No shell
  is involved, every path is passed as its own argv element, and both values
  reach that line absolute via resolveInitHooksContext.

Review iteration 1, blocking:
- internal/config: give the secret-config guard the inherited-env fallback
  that the structurally identical hook guard in cmd/bd/hooks.go already has.
  isGitTracked is the fail-open half of "refuse to write a secret key into a
  git-tracked config.yaml", and the scrub alone narrowed it to upward
  discovery from the config file's directory: under a detached work tree
  (GIT_DIR + GIT_WORK_TREE with no in-tree .git) the probe reported
  "untracked" and the secret was written into the tracked file. Probe the
  scrubbed environment first so inherited routing cannot hide a tracked
  file, then the inherited one; either probe reporting the path as tracked
  refuses the write. Adds the legitimate-routing subtest that the
  poisoned-routing matrix could not express.
- cmd/bd/config.go: the new comment claimed "All role commands ignore
  inherited Git routing". Only the writers were hardened -
  routing.DetectUserRole, beads.RepoContext.Role, `bd config show` and
  `bd doctor` still resolve beads.role through the inherited environment, so
  `bd config get beads.role` and `bd config show` can disagree under one
  environment. Narrow the comment to the four verbs it covers; widening the
  boundary to the readers is a separate change.

Review iteration 1, non-blocking:
- cmd/bd/worktree_cmd.go: disclose that ClearRouting unsets the variables on
  the bd process itself, and state what clearing the discovery-scope
  controls does to repository selection. The comment previously claimed the
  opposite of what the init path's own note admits.
- cmd/bd/init_proxied_server.go: drop isRoleGitRepo. With workDir set, gitUC
  is NewInitGitRepository(workDir), whose IsGitRepo runs the same
  `git rev-parse --git-dir` with the same Dir and scrubbed env; with workDir
  empty the helper returned its fallback. It was isRepo in both arms, plus a
  second git subprocess per `bd init --proxied`.
- cmd/bd/doctor/gitignore.go: omit the leading blank line when creating a
  fresh .gitignore, matching the two sibling writers this PR already
  conditionalized in cff94aa43.

Review iteration 2, non-blocking:
- cmd/bd/worktree_cmd.go: iteration 1's own rewrite lumped
  GIT_DISCOVERY_ACROSS_FILESYSTEM in with GIT_CEILING_DIRECTORIES as
  "removes an inherited stop". That is backwards. git(1) documents that
  discovery "does not cross filesystem boundaries" by default and that this
  variable "can be set to true to tell Git not to stop at filesystem
  boundaries" - it only ever permits, so clearing it *adds* a stop and
  narrows the walk. Split the clause per control: the ceiling widens,
  GIT_DISCOVERY_ACROSS_FILESYSTEM narrows (a repository reachable only
  across a mount point is no longer found by any `bd worktree` verb, with no
  opt-out), and ClearRouting's GIT_CONFIG prefix match drops the whole
  GIT_CONFIG* family for the command's lifetime rather than for one child
  probe. This comment is the only in-tree assertion about the variable's
  direction; export_auto.go:1083-1085 groups the two without claiming one.
- cmd/bd/config.go: "bd config's own beads.role reads and writes" covered
  `bd config show`, which the very next sentence lists as an exception. Name
  the four verbs that do scrub (get/set/unset/set-many, at config.go:209,
  :355, :609 and :902 - the only four git invocations in the file).
- internal/config: make the guard's fail-open default unspellable. The
  mirrored helper took `envs ...[]string`, so a future zero-probe call would
  fall through to "untracked" and write the secret with no compiler
  backstop. Promote the first environment to a required parameter. The tail
  stays variadic rather than matching the twin's fixed (clean, inherited)
  arity because the fallback's fixture guard has to probe one environment
  alone, and exec treats a nil Env as "inherit the current process" rather
  than as a disabled probe.

Pre-approval CI repair:
- Annotate the four gosec taint findings this PR newly introduces in package
  cmd/bd: G704 on the two connectivity probes in dolt.go, G702 on the
  staged-deletion probe in hooks.go and on the ls-remote probe in
  sync_git.go. None of the four is reported by the PR lane, whose lint is
  scoped to the diff (only-new-issues / --new-from-merge-base), and all four
  sit on lines this PR does not otherwise touch - but main.yml runs the same
  wrapper with BD_LINT_NEW_FROM_MERGE_BASE unset and sweeps the whole tree,
  so merging as-is turns main's Lint and PR Lint jobs red. Measured
  whole-tree at pr.yml's pinned golangci-lint v2.10.1 with
  --build-tags=gms_pure_go: origin/main 0 issues, this head 4, this head
  with the annotations 0. The findings are taint over-approximation rather
  than new exposure: gosec's analysis is not field-sensitive, so routing
  config discovery through env-derived paths marks the whole store value
  tainted and every remote URL read back off it inherits that. Each
  annotation states why its own call site is safe; the additions are
  comment-only, with no deletions and no behaviour change.

  The hooks.go annotation sits on the isExportFileStagedForDeletion
  declaration rather than on the exec.Command call. main has since rewritten
  that body to address the export file through nearestExistingDir +
  filepath.Rel, so a call-site comment both conflicted with the merge and
  described an argument the merged body no longer builds. On the declaration
  it merges cleanly and its justification holds for either body.

Pre-approval base refresh (rebased onto 511849496):
- Reconcile this PR with gastownhall/beads#6477, which landed on main after
  this branch was first rebased and which changes the same reader. The two
  changes collide in both directions, and neither side's CI can see it: the
  PR lane builds this branch against its own base, main's lane never has the
  PR, and only the merged tree fails.
- #6477 direction: its new subtest
  TestConfig_ReadFailuresAreNotMissing/invalid_routing_boolean poisons
  GIT_CONFIG_NOSYSTEM and expects the beads.role read to exit 128. This PR
  scrubs GIT_CONFIG* for exactly that key, so git never sees the poison and
  the read succeeds. Replaced that row with
  TestConfig_BeadsRoleScrubsInheritedRoutingEnv, which pins both halves of
  the new contract: beads.role reads through the scrub, and a key outside it
  (user.name) still surfaces the same poison as an exit-128 read error
  rather than as an absent key. #6477's general guarantee is untouched -
  malformed_config still proves it for beads.role through the repository's
  own config file.
- Opposite direction: this PR's own
  TestInitGitRepositoryUsesSelectedDirectory/captured_home asserted
  require.NoError on a generic-constructor read, commented "The existing
  reader maps Git exit errors to absence" - the precise behaviour #6477
  removed. Expect the propagated exit error instead. The test's intent is
  unchanged and in fact better served: only the current caller environment
  can see the changed HOME's broken .gitconfig, so that error is itself the
  proof that generic role reads still use it.

* test(init): retarget the bare row to the work-tree-less install policy

This PR's TestInitEmbeddedHooksSelectedTail/bare row (authored
2026-09-09) asserted that a bare repository fails to resolve hooks
and installs nothing. #6457 (6a4b4aa14e, 2026-09-27) added
git.ResolveWorkTreelessHooksContext specifically to end that
behavior -- its own comment calls out "turning a supported
repository into a warning and no install at all" as the defect it
fixes -- so the row pinned a policy main had deliberately
superseded by the time the two met.

Retargeted in place rather than deleted, so the bare shape keeps
coverage through the embedded-init entry point (main's new
bare/git_dir_cwd rows cover only the proxied path): bare now
installs like any other selected repository, and being its own
common directory, its hooks path lands in its own config.

Mutation-proved load-bearing: removing the work-tree-less fallback
reds this row alone (the other eight rows stay green) with
".../hooks/pre-commit: no such file or directory" -- i.e. it
reproduces the original expectation exactly.

---------

Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com>
Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-29 16:54:33 -07:00
ecuthiell
cb9a68896e
fix(hooks): keep standalone operations in one selected Git context (#6463)
* fix(exec): match Windows environment key identity (#5618)

Centralize os/exec-compatible environment-key comparison and use it for credential, metrics, Git-hook, trace, and repro subprocess filters. Preserve exact Unix semantics and Unicode near-collisions.

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell
Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com>

* fix(worktree): scrub inherited Git routing state

Establish CWD as the worktree repository boundary before discovery can consume inherited Git routing. Fence the startup config probe, clear routing in-process before root pre-run discovery, and retain command-owned subprocess scrubbing as defense in depth without changing PID or signal semantics.

Fixes #5531

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell

* refactor(worktree): explain owned filtering and remove an unused shim

Document why filtering the fresh routing slice in place is safe and call
the shared routing-key classifier directly from tests. Retain the two
forwarders used by production worktree subprocess/removal paths.

Review: https://github.com/gastownhall/beads/pull/5623#pullrequestreview-5098421671
Bead: saa-cgh.23
Agent-Signature: unknown-model/unknown-reasoning

* fix(config): isolate identity and tracked-file Git probes from routing

Reuse the worktree routing owner for GetIdentity and isGitTracked so
explicit cwd/path selection is not displaced by inherited repository,
index or injected config state. Preserve identity precedence and the
tracked-secret refusal contract, with real target/decoy regressions.

Follow-up: https://github.com/gastownhall/beads/issues/6222
Dependency: https://github.com/gastownhall/beads/pull/5623
Reported-by: bee-ghosttrack
Bead: saa-cgh.93
Agent-Signature: unknown-model/unknown-reasoning

* test(execenv): exercise every environment operation under both host rules

Thread the host choice through narrow private helpers behind the existing
exported functions. Keep one normalization owner and retain native wrapper
tests; the additional table covers both host branches for equality, prefix
matching, last-wins lookup, filtering and input preservation.

Review: https://github.com/gastownhall/beads/pull/5672#pullrequestreview-5096948965
Bead: saa-cgh.78
Agent-Signature: unknown-model/unknown-reasoning

* docs(worktree): explain startup Git environment scope (saa-cgh.23)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(execenv): exercise exported host policy wiring (saa-cgh.78)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(config): share subprocess key identity for Git routing (saa-cgh.93)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(gitignore): preserve CRLF when appending project rules (saa-cgh.96)

Reported by bee-ghosttrack in gastownhall/beads#6343.

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(hooks): isolate tracked-file guard from Git routing (saa-cgh.98)

Follow-up to bee-ghosttrack's review of gastownhall/beads#6322; refs #6356.

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(config): isolate role commands from Git routing (saa-cgh.99)

Follow-up to bee-ghosttrack's review of gastownhall/beads#6322; refs #6357.

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(gitignore): pin detector edge cases and clarify append behavior (saa-cgh.96)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(gitignore): preserve line endings in Git exclude appends (saa-cgh.104)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* refactor(gitignore): share append byte composition (saa-cgh.105)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(env): exercise shared key helpers on native Windows (saa-cgh.78)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(gitignore): clarify exclude fixture path variable (saa-cgh.104)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* docs(gitignore): explain append aliasing and trailing CR completion (saa-cgh.105)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* refactor(gitenv): share key parsing and normalize routing membership once (saa-cgh.93)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(gitignore): refuse exclude writes after read errors (saa-cgh.110)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* docs(config): explain role command routing policy (saa-cgh.99)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(hooks): retain legitimate inherited tracking context (saa-cgh.98)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* refactor(gitignore): use shared composition for exclude rules (saa-cgh.111)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(hooks): isolate trusted global configuration fixture (saa-cgh.98)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(gitignore): omit the empty exclude leading separator (saa-cgh.112)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(git): isolate domain role configuration from inherited routing (saa-cgh.109.5)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(hooks): isolate role cleanup in the selected repository (saa-cgh.109.4)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): probe the selected repository before configuring roles (saa-cgh.109.8)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(hooks): reset only common local role configuration (saa-cgh.109.10)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(hooks): scope hooks-path cleanup to selected common config (saa-cgh.109.11)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* docs(hooks): explain conservative tracked-file guard (saa-cgh.98)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* docs(init): explain role probe discovery ceiling behavior (saa-cgh.109.8)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): bind proxied tail Git operations to selected directory (saa-cgh.109.14)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* refactor(git): resolve hooks paths in an explicit read-only context (saa-cgh.109.17.1)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): bind exclude writers to the selected Git directory (saa-cgh.109.16)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* Bind init hook operations to the selected repository (saa-cgh.109.17)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* Give the hooks tail fixture an explicit remote context (saa-cgh.109.17)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(git): canonicalize the hooks fixture repository root (saa-cgh.109.17.1)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(hooks): make worktree role preservation independent (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* Keep init role operations on the captured selected Git context (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* Clarify hooks resolver ownership and preserve work-tree diagnostics (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* Align selected-tail fixtures with captured role authority (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* Report selected config read failures during hook reset (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* Explain restoration of absent routing variables in selected exclude tests (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* fix(hooks): keep successful config stdout separate from diagnostics (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): complete selected hook options and alias handling (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* fix(hooks): keep standalone operations in one selected Git context (saa-cgh.120.4)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* Assert standalone hook diagnostics through the CLI stderr contract (saa-cgh.120.4)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(hooks): isolate output mode and accept repository path aliases (saa-cgh.120.4)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(hooks,config): clear the out-of-repo hooks path, close the fail-open secret guard

Maintainer adoption fixes for the three majors raised by the #6463 review.

1. `bd hooks install --beads` configures <effective .beads>/hooks, which
   BEADS_DIR or a .beads/redirect can place outside the repository, but the
   cleanup predicate (doctor.IsBeadsManagedHooksPath) matched only the two
   repo-relative forms. Uninstall therefore deleted the hook files and left
   core.hooksPath pointing at the emptied directory: .git/hooks stays shadowed,
   every hook is silently disabled, and beads-managed config is still installed
   -- the exact failure the GH#4440 contract at hooks.go:1505 exists to stop.
   `bd doctor --fix` shares the predicate, so nothing repaired it either.

   At base the same command wrote files to FindBeadsDir()/hooks but configured
   <mainRepoRoot>/.beads/hooks, a value the predicate does match, so the config
   was always removable. Making the write target consistent was the right fix;
   it just left the cleanup predicate behind. The regressing slice is
   post-uninstall removability.

   The predicate now takes the resolved storage hooks directory explicitly, and
   uninstall, `bd doctor --fix` and CheckHooksPath all resolve it through one
   new helper (doctor.BeadsManagedStorageHooksDir -> beads.FindBeadsDir), which
   is the same resolution install itself performs. Deliberately not
   ResolveBeadsDirForRepo: that is repo-anchored and blind to BEADS_DIR, i.e.
   half the finding's population. The new arm is gated on a resolved storage
   directory so it can never reach a third-party hooksPath.

   The `beads` subtest flips from "outside-storage predicate remains
   conservative" to asserting core.hooksPath is absent after uninstall; the
   doctor side gains TestFixHooksPath_ClearsDanglingOutOfRepoStorageHooks and
   five predicate table rows, including the negatives that pin the gating.

2. internal/config.isGitTracked gained `cmd.Env = gitenv.ScrubRouting(...)` with
   no inherited fallback. Its only caller is fail-open by construction -- a
   probe that cannot answer means "untracked" and the secret write proceeds.
   Probed directly with real git: in a bare-repo-plus-external-work-tree layout
   the scrubbed probe exits 128 while the inherited one exits 0, so scrubbing
   alone made `bd config set ai.api_key` write the secret into a git-tracked
   config.yaml that base refused -- a hardening that moved a guard toward
   exposure. It now uses the two-probe shape this same range already applies in
   isGitTrackedFileWithEnv (scrubbed first, inherited fallback, either index
   tracking the file refuses the write).

3. cmd/bd/config.go's "All role commands ignore inherited Git routing" is a
   false universal: the readers that decide maintainer-vs-contributor
   (internal/routing, beads.RepoContext.Role, doctor/role.go, config_show.go)
   are unscrubbed, so GIT_CONFIG_COUNT/KEY/VALUE still flips the role. Narrowed
   to what is true -- bd config's own role read and write -- and it now names
   the uncovered reader plane instead of claiming coverage over it.

   The reader-scrub arm is deliberately not taken here: #6461's published head
   already hardens all four reader files (verified at refs/pull/6461/head), so
   duplicating it would rewrite four files an open sibling PR is already
   changing. No sibling head is an ancestor of this one, so whichever leaf
   merges first must carry the reader legs.

Also fixed, non-gating and nearby:

- install/uninstall act on the selected config-scrubbed hooks path while every
  status and execution reader (bd hooks list, bd doctor, runChainedHook) still
  resolves through the inherited context -- and git itself honors the inherited
  core.hooksPath. When the two disagree, a warning now names both paths instead
  of reporting a bare success that `bd hooks list` will contradict. The
  inherited path was already computed, so this costs no extra subprocess.
- the `rev-parse --absolute-git-dir` failure now carries git's stderr, as
  loadGitContext does for the same class of failure.

Second review iteration: the three majors above were validated fixed by both
lanes, leaving one minor and two nits, none of them merge gates. The minor is
accepted with its slice pinned; the rest is bookkeeping.

- The cleanup predicate recognizes what install would configure *right now*
  (doctor.BeadsManagedStorageHooksDir -> beads.FindBeadsDir), not the value
  install actually wrote, and every FindBeadsDir arm reads live inputs
  (BEADS_DIR, redirect contents, storage existence, process cwd). When those
  drift between install and cleanup the value becomes unclearable again. Closing
  it needs install to record what it wrote (a local beads.hooksPath key) and the
  predicate to match the record -- new persisted surface, deliberately not added
  in an adoption fixup after the review converged. Filed as bd-s76jm. The slice
  is now pinned rather than silent, by two tests that must flip when bd-s76jm
  lands and that pair with the existing opposite-polarity pins:
  TestFixHooksPath_LeavesDanglingStorageHooksWhenStorageIsGone (whole storage
  deleted -- the trigger CheckHooksPath's own docstring names for GH#4440) and
  TestStandaloneBeadsUninstallLeavesHooksPathWhenResolutionDrifts (BEADS_DIR set
  at install, absent at uninstall: the hook files are deleted and
  core.hooksPath survives). Predicate-level, `storage hooks with no storage
  resolved` -> false already pinned it.
  Not taken instead: widening the predicate by path shape. The arm is gated on a
  resolved storage directory precisely so it cannot reach a third-party
  hooksPath, and two table rows pin that.
- cmd/bd/config.go's narrowed comment scoped its guarantee to "bd config's own
  ... read and write" while listing `bd config show` as an unscrubbed exception
  -- and `bd config show` is a bd config read (config_show.go:336), so the
  scoping clause contradicted its own exception list. It now names the four
  subcommands that really are scrubbed. Note that is get/set/set-many/unset:
  config.go:903 is `bd config set-many`, so the reviewer's suggested
  "get/set/unset" wording would have under-named the set.

The four items this commit previously called "tracked follow-ups" carried no
bead ids, which made them declines that would evaporate at merge. Now filed:

- bd-ewdt8: the GH#4440 uninstall regression suite still exercises the
  production-dead uninstallHooks/resetHooksPathIfBeadsManaged rather than the
  shipped hooksUninstallCmd route. Tabling those cases over both entry points is
  a test-only refactor across nine call sites; the shipped route does now carry a
  real hooksPath-clearance assertion (item 1).
- bd-ez09k: exposing GitDir on git.HooksContext to drop the extra rev-parse is
  declined on risk, not cost (loadGitContext's absolute git dir is anchored on an
  already symlink-resolved workDir, while `rev-parse --absolute-git-dir` runs
  from the raw cwd, so substituting it changes the provenance of the pinned
  GIT_DIR inside the very resolver under review, for a finding with no gate
  impact); and `isRoleGitRepo`'s doubled probe (init_proxied_server.go) is
  untouched because all four open sibling PRs rewrite that file (32-57
  insertions each).
- bd-16d58: `bd init` still installs beads hooks through the legacy
  installHooksWithOptions (init.go:2072, beadsHooks=true), which writes files to
  FindBeadsDir()/hooks while configuring <repoRoot>/.beads/hooks. Both values are
  now clearable, but that route's install/config mismatch remains. Corrected
  scope: `bd config apply` is not in this population -- config_apply.go:202
  passes beadsHooks=false, so it takes the common-git-dir branch and configures
  no hooksPath at all. bd-s76jm blocks it: making this route configure an
  out-of-repo value without the recorded-value fix would trade a
  hooks-never-run bug for an unclearable-core.hooksPath one.

Validation (env -u BEADS_DIR, private TMPDIR):

- internal/config: full package green.
- cmd/bd/doctor: full package run at the reviewed head and with this fixset
  produce an identical 7-test failure set, all environment-driven (reachable
  Dolt server, global beads.role=maintainer, ambient dolt.host/dolt.user).
- cmd/bd: the full package exceeds go test's 10m default at the reviewed head
  too, aborting before it reaches any hooks test (pr.yml:973 documents this and
  uses -timeout=30m). Instead, all 51 tests in the four files that touch the
  changed symbols pass under CI's flags: -tags gms_pure_go -race -short.
- go vet clean for linux, CGO_ENABLED=0, and GOOS=windows CGO_ENABLED=0 over
  cmd/bd/..., internal/config/... and internal/git/... -- the two new
  unconstrained cmd/bd test files still compile in the no-cgo lanes.
- Mutation proofs, each reddening only its own pin while every incumbent stays
  green: removing the predicate's storage arm reds exactly
  TestIsBeadsManagedHooksPath/out-of-repo_storage_hooks,
  TestFixHooksPath_ClearsDanglingOutOfRepoStorageHooks and
  TestStandaloneHookCommandsUseSelectedContext/beads; removing isGitTracked's
  inherited fallback reds the new external-work-tree test with
  `refusal = <nil>`, the fail-open write itself, while the three pre-existing
  routing cases stay green; suppressing the divergence warning reds only
  TestStandaloneHooksWarnOnEffectivePathDivergence.

Second-iteration validation (same flags):

- cmd/bd/doctor -run 'TestFixHooksPath|TestCheckHooksPath|TestIsBeadsManagedHooksPath':
  29/29 === RUN green, counted rather than read off a bare `ok`.
- cmd/bd, the five hooks-context tests: 16/16 === RUN green, including the
  incumbent .../beads arm that asserts the value IS cleared without drift. That
  arm and the new drift test differ by one setup line and assert opposite
  outcomes, which is what makes the new pin non-vacuous; each new test also
  asserts its own precondition (no storage resolves) so it cannot pass for the
  wrong reason.
- gofmt, git diff --check, go build, and go vet clean for linux, CGO_ENABLED=0
  and GOOS=windows CGO_ENABLED=0 over cmd/bd/... -- the added doctor import in
  cmd/bd/hooks_worktree_test.go compiles in the no-cgo lanes.
- cmd/bd/config.go's delta is comment-only, so no behavior and no generated CLI
  docs are affected.

Pre-approval CI repair: main advanced 11 commits after the review loop, and
the merged tree (this head merged with main) reds two tests that are green on
each side alone. Base-parity proves it: internal/storage/domain/git is 31/31 at
main alone and 33/33 at the reviewed head alone, but 5 FAIL merged. GitHub
builds refs/pull/6463/merge, so this is the tree CI will actually test.

Both reds are the same two-way collision between this PR's role-read hardening
and #6477 ("preserve config read errors instead of treating them as absent"):

- This PR's TestInitGitRepositoryUsesSelectedDirectory/captured_home asserted
  `require.NoError` on a generic `beads.role` read whose HOME holds a broken
  .gitconfig, with the comment "The existing reader maps Git exit errors to
  absence." #6477 deliberately deleted exactly that premise, so the broken
  config now surfaces as a real error (exit 128). HOME is not a routing key, so
  the changed HOME is still visible to the generic reader -- which is what the
  subtest exists to prove. The assertion flips to `require.Error`; `found` and
  the empty value still hold, and the selected-constructor half is untouched.

- #6477's TestConfig_ReadFailuresAreNotMissing/invalid_routing_boolean poisons
  GIT_CONFIG_NOSYSTEM and read `beads.role`. gitenv.IsRoutingKeyForOS treats any
  GIT_CONFIG* key as routing (routing.go:61, a prefix rule, not the explicit
  map), so this PR's role-read scrub strips the poison and the read succeeds --
  #6477's row is obsoleted by design for the one key this PR hardens, and its
  tail BeadsRole assertion with it. The row is retargeted to test.marker, a key
  that still inherits routing, which preserves #6477's contract (a routing-env
  read failure must surface as an error, exit 128 with a diagnostic) on the same
  mechanism. Its role-read leg now asserts the hardened outcome positively, so
  the boundary between the two contracts is pinned rather than dropped. The two
  untouched rows (malformed repo config, invalid key) never depended on routing
  env and stayed green throughout.

Repair validation, on the merged tree, env -u BEADS_DIR and a private TMPDIR
outside the worktree:

- internal/storage/domain/git: 45/45 === RUN PASS, 0 FAIL, 0 SKIP.
- Non-vacuity: dropping the GIT_CONFIG_NOSYSTEM poison reds the retargeted row,
  so it still exercises the routing mechanism rather than passing trivially.
- cmd/bd blast radius (188 selectors from every cmd/bd test file either side
  changed): the failing-name set is identical to main's under the same selector
  and host -- 16 names both sides, zero new -- while RUN rises 393 -> 529 and
  PASS 357 -> 493, so all +136 added executions pass.
- cmd/bd/doctor full package: identical 6-name failure set at main alone and
  here; RUN 876 -> 896 and PASS 855 -> 875. All six are host-environmental
  (global beads.role=maintainer, a live Dolt server on 127.0.0.1:3307).
- internal/config 398/398, scripts 98 RUN/0 FAIL (including #6482's rewritten
  check_doc_freshness_test.go), gitenv+execenv+githooksenv+gittraceenv 64 RUN,
  internal/git+gitignore 68/68, storage/domain/fs 84/84, dolt credentials 34/34,
  metrics 58/58, drift packages (beads, query, timeparsing, issueops, schema)
  1559 RUN/0 FAIL.
- scripts/check-doc-freshness.sh passes on the merged tree, which clears #6482's
  new duplicate-marker failure mode against the DOCS rows this head touches
  (cmd/bd/main.go, cmd/bd/config.go, cmd/bd/*.go).
- go build ./... exit 0; go vet exit 0 over all 20 changed packages for linux,
  CGO_ENABLED=0 -tags gms_pure_go, and GOOS=windows CGO_ENABLED=0.
- BD_LINT_NEW_FROM_MERGE_BASE=511849496 make ci-pr-lint: gofmt clean,
  golangci-lint 0 issues, golangci-lint (windows) 0 issues. This is the gate a
  never-pushed maintainer fixup otherwise evades entirely.

The base merge is a separate commit below this one so the maintainer fixup stays
a single commit; its tree was verified identical to an independently computed
git merge-tree of the reviewed head and main.

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

* build(bazel): restore the internal/utils debug dep the merge dropped

Merge-queue inference repair for PR #6463 (stop reason ci_repairable).

The three Bazel lanes were red on this PR and green on main -- eight
consecutive successful bazel.yml runs on main, including the tip this branch
merged. The cause is the merge commit 86defb414, not the PR's own change: main
carries "//internal/debug" in internal/utils' go_library deps (added by #6907's
BUILD sync), and this branch's copy of internal/utils/BUILD.bazel still dates
from #6798. The merge kept the branch side and discarded main's newer content,
so the dep row was lost while internal/utils/id_parser.go -- which is on main
and imports internal/debug -- still needs it.

Regenerated with the repository's own `make bazel-sync`; the result is
byte-identical to origin/main's version of the file, and a second sync is a
no-op, so this restores exactly what the merge dropped and nothing else.

Proven by counterfactual: with the row removed, `bazel build
//internal/utils:all` fails with "GoCompilePkg ... compilepkg: missing strict
dependencies" -- the CI failure class -- and with it restored the same command
exits 0 (390 actions). `go build ./...` is clean and `go test ./internal/utils/`
passes.

---------

Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com>
Co-authored-by: Bee <bee@ghosttrack.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-29 13:20:38 -07:00
postoso
9017d33745
feat(count): accept --has-metadata-key (#6282)
bd list, bd ready and bd search all take --has-metadata-key. bd count did
not, so counting the rows that merely carry a key meant listing them and
measuring the page. This is the last metadata-filter parity gap between
count and the listings.

The storage layer already carries the filter: types.IssueFilter has
HasMetadataKey and sqlbuild.AppendMetadataClauses consumes it. What was
missing is the role field, the builder wiring, the CLI flag and the HTTP
contract, so this is one change rather than a stack.

Parsing matches list_input.go and ready_input.go, including the key
validation. BuildCountFilter now passes the key to ValidateMetadataFilters
instead of the empty string it passed before, which makes the role's
existing refusal reachable from the count surface; failReadErr already
classifies that error as a 400 on has_metadata_key.

apigen types are regenerated from the spec via go:generate, not hand
edited. The pinned CLI docs are untouched.

Fixes #6160

Co-authored-by: postoso <postoso@users.noreply.github.com>
Co-authored-by: Gas City Adopt-PR <noreply@example.com>
2026-09-29 13:16:37 -07:00
ecuthiell
8269a88cbf
fix(compact): target external GC at the active database (#6327)
* fix(compact): report active database size (#5619)

Measure legacy admin compact --dolt reporting through ActiveDatabaseSizer so sibling databases cannot distort reclaimed-space numbers. Omit unavailable advisory measurements without blocking GC.

Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com>

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell

* docs(compact): explain the legacy size field names

Keep the existing compact JSON schema distinct from the newer GC helper.
The active external-GC target is addressed by the separate issue6313 leaf.

* fix(compact): select the authoritative local active GC directory

Ask the active storage instance for its optional external-GC directory
capability. Reuse the authority captured at store open, and refuse stale,
unsupported or invalid local targets rather than guessing from a root,
general CLI path or advisory size. Preserve archive-level fallback behavior.

Add native owned-process target and no-launch regressions plus instance
authority tests; retain the parent active-size and legacy JSON contracts.

Fixes #6313

* fix(compact): resolve GC capability through storage decorators

Use the existing storage unwrapping boundary so external GC sees the captured
active database behind the root command's dependency, telemetry and hook
decorators. Cover owned, shared and unsupported stores through the real chain,
and describe the active database in compact help.

Refs gastownhall/beads#6313
Agent: unknown-model/unknown-reasoning

* fix(compact): preserve external GC refusal diagnostics (#6313)

Route all four new target refusals through the standard error/hint formatter
and assert their stderr schema, message, hint and exit status. Preserve the
relative-path refusal and unavailable dry-run target omission. Update the
requested compact and flatten help mirrors without regenerating other docs.

Addresses the diagnostics and documentation review on PR #6327. Existing
PR #5668 ancestry and mandatory parent-first sequencing remain unchanged.

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* docs(compact): align flag help with active GC target (saa-cgh.94)

Authored by /root/cgh86_review; closes the independent root review help finding.

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* docs: retain release-pinned CLI references (saa-cgh.94)

Preserve corrected live compact/flatten help while generated references continue to match docs/cli-docs.pin v1.2.2. Fix the exact six-line hosted docs-policy failure without changing pin authority.

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(compact): classify cancellation before the GC authority refusal

Maintainer review fixes for #6327, review iteration 1. Non-gating findings
only: the synthesis and the quality scorecard both returned approve with no
blocker and no major finding.

Taken:

- Error Handling & Resilience (minor, both lanes). runCompactDolt formatted a
  cancelled or expired context as the permanent "cannot select a local
  database" refusal plus its four-cause hint, and in --dry-run turned it into a
  hard exit-1. Classify context.Canceled/DeadlineExceeded ahead of the
  ErrUnsupported arm and report the interruption instead. The ctx probe stays
  in ExternalGCPath: it is the only cancellation checkpoint before the
  uninterruptible external `dolt gc`, so the finding's other arm (drop the
  probe) would trade a misleading message for launching a multi-minute GC on an
  interrupted command.

- Change Impact / Blast Radius (minor). Document why
  resolveLocalActiveDatabaseDir keeps the cfg.AutoStart conjunct, and make the
  CLI hint name the remedy (`bd config set dolt.auto-start true`) instead of
  only the condition. The offered code arm is declined: AutoStart rides
  resolveAutoStart's own exclusions (forced false for ServerModeExternal and
  under BEADS_TEST_MODE=1), so dropping it widens GC authority - a behavior
  change, not a cleanup.

- Release Safety (minor). Add the three new test files to the gazelle explicit
  go_test srcs lists so this PR's assertions are visible under `bazel test`.
  Verified with `bazel run //:gazelle -- --mode=diff`: gazelle requests none of
  the three, so the rows match its own output. The two rows it still wants are
  pre-existing base drift in unrelated files and are left alone.

- Test Evidence Quality (nit). The two "unsupported ... through decorators"
  rows were measured vacuous for the decorator claim. Pin the refusal's origin
  through ErrUnsupported.Backend ("external" = the active store refused,
  "active store" = the interface assertion missed) and pin the opposite
  polarity on the size-only/locator-only rows. Residual recorded on the test:
  the dry-run decorator row still cannot discriminate, because its benign
  preview is identical for both origins.

Declined, and carried to the human-approval summary:

- Debuggability & Operability (minor, gate impact none). Reusing the `bd gc`
  companions adds production output in an iteration no further review pass
  grades, and the alternative arm would assert the refs are left in place
  "deliberately", which nothing in the change establishes.

- Resource Lifecycle & Cleanup (nit, Required fix: none). exec.CommandContext
  would kill a mid-flight `dolt gc`; that is a data-safety question for the GC
  path rather than a cleanup.

Validation: `go build ./...` and `go vet` on cmd/bd + internal/storage{,/dolt}
clean; scripts/ci/pr-lint.sh against the pinned base green (gofmt,
golangci-lint 0 issues, windows cross-lint 0 issues), proved non-vacuous by a
misspell planted on an added line; 66 PASS / 0 FAIL / 0 SKIP over the covering
cmd/bd selectors. Both new pins are mutation-proved: removing the
classification arm reds exactly the three new cancellation rows and nothing
else, and dropping storage.UnwrapStore now reds three decorator rows where it
previously reddened two. internal/storage/dolt/store.go is comment-only.

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Gas City Merge Queue <merge-queue@gascity.local>
2026-09-29 08:27:43 -07:00
Jones
89348699b0
fix(doltremote): treat s3:// as a native Dolt remote scheme (#5948)
* fix(doltremote): treat s3:// as a native Dolt remote scheme

s3:// URLs previously survived Normalize only by falling through, and the
SCP heuristic treated any "@" in a URL as an SCP-style git remote, so an
s3 URL with "@" in its path or query string would be rewritten into a
bogus git+ssh remote. Add s3:// to NativeSchemes and anchor SCP detection
to inputs without a "://" scheme that match a user@host:path grammar.

* test(doltremote): pin the s3:// entry and the dotless host:pa@th case

Follow-up to the #5948 review. Deleting "s3://" from NativeSchemes made
no test fail, so TestNativeSchemesContainsEachNativeScheme now asserts
every entry the list holds; removing the s3:// line fails its s3://
subtest.

The base change also flipped a fourth behavior its description did not
list: a dotless pre-colon token whose only "@" sits after the colon
("host:pa@th", "alias:repo@v1") used to classify as SCP-style on the
bare strings.Contains(url, "@") check and normalize to
git+ssh://host/pa@th. It now classifies false and passes through
Normalize unchanged. Both inputs are pinned as rows in
TestIsSCPStyleGitURLRejectsNonSCPInputs; against origin/main's
remote.go they fail.

Normalize's doc comment now lists s3:// with the other native schemes.

* build(bazel): add go_test target for internal/doltremote

The PR adds remote_test.go and remote_invariant_test.go to a package whose
BUILD.bazel (added on main by #6798) declares only a go_library. Generated by
bazel run //:gazelle; no hand-written lines.

* fix(doltremote): guard FromGitURL's SCP split, cross-reference the SCP grammars

Maintainer review fixes for the four non-gating findings in the iteration-1
synthesis (0 blockers, 0 majors; quality scorecard 986/approve). The PR's own
fix is unchanged.

Contract fidelity, the one gate-impact-minor finding: FromGitURL is exported and
cmd/bd's gitURLToDoltRemote calls it directly, bypassing Normalize's
classification. Its first-colon split still rebuilt s3://bucket/team@prod/db
into git+ssh://s3///bucket/team@prod/db, the exact string this PR removes from
Normalize. That split now obeys the same "://" rule as isSCPStyleGitURL.

This takes the finding's second offered arm over its first. Gating on
isSCPStyleGitURL(url) instead changes 17 of 31 inputs across the package's own
corpus, against 9 for the "://" guard; the 8 extra are the SCP hosts that
predicate deliberately declines to classify - IDN hosts, non-ASCII userinfo and
dotless aliases - which FromGitURL converts correctly today.
TestFromGitURLStillConvertsSCPForms pins them, and mutating to the rejected arm
reds exactly those three rows while the new regression pin still passes.

NativeSchemes: the finding's "add az:// and oci:// for consistency" arm is
declined and the documentation arm taken instead. The PR body scopes this change
to s3:// and defers az:// to #6227 explicitly; #6227 is open, and it pairs
NativeSchemes with dolt.IsBackupURL - the site where the gap actually changes
behavior - so adding the entry here would have overridden a tracked contributor
decision while closing only half the bug. oci:// is in neither authority's
native list. The list's doc comment now records that narrowing, points at
remotecache.remoteSchemes as the fuller authority, and states that membership is
inert: every entry contains "://", so isSCPStyleGitURL rejects it and
Normalize's closing "return url" returns the same bytes listed or not. Dropping
gs:// reds one census leaf and no behavioral test, which measures that claim
rather than asserting it. The new FromGitURL table covers az:// and oci://
precisely because the guard is keyed on "://" and not on list membership.

Duplicate SCP grammar: scpStyleGitURLPattern's first alternative is
byte-identical to remotecache.gitSSHPattern, and the whole pattern is a superset
by exactly the user-less dotted-host form - the form on which the two already
disagree in production. Both regexes now cross-reference each other and the
divergence is pinned from each side. Exporting a shared matcher was the other
offered arm; it would have widened remotecache.IsRemoteURL's accept set, a
behavior change in a second package for a non-gating finding.

normalizeRemoteURL's doc comment restated Normalize's rules and had drifted
twice: it never gained s3://, and it named gitURLToDoltRemote as the converter
when the body calls doltremote.Normalize directly. Collapsed it to a reference
so the surface cannot drift again.

Codex's prescribed remedy for the hollow NativeSchemes census subtest is
declined, as the synthesis directs: asserting Normalize(scheme+"bucket/x") per
scheme passes against an empty list, for the same inertness reason above. The
subtest's comment, which claimed to protect a fast path it cannot observe, is
corrected instead.

go test ./internal/doltremote/ ./internal/remotecache/ green; cmd/bd named
selector 56 pass, 0 fail, 0 skip; go build ./..., go vet and gofmt clean; bazel
test passes on both packages; gazelle and go_srcs.py --check report no BUILD
drift.

---------

Co-authored-by: Julian Knutsen <julian@gastownhall.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-29 06:28:57 -07:00
Jim Wordelman
ba1e542299
test(dolt): make git-protocol CLI/SQL routing and Pull's silent-staleness failure mode observable (#5955)
* test(dolt): red — Make git-protocol CLI/SQL routing and Pull's silent-staleness failure mode observable (refs be-9i0yq.2)

Adds TestPushPullLogSQLRouteForFileRemote and
TestPushPullLogCLIRouteForGitProtocolRemote, asserting Push/Pull log which
route (CLI vs SQL) they took. Neither asserted log substring exists anywhere
in store.go today (confirmed via grep) and pushToRemote/pullTransportReporting
currently make zero log calls, so these assertions would fail under current
code.

Live RED verification (running the suite and observing an actual failure) is
blocked in this sandbox: the Dolt SQL server is unavailable due to a known,
already-escalated Docker/containerd content-store corruption issue (mayor
escalation gm-wisp-aa7x7w), so skipIfNoDolt(t) skips both tests before
reaching their assertions rather than failing them. Substituted: static
compile and vet checks both clean, plus a manual trace confirming zero
existing route-logging output for these functions.

* feat(dolt): green — log push/pull CLI-vs-SQL route decisions (refs be-9i0yq.2)

pushToRemote and pullTransportReporting each pick between a dolt CLI
subprocess and an in-process SQL call across several routing gates
(git-protocol, credentials, cloud-auth, local-remote for push), but which
route a given call actually took was only recoverable by reading source.

Add logRouteDecision, called at each CLI return point and once for the
shared SQL fallback in both functions, so `dolt push route: CLI|SQL
(remote=...)` and the pull equivalent are always in the log.

Verified via `go build`/`go vet` (clean) and a scratch unit test asserting
logRouteDecision's exact output against all four RED-test substring checks
(deleted before commit, not part of this changeset). Live RED/GREEN
execution of route_logging_test.go itself still SKIPs in this sandbox
(Dolt SQL server unavailable via Docker), so the hard gate is substituted
per the same transparency already recorded on the RED step: build+vet
clean, scratch-verified helper output, and a full internal/storage/dolt
regression run showing zero new failures beyond the known pre-existing
TestWispSeesCustomTypeRegisteredInTransaction port-conflict.

# guard-ack:bd-build-migrates-store

* test(dolt): fix CLI-route logging test's self-skip construction defect (refs be-9i0yq.2, review be-j7eon)

TestPushPullLogCLIRouteForGitProtocolRemote used plain New(), which in this
harness resolves to a client of the shared containerized test server
(testmain_test.go) rather than a store with its own local .dolt directory.
CLIDir() and hasCLIDatabase() were therefore always empty/false, so the test
always hit its own skip branch and never exercised CLI routing at all.

Move it into a new integration-tagged file and give it its own local
dolt sql-server via startLocalDoltServer, the same arrangement
TestGitRemoteEmbeddedPushPull uses, so the store has a real on-disk
CLI-accessible database. Confirmed the test now runs (not skips) and
passes, asserting the CLI-route log lines it always meant to check.

TestPushPullLogSQLRouteForFileRemote is untouched and keeps its original
build classification (no integration tag) since it works correctly as-is
against the shared test server.

* chore: release gate PASS for be-j4oer (git-protocol route logging + pull-staleness observability)

Review: be-5u36o (PASS). Deploy bead: be-j4oer.

* fix(dolt): route the push/pull route line through the gated debug sink

logRouteDecision used log.Printf, which is unconditional stderr with the
stdlib timestamp prefix. Unlike the three other log.Printf calls in this file
-- all warnings on exceptional paths -- this one fires on every push and every
pull, so it would have put a line in front of every user on every operation,
including under --quiet. debug.Logf is the gated sink for exactly this and was
already imported; under BD_DEBUG or -v the line stays as discoverable as it
was. Note debug.Logf does not append a newline, so the format string carries
one.

Both route-logging tests captured the process-global log writer to observe it.
They now use a shared captureRouteLog helper that enables the debug sink and
captures os.Stderr, which also removes the log.SetOutput mutation the review
flagged as a hazard next to this package's seven t.Parallel files. The helper
and both call sites carry an explicit must-not-become-parallel note, since it
still touches two process globals (os.Stderr and debug's verbose flag). The
t.Fatalf calls moved out of the captured closure: t.Fatalf runs Goexit, which
would have skipped the os.Stderr restore and left the pipe installed.

Red/green against a live dolt-sql-server: with log.Printf restored the SQL
route test FAILs with an empty capture, because the log package holds the
os.Stderr it captured at init and never sees the swap; with debug.Logf it
PASSes in 5.13s. The test therefore gates the sink rather than passing either
way. (refs be-j4oer)

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

  release-gates/be-j4oer-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

* chore(bazel): enumerate route_logging_test.go + //internal/debug dep (make bazel-sync)

Generated by `make bazel-sync` (bazel run //:gazelle) at the adopted head.
Base landed internal/storage/dolt/BUILD.bazel and the advisory Bazel lane
(.github/workflows/bazel.yml, #6881) after this PR was written, so the PR
adds an untagged test file to a package whose go_test srcs are an exhaustive
enumeration (207 enumerated == 207 untagged on disk at base; the 15 unlisted
files are all //go:build integration).

Without this, `bazel test` fake-greens ("Executed 1 out of 1 test: 1 test
passes" while test.log says "no tests to run") and two steps of the Bazel
workflow red: the Go-test-equivalence check (a test go test runs that Bazel
did not) and the BUILD-files-in-sync check.

route_logging_integration_test.go is correctly left unenumerated: it carries
//go:build integration, matching base parity for all 15 such files.

* review(dolt): scope the route-log doc comment and harden captureRouteLog cleanup

Maintainer review fixups for PR #5955 (iteration 1). Both are non-gating
minor/nit items from the review synthesis; no blocker or major was filed.

logRouteDecision's doc comment claimed "This fires on every push and every
pull". It does not: the federation peer plane makes the same CLI-vs-SQL
decision at six sites in federation.go (pushRefToPeer :43,:51,
pullFromPeer :108,:119, Fetch :174,:183) and logs nothing, so a debugger
following the new lines could read peer silence as "no peer transfer
happened". Scope the comment to the main-remote plane and name the
uninstrumented sibling. Instrumenting the peer plane itself is deliberately
left as a follow-up rather than widening this PR's blast radius.

The same comment said "three remaining log.Printf calls in this file"; there
are five (store.go:1333, 3824, 4178, 4237, 4727), all still exceptional-path
warnings, so the argument holds and only the count was wrong. Dropped the
numeral rather than correcting it, since it rots on every unrelated edit.

captureRouteLog restored the process-global os.Stderr inline after fn()
returned. A future fn that panics or reaches t.Fatalf (runtime.Goexit) would
skip that restore and leave os.Stderr pointed at a pipe nobody drains,
silently swallowing every later test's output in the package. Register the
restore via t.Cleanup as well, keeping the inline drain for the happy path.

Comment-only in store.go; no behaviour change and no signature change, so
BUILD.bazel needs no regeneration. Verified: gofmt clean, go build and
go vet clean under both the untagged and integration tag sets, and
go test -tags integration -run TestPushPullLog ./internal/storage/dolt/
gives 2 RUN / 2 PASS / 0 FAIL / 0 SKIP.

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

* chore(bazel): enumerate route_logging_integration_test.go for the merge-target gazelle convention

The base advance since this PR was adopted changed the root BUILD.bazel
gazelle directive from

  # gazelle:build_tags gms_pure_go
to
  # gazelle:build_tags gms_pure_go,integration

(the bazel integration-tag lane work, #6916 and siblings). Under the old
directive gazelle deliberately omitted //go:build integration files from
go_test srcs -- at the adopted base internal/storage/dolt enumerated 207
of 222 on-disk test files, the 15 omissions all integration-tagged -- which
is why the earlier bazel fixup (c79777b) correctly listed only
route_logging_test.go and why a134bf45's "BUILD.bazel needs no
regeneration" was true when written. Both remain true at that base; this
commit is a consequence of the base moving, not a correction of either.

At the merge target the convention is inverted: internal/storage/dolt
enumerates 226 of 226 on-disk test files including all 16 integration-tagged
ones, and `make bazel-sync` on origin/main alone rewrites nothing. Merging
this PR as-is therefore leaves route_logging_integration_test.go as the only
unenumerated test file in the package.

Measured on the merged tree (merge-tree of origin/main e1b2e79 with the
adopted head, materialized in a scratch worktree), running bazel.yml's
"BUILD files in sync" step verbatim -- `make bazel-sync-check`,
`make bazel-sync`, `git status --porcelain --untracked-files=all` -- yields
exactly one drift row, `M internal/storage/dolt/BUILD.bazel`, whose diff is
the single line added here. That step exits 1 on any drift, and pr.yml's
ci-gate lists BAZEL, BAZEL_TEST, BAZEL_PURE, BAZEL_EMBEDDED,
BAZEL_DOLTSERVER, BAZEL_PROXIED and BAZEL_SERVER_STORAGE in
CI_GATE_REQUIRED, so the drift would fail a required context rather than an
advisory lane (scripts' TestBazelWorkflowIsAdvisory no longer exists at the
merge target).

The added line is byte-identical to gazelle's own output at the merge
target, in gazelle's sort position. No Go source, no build tag and no
dependency changed, so the go_test deps list is untouched.

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

---------

Co-authored-by: Julian Knutsen <julian@gastownhall.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-29 06:27:10 -07:00
Athos Bernardes
ff3a6e050d
test(dolt): prove bd create rolls back fully on label-event failure (ga-xcq1ph) (#5989)
* test(dolt): prove bd create rolls back fully on label-event failure (ga-xcq1ph)

ga-xcq1ph reported that, under real Dolt write contention, `bd create` with
multiple labels printed an error naming a generated issue ID ("failed to
record label event ... context canceled / transaction has already been
committed or rolled back") and that ID never persisted. The open question was
whether this is silent partial persistence or a fully-rolled-back transaction
whose error text happens to mention the doomed ID.

TestCreateIssueRollsBackFullyOnLabelEventFailure deterministically injects
the exact failure shape (a label's "Added label" event insert returning
context.Canceled) into a real Dolt transaction, without racing a wall-clock
timeout against a live contention window, then rolls back exactly as
DoltStore.withWriteTx does on any callback error. It confirms the issue, its
first label, and its events all fail to persist -- and, sabotaged locally to
commit instead of rollback, the same test correctly fails, proving the
assertions are not vacuous.

Combined with reading the call chain (cmd/bd/create.go -> ops.Create ->
issueOperations.Create -> withRetryTx -> withWriteTx), this rules out silent
data loss: withRetryTx's error classifiers (isDoltAutocommitRollbackError /
isSerializationError / isRetryableError) never match context.Canceled, so the
failure surfaces once as a real error with exit code 1, nothing printed as
"created". No production code changes -- this closes a real gap in coverage
(no existing test exercised a mid-transaction failure during PersistLabels)
without changing any behavior.

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

* test(dolt): reproduce sql.ErrTxDone from a real mid-tx context cancel (ga-xcq1ph)

Addresses PR review feedback from bee-ghosttrack (2026-09-03,
MERGE-AFTER-FIXES verdict):

1. Reword the existing test's doc comment: it "mirrors" withWriteTx's
   rollback behavior by hand, it does not exercise the wrapper itself.

2. Add TestCreateIssueRollsBackFullyOnContextCancelMidTransaction. The
   existing test's injected context.Canceled never reaches the real
   transaction, so it can't reach the state where partial persistence
   would actually be conceivable: database/sql's own background
   awaitDone goroutine tearing the transaction down on its own after a
   real context cancellation, racing the caller's own Rollback(). That
   race is what produced the original report's second error --
   sql.ErrTxDone ("transaction has already been committed or rolled
   back") -- and it's a materially different state than a manually
   rolled-back, still-alive transaction.

The new test cancels a real, BeginTx-scoped context mid-transaction,
polls for sql.ErrTxDone to confirm the background rollback actually
completed, confirms the follow-up Rollback() call reproduces the
original error text verbatim, and re-queries on a fresh connection
(store.db, not the dead tx) to prove this state also rolls back
cleanly with no partial persistence.

Verified locally against a throwaway native dolt sql-server (this
machine has no Docker for the repo's testcontainer harness): both
tests pass, and disabling the new test's cancel trigger makes it fail
on the expected assertion -- confirming it isn't vacuous.

* chore(dolt): bazel srcs for create_rollback_test.go + correct its withWriteTx citations

Maintainer fixup for PR #5989 (fork branch; contributor commits untouched).
Two parts.

1. internal/storage/dolt/BUILD.bazel, generated by 'bazel run //:gazelle'.
   The PR adds an untagged test file; the package's go_test srcs list is
   enumerated exhaustively (226 entries before this change, 227 after, which
   is every *_test.go on disk in the package at this base), so without this
   the new tests are invisible to Bazel. Commit 6da2a4347 (#6881) added
   .github/workflows/bazel.yml, whose tools/bazel/equivalence.py step fails on
   any Go test that 'go test' runs and Bazel did not, and whose
   'make bazel-sync' step fails on BUILD drift. Fork PRs run that lane.

2. create_rollback_test.go, comments only -- review iteration 1's one minor
   and one nit, both non-gating (synthesis and scorecard both approve).
   - Three comments cited store.go:1195 as the home of
     errors.Join(err, tx.Rollback()). That line sits in withRetryTx's backoff
     configuration; the join is in commitWriteTx, which withWriteTx delegates
     to. Now cited by symbol rather than line number, so the citation cannot
     drift again.
   - The comments described the hand-rolled BeginTx + manual tx.Rollback() as
     "exactly what withWriteTx does". Narrowed to say which half is mirrored
     and which is not: commitWriteTx installs three transaction-scoped
     activations before invoking the callback
     (scopeEventsJournalTransaction, scopeVersionedHistoryTransaction,
     issueops.ScopeBlockedRecheckTransaction) and runs a post-commit blocked
     recheck on the success path. An unregistered tx journals nothing
     (journalEnabled defaults to false for a tx absent from the scope map), so
     the comments now record that adding a bd_events_journal or issue_versions
     cleanliness assertion to this shape, or moving the injection point
     downstream of those seams, would pass vacuously. Driving the real wrapper
     is left out deliberately in test 2, whose subject is database/sql tearing
     the transaction down independently of any wrapper.

Part 2 changes no code: comments only, no production or test behavior change.

Verified at this tree (rebased onto cda2407115): gofmt clean; git diff --check
clean; go vet ./internal/storage/dolt/ exit 0, and again under CGO_ENABLED=0
and GOOS=windows CGO_ENABLED=0; the BUILD.bazel line reproduced by deleting it
and re-running 'make bazel-sync', which restored the file to the byte-identical
blob e5f4157bbd with no other drift in the tree; and both tests pass against a
live Dolt server -- 2 PASS / 0 FAIL / 0 SKIP, ok ... 20.869s.

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Julian Knutsen <julian@gastownhall.com>
2026-09-29 04:45:12 -07:00
Jim Wordelman
9b215a40eb
fix(storage): widen schema-init timeout headroom for migrating-store-open tests (#5999)
* test(dolt): red — flaky: TestCrossProject_* fail with 'schema init: context deadline exceeded' under host load (refs be-696w)

* feat: green — flaky: TestCrossProject_* fail with 'schema init: context deadline exceeded' under host load (refs be-696w)

* docs(dolt): state the package-wide cost of raising testTimeout

Review #5999: "this isn't a two-test change ... please say that in the
constant's comment."

Measured on this branch: testContext is called from 125 files in the
package, and testTimeout is multiplied at 13 5*testTimeout sites — all
dropCtx database-drop cleanups, in initschema_pool_poison_test.go,
schema_version_test.go, schema_skew_test.go, remote_migrate_gate_test.go
and smart_remote_migrate_gate_test.go. 45s to 90s takes those from 225s to
450s, so a genuinely hung drop reports in 7.5 minutes rather than 3.75.

States that as the accepted trade rather than leaving it implicit, and
names the alternative (give schema init its own bound) so a future reader
lowering this constant back knows what to do instead.

Comment-only; no behavior change. TestSchemaInitTimeoutHasLoadHeadroom
still passes, vet clean.

Refs be-1nl2h.

* test(dolt): maintainer adoption fixes for #5999

Bazel: list schema_init_timeout_test.go in the dolt go_test srcs, so
`bazel test //internal/storage/dolt:dolt_test` actually runs the PR's
regression guard. The srcs list is enumerated explicitly and was
exhaustive for untagged tests at the base, so without this line bazel
reports PASSED while selecting none of the PR's tests.

Review fixes (attempt 1 — synthesis minor + nit, both non-gating):

- dolt_test.go: the testTimeout cost disclosure stated hard counts (125
  caller files, 13 `5*testTimeout` sites, 5 named holder files) that
  were exactly right at the contributor's merge base and went stale
  across the ~210-commit base advance. Measured at this head they are
  133 / 16 / 7 — every count wrong in the understating direction, i.e.
  the disclosure undersold the exact cost it exists to make visible.
  The two unnamed holder files (shared_store_migrate_gate_test.go,
  smart_gate_data_behind_test.go) account for exactly the +3 and carry
  the same dropCtx shape, so only the enumeration was stale, not the
  characterization. Replaced the literals with the grep that
  reproduces them rather than re-pinning numbers that already decayed
  once. The derived arithmetic (225s->450s, 3.75->7.5 min) is
  base-independent and is left unchanged.

- schema_init_timeout_test.go: cite the sizing rule so the 90s floor is
  derivable rather than folkloric. The caller's budget must cover cold
  server start, the Ping, the schema-init retry wrapper's full
  serverRetryMaxElapsed (30s) and one migration pass — and that wrapper
  cannot absorb its own exhaustion, because
  initSchemaOnDBWithRetryAndGateBootstrapHeal composes its backoff with
  backoff.WithContext on the caller's context. Same sizing rule
  initschema_multiprocess_test.go documents for its own ctx.

Both review edits are comment-only; no code, test or assertion changed.

Declined the nit's optional rename of TestSchemaInitTimeoutHasLoadHeadroom:
the stamped 2-arm mutation proof and the banked CI green both identify
that test by name, so renaming it would invalidate the only executed
by-name evidence this PR has, for a naming preference the reviewer
itself marked optional.

---------

Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
2026-09-29 04:04:13 -07:00
Julian Knutsen
cda2407115
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>
2026-09-29 03:07:09 -07:00
Julian Knutsen
51a7c8e324
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>
2026-09-29 02:26:09 -07:00
Julian Knutsen
2bb5337355
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>
2026-09-29 02:10:46 -07:00
Julian Knutsen
d803ec9126
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>
2026-09-29 01:48:15 -07:00
seanmartinsmith
8870c6866d
fix(prime): describe the memory split instead of prohibiting MEMORY.md (#6111)
* fix(prime): describe the memory split instead of prohibiting MEMORY.md

The memory guidance predates harness-native auto memory, whose index file
is also named MEMORY.md and is machine-local rather than the multi-account
fragmentation case the line was written against. As written it tells agents
to file per-operator content in the shared, replicated store - the one place
it does not belong.

Rewrite the four renderings of that sentence to describe the split the two
stores actually have: durable project facts in `bd remember`, per-operator
preferences in the harness's own memory. The fragmentation warning stays,
pointed at the case where it is true.

Refs #5169

Executed-By: pc

* fix(prime): bring the codex template in line, add CHANGELOG entry

Review on #6111 found a fifth rendering of the prohibition:
internal/templates/agents/defaults/beads-section-codex.md:19 says
"do not create ad hoc memory files" without the literal MEMORY.md, so the
grep that scoped the first commit missed it. It ships through bd init for
the codex harness, the same re-introduction path the minimal template was
included for. Reword it to the same split.

Add the CHANGELOG entry under Unreleased / Changed, matching #6011.

Refs #5169

Executed-By: mac

* fix(prime): pin the memory-guidance invariant, drop the storage claim

Maintainer review fixes for the adoption of #6111, iteration 1. Both items are
non-gating (scorecard 981/approve, no blocker or major); they are taken because
the rebased branch needs a maintainer push either way.

Test Evidence Quality (minor): nothing asserted that the four renderings had
stopped prohibiting the harness's own MEMORY.md. The only pin on these bodies
was a presence check for `bd remember`, which passed identically before and
after the rewording, so re-introducing the prohibition at any one site would
have left every test green. Added negative assertions to
TestRenderSectionMinimal and TestCodexSectionBody, plus
TestPrimeMemoryGuidanceDoesNotProhibitHarnessMemory covering both the CLI and
MCP renderings. Asserting the absence of the old prohibition, rather than
pinning the new prose, keeps the guard valid under any future rewording.

The review prescribed `!strings.Contains(body, "MEMORY.md")` at every site. That
is vacuous for the Codex body, which spelled its prohibition "do not create ad
hoc memory files" and never named the file (0 occurrences at ae1a493e0), so that
site asserts both spellings.

Measured, not assumed: restoring all three rendered surfaces to their
upstream-base blobs reds exactly the new assertions -- templates 31 PASS /
2 FAIL, the Codex failure on "ad hoc memory files" and not on MEMORY.md, and
both subtests of the prime pin -- while every incumbent stays green. That same
revert was fully green before this commit.

Debuggability (nit): the full rendering ended "they aren't project knowledge and
beads doesn't store them", which states a capability (`bd remember` will in fact
persist any string handed to it) rather than the intended policy, and was the
odd one out among the four surfaces. Reworded to "so keep them out of beads"
rather than the suggested "so don't put them here": in the rendered text "here"
has no antecedent, and the nearest location named is the harness's own memory,
which would invert the sentence.

Validation: gofmt clean, go build ./... exit 0, go vet clean on both packages,
golangci-lint 2.10.1 reports 0 issues, internal/templates/agents 33P/0F/0S,
prime run-set green.

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

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-29 01:23:19 -07:00
Julian Knutsen
c4b1cb699d
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>
2026-09-29 01:08:10 -07:00
Julian Knutsen
e7138e93af
ci(bazel): server-Dolt storage and proxied tiers on remote execution (#6940)
* test(integration): let SubprocessRunner reuse a prebuilt test binary

BEADS_TEST_SUBPROCESS_BINARY hands SubprocessRunner an already-built test
binary of the package instead of running `go test -c`, which no Bazel
action can do offline (it needs the module source tree and module cache).
A Bazel target passes the running go_test itself: the helper tests
(TestHelperSchemaInit, TestHelperMultiStore) live in the same package.
Unset, behavior is unchanged.

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

* test(dolt): keep a lane's REQUIRE switch out of the leak-probe child

TestSuiteFixtureLeakFailsOwningSuite re-runs the suite with
BEADS_TEST_SKIP=dolt on purpose. When the parent runs under
BEADS_TEST_REQUIRE_DOLT_CONTAINER=1 (a fail-closed server lane), the child
inherited it and TestMain exited FATAL before the leak sweep the test
checks. Clear it in the child like the other suite-scoped variables.

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

* feat(bazel): proxied-server and server-Dolt storage tiers (D6d, D6e)

PR Risk's "Test (Proxied Dolt Cmd N/15)" (also main.yml's) and "Test
(Server Dolt Conformance)" / "Test (Server Dolt Full Suite N/16)" as
Bazel variants against local dolt sql-servers (internal/testutil local
backend, pinned dolt from the test wrapper), fail-closed like the
dolt-server lane:

- //cmd/bd:bd_proxied_test: 15 shards; shard k runs the job's
  proxied-test-shard.sh k+1 15 through go_test_manifest_shard.sh over the
  race bd_test, non-race bd_for_tests as the subprocess bd,
  BEADS_TEST_PROXIED_SERVER=1, GOMAXPROCS=4. Tag dolt-server-proxied,
  --config=doltserver-proxied (the doltserver lane's build).
- //internal/storage/dolt:dolt_server_{conformance,full}_test over
  dolt_race_off (go_test_race_off of dolt_test: the jobs' binary is not
  race); the full suite runs server-storage-test-shard.sh k+1 16 with
  BEADS_TEST_ENV_RUN_DOLT=1 and hands SubprocessRunner its own binary.
  Tag dolt-server-integration, --config=doltserver-integration, whose
  build flags are exactly --config=integration's, so the tier shares that
  lane's compile (race-off deps land where bd_for_tests already is)
  instead of compiling the tagged graph a third time.
- dolt_test gains //internal/storage/schema:migrations as data (the
  PR4107/migration replay tests read ../schema/migrations).
- test_env.sh: BEADS_TEST_GIT_IDENTITY=1 writes the jobs' global git
  identity ("Configure Git"); the git-remote tests commit in fresh repos.
- Both tags join the taxonomy and bazelPRCoreExcludedTags, so prcore/ci
  and integration exclude them.

Per-shard names and statuses equal a replay of the jobs' commands
(container backend) for all 32 jobs.

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

* ci(bazel): run the proxied and server storage tiers remotely (advisory)

bazel-doltserver gains a second, remote-only step, `bazel test //...
--config=doltserver-proxied` (15 shards of ~5-10 min with a busy dolt
sql-server each do not fit a GitHub-hosted runner; forks and rbe=off keep
the local lane unchanged). bazel-integration gains `bazel test //...
--config=doltserver-integration`, which shares its build flags, so the
server storage tier compiles nothing the integration step has not. Both
steps write their own BEP, run check_testcases.py on it, run even when the
job's first test step failed, and upload logs on failure.

Policy (TestBazelDoltServerTiersMirrorPRRisk): each variant runs its jobs'
shard script with their shard total and has script + manifest in data;
the conformance variant passes the job's flags; the jobs' race/non-race
binaries and switches (BEADS_TEST_PROXIED_SERVER, BEADS_TEST_ENV_RUN_DOLT)
match; doltserver-integration's tags and race equal --config=integration's;
the steps are pinned to their jobs. checkDoltServerRules now holds all
three dolt-server lane tags to the local-backend, fail-closed,
remote-capable rules.

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

* ci(bazel): run the proxied and server storage tiers in jobs of their own

Review of D6d/e: as steps of bazel-doltserver and bazel-integration the
tiers inherited those jobs' gating (a caller switching the integration
lane off would drop PR Risk's PR-time server tier; a gate requiring the
dolt-server lane would silently require the proxied tier too) and
lengthened their critical paths.

bazel-proxied (--config=doltserver-proxied, 15 shards) and
bazel-server-storage (--config=doltserver-integration: conformance + 16
shards) are remote-only jobs that need only rbe, each with its own BEP,
check_testcases.py step and log upload, 25-minute test step inside a
30-minute job. bazel-doltserver and bazel-integration are back to their
previous content, including the dolt-server step's 80-minute timeout for
local runs. The server tier shares bazel-integration's compiles through
the remote cache (same build flags).

The proxied tier mirrors PR Risk's race bd-cmd-test; main.yml's twin
job runs build-artifacts' non-race one, so Bazel is the stricter of the
two. Comments now say so, and the policy test pins main.yml's build so a
change there is noticed. Policy: the new jobs are pinned (command,
config, remote-only if, BEP + testcase steps, timeouts, log upload), and
no tier step may run in bazel-integration or bazel-doltserver.

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

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 23:01:40 -07:00
Julian Knutsen
73018a69eb
fix(dolt): publish the blocked-state recheck after its transaction commits (#6876)
* fix(dolt): publish the blocked-state recheck after its transaction commits

Post-merge review of #6719 (landed 511849496..1ed5b3330) raised two majors
against the post-commit blocked-state recheck. Both are fixed here.

1. Publication ordering. recheckBlockedAfterCommit minted its Dolt commit
   with doltAddAndCommitInTx while its own recompute transaction was still
   open. That helper's doc block declares the ordering a live
   production-observed lost-update hazard (LatentLabsSpace/NEXUS#92):
   DOLT_ADD stages the whole table from the session's BEGIN-time root, so
   the minted commit writes every concurrently committed row in the staged
   tables back to its BEGIN-time value. The recheck is the worst possible
   adopter, because it runs precisely and only when concurrent unblocking
   writes are racing on issues. It now mirrors
   runIssueOperationTxWithMessage: the recompute runs alone inside
   withRetryTx, its IssueRowsChanged verdict is captured by plain
   assignment, and doltAddAndCommitPostTx publishes after the SQL
   transaction has committed, against the post-merge root. A failed
   trailing commit is accounted like that path's — post_tx_commit_dropped
   plus a log line — and not as a recheck failure, because the flag repair
   itself is committed and durable, so telling an operator the rows may be
   stale and prescribing `bd recompute-blocked` would be false.

2. Test evidence. The wiring from a committed public write to the
   post-commit recheck had no regression pin on either tier: deleting both
   Dolt runner tails left the whole TestCloseRecheckBlocked suite green,
   because those tests either call recheckBlockedAfterCommit themselves or
   take the pending set out of the transaction before the runner can.
   TestCloseRecheckBlocked_RunnerTailRechecksACommittedWrite now drives the
   race through withRetryTx and withWriteTx, one arm each (they carry
   separate tail calls), and asserts the dependent settles with no help
   from the test; each arm reads the dependent's flag inside the write's own
   transaction first, so a collapsed race window fails loudly instead of
   passing vacuously. TestEmbeddedBlockedRecheckSettlesWhatTheWriteRecorded
   does the same for withConn's tail on the serialized embedded tier,
   leaving the pending set in the transaction for the store to take.

   That embedded pin needed a second pass: its first form asserted on
   types.Issue.IsBlocked, which GetIssue never hydrates — is_blocked is not
   in sqlbuild.IssueBaseColumns — so the assertion could not fail and the
   arm survived deleting the tail. It now reads the stored flag through
   embeddedIsBlocked. The pre-existing "graph ends settled" assertion in
   the sibling test had the same defect and is fixed the same way, with its
   comment corrected to say what it actually pins (the in-transaction
   recompute, since each write there takes its own pending set).

The ordering itself cannot be pinned behaviorally — the hazard needs a
writer that commits inside the recheck's own transaction window, and no
seam exposes it — so it gets a structural guard in the shape the journal-
and version-scope completeness guards already use, with liveness anchors so
a rename cannot turn it into a tautology. Restoring the in-tx ordering
leaves every behavioral test in the package green and reds only that guard,
which is why it is here.

Mutation evidence for both pins, re-measured for this push. Deleting all
three runner tails (both Dolt, plus embedded withConn) reds exactly the two
new tests — both arms of the Dolt one at close_recheck_blocked_test.go:240,
and the embedded one at blocked_recheck_internal_test.go:180 — and nothing
else in either package. Restoring the in-tx publication ordering reds only
TestPostCommitRecheckPublishesOutsideItsTransaction.

The non-gating disclosure corrections the same review raised ride the next
commit. The rest — a recheck-scope completeness test, noteBlockedRecheck on
the sibling in-transaction recomputes, and routing
RemoveDependencyWithOptions through withRetryTx — stay out of this PR and
are tracked as beads.

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

* docs(blocked-recheck): correct the residue claim and the out-of-scope list

Three non-gating items from the same post-merge review of #6719, all
disclosure rather than behavior.

blocked_recheck.go's package doc claimed the writes it does not record can
at worst leave a dependent "flagged ready while blocked". A sibling comment
two files away refutes that universal: addDependencyInTx documents that
parent-child adds are not monotonic, because adding an already-closed child
can satisfy an any-children waits-for gate. So an add of a still-open child
racing the close of that child strands the waiter in the other direction —
flagged blocked while ready and hidden from `bd ready`, which is the #6716
shape the recheck exists to fix, reached through `bd dep add` or
`bd create --parent`. The doc now states both directions. Recording the add
paths is the code fix, and it stays tracked separately.

The CHANGELOG's list of writes that still need the `bd doctor` /
`bd recompute-blocked` repair named `bd batch`, `bd cook`, `bd mol squash`,
`bd mol burn`, `bd duplicates --merge` and the wisp writes, but not the
proxied-server route: under `--proxied-server` the ordinary single verbs are
served by the uow provider (`bd close` reaches runCloseProxiedServer and its
BatchCloser), and no uow write is scoped. A proxied-mode operator reading
that list would have concluded their plain `bd close` races were fixed. The
code doc already disclosed this correctly; only the user-facing text did not.

closeIssueInTx hand-concatenated its recheck label instead of calling
statusChangeRecheckLabel, which exists so that a close through update and a
close through CloseIssue mint the same message. The helper returns the
identical string for the closed status, so no recheck commit message moves —
close_recheck_blocked_test.go:129 and :242 still assert the same text and
still pass.

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

* build(bazel): add the recheck publication guard to the dolt_test srcs

The post-merge review of #6719 found that this PR's own new test file,
internal/storage/dolt/blocked_recheck_publication_test.go, never reached
the go_test(name = "dolt_test") target. That target uses a gazelle-managed
explicit srcs list -- it names close_recheck_blocked_test.go and
journal_scope_completeness_test.go -- and the new file was missing from it,
so `bazel test` silently skipped the only pin on the ordering half of the
finding-1 fix.

Nothing caught it. The package's go_srcs filegroup is a glob(["**/*.go"]),
and `make bazel-sync-check` (tools/bazel/go_srcs.py --check) plus
scripts/bazel_policy_test.go only ever compare those glob filegroups, never
a go_test srcs list, so the sync check stays green while the target drops
the file. The glob filegroup sitting next to the explicit list is a decoy:
`bazel query 'kind("source file", deps(...))'` also reports the file as
present through it, and only `labels(srcs, //internal/storage/dolt:dolt_test)`
distinguishes the two -- that query returns the file with this line and
returns nothing without it.

Generated with `bazel run //:gazelle` and reduced to this PR's own file.
The same run also wants to touch twelve other BUILD.bazel files and to add
cli_mirror_ref_test.go to this same list; all of that drift reproduces
byte-identically from this branch's base commit with no part of this PR
applied, so it belongs to whoever landed those files, not here.

//internal/storage/dolt:dolt_test builds with the entry added, so the file
needs no new dep -- journalscan was already in the target's deps.

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

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-28 21:20:51 -07:00
Julian Knutsen
90b84ea150
ci: auto-push Bazel BUILD sync fixes to PRs; harden docs autofix (#6907)
* ci(bazel): auto-push `make bazel-sync` fixes to PR branches

bazel.yml's BUILD sync step now writes the BUILD.bazel / MODULE.bazel /
MODULE.bazel.lock part of its drift as the bazel-sync-patch artifact
(scripts/ci/bazel-sync-patch.sh) and still fails. The new bazel-autofix.yml
workflow_run job (on "Bazel" and "PR") applies it with
scripts/bazel-autofix-push.sh: a sync commit on same-repo PR branches, an
idempotent apply-recipe comment on fork PRs.

Same security model as docs-autofix: the write-permission side never checks
out or runs PR code, extracts only the two expected regular files, and
refuses any patch naming a path outside an anchored allowlist (no hidden or
`..` segments, nothing under third_party/) or carrying a mode change,
symlink, rename or binary hunk; `git apply --index` and a post-apply check
back that up. Reuses the DOCS_AUTOFIX_TOKEN secret for the push.

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

* build(bazel): add bazel_autofix_push_test.go to scripts_test

`make bazel-sync` output, produced by scripts/ci/bazel-sync-patch.sh and
applied with scripts/bazel-autofix-push.sh as an end-to-end exercise of the
new autofix path.

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

* fix(ci): harden the bazel and docs autofix push scripts

Addresses the security review of the autofix pipeline, identically in
scripts/bazel-autofix-push.sh and scripts/docs-autofix-push.sh (the
security-critical functions are now shared verbatim):

- validate_patch refuses ANY "rename "/"copy " header (the legacy
  "rename old/new" form slipped past and, on docs-autofix, pushed a
  scripts.sh -> docs/cli-reference/x.md rename), checks every "index "
  line whatever its ids, takes creations/deletions/renames from
  `git apply --summary`, and reads names from `--numstat -z` (which
  names only the NEW path of a rename; the old comment was wrong).
- docs-autofix gains the post-apply staged re-check and a --check mode.
- The patch is applied to an index in a bare clone (read-tree +
  apply --cached + commit-tree): the PR tree never touches the disk.
  All git calls run with core.hooksPath=/dev/null, GIT_LFS_SKIP_SMUDGE=1.
- Push is leased: --force-with-lease=refs/heads/$HEAD_BRANCH:$HEAD_SHA.
- The PR must target this repo, and the head branch must be neither
  protected nor under a ruleset per the GitHub API (fail closed), on top
  of the name list.
- Only a marker comment written by github-actions[bot] is ever edited.
- bazel-autofix only pushes files in packages the PR changed
  (merge-base..head, computed from fetched refs), MODULE files only when
  go.mod/go.sum/MODULE changed; base-branch drift is left alone and
  listed, and a patch with nothing attributable gets a comment only.

Tests cover each reviewer attack for both scripts (--check and the full
flow against a local bare remote and fake gh), the staged check alone
with the validator disabled, spoofed comments, protection/ruleset/API
errors, the lease, main drift, and symlinked PR trees.

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

* fix(ci): trigger bazel-autofix on Bazel only; share job-level concurrency

- bazel-autofix.yml triggers only on "Bazel": pr.yml never calls
  bazel.yml, so "PR" runs never carry the artifact, and their completions
  cancelled real fixes through the workflow-level group. The policy test
  now requires the triggering workflow to run on pull_request and upload
  the consumed artifact instead of asserting the false claim.
- Both autofix workflows use one job-level concurrency group per head
  branch (autofix-<head repo>-<head branch>) without cancel-in-progress:
  skipped runs take no part, and the two bots queue instead of racing.
- Base checkouts use persist-credentials: false; docs-autofix extracts
  only cli-docs-freshness.patch, as a regular file, outside the workspace.
- Policy tests for the trigger, concurrency scope, checkout, and the
  scripts' shared guards (rename/index checks, comment author, lease,
  protection lookup, index-only apply, hook-free git).

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

* fix(ci): tighten autofix attribution, circuit breaker and PR selection

Re-review follow-ups for the bazel and docs autofix push scripts:

- Root package: paths outside any Bazel package (docs/, .github/,
  README.md, ...) no longer count as changing //:. Only root-level Go and
  build inputs (*.go, *.s, *.c, *.h, *.bzl, go.mod, go.sum, BUILD.bazel,
  MODULE.bazel*) make root BUILD.bazel drift the PR's, so main's root
  drift is not pushed onto a docs-only PR.
- Circuit breaker: the head subject is read from the fetched commit (no
  API), a failed read counts as non-convergent, and the check runs only
  once the PR's own staged fix is non-empty. A bot head whose remaining
  drift is main's now gets the "files this PR did not change" comment
  instead of a wrong "did not converge" one. Same in docs-autofix.
- PR selection: several open PRs can share one head branch. bazel picks
  the one whose number matches the artifact metadata (among PRs already
  matching head repo/branch/base repo; head sha still verified); without
  a unique match both scripts skip instead of taking .[0].
- The privileged clone fetches only the head (and, for bazel, base)
  branch into an init'ed bare partial repo instead of cloning every
  branch.
- docs-autofix job gets timeout-minutes: 10 (it shares a non-cancelling
  concurrency group with bazel-autofix).

Tests: docs-only/README/workflow/Makefile PRs with root drift get no push,
a root Go change gets root BUILD.bazel; breaker cases (bot head with own
vs main drift, unreadable subject) for both scripts; PR selection by
metadata and ambiguity; HEAD_SHA 40-hex guard; staged-check mode arm; a
--summary-only validator copy; both workflows' download steps run as
written against a fake gh (run-scoped artifact listing, only the named
files extracted, symlinked entries refused); timeout asserted for both
jobs.

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

* fix(ci): bazel-autofix requires bash 4; skip its tests on macOS bash 3.2

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

* test(ci): skip every autofix script test on bash < 4

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

* build(bazel): sync internal/utils BUILD with main

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

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 17:23:27 -07:00
Jim Wordelman
2c4bedf4ff
test(configfile): neutralize ambient BEADS_DOLT_SERVER_PORT in TestEnvVarOverrides fallback subtest (#6221)
* test(configfile): green — neutralize ambient BEADS_DOLT_SERVER_PORT in TestEnvVarOverrides fallback subtest (refs be-k5jdp)

* docs(release-gates): PASS 7/7 — be-c8kgv (ambient BEADS_DOLT_SERVER_PORT leak into BEADS_DOLT_PORT fallback subtest)

Independently re-verified review bead be-3fspd's evidence: package-level
52 PASS/0 FAIL/0 SKIP, target subtest green, gofmt/vet clean, 0 divergence
from origin/main, zero-conflict merge-tree simulation.

* test(configfile): neutralize the ambient vars the remaining TestEnvVarOverrides subtests inherit

Review finding 1 (blocking) on PR #6221: the sibling subtest "invalid port
env var falls through to config" has the same ambient-leak bug this PR is
titled after. It sets BEADS_DOLT_SERVER_PORT="not-a-number", so
GetDoltServerPort fails the Atoi and falls through to os.Getenv("BEADS_DOLT_PORT")
(configfile.go:514) — which the subtest never pins, so it reads the ambient
value instead of the config value it asserts.

Reproduced on this head, not on main:

  BEADS_DOLT_PORT=28231 go test ./internal/configfile/... -run TestEnvVarOverrides
    --- FAIL: TestEnvVarOverrides/invalid_port_env_var_falls_through_to_config
        configfile_test.go:1080: GetDoltServerPort() = 28231, want 3308

Two more subtests in the same function have the identical shape: "database
default" and "database config value" both assert the config/default path of
GetDoltDatabase without pinning BEADS_DOLT_SERVER_DATABASE, which outranks
both (configfile.go:561).

  BEADS_DOLT_SERVER_DATABASE=ambient_db go test ./internal/configfile/... \
      -run TestEnvVarOverrides
    --- FAIL: TestEnvVarOverrides/database_default
        configfile_test.go:1121: GetDoltDatabase() = "ambient_db", want "beads"
    --- FAIL: TestEnvVarOverrides/database_config_value
        configfile_test.go:1128: GetDoltDatabase() = "ambient_db", want mydb

All three take the same one-line fix as the subtest already fixed here, so
they are folded in rather than deferred to another round trip. With all three
ambient vars set at once, TestEnvVarOverrides is 9/9 PASS.

Refs be-sf0uk, be-s0af7.

* docs(release-gates): scope the be-c8kgv diff accounting to the source commit

Review finding 2 (nit) on PR #6221: the gate record described the PR as
"Smallest possible diff (1 file, +1/-0)", and criteria 3c and 7 cited
`git diff --stat origin/main...797d4a9e0` — a different SHA from the PR head.

The per-criterion numbers were accurate for the commit the gate actually
evaluated, so they are kept and scoped explicitly to `797d4a9e0` rather than
rewritten. The Disposition no longer claims that accounting for the PR as a
whole, and the now-obsolete "correctly deferred" note on be-s0af7 records that
the reviewer overruled the deferral.

Adds a review-response addendum carrying the current file/line accounting and
the red/green evidence for both findings.

Refs be-sf0uk.

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

  release-gates/be-c8kgv-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
2026-09-28 15:46:18 -07:00
Bùi Phan Viết Cường
5cc896c8f0
fix(lint): suppress two darwin-only gosec findings and cross-lint the darwin build in CI (#6243)
* fix(lint): suppress two darwin-only gosec findings and cross-lint the darwin build in CI

scripts/ci/pr-lint.sh lints natively on the ubuntu runner plus one
GOOS=windows CGO_ENABLED=0 cross-lint, so files behind //go:build darwin
(and the !windows && !linux fallbacks) were never linted in CI. Linting the
darwin build reports two gosec findings that are clean on linux:

- internal/config/permissions_open_nonlinux.go: G304 on os.Open(path). The
  file comment already explains why it is safe (fixBeadsDirPermissions
  re-checks descriptor identity before chmod); it just had no directive.
- internal/utils/path_case_darwin.go: G103 on unsafe.Pointer. A directive
  existed but sat on the first line of a multi-line unix.Syscall call,
  while gosec reports the argument line four lines down, so it never
  covered the finding. It now sits on its own line above the statement,
  the placement cmd/bd/nocow_linux.go already uses.

Add a GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 cross-lint block to
pr-lint.sh mirroring the windows block (same flags, same lane scoping,
skipped when the native target already matches), and update the three
places that described the wrapper as two passes: engdocs/LINTING.md,
engdocs/CI_CLEANUP_PLAN.md and the comment in main.yml.

The darwin pass is compile-only on the Linux runner: no macOS runner, no
change to the pr-lint platform column. Like the windows pass it is
CGO_ENABLED=0, so darwin+cgo code stays outside its reach.

* docs(linting): bump the Last reviewed marker alongside the pr-lint change
2026-09-28 15:44:52 -07:00
Julian Knutsen
6daa06244b
build(bazel): integration-tag lane (--config=integration) matching main.yml (#6916)
* fix(test): keep TestDoltServer_StartStop_UnixSocket's socket path short

t.TempDir() nests the test's name, which alone pushes the socket path past
the 104-byte sun_path guard under any TMPDIR longer than /tmp: the Bazel test
wrapper's per-process TMPDIR (114 bytes) and macOS's /var/folders/... both
silently skipped the test that main.yml's integration job runs. Put the
socket in a short os.MkdirTemp directory instead.

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

* fix(testutil): let SubprocessRunner build with a declared go command

SubprocessRunner.Build ran `go` from PATH. Under Bazel there is no Go
toolchain on PATH, so //internal/testutil/integration's
TestBuildErrorIsMaskedByChmod failed there. BEADS_TEST_GO_BINARY, resolved
like any other runfile, now names the go command; unset, it is still `go`.

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

* feat(bazel): integration-tag lane, --config=integration

main.yml's "Main Linux integration packages (N/6)" and "cmd/bd (N/8)" jobs
(and nightly's Full Test Suite) run every package with
-race -tags=integration,gms_pure_go, no -short and BEADS_TEST_SKIP=dolt.
Bazel never built the 55 `//go:build integration` files: gazelle drops a
file whose constraint names a tag it does not know.

- Root `gazelle:build_tags gms_pure_go,integration`: gazelle now lists the
  integration files in srcs and their imports in deps, and generates
  //internal/testutil/integration (integration files only). rules_go filters
  those files out of every other build, so --config=ci runs what it ran.
- --config=integration sets the tag for the whole build, like `go test
  -tags`, plus the jobs' race, BEADS_TEST_SKIP=dolt, -test.parallel=4 and a
  1200s/19m timeout pair (rbe-west's action limit; the jobs pass 30m). The
  same variants as PR core stay out (requires-docker, embedded, manual), so
  `bazel test //... --config=integration` runs the union of the 14 shards.
  A per-target gotags variant would not save the compile (gotags transitions
  the whole dep graph) and would need a second, duplicated target per package
  plus a tag to drop the plain one from this lane.
- //internal/testutil/integration:integration_test gets the pinned SDK's go
  for SubprocessRunner's `go test -c`.
- TestBazelIntegrationLaneMatchesMainWorkflow pins test:integration to
  main.yml's tags/race/BEADS_TEST_SKIP and gazelle's build_tags to a superset
  of the tags; bazel.yml's `make bazel-sync` diff already fails when a file
  gains the integration tag without a BUILD sync.

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

* build(bazel): sync scripts BUILD for upgrade_smoke_loop_test.go

make bazel-sync on current main adds the test file #6398 added.

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

* fix(bazel): derive the integration lane's tag exclusions from PR core's

After main added the dolt-server tag, test:integration's filter still
selected those targets, and 5 of them fail under BEADS_TEST_SKIP=dolt. The
filter now excludes dolt-server, and the policy test no longer pins one
string: bazelPRCoreExcludedTags (kept equal to the taxonomy entries that say
"excluded from --config=prcore/ci") is the list both lanes check, the
integration lane minus the tags it runs. Every --test_tag_filters in the
lane or a config expanding it must exclude them, and no -test.short,
-test.skip, -test.run or --test_filter may reach it.

New tag integration-only for //internal/testutil/fixtures:fixtures_test and
//internal/testutil/integration:integration_test, whose tests are all
`//go:build integration`: --config=prcore/ci excludes them instead of
running two empty targets; --config=integration runs them. The .bazelrc
notes that ci and integration share bazel-testlogs.

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

* docs(bazel): note shared testlogs and dolt_test's subprocess build

bazel.yml's equivalence step reads bazel-testlogs, which --config=integration
shares with --config=ci, so a job running both lanes must check each right
after its own run. //internal/storage/dolt:dolt_test's SubprocessRunner tests
need a real `go test -c` with a module cache; they stay skipped under the
lane's BEADS_TEST_SKIP=dolt, so the target gets no go SDK data.

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

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 14:11:34 -07:00
Robin Carswell
4c29640f76
feat(ids): say when a partial ID resolved to something else (#6302)
* feat(ids): say when a partial ID resolved to something else

ResolvePartialID tries an exact match first and only then falls back to
leading-prefix abbreviation (a3f8 -> a3f8e9). Ambiguity is already handled
well: two or more candidates return ErrAmbiguousID naming all of them. But a
*sole* abbreviation match was returned silently, so a caller could act on an
issue it never named with nothing to indicate the substitution.

The case that motivates it: a hierarchical child is a valid leading-prefix
match for its own parent's ID, because "." is a legal ID character and the
prefix test has no boundary. So once a parent ID is vacated — renamed away, or
deleted — `bd show <parent-id>` returns the child, exit 0, no signal. With
exactly one descendant it is silent; with two or more the existing ambiguity
error catches it. The silent case is the dangerous one.

Rather than narrow resolution (e.g. requiring a boundary so a child stops
abbreviating its parent), which changes semantics and risks breaking
legitimate abbreviations, this announces the substitution and leaves the
documented abbreviation UX alone.

Emitted from the resolver, not from individual commands: ResolvePartialID has
64 non-test call sites, so a per-command notice would be applied
inconsistently. One emission point covers all of them, and it sits at the only
return that hands back an issue the caller did not name.

stderr, never stdout, so --json payloads and piped output are byte-for-byte
unchanged. Gated on --quiet and BD_NO_PARTIAL_ID_NOTICE, following the
BD_NO_DEP_TYPE_WARNING precedent in cmd/bd/dep.go. Deliberately not gated on
stderr being a terminal, which is where it departs from that precedent: the
callers most exposed to acting on the wrong issue are scripts, hooks and
agents, and those are exactly the non-TTY ones.

Tests: the gate matrix (quiet, env opt-out, identical/empty resolution), the
message text, and end-to-end resolution over a small in-package fake store —
the existing resolver tests need a live Dolt server and self-skip without one,
so they cannot pin this in CI. Verified the end-to-end test fails without the
emission.

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

* docs(changelog): link the partial-ID notice entry to its PR

Matches the surrounding entries, which each cite the PR or issue they came
from. No code change.

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

* test(ids): cover the second silent return; disclose the notice's breadth

Review follow-up on #6302.

MAJOR — CHANGELOG understated the scope. The notice fires on every
leading-prefix abbreviation, not only the vacated-parent shape, so the ordinary
documented a3f8 -> bd-a3f8e9 path emits a line too, once per resolved argument.
The entry now says so, and says why the breadth is deliberate: a .-boundary
rule would fix parent/child and leave bd-x.1 -> bd-x.11 just as silent.

MINOR — an emission planted at the in-loop exact-hash return survived the
suite. The suggested repro (prefix-less a3f8e9 -> bd-a3f8e9) does not reach
that return: resolution has TWO fast paths, one on the raw input and one on the
prefix-normalized input, and the normalized one catches that case first. The
in-loop return is reached only CROSS-PREFIX, where the issue's real prefix is
an allowed one other than the configured default, so both fast paths miss and
the search loop matches on hash alone.

TestResolvePartialIDSilentOnCrossPrefixExactHashMatch covers it (configured
prefix bd, allowed hq, store holds hq-a3f8e9, input a3f8e9) and was verified to
fail with that mutant planted and pass without it. The prefix-less case is kept
as its own test, since it pins the normalized fast path staying silent.
TestResolvePartialIDNotifiesOnOrdinaryAbbreviation pins the breadth the
CHANGELOG now discloses.

Also: captureStderr restores os.Stderr from a defer so a panicking test cannot
swallow later tests' output, and closes the read end.

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

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-09-28 13:12:39 -07:00
ecuthiell
4dc96f6f21
fix(config): identify native config environment in path errors (#6325)
* fix(config): name the native config environment source in errors

Identify APPDATA on Windows, HOME on Darwin/iOS, home on Plan9, and the
selected XDG_CONFIG_HOME or HOME source on other Unix hosts. Only error
labels change; the standard-library resolver and path precedence remain
the same, and the original wrapped error is retained.

Fixes #6314
Reported-by: bee-ghosttrack
Bead: saa-cgh.95
Agent-Signature: unknown-model/unknown-reasoning

* test(config): exercise native source diagnostics on the required platforms

Select the diagnostic parent and its two XDG states through one Bash3.2
driver in the existing three-host preflight matrix. Bind the declared OS
to Bash and the setup-selected Go host/target, retain child process status,
and reject missing, duplicate, unexpected, failed or skipped execution.

Preserve existing platform steps, job identity and required gate mapping.
Use the existing YAML workflow helpers to pin the new placement.

Follow-up: https://github.com/gastownhall/beads/issues/6314
Bead: saa-cgh.95
Agent-Signature: unknown-model/unknown-reasoning

* fix(config): keep native diagnostics with candidate builder (saa-cgh.95)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell
2026-09-28 12:17:20 -07:00
Julian Knutsen
3d76cbd4e9
ci(bazel): dolt-server lane on remote execution (replaces the docker lane) (#6898)
* test(bazel): dolt-server lane for the storage domain + uow job

--config=doltserver runs pr.yml's "Test (storage domain + uow)" job as
remote-executable Bazel tests: each dolt-server target runs an existing
go_test binary with BEADS_TEST_DOLT_SERVER=local, so every Dolt server
is a `dolt sql-server` child of the test process, started from the
pinned dolt the test wrapper already ships. No docker, no
no-remote-exec, and BEADS_TEST_REQUIRE_DOLT_CONTAINER=1 fails a target
whose server cannot start, so cached results are trustworthy.

- db_dolt_test, uow_dolt_test (8 shards), tracker_dolt_test,
  fix_dolt_test (4 shards, BEADS_FIX_REQUIRE_DOLT=1); GOMAXPROCS=4 like
  the job's runner.
- no -short twins of domain, domain/fs, domain/git and
  tracker/conformance, so the lane alone runs every package of the job.
- tag `dolt-server` in the taxonomy; test:prcore (and so test:ci)
  excludes it. The requires-docker variants stay as the A/B control.

Remote (default instance, --nocache_test_results): 9/9 PASS in 113 s
wall; longest shard 111 s (uow). Per-test statuses, subtests included,
equal the job's go test -json on the same tree: 0 differences.

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

* test(bazel): contract corpus on the dolt-server lane

protocol_dolt_test runs protocol_test as pr.yml's "Contract corpus" job
does (non-race via protocol_race_off, BEADS_PROTOCOL_REQUIRE_DOLT=1) with
the local dolt sql-server backend, in 8 shards, so the corpus golden,
determinism and conformance tests run on remote workers and cannot skip.

Remote: 8 shards, longest 53 s. 153 tests (151 PASS / 2 SKIP, subtests
included) equal the job's go test -json: 0 differences.

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

* ci(bazel): run the dolt-server lane in place of the docker lane

bazel.yml's container-lane job becomes bazel-doltserver: `bazel test
//... --config=doltserver`, whose targets start their own dolt
sql-servers and so execute on the remote workers (locally for forks and
rbe=off) instead of against the runner's docker daemon. The docker lane
stays reachable as the A/B control: workflow_dispatch dolt-lane=docker
runs --config=docker in the same job, with the image pull that only it
needs. Still advisory; runner, rbe-west gate and secret handling are
unchanged. Policy test and TESTING.md follow.

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

* fix(bazel): reap processes left in a test's private root on exit

A Bazel test timeout signals the test's process group, which misses the
detached bd db-proxy-child processes (Setsid) and the dolt sql-servers they
start. A proxy that died without its idle timeout left its server orphaned on
a persistent remote worker. test_env.sh's EXIT trap now kills every process of
the current user whose command line names the action's private mktemp root
(pkill -f, two passes; a /proc scan when pkill is absent) before removing it.
The root is unique per action and never in the wrapper's own argv; cleanup
still cannot change the test's exit status.

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

* test(bazel): fail closed on every dolt-server target, checked per rule

The no-short twins (domain, domain/fs, domain/git, tracker/conformance) now
pin BEADS_TEST_DOLT_SERVER=local and BEADS_TEST_REQUIRE_DOLT_CONTAINER=1 like
the lane's other targets, so a Dolt-server test added to those packages fails
instead of skipping into a cached pass.

TestBazelDoltJobMirrorsContainerJobs checked the env with a file-wide
substring search, so a docker variant in the same BUILD file covered for a
dolt-server target that lost it. It now parses each rule tagged dolt-server
and requires both variables, BEADS_FIX_REQUIRE_DOLT on fix_dolt_test,
BEADS_PROTOCOL_REQUIRE_DOLT on protocol_dolt_test, and no no-remote-exec.

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

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 05:17:36 -07:00
Julian Knutsen
6dbd9dbf65
ci(bazel): embedded-Dolt tier under Bazel, shard-for-shard with PR Risk (#6896)
* fix(test): find the module root only when the concurrency test builds its binary

TestConcurrencyMultiProcess looked up go.mod before checking
BEADS_TEST_EMBEDDED_TEST_BINARY, so a pre-built binary run outside a
checkout (Bazel's runfiles hold no go.mod) failed before using it. Only
the fallback go test -c build needs the module root.

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

* fix(bazel): job-mode equivalence reports TestEmbedded tests Bazel ran extra

The extra-test check always ignored ^TestEmbedded names, the --config=ci
lane's implicit skip, so a job comparison of the embedded tier could not
see a Bazel variant running more TestEmbedded* tests than the CI job.
Apply the skip only outside --job.

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

* feat(bazel): embedded-Dolt tier variants and --config=embedded

PR Risk's embedded tier as embedded-tagged variants over the existing
race test binaries (no second compile):

- //cmd/bd:bd_embedded_test (20 shards) and
  //internal/storage/embeddeddolt:embeddeddolt_embedded_test (5 shards)
  run the jobs' own shard scripts through go_test_manifest_shard.sh, which
  maps Bazel shard k to the script's shard k+1 of n and stops the binary
  from sharding again. Each Bazel shard runs exactly the tests of the CI
  job with the same number (same discovery, committed manifest and hash
  fallback, binary flags). A plain -test.run ^TestEmbedded would not: nine
  TestEmbedded* functions outside *_embedded_test.go run in no CI job.
- embeddeddolt_conformance_core_test / _audit_test pass the conformance
  jobs' exact selectors and -test.timeout=30m.
- cmd shards use the race //cmd/bd:bd as BEADS_TEST_BD_BINARY, like the
  jobs' /tmp/bd-embedded-test.

test:embedded: race, tag filter embedded, build_tests_only, the jobs'
-test.parallel (4) and no -short/BEADS_TEST_SKIP; eternal is capped at
1200s, rbe-west's maximum action timeout.

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

* ci(bazel): run the embedded-Dolt tier in bazel.yml

New advisory job bazel-embedded (same runner, rbe-west gate and secret
handling as the other Bazel jobs) runs bazel test //... --config=embedded.
It is a job of its own so the tier's long race shards stay off
bazel-test's critical path and budget; it compiles nothing bazel-test does
not.

TestBazelEmbeddedJobMirrorsEmbeddedTier ties the config and variants to
pr-risk.yml: race builds, shard totals and scripts, BEADS_TEST_EMBEDDED_DOLT,
the race subprocess bd, the conformance selectors, and no -short.

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

* chore(bazel): sync BUILD files after rebase onto main

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

* fix(bazel): Go timeouts below Bazel's 1200s cap for embedded variants

rbe-west caps actions at 1200s, so the eternal embedded variants are killed
there, and rules_go's wrapper ignores that SIGTERM: a hang ended as a bare
TIMEOUT without the goroutine dump the pr-risk.yml jobs rely on. The cmd
shards (job: -test.timeout=20m) and conformance core/audit (job: 30m) now
pass -test.timeout=19m, a documented deviation, so Go's timeout fires first.
Storage shards keep the job's 15m, which already does.

Correct the .bazelrc and BUILD comments that claimed the variants keep "the
jobs' own" timeouts, and state each target's effective limit. The policy
test now pins the 19m on the cmd shards and in place of the conformance
jobs' 30m (and flags a change of the jobs' value).

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

* ci(bazel): fail bazel-embedded on targets or shards that ran no tests

The embedded variants inherit silent passes from PR Risk's shard scripts:
a shard the manifest assigns nothing exits 0 ("no tests assigned"), and a
manifest missing from the runfiles falls back to hash assignment, so every
shard still passes but no longer runs its job's tests.

- tools/bazel/check_testcases.py reads the run's BEP and fails if any tested
  target's test.xml, or any shard's, is missing or lists no top-level test
  (reusing equivalence.py's BEP and testlogs helpers). bazel-embedded writes
  a BEP and runs it after the tests; test logs now upload on any failure.
- The policy test requires each manifest-sharded variant's data to hold its
  shard script and the script's default manifest, and pins the new step.

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

* ci(bazel): run bazel-embedded only with remote execution

Fork PRs and rbe=off dispatches ran the embedded-Dolt tier locally: 27 race
test processes (~7-10k test-seconds) plus the race compile of cmd/bd on one
GitHub-hosted runner, est. an hour or more per fork PR against the pool
whose job cap this track exists to relieve, while pr-risk.yml's embedded
jobs already run those tests for forks. bazel-embedded now runs only when
rbe-west is on (RBE_WEST_WORKERS, same repo, rbe != off); its job and step
timeouts shrink to the remote budget (60/50 min).

The policy test pins this job's if and keeps every other job on the shared
fork / rbe=off rule.

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

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 04:41:10 -07:00
Julian Knutsen
671715bb8b
test(testutil): opt-in local dolt sql-server backend for Dolt-backed tests (#6891)
* test(testutil): local dolt sql-server backend behind the Dolt test server API

Add a second backend to internal/testutil behind the unchanged container
API (EnsureDoltContainerForTestMain, RequireDoltContainer,
StartIsolatedDoltContainer[Handle], NewContainerProvider,
RestartSharedDoltContainer, DoltContainerCrashed, IsolatedDoltContainer
Stop/Start/CurrentPort/Exec): the test process spawns `dolt sql-server`
from the pinned dolt CLI instead of a dolthub/dolt-sql-server container.

- BEADS_TEST_DOLT_SERVER=local|container selects it; unset keeps plain
  `go test` on the container (no behavior change) and makes `bazel test`
  use the local backend. Other values fail instead of guessing.
- The CLI (BEADS_TEST_DOLT_BINARY, else PATH) must be the image's version.
- Provisioned like testcontainers' dolt module: root@% (DOLT_ROOT_HOST=%),
  database beads_test, user test/test. Clean env, TZ=UTC, GOMAXPROCS=4,
  own dolt global config with metrics and the version check disabled.
- Loopback port picked here (dolt rejects -P 0), never 3307, retried when
  another process wins the port; readiness requires the server's own
  "Server ready" line plus a bounded ping, so a foreign listener on a
  contested port cannot pass for it.
- State lives under the TMPDIR captured at package init, outside every
  PinSuiteTempRoot root, so suite leak sweeps never see it. The server
  stays in the test's process group (bazel's group kill reaps it) with
  Pdeathsig on Linux.
- BEADS_TEST_REQUIRE_DOLT_CONTAINER=1 now also makes every TestMain that
  only warned about an unavailable server exit 1
  (DoltUnavailableForTestMain), plus the shared proxied harness.
- dolt_benchmark_purge_test finds .dolt_dropped_databases relative to
  Exec's working directory (the data dir in both backends).
- TestDoltServerFingerprint checks each available backend against one
  checked-in fingerprint (users, grants, databases, server variables);
  local-backend tests cover the bind-race retry, 3307, crash detection,
  Stop/Start, Exec cwd, state outside the suite root, and teardown.
- Bazel: the requires-docker variants pin BEADS_TEST_DOLT_SERVER=container
  so the docker lane stays the container A/B control; the test wrapper's
  dolt global config disables metrics and the version check.

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

* fix(testutil): select the local Dolt test server only when asked for

Under Bazel an unset BEADS_TEST_DOLT_SERVER used to mean the local
backend, so every non-ci `bazel test` started servers for Dolt suites no
lane runs with one (//internal/storage/dolt:dolt_test went from a 16 s
skip to a timeout). Unset now means container everywhere: in a Bazel
action without docker that is the pre-existing warn+skip, and only a
target's env or --test_env=BEADS_TEST_DOLT_SERVER=local starts local
servers. Plain `go test` is unchanged.

The docker variants keep their container pin: a rule env beats
--test_env, so a local-backend invocation cannot flip the docker lane.

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

* fix(testutil): harden the local Dolt test server's host footprint

- DOLT_DISABLE_EVENT_FLUSH=1 for every dolt the backend runs (and in the
  Bazel test wrapper): the metrics/versioncheck keys stop network calls
  but not the detached `dolt send-metrics` child each command forks on
  exit, which re-created the version probe's removed HOME (one leaked
  bdt-doltver-* per test process) and raced terminate's RemoveAll.
- Every bdt-dolt-*/bdt-doltver-* root records its owner PID, and the
  first use of the backend in a process removes this user's roots whose
  owner is dead (the SweepDeadSuiteRoots rule; a copy, since doltserver's
  tests import testutil). A panicking, timed-out or killed test binary,
  or a package whose TestMain never terminates the singleton, no longer
  leaks a 40-100 MB state dir per run.
- secure_file_priv is the state root's sfp/ directory, set through a
  per-launch --config file (dolt ignores other flags with --config): a
  local server runs as the test user on the host with a passwordless
  root@%, so LOAD_FILE / INTO OUTFILE must not reach the user's files.
  The fingerprint treats that path as the container's "".
- Fingerprint: character_set_server, collation_server,
  max_allowed_packet, transaction_isolation, lower_case_table_names,
  lower_case_file_system (compared on Linux only: APFS reports ON),
  wait_timeout, innodb_lock_wait_timeout.
- The local backend's own tests skip off Linux (no Pdeathsig, so a
  killed test binary would orphan servers on the macOS runners) unless
  BEADS_TEST_DOLT_SERVER=local asks for them.

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

* ci: compare the container and local Dolt test servers in the domain+uow job

TestDoltServerFingerprint's container half never ran in CI: only the
test-domain-uow job has both the pulled image and the pinned dolt CLI,
and it never ran ./internal/testutil. Run the fingerprint there (with
BEADS_TEST_REQUIRE_DOLT_CONTAINER=1 so the container half cannot skip)
so an image bump that drifts the container side fails in the PR.

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

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 04:06:49 -07:00