beads/internal/storage/issueops/bootstrap.go
CI Bot 67d38d2620 Trim this series' comments toward the repo's own density
Ten agents over 216 files, one directory-balanced group each, working to a
rubric that named what to cut (duplication narration, restatement of the next
line, the governing rule echoed in every command file, throat-clearing) and
what to keep (traps, invariants, security, tracker ids, behaviour changes, and
the "why a naive simplification destroys this assertion" rationale).

Net 1,523 lines. Density against this repo's own per-directory norm on main:

  cmd/bd              33.6% -> 27.3%   (main 10.7%)
  internal/storage    26.1% -> 23.1%   (main 14.1%)
  backend/conformance 34.0% -> 29.6%   (main 22.8%)
  internal/httpapi    30.9% -> 27.8%   (main 30.6%, now below)
  overall             34.7% -> 31.6%

Every agent landed at 18-25% rather than the 30% asked for, and every one gave
the same reason independently: what remained was on the keep list. Ten separate
judgements agreeing is the most useful result here — the prose is dense, but it
is mostly load-bearing, and the shortfall is the honest answer rather than a
failure to try.

TWO REVERTS, both to protect something worth more than the lines.

issueops/ is back to its pre-trim state, giving up 610 lines. The conformance
contracts cite the leaf docs BY LINE — "pins treewalker.go:52-66" — 155 times.
Trimming the cited files silently repointed those at whatever text moved into
those numbers, across agent boundaries so no agent could see it. A semantic
remapper recovered 141 of them, but 23 needed judgement and several landed on
struct fields. The leaf docs are the spec the contracts are written against;
they are the one place in this change where dense prose IS the deliverable, and
keeping them stable is worth more than the 610 lines. tree_walker_contract.go
and version_reconciler_contract.go went back for the same reason: an agent had
deleted a paragraph containing a citation, so positional restoration could not
align them.

After the reverts, exactly 5 citations point into a still-trimmed file and 2 of
those are weak — both in cmd/bd/config_guard_test.go, which this series never
touched and whose citations were already wrong on main (init.go:361 pointed at
a closing brace; the guard it names is at init.go:1499).

VERIFICATION. A guard strips every comment and all whitespace from each of the
193 modified files at HEAD and in the worktree and requires the two to be
byte-identical, so a code change cannot hide in a comment diff. It handles `//`
inside string and raw-string literals, and was tested against a deliberate code
change before being trusted. gofmt clean, go build, go vet, golangci-lint 0
issues, and the two AST-based tests that PARSE trimmed files — the timed
provider binding pin over claim.go and the serve database-source gate over
serve.go — both pass.

One real defect found while trimming: checkDatabaseSource's doc block ran into
`// sourceRoles is ...` with no blank line, so godoc attached thirty-one lines
of the wrong prose to func sourceRoles and left checkDatabaseSource
undocumented. Fixed by separating them.
2026-08-06 08:06:59 +00:00

76 lines
3.1 KiB
Go

package issueops
import (
"context"
"github.com/steveyegge/beads/internal/workapi"
publicops "github.com/steveyegge/beads/issueops"
)
// This file holds the store-backed bodies behind issueops.Bootstrapper and
// issueops.InitVerifier.
//
// They live here rather than in an importable internal/workapi/store<role>
// package for the reason SweepInTx and DetectCycleReportInTx do: the work is a
// read and the write it QUALIFIES, and those two must see one snapshot or the
// refusal is a suggestion. The two Dolt-backed stores share these bodies and
// differ only in how they reach a transaction, so they are ONE vote and the
// unit-of-work provider is the second.
// BootstrapInTx seeds an unidentified substrate's identity, refusing an
// identified one, inside ONE transaction.
//
// It assumes a request already normalized and refused by
// workapi.ValidateBootstrapRequest, which the accessors run BEFORE opening a
// transaction.
//
// THE READ AND THE WRITE SHARE THE TRANSACTION, which is the whole reason this
// body is shaped as a function over a *sql.Tx: two inits racing against one
// shared database is the ordinary case for a bts-provisioned server, and a
// refusal decided outside the transaction that writes is one both racers pass.
//
// The per-clone bookkeeping `bd init` seeds alongside the identity is not here
// and not on the role; see issueops.Bootstrapper for why.
func BootstrapInTx(ctx context.Context, tx DBTX, req publicops.BootstrapRequest) (publicops.BootstrapResult, error) {
prefix, projectID, err := verifyIdentityInTx(ctx, tx)
if err != nil {
return publicops.BootstrapResult{}, err
}
if err := workapi.RefuseIdentifiedSubstrate(prefix, projectID); err != nil {
return publicops.BootstrapResult{}, err
}
if err := SetConfigInTx(ctx, tx, workapi.ConfigKeyIssuePrefix, req.Prefix); err != nil {
return publicops.BootstrapResult{}, err
}
if err := SetMetadataInTx(ctx, tx, workapi.MetadataKeyProjectID, req.ProjectID); err != nil {
return publicops.BootstrapResult{}, err
}
return publicops.BootstrapResult{Prefix: req.Prefix, ProjectID: req.ProjectID}, nil
}
// VerifyIdentityInTx reads the substrate's identity inside one transaction.
func VerifyIdentityInTx(ctx context.Context, tx DBTX) (publicops.VerifyIdentityResult, error) {
prefix, projectID, err := verifyIdentityInTx(ctx, tx)
if err != nil {
return publicops.VerifyIdentityResult{}, err
}
return publicops.VerifyIdentityResult{Prefix: prefix, ProjectID: projectID}, nil
}
// verifyIdentityInTx reads the pair the bootstrap refusal and the verifier both
// ask about, so the two cannot disagree about what "identified" means. Both
// reads happen even when the first already decides the outcome: the verifier
// publishes the pair, and the refusal names both values.
func verifyIdentityInTx(ctx context.Context, tx DBTX) (prefix, projectID string, err error) {
prefix, err = GetConfigInTx(ctx, tx, workapi.ConfigKeyIssuePrefix)
if err != nil {
return "", "", err
}
projectID, err = GetMetadataInTx(ctx, tx, workapi.MetadataKeyProjectID)
if err != nil {
return "", "", err
}
return prefix, projectID, nil
}