* 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>