beads/cmd/bd/recompute_blocked_proxied_server.go
Steve Yegge e68d9e5a0b
feat(recompute-blocked): port to proxied-server mode + cross-mode cascade parity suite (bd-04vav) (#5363)
* feat(recompute-blocked): port to proxied-server mode (bd-04vav)

`bd recompute-blocked` stops refusing proxied-server mode. It is the
mode-independent repair for a stale is_blocked column (bd-6dnrw.37) and
wh-bridge-sync's remedy after a cross-machine merge, so a constellation
running on the proxied plane without it has no way to repair the flag
`bd ready` trusts.

Parity is by construction rather than by assertion: the whole
in-transaction body (dirty-graph guard + fixpoint recompute), the commit
message, and the staging set now live in ONE place,
versioncontrolops.GuardedRecomputeAllBlockedInTx /
BlockedRecomputeCommitMsg / BlockedRecomputeStagedTables, which the
embedded store, the server store and the new proxied route all call. The
CLI's two rendered branches are likewise one function shared by both
routes. Nothing about the repair's semantics is restated per mode; what
differs is only how each mode gets its connection.

The proxied route runs on a PINNED non-transactional connection
(uow.MaintenanceProvider, as compact/gc already do) rather than through
uow.RunTx*, for two reasons specific to this command: the post-commit
DOLT_ADD/DOLT_COMMIT are stored procedures Dolt refuses inside an
explicit transaction, and the uow commit path stages with '-Am' while
this repair must stage `issues` ALONE — a commit whose entire content is
a derived flag has no business sweeping an unrelated dirty working set,
which is the very thing the read-side guard exists to prevent.
StageAndCommit grows an empty-author form for that call: proxied-mode
commits are unauthored by design (uow.Tx.Commit passes no --author), and
an empty '--author' argument would be malformed rather than
unattributed.

admin cleanup stays gated. The 2026-08-04 recon on bd-04vav found it has
no wheelhouse call sites, so porting it would be untested surface area
bought for nobody.

TestProxiedServerRecomputeBlocked is a cross-mode oracle: the same
corrupt-then-repair scenario is replayed against a classic embedded
workspace and a proxied one, and every observable — both rendered
branches and the corrected-row count — must match, with the shared
values additionally pinned so a symmetric regression in both modes still
fails. It also covers what wh-bridge-sync actually depends on
(idempotency, honest exit codes), that a no-op repair mints no Dolt
commit, and that the dirty-graph refusal survived the port.

Part of bd-vxavz (proxied-server capability parity).

* test(delete/prune/purge): cross-mode cascade parity, and a data-loss divergence (bd-04vav)

The verification half of F7. Proxied `bd delete` "always cascades"
(--cascade is refused outright) while classic cascades only when asked,
so the question the constellation needs answered before cutover is not
"is the flag there" but "does the cascade reach anything classic would
have left alone" — on the shapes the wheelhouse actually runs.

TestProxiedServerCascadeParity replays three of them against a classic
embedded workspace AND a proxied one and compares the outcomes, so a
difference is reported as a difference rather than as one mode's test
failing alone: wh-gate-sweep's delivery-ledger purge, the wisp-decay
close + `purge --pattern '*' --force` pair, and a reference-aware durable
`prune` sweep.

FINDING — proxied delete of a gate destroys the bead it gated.
`bd gate create --blocks <target>` records the edge as target
DEPENDS-ON gate, so the gated bead is a DEPENDENT of the gate row. On the
proxied plane wh-gate-sweep's `bd delete <gate> --force` therefore
deletes the target and everything downstream of it; classic leaves both
standing. Measured, not inferred: proxied {gateGone:true,
targetSurvives:false, siblingSurvives:false} vs classic {true, true,
true}. This is a shared-server cutover blocker, and the fix is a design
call on what --cascade should mean in proxied mode (three existing
proxied delete suites deliberately pin today's unconditional cascade), so
it is filed rather than smuggled in here.

The subtest CHARACTERIZES the defect: the classic half pins the correct
behavior, the proxied half pins exactly today's blast radius, and the
comparison is logged loudly. The suite stays green while the divergence
is open and fails the moment the damage changes in EITHER direction —
including when it is fixed, at which point the expectation is flipped to
match classic and the paragraph explaining it goes away.

Wisp decay and prune agree across modes with no divergence: the closed
wisp is reclaimed while a durable closed bead and an open wisp survive
(purge is ephemeral-only and closed-only), and prune protects a closed
bead an open bead still cites.

Part of bd-vxavz (proxied-server capability parity).
2026-08-05 12:11:53 -07:00

50 lines
2.2 KiB
Go

package main
import (
"context"
"database/sql"
"github.com/steveyegge/beads/internal/storage/versioncontrolops"
)
// runRecomputeBlockedProxiedServer routes bd recompute-blocked through the
// proxied-server plane (bd-04vav).
//
// The repair itself is not reimplemented here: the guard, the fixpoint
// recompute, the staging set and the commit message all come from
// versioncontrolops.RecomputeAllBlockedOnConn, the same code the embedded and
// server stores run, so the two modes cannot compute different flags or land
// different history. What is mode-specific is only how the connection is got.
//
// It runs on a PINNED non-transactional connection rather than through
// uow.RunTx*, for two reasons the other proxied ports do not have:
//
// - The repair's post-commit DOLT_ADD/DOLT_COMMIT are stored procedures,
// which Dolt refuses inside an explicit transaction — the same reason every
// other versioncontrolops entry point takes a conn.
// - The uow commit path stages with DOLT_COMMIT('-Am', …). This repair must
// stage `issues` ALONE: it derives a flag from the graph and has no business
// sweeping an unrelated dirty working set into its commit, which is exactly
// what the dirty-graph guard exists to prevent on the read side.
//
// The exit code is the whole downstream contract (wh-bridge-sync runs this under
// a timeout cap, treats rc 124 as "still running server-side", and retries up to
// 3 times because the operation is idempotent): success is 0, and every failure
// — an unreachable server, a dirty graph, a killed query — is a nonzero HandleError.
// Nothing here invents a green.
func runRecomputeBlockedProxiedServer(ctx context.Context) error {
var changed int64
if err := runProxiedNonTx(ctx, func(ctx context.Context, conn *sql.Conn) error {
var rerr error
changed, rerr = versioncontrolops.RecomputeAllBlockedOnConn(ctx, conn, "")
return rerr
}); err != nil {
// runProxiedNonTx reports its own provider failures and returns an
// already-rendered exit; re-wrapping would print a second Error line.
if _, reported := exitCodeFromError(err); reported {
return err
}
return HandleError("recompute is_blocked: %v", err)
}
return renderRecomputeBlocked(int(changed))
}