BuildListFilter pushes SortBy into the SQL filter; BuildQueryPlan did not. So
for a filter-expressible expression the database bounded the page in STORAGE
order and the display sort ran afterwards in Go, which makes "which N rows are
in the page" a property of whatever order the engine happened to return.
The two bodies then disagreed. The store body over-fetches one row as a
has-more probe and FinishPage sorted that probe INTO the page before cutting;
the unit-of-work body trims to Limit natively and never sees it. Same
expression, same --sort, same --limit, different rows — the exact failure
FinishPage's own comment cites as the reason it exists.
Pushed down, the bound and the order are one decision the engine makes: the
page is the first Limit rows in the requested order on every backend, and the
probe row is genuinely last, so cutting removes precisely it.
RunQuerierSortBoundsThePageInOrder pins it. The fixture is built so storage
order and sort order DISAGREE — four matches, limit two, and the two rows that
should win carry the worst priorities so the default engine order puts them
outside the three rows an over-fetch sees. Verified by mutation: without the
push-down the store leg returns [b y] where [a b] is correct.
It sorts by `title`, not `id`: sqlbuild routes `id` to a GO-SIDE sort
(natural id ordering has no SQL spelling), so no push-down can apply there and
both bodies bound in storage order alike. A first draft of this case used
`id` and passed against the unfixed code for exactly that reason.
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.
Fifteen paragraphs of the form "this file used to hold a second copy of <cmd>:
it parsed the flags again, opened a unit of work...". The fact that a second
implementation existed explains nothing about the code that is there now, and
the commit that removed it says so in more detail than a doc comment should.
Reviewed individually rather than pattern-matched. A first pass keyed on
phrases like "used to" and "this slice" flagged 130 paragraphs and would
have taken out design rationale with them — it cut bootstrapper.go's "WHY ONLY
THIS SLICE OF bd init IS A ROLE" because "THIS SLICE" matched a pattern
meant for programme slices. That pass was reverted. Of the 69 paragraphs a
tightened pass surfaced, these 15 are the ones carrying no live information;
the other 54 explain an invariant, a trap, or a behaviour change a user sees,
and stay.
`bd init` had two implementations of what a workspace's identity IS. The direct
route read issue_prefix out of the config plane at init.go:1358 and _project_id
four hundred lines later, decided adopt-vs-write with two helper predicates, and
wrote both keys by name. The proxied route called domain.BootstrapUseCase, which
held its own list of which keys an identity is made of, wrote them
unconditionally, and folded the Dolt remote into the same call. The two agreed on
the key names and disagreed on the rule, and no test compared them.
ONLY THE IDENTITY SEAM IS A ROLE. Everything else init does — creating .beads/,
writing metadata.json and config.yaml, initializing git, installing hooks,
starting a Dolt server — CREATES the substrate or the workspace around it, and a
role is reached through an accessor ON a store, so it cannot be what makes the
store exist. init.go alone is 3,060 lines; this commit touches the part that
happens inside the database.
TWO ROLES, AGAINST THE VersionReconciler PRECEDENT. That one is a read and a
write on one role because they are two shapes of one question, and every word of
that is true here too. The test that separates them is different: can one caller
be entitled to the READ and not the WRITE? Here yes, and not hypothetically —
`bd init --team-server` adopts a bts-provisioned identity and is forbidden to
write one, and a gateway credential may be read-only. Those paths now hold an
InitVerifier and never obtain a Bootstrapper, which the type system checks;
with one role they would hold the writer and the suppression would stay where it
is today, in three should* predicates on the CLI.
Q8 ANSWERED IN THE ROLE. Bootstrap over an already-identified substrate is
ErrAlreadyIdentified, carried by an *AlreadyIdentifiedError naming what was
found, decided from the same read the write would have followed inside ONE
transaction. Either marker is enough: a substrate several rigs share carries a
prefix one of them chose, and overwriting it renames every id the others are
about to mint. The guard now sits below both front doors instead of in front of
one, so gateway and adopt paths inherit it, and re-identifying is something
somebody asks for rather than something init does twice.
THE ROLE OWNS THE IDENTITY AND NOTHING ELSE. BootstrapProject wrote six values;
BootstrapRequest carries two. The fingerprints, the synced-at marker and the
recorded binary version are refreshed on EVERY init, adopt or not — a fresh clone
of an already-identified database needs its own fingerprints precisely because it
bootstrapped nothing — so a refusable one-time write would mean either a refusal
that stops recording them or a write that is no longer one-time. bd_version has a
second reason: it is VersionReconciler's key. The Dolt remote left too; it is
where the database syncs to, not what it is, and putting them in one call is what
let a remote that could not be created fail a bootstrap that had already
succeeded. domain.BootstrapUseCase is DELETED and domain.ConfigUseCase gains
SetMetadata, the write half of the GetMetadata it already published, so the
unit-of-work body can read, refuse and write in one transaction.
THE DEFECT. Proxied `bd init` against a database another rig had already
identified rewrote both markers with its own derived values. It verifies and
adopts now, printing the direct route's existing line, with the role's refusal as
the backstop. The direct route's two identity reads also became one snapshot, so
the prefix it adopts and the project id it reconciles against can no longer come
from either side of a concurrent write; shouldConsultInitProjectID still gates
whether the id is USED, so which identities init adopts is unchanged.
CONFORMANCE. backend/conformance/bootstrapper_contract.go holds twelve cases —
both roles in one file, because every promise on either is a statement about the
other — run at all three implementations with ZERO PARKS and zero divergences.
They deliberately do not re-test the decision: the validator's and the refusal's
whole tables are pinned without a database in internal/workapi/bootstrap_test.go.
What only a real backend can show is asserted instead: that the identity is there
for the NEXT caller (a new transaction on the unit-of-work backend), that a
refusal and a validation failure leave the markers EXACTLY as they were, that the
verifier reports an unreadable identity as an error rather than as an empty one,
and that a bootstrap costs at most one version-control entry. Two independent
bodies plus an engine check, not three votes: dolt and embeddeddolt share
internal/storage/issueops.BootstrapInTx and VerifyIdentityInTx and differ only in
how they reach a transaction. The bodies live there rather than in an importable
store<role> package because the read and the write it qualifies must see one
snapshot, which storage.DoltStorage cannot express — so there is no constructor
for a depguard entry to deny.
NO HTTP OPERATION, and that is a decision. A server can only serve a database it
is already bound to, and binding it required the identity this role writes, so
the only caller that could reach such an endpoint would be asking a running
server to identify a workspace that is by construction already identified — which
is the refusal. Bootstrapping over an unauthenticated surface is a different risk
class from reading one. The read half already has an endpoint:
ContextResponse.project_id on GET /v0/beads/context is InitVerifier's answer, on
the wire, today. Recorded in both leaf docs and in the checklist.
USER-VISIBLE, for the wave's changelog pass: proxied init adopts instead of
overwriting on a shared database; `bd init` no longer heals a substrate carrying
a prefix and no project id, which is Q8 as written; an explicit BEADS_DIR outside
the repo now gets a project id written from its own metadata.json instead of
being left half-identified. Reasoning and the alternatives are in
/data/tmp/sd-server/AMBIGUITIES.md as A-ini-0..7.
A-ini-0 IS A FALSE PREMISE IN THE BRIEF, not a finding about the code: bd-zl3u8,
bd-jtp1h and bd-yby99 do not exist in the workspace at BEADS_DIR. Verified by two
bd binaries failing to open it and by a direct SQL read of all 5,603 issues.
Everything else the brief asserted about the code checked out, so the spec used
was the brief plus Q8 plus A2.
Verified: build, vet, gofmt clean; golangci-lint 0 issues (its unparam check is
what found resolveInitIssuePrefix's now-dead `write` return, removed here);
TestBootstrapperContract 12/12 at dolt, embeddeddolt and uow; internal/workapi,
internal/storage, internal/telemetry, internal/jira, issueops, the root layering
pins and the whole internal/storage/domain and internal/storage/uow packages
green; internal/httpapi green and `make api-check` clean with no spec or
generated diff; TestInit* and TestResolveInit*/TestApplyInitGateway* and
TestCorpusGolden and TestDoctor* green under BEADS_TEST_EMBEDDED_DOLT=1;
TestProxiedServerExternalCreate, TestProxiedServerPing and TestProxiedServerUpdate
green under BEADS_TEST_PROXIED_SERVER=1, each of which runs
`bd init --proxied-server` in its harness; TestProxiedLookup green.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
THE TWO ROUTES DISAGREED ABOUT WHAT --force MEANS on a destructive command.
On a local database `--force` deletes the named beads and orphans their
dependents; on a team server it deleted the whole dependent subtree, `--cascade`
was REFUSED outright ("not supported in proxied-server mode (delete always
cascades)") and Cascade was hardcoded true at both call sites. So there was no
way to delete one bead on a team server without taking everything under it, and
asking for the safer behaviour was an error.
Q1 ANSWERED IN THE ROLE. issueops.Deleter has one method, reached through
store.Deleter() and the provider's own accessor, and the three modes are request
fields: no flags refuses over a dependent the request did not name, Force
orphans it, Cascade deletes the closure. The guard is workapi's and the body's,
below every front door, for the reason Sweeper's require-a-filter gate is: a
second front door that inherited the capability without the guard would orphan a
workspace's graph by omission — which is exactly what this commit's HTTP
operation would otherwise have been.
IT IS A DIFFERENT ROLE FROM Sweeper, not a mode of it. Sweeper erases a set the
caller DESCRIBED; this erases rows the caller NAMED. That is what decides where
each one's safety lives: a description can be accidentally too wide, so Sweeper
carries a require-a-filter refusal; a list of ids cannot be, so this one's guard
is about the graph.
THE DEFECT. The direct route's batch path deleted the rows in one transaction
and then rewrote `[deleted:ID]` into the neighbours' text afterwards, discarding
every update error. A failure in the window left a workspace whose beads were
gone and whose descriptions still cited them by id. The existence probe, the
guard, the cascade expansion, the deletion and the rewrite are now one
transaction. WHAT THAT COSTS is written into the leaf beside the promise: the
transaction is as large as the deletion plus its neighbourhood, so a batch with
a very large neighbourhood fails whole. It is NOT Sweeper's trade (bd-hysee) —
the delete itself was already one transaction on every route — and the part that
is new is named rather than measured, which is recorded for sign-off.
TWO MORE DEFECTS the single call site removed. The one-id path held its own
transaction that removed each edge by hand, so it never reported labels, events
or orphans; and `domain.DeleteIssuesParams.EnforceCascadePolicy` and `.Force`
were declared, documented in fifteen lines describing exactly these three modes,
and READ BY NOTHING. They are deleted; the policy lives in the role now.
THE CONTRACT IS WHAT WAS DELETED, not what was reported.
backend/conformance/deleter_contract.go holds eleven cases, each citing the leaf
doc, run at all three backends with ZERO PARKS and zero divergences. Every case
that acts asserts row counts through QueryScalar rather than trusting the result
the delete reported about itself. They are TWO INDEPENDENT BODIES plus an engine
check: dolt and embeddeddolt share internal/storage/issueops.DeleteInTx and
differ only in how they reach a transaction, and the unit-of-work provider
reaches the same questions through the domain use cases. It does NOT duplicate
backend/conformance/audit_issue-lifecycle.go, which stays the right home for
`DeleteIssues` at the STORAGE seam: that suite's Factory hands back a bare
storage.DoltStorage, so the unit-of-work backend — where the guard did not exist
at all before this commit — can never run a case placed there.
`bd serve` gains POST /v0/beads/issues:delete, spec first. The dependents guard,
the all-or-nothing id resolution and the reference rewrite are the role's, so
the handler is argument validation and a projection. `cascade` and `force`
default false, which is the guarded mode; DeleteIssuesResult is not
x-go-type-pinned for the reason SweepResult is not, and a reflection test keeps
the projection honest. No page envelope, so nothing to pin in pinning.go.
USER-VISIBLE, and the CHANGELOG says so loudly: a team-server script relying on
the implicit cascade starts leaving orphans; `bd delete <one-id>` without
--force now refuses over an outside dependent, converging the direct route's
three paths onto the answer two of them already gave; the proxied `--json`
result gains `orphaned_issues`. Reasoning and the alternatives are in
/data/tmp/sd-server/AMBIGUITIES.md as A-del-1..6.
Verified: build, vet, gofmt clean; golangci-lint 0 issues; make api-check
(regenerate-and-diff plus the httpapi suite) green; TestDeleterContract 11/11 at
dolt, embeddeddolt and uow; the internal/workapi delete unit tests; the
internal/storage, internal/telemetry and root layering pins;
TestConformance/Audit/issue-lifecycle and the dolt TestDeleteIssues* family
(this commit refactors DeleteIssuesInTx's guard); TestEmbeddedDelete,
TestEmbeddedDeleteJSONDependencyErrorContract, TestBurnWisps,
TestWispGCProtectsActiveWisps and TestCLI_WispGCExcludeType under
BEADS_TEST_EMBEDDED_DOLT=1; TestProxiedServerDelete{,ForceOrphans,Wisp,
Concurrent}, TestProxiedServerMolBurn and TestProxiedServerWispGC under
BEADS_TEST_PROXIED_SERVER=1; and TestProxiedLookup*.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
STAGE TWO OF TWO. Stage 1 (aa10a725e) added MaxRows and SkipCounts to
ListRequest and flipped no routes; this is the flip, plus the one role the
decoration needed.
TWO PARTS, and the role first because the flip needs it.
THE ROLE. `issueops.BlockingAnnotator` answers the decoration a listing prints
beside each row — `(parent: X, blocked by: Y, blocks: Z)` — for the ids of a
page that has already been chosen. It is its own role rather than EdgeReader
growth (Q12 asked and answered two), and the distance between them is larger
than it looks: EdgeReader returns STORED ROWS of every type with targets
spelled as stored, no status consulted, and a per-anchor Missing flag from an
existence probe; this one returns a DERIVED summary of two types with closed
blockers dropped, the inbound direction included, and NO existence probe at
all. It is not Reader growth either — it has no order of its own, nothing it
returns depends on how the page was chosen, and a ListRequest field would have
implied the annotation was part of the query.
THERE IS NO MISSING FLAG, and that is a decision the leaf states rather than an
omission: an id that names nothing and an id with no live blocking edges
decorate identically, so a probe would be a read whose answer no caller can
use. One conformance case asserts that ABSENCE of a distinction.
A BLOCKER THIS DATABASE HOLDS NO ROW FOR COUNTS AS OPEN — an `external:`
reference, a foreign-repository id, a row whose issue was deleted. An
unreadable status is not `closed`, and a listing that hid a blocker it could
not resolve would report work as unblocked on the strength of a row it never
found. Both implementations already did this; it now has a sentence and a case.
THE ORDER WITHIN EACH LIST IS NOW PINNED, ascending with repeats collapsed, and
this is the commit's ONE user-visible change. Both lists are joined into one
line of output, so the query's natural order was user-visible bytes that could
move between runs. It affects only rows with two or more live blockers, and it
is recorded as A-blk-2.
TWO BODIES, NOT THREE. dolt and embeddeddolt share
storage/issueops.ExecuteBlockingAnnotation inside their own read transaction;
the unit-of-work provider is the genuinely separate one — it reads BOTH
dependency tiers for every id and merges, where the store side partitions the
ids by plane, and it resolves statuses only for the ids a row mentioned.
FinishBlockingAnnotation is what makes the SHAPE of the answer one decision
rather than two. Seventeen cases, three wirings, ZERO PARKS.
THE HTTP HALF. GET /v0/beads/dependencies/blocking, spec first, `make api-gen`
after. `IssueBlocking` is x-go-type-pinned to the role package the way `Cycle`
and `CycleMember` are, and BOTH the schema and the envelope's Items are pinned
in internal/httpapi/pinning.go — the v2.6.0 allOf trap was checked (the
generated type is a bare alias) and bd-5o3gt did not become two. The size bound
is maxDependencyAnchors, SHARED with the stored-edge read rather than given a
constant of its own: the two operations are asked about the same page of ids,
and two numbers would let a client ask one about a page the other refuses.
`dependencies.blocking` joins the capability vocabulary; `checkDatabaseSource`
grows a required role, which is the edit that reaches code this commit did not
write.
THE FLIP, one mode at a time and named as such in the code. FIRST `--json`:
the role's List runs the same LoadStoreListConfig, the same BuildListFilter and
the same workapi.FinishPage the branch ran longhand, so the page is unchanged
bytes and ErrTooManyRows still reaches handleMaxRowsError for exit 2. SECOND
every text rendering, with SkipCounts set — stage 1 added that field for this
arrival, and without it the flip would trade a plain scan for three aggregate
joins on the most-run command in the tree. THIRD the decoration.
WHAT STAYS OFF THE ROLE is --watch and the hierarchical --parent tree, the two
modes that consume the FILTER as a value. The bead also named --deps and
--format, and its stated reason — "reach no epilogue on either route" — is
false for both: they run FinishPage and printTruncationHint today. What is
genuinely off-role in those two is the WHOLE-GRAPH dependency-record load they
perform, which is neither a page nor the blocking decoration; their page comes
from the role like every other mode's. Recorded as A-blk-3 with the reading
this commit proceeded under, which is also the reading stage 1's own message
states ("stage 2 moves bd list's TEXT path onto the role").
The proxied route loses `runListProxiedReady`: --ready is ListRequest.ReadyFlag
and picking the ready query from it is the role's job on both routes. Two
functions differing only in which use-case method they called is the drift this
replaces.
PROVABLY INERT AT THE CLI, measured rather than argued: 31 `bd list` / `bd
children` invocations — every output mode, both cap knobs, --ready, --parent,
--format, --deps — run against a binary built from integration/facade-wave-3
and one built from this commit, over ONE shared workspace, differ on exactly
the two multi-blocker lines A-blk-2 predicts and nothing else in 687 lines. A
base-against-base run isolates the one other moving line as the
once-per-period install tip.
The forbidigo exception list did NOT shrink, and the count in
issueops/reader.go's claim is unchanged. cmd/bd/list.go and
list_proxied_server.go were never on it; cmd/bd/list_show_filter_modes.go still
is, because the tree walk, the watch loop, the proxied builder call and `bd
show --current` all still name the type. Said in the config rather than implied
by silence.
Verified: build, vet, gofmt clean; golangci-lint 0 issues; the seventeen new
cases at dolt, embeddeddolt (BEADS_TEST_EMBEDDED_DOLT=1) and uow, all green
with no skips; internal/httpapi and make api-check; internal/storage,
internal/telemetry, internal/jira, internal/workapi/..., issueops and the root
layering pins; the embedded `bd list`/`bd children`/max-rows CLI suites,
TestProxiedServerList under BEADS_TEST_PROXIED_SERVER=1 (58 subtests including
tree_parent, the three format modes, ready pagination and the three max-rows
refusals), TestProxiedLookup*, and the protocol corpus package.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`bd purge` selected closed wisps in one transaction and deleted them in
another. A bead closed, unpinned or cited in the window between the two was
judged on one state and acted on in a different one — the TOCTOU the bead
names — and the proxied twin held a second copy of the whole flow: its own
candidate filter, its own glob match, its own closed_at recheck, its own
reference scan and 190 lines of output kept character-identical to the direct
route's by hand.
PURGE AND PRUNE ARE ONE CAPABILITY, which the design left open and the code
answers plainly: both routes already ran ONE function with a `purgeScope`
struct choosing the tier. So issueops.Sweeper has ONE method, reached through
store.Sweeper() and the provider's own accessor, and SweepRequest.Tier selects
the plane — `ephemeral` is purge, `durable` is prune, and the two are disjoint
by construction. What genuinely differed became request fields rather than a
second role: the require-a-filter refusal keys on Tier, and the citation
protection is ASKED FOR (ProtectReferenced) instead of being inferred from a
command name, which is what the shared body did (`scope.cmdName == "prune"`).
Q9 ANSWERED IN THE ROLE. The require-a-filter gate is
workapi.ValidateSweepRequest, below every front door: a durable sweep with
neither a cutoff nor an id pattern is ErrValidation. It is a safety invariant,
not presentation — without it a second front door is one handler away from an
unguarded mass delete, which is exactly what this commit's HTTP operation would
otherwise have been. The CLI keeps its friendly message, and says in place that
it is there for the WORDING while the guard is the role's; the contract case is
what proves the guard survives that branch being deleted.
THE DEFECT, AND ITS PRICE. The whole sweep is now one transaction, so the set
the result describes IS the set it deleted. That gives up the server-backed
store's batched wisp deletion (200 per transaction, added for Dolt's 10s write
timeout after bd-2ehd and ff-tqm): a sweep too large now fails WHOLE. That is
the better failure — the partial one it replaces reported a deleted count of
ZERO while having deleted rows — and the other two backends already worked this
way. It is written down as a promise WITH its cost, and recorded for sign-off.
TWO MORE DEFECTS the single call site removed. `--dry-run` passed force=false
to the delete where the real run passed force=true, so a preview could FAIL
over dependents the sweep would have orphaned — and the CLI answered that
failure with zeros. And `filepath.Match`'s error was discarded on both routes,
so `--pattern '['` printed "No closed beads to prune" and exited 0; it is now
ErrValidation quoting the pattern.
THE CONTRACT IS WHAT WAS DELETED, not what was reported.
backend/conformance/sweeper_contract.go holds ten cases, each citing the leaf
doc, run at all three backends with ZERO PARKS and zero divergences. Every case
that acts asserts row counts through QueryScalar rather than trusting the
result the sweep reported about itself, which on a destructive operation is the
assertion that matters; every case scopes itself with an id pattern, because a
sweep is asked of a whole TIER and an unscoped one would clear the next case's
seeds. They are TWO INDEPENDENT BODIES plus an engine check: dolt and
embeddeddolt share internal/storage/issueops.SweepInTx and differ only in how
they reach a transaction, and the unit-of-work provider reaches the same four
questions through the domain use cases.
THE HTTP OPERATION, spec first (per bd-jtp1h's A2 scope decision):
POST /v0/beads/issues:sweep, capability `issues.sweep` — the first DESTRUCTIVE
operation on a surface that was reads plus one claim. It is a collection-level
custom method with a body rather than DELETE with a query string, because a
dropped query parameter widens what is erased where an unknown body member is
refused by name. The handler decodes six members and calls the role; it does
not implement the safety gate, the tier vocabulary or the glob, all of which
are the role's ErrValidation reaching the wire as a 400 through failSweepErr.
No component carries allOf and none is x-go-type-pinned — there is no canonical
Go struct whose JSON encoding is this body, since the CLI publishes these
numbers under `purged_count`/`pruned_count` — so the projection is tested
instead. `bd serve --help` grew a DESTRUCTIVE OPERATIONS section and the
--allow-non-loopback warning now says peers can bulk-delete closed beads.
`bd gc` keeps the closed-candidate recheck by calling the SAME pure function
the role calls (workapi.FilterSweepCandidates), so the two cannot drift; the
reference matcher and its 10K-body budget moved to internal/workapi with the
scan. cmd/bd/purge.go and purge_proxied_server.go LEFT the forbidigo exception
list, which is how a role commit proves its front doors reached the role.
USER-VISIBLE, for the wave's changelog pass: the version-control label for a
sweep is now `bd: sweep <n> <tier> bead(s)` on both routes, where proxied wrote
`bd: prune <n> bead(s)` and direct wrote `bd: delete <n> issue(s)` — an HTTP
sweep is not `bd prune`, so the label names the operation and the tier from
every door; a malformed `--pattern` now exits non-zero; `--dry-run` no longer
refuses over dependents the real sweep orphans; and `bd serve` gains a
bulk-delete endpoint. Reasoning and the alternatives are in
/data/tmp/sd-server/AMBIGUITIES.md as A-swp-1..9.
Verified: build, vet, gofmt clean; golangci-lint 0 issues; make api-check
(regenerate-and-diff plus the httpapi suite) green; TestSweeperContract 10/10 at
dolt, embeddeddolt and uow; the internal/workapi, internal/storage and
internal/telemetry suites; TestEmbeddedPurge, TestEmbeddedPurgeConcurrent,
TestEmbeddedPrune, TestPrune_protectsBeadCitedByCustomStatusBead and
TestEmbeddedGC under BEADS_TEST_EMBEDDED_DOLT=1; TestProxiedServerPrune under
BEADS_TEST_PROXIED_SERVER=1; TestProxiedLookup*; and the root layering pins.
The protocol corpus has no purge/prune case to account for.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
STAGE ONE OF TWO. Fields, not methods, and no route flips — those are stage 2
(bd-5k21g). `issueops.ListRequest` gains MaxRows, MaxRowsSource and SkipCounts,
each with a conformance contract running at all three backends and zero parks.
MAXROWS IS THE EXACT INVERSE OF OFFSET, which is why it needed no new shape.
Offset is honored by the unit-of-work body — it renders OFFSET — and refused by
the store-backed one with a typed *ErrUnsupported. The cap points the other way:
the store search path enforces it after the scan (EnforceMaxRowsCap), and the
unit-of-work query path (internal/storage/domain/db) reads no cap at all, so a
request carrying one would come back as the FULL uncapped answer with nothing on
it to say so — a caller that set a circuit breaker handed exactly the runaway
query it was guarding against. It refuses instead, naming the operation and the
backend. `bd list --max-rows --proxied-server` has always refused one layer up
in the CLI for that reason; this is the same refusal for the callers that are
not the CLI. RunReaderListMaxRowsIsHonoredOrRefused mirrors
RunReaderOffsetIsHonoredOrRefused, including the never-silently-ignored clause,
and asserts the complement too: a cap the result set FITS inside must still come
back as an ordinary page, or a body that refused every cap out of hand would
pass.
MAXROWSSOURCE is the third field and the bead named two. It is attribution
only — it decides no answer — but `handleMaxRowsError` falls back to
"BEADS_MAX_ROWS" when it is empty, so a request that carried the number without
the source would make stage 2's route flip start telling operators to raise the
wrong knob. The contract asserts it comes back on the cap error.
SKIPCOUNTS is the SkipLabels precedent one column over: the three cardinality
joins are dropped and DependencyCount/DependentCount/CommentCount come back
zero, to be read as unknown rather than as none. It has to land WITH MaxRows —
stage 2 moves `bd list`'s TEXT path onto the role, and that path calls
SearchIssues today and projects no counts at all, so arriving on a counted page
without a way to opt out is a straight perf regression. The expensive member is
the reverse-blocker aggregate, which joins on a COALESCE key the pure-Go
analyzer cannot auto-index — the known embedded sore point, and the reason the
knob is worth having at all.
The contract's second half is the load-bearing one: NOTHING ELSE MOVES. Same
rows, same order, same has-more, same Parent — asserted by running the identical
request both ways rather than against a written-out expectation. Parent is the
tripwire: it rides the same mega-query and is not a cardinality, so an
implementation that made an aggregate join inner, or suppressed the parent join
too, would answer a strict subset and still look like it had "skipped the
counts".
WHAT THE SQL DOES. sqlbuild.SearchCountsSQL's two trailing hydration bools
become one CountsHydration value, so a path cannot pick up one opt-out and drop
the other, and both stores plus the unit-of-work repository read the pair
through one helper. A suppressed aggregate is projected as a constant IN PLACE
rather than removed: the scan reads the six extra columns positionally, so the
shape is invariant. Ready work passes the zero value at every call site —
types.WorkFilter carries neither knob, which is what "SkipLabels and SkipCounts
are not carried onto the ReadyFlag arm" means, now stated where a caller reads
it. MaxRows IS carried there; reader_ready_scope.go already claimed so, and this
is the commit that makes the claim true, since until now the field existed only
on the filter.
ONE HAND-ROLL DELETED. `bd list` built the filter through the shared builder and
then reached in and stamped filter.MaxRows/MaxRowsSource onto it — the
"build it, then change it" half-step this programme exists to make unreachable,
and the reason the cap was invisible to every implementation of Reader.List. The
cap is resolved in gatherListInput onto the request, BuildListFilter is now the
only writer of those two filter fields, and the proxied refusal reads the
already-resolved value (rejectResolvedMaxRowsUnderProxiedServer) so a malformed
BEADS_MAX_ROWS still warns exactly once.
PROVABLY INERT AT THE CLI, measured rather than argued: 22 `bd list` / `bd
children` invocations — every output mode, both max-rows knobs, the malformed
and negative cases — run against a binary built from integration/facade-wave-2
and one built from this commit, over ONE shared workspace so both read identical
data, differ on exactly one line of 617. `bd list --max-rows -1 --status bogus`
now reports the malformed flag instead of the invalid status; both exit 1, it
needs two bad arguments to reach, and it is recorded as A-lst1-3.
NO OPENAPI OPERATION AND NO NEW QUERY PARAMETER, deliberately, recorded as
A-lst1-1. `bd list`'s operation (GET /v0/beads/issues) already exists and is
already on the role, and neither field can be published on it yet: `bd serve`
always builds a provider-backed server, which REFUSES max_rows, so the parameter
would be one the reference server can never honor; and skip_counts would set
three unconditional integers on a PINNED response component to zero, leaving a
client unable to tell "no dependencies" from "not computed" — the failure
comments_omitted exists to prevent on the detail view. `make api-check`
regenerates nothing.
Verified: build, vet, gofmt clean; golangci-lint 0 issues; the two new cases at
dolt, embeddeddolt (BEADS_TEST_EMBEDDED_DOLT=1) and uow, plus the whole Reader
contract at all three; the builder golden (35 recorded cases plus two new ones
for the new fields) and the counts-SQL shape test; internal/httpapi and
make api-check; internal/storage/{issueops,domain/...}, internal/workapi,
internal/types, internal/telemetry, the root package; the embedded
`bd list`/`bd children`/max-rows CLI suites, TestProxiedServerList under
BEADS_TEST_PROXIED_SERVER=1 (including reject_max_rows_flag,
reject_max_rows_env and allow_max_rows_zero), TestProxiedLookup*, and the
protocol corpus package.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`bd query "type=bug OR label=urgent"` has been answering with a prefix of its
answer and calling it complete. The expression language has OR, NOT and
parentheses, which no storage filter expresses, so both routes fetched a WINDOW
of candidate rows — max(3*limit, 100) — and applied the expression to those in
memory. A match past row 100 was absent from the page and unreported by
has-more. The same six lines of arithmetic were written twice, once per route,
and both copies were wrong in the same way.
THE ROLE. issueops.Querier, reached through store.Querier() and the provider's
own accessor. One method over a request whose predicate is a SENTENCE rather
than a set of fields, which is what makes it a role instead of a mode of
Reader: a ListRequest is a conjunction — every field narrows — and no
arrangement of its twelve callers' fields expresses a disjunction. It is
equally not a raw query passthrough; the language names no table, no join and
no column outside a closed vocabulary, which is why a contract can promise
anything about it at all.
THE FIX, which Q3 approved as user-visible. A predicate query's filter now
carries NO row limit: the predicate sees every candidate row, the page is the
first Limit MATCHES of the complete matching set, and has-more is exact. The
decision has one home, internal/workapi.BuildQueryPlan, which both bodies
execute. The cost is stated rather than hidden — a broad OR over a large
workspace now reads every row its base filters admit — and CHANGELOG.md says so
in the same words.
WHAT PINS THE FIX, at three levels, because the contract alone cannot see it.
TestBuildQueryPlanLeavesAPredicateQueryUNBOUNDED asserts the arithmetic in
microseconds. TestAPredicateQueryFindsAMatchBeyondTheOldWindow seeds 101 rows at
ONE backend and reads back the match at row 101 — verified to discriminate:
with the old window temporarily reinstated it returns zero rows. The portable
contract asserts the PROMISE the window broke (a page is a prefix, has-more is
exact) and, confirmed by the same experiment, does NOT discriminate the old
window at its small scale; the contract's header says so rather than implying
coverage it does not have.
THE CONTRACT. backend/conformance/querier_contract.go holds nine cases, each
citing the leaf doc by line, run at all three backends with ZERO parks. TWO
independent bodies plus an engine check: dolt and embeddeddolt share
internal/workapi/storequerier, and the unit-of-work provider is genuinely
separate — it is the only leg on which the Offset case takes its HONORED branch,
since that seam renders OFFSET where the store body refuses uniformly.
TWO SMALLER USER-VISIBLE CHANGES ride along, both filed in AMBIGUITIES.md
(Q22, Q23) for the owner's batch. `--offset` with an OR/NOT expression is no
longer refused: the offset skips MATCHES, which is only meaningful now that
every match is seen, so an error became an answer. `--limit -1` is now
ErrValidation instead of an undocumented second spelling of unlimited. The
`--offset` + `--sort` refusal survives and moved INWARD — the role makes it, for
every caller, because the order is applied to the rows the query bounded and
each page of an offset walk would be sorted for itself — so its wording changed
with its address, as did the wording of a malformed expression on both routes.
A DEFECT FOUND AND NOT FIXED, recorded as A-qry-1 rather than papered over: an
UNLIMITED request carrying an Offset renders SQL the Dolt engine answers with a
recovered panic (makeslice: cap out of range, out of topRowsIter). It predates
this role — `bd query --offset N --limit 0 --proxied-server` built the same
filter — and it is a storage-seam bug, so the contract case asks its question at
a bounded limit and says why at the case site.
THE HTTP OPERATION, spec first (per bd-jtp1h's A2 scope decision):
GET /v0/beads/issues:query, capability `issues.query`, answering a new QueryPage
{items, has_more}. It publishes no cursor and no `offset`: a predicate query's
matching set is assembled outside the database, so there is no keyset position
to encode, and an offset is honored by one database source and refused by the
other, which is not a difference to put on a wire. QueryPage carries no allOf
and its Items are pinned in pinning.go beside ReadyPage's and IssuesPage's — the
edit wave 2 missed once (bd-8ri3m). Adding a second sort enum made oapi-codegen
disambiguate the FIRST one, renaming the generated ListReadyWorkParamsSort
constants (Hybrid -> ListReadyWorkParamsSortHybrid); nothing outside the
generated file named them. httpapi.Config's roles source grows a required eighth
member, and a Config complete under the previous release is now refused at
Listen rather than nil-dereferencing on the first issues:query request.
WHAT ELSE CONVERGED. Both output modes read ONE query — the counted one --json
always used — so a predicate can no longer be applied to two different row sets
depending on the flag (A-qry-1's neighbour, Q24). The direct route prints the
truncation hint for the first time, not by new choice but because it finally has
an honest has-more to print.
Incidental: internal/storage/role_accessor_decorator_test.go's four
near-identical "the four read roles" paragraphs — one appended by each wave-2
slice — are collapsed into the one accurate paragraph the table needs. Same
defect as bd-8ri3m, comments only.
Verified: build, vet, gofmt clean; golangci-lint 0 issues; make api-check green;
TestQuerierContract 9/9 at dolt, embeddeddolt and uow;
TestAPredicateQueryFindsAMatchBeyondTheOldWindow; the internal/httpapi package
suite; internal/workapi, internal/storage, internal/telemetry, internal/query
and the root package; TestEmbeddedQuery under BEADS_TEST_EMBEDDED_DOLT=1 and
TestProxiedServerQuery under BEADS_TEST_PROXIED_SERVER=1; TestProxiedLookup*.
The protocol corpus drives no `bd query` invocation and is untouched.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The version markers had two implementations of one rule. The direct route read
bd_version and bd_version_max out of the metadata plane in
cmd/bd/version_tracking.go, compared them with doctor.CompareVersions and wrote
them back; the proxied route opened a unit of work and called a ReconcileVersion
method on the config use case, which held its own copy of the same comparison,
the same two downgrade guards and the same high-water rule. The two agreed, but
nothing made them agree and no test compared them. Both now ask for a role, and
the difference between the routes is which accessor answers.
THE ROLE BELONGS TO NO COMMAND, and it is the only one in this programme that
does not. It fires from PersistentPreRun on EVERY startup, on both routes,
before the command the user typed has run — which is exactly why it went
unnoticed: `bd version` prints two strings, opens no store and reaches none of
this, so the state machinery was hiding behind a command that does not use it.
THAT ORIGIN IS A CONSTRAINT ON THE PROMISES, not a piece of history, and the
leaf doc says so where a reader will meet it. A role that runs before every
command pays for itself on every command, so it does two point reads on the path
that changes nothing, loads no configuration, takes no lock, repairs nothing —
and, the clause that matters most, it NEVER refuses the command in front of it.
A downgrade is an OUTCOME with a nil error, because an older binary is allowed
to use a workspace a newer one has opened; a genuine failure is an error the
CALLER logs and walks past, which both front doors do at debug level. A role
whose callers must ignore its errors has to say so where the promise is made
rather than leave each caller to decide.
TWO METHODS, ONE ROLE. RecordedVersion and ReconcileVersion are two shapes of
one question — the write's promise IS a statement about what a later read
returns — which is what the governing rule permits a role to be born with, and
WorkspaceConfig set the precedent. It is not padding: the direct front door
needs the READ alone. autoMigrateOnVersionBump probes a read-only store first so
an already-current workspace never pays for the writable open, and before this
commit that probe read the metadata key by hand — the "CLI knows the storage
key" shape this programme exists to remove, on the hottest path in the codebase.
WHY IT IS NOT WorkspaceConfig WITH TWO MORE KEYS. Two planes, two lifetimes. A
workspace setting is durable and travels with the database; these two markers
are dolt-ignored, do not survive a clone and are deliberately different per
machine. Publishing them through the settings plane would put a value that
cannot be shared behind an interface whose whole promise is that its values are.
ONE DECISION, THREE SUBSTRATES. workapi.PlanVersionReconcile is the pure planner
every implementation decides through; domain.ConfigUseCase LOSES ReconcileVersion
and gains SetLocalMetadata, the write half of the GetLocalMetadata it already
published, so the unit-of-work body can read, plan and write in ONE transaction.
Deleting the use-case method is what makes the rule single-sourced rather than
duplicated under a role.
CONFORMANCE. backend/conformance/version_reconciler_contract.go holds nine cases
run at all three implementations with ZERO parks and zero divergences. They
deliberately do NOT re-test the decision: the planner's whole table — upgrade,
no-op, both refusals, the catch-up to the mark, the dotted comparison in which
1.2.0 and 1.2.0-rc1 are equal — is pinned without a database in
internal/workapi/versionreconcile_test.go, and repeating it here would be
testing one pure function three times over three sql-servers. What only a real
backend can show is asserted instead: that a recorded marker is there for the
next caller (a new transaction on the unit-of-work backend), that a refusal and
a validation failure write NOTHING, that reconciliation adds no history entry at
all, and that a reconciliation which CANNOT COMPLETE reports an error and leaves
both markers standing. Two independent bodies plus an engine check, not three
votes: dolt and embeddeddolt share internal/workapi/storeversionreconciler.
The fixture carries one hook the frozen roleFixtureKit cannot supply, built at
each wiring site the way CycleDetectorFixture.Exec is: the two states that
matter most — a recorded version BELOW the high-water mark, and its catch-up —
are states the role can never produce, so they are seeded past it.
THIS IS THE FIRST COVERAGE THE DIRECT ROUTE'S RECONCILIATION HAS EVER HAD. Its
round-trip tests (MigratesVersion, AlreadyMigrated, RefusesDowngrade,
TracksMaxVersion) were deleted with the SQLite backend and never replaced; the
note recording that is still in cmd/bd/version_tracking_test.go. The seven
subtests of the deleted use-case method go with it, replaced by the exhaustive
planner table plus nine cases at three backends.
NO HTTP OPERATION, and that is a decision rather than an omission — recorded in
the leaf doc and as A-ver-2 for the owner. The markers are clone-local: they
describe the machine holding the database, so a remote client reading them
learns something it cannot compare against anything it holds. The one version
fact a client CAN act on, the serving binary's release, is already published as
ContextResponse.bd_version, which the document already names as the only field a
client may compare as a version. A write endpoint is worse: reconciliation is an
effect of a PROCESS STARTING, and a client asking a server to record the
client's version would be asking it to lie about which binary holds the
database. If the owner wants a read-only GET /v0/beads/version, the role, the
accessor and both bodies are already here.
NO USER-VISIBLE CHANGE. Every outcome is identical; only three debug lines
moved. One accidental behaviour became deliberate: a binary whose Version string
is empty used to be handled by the downgrade guard on a populated workspace and
by an equality short-circuit on an empty one, and is now an explicit
ErrValidation that writes nothing either way.
ENFORCEMENT. storeversionreconciler joins the cmd-bd-role-constructors deny
list. The version path never named types.IssueFilter, so there is no forbidigo
exception to remove. engdocs/ADDING_AN_ISSUEOPS_ROLE.md gains the two things
this role taught the checklist: a role may honestly have NO HTTP surface, and a
contract case may need a fixture hook for a state the role cannot produce.
Verified: build, vet, gofmt clean; golangci-lint 0 issues;
TestVersionReconcilerContract green at dolt (9/9), embeddeddolt (9/9) and uow
(9/9); the planner unit tests, both decorator enumerations, the root layering
pins, internal/jira and the internal/storage/domain/db config suite green;
internal/httpapi green and `make api-check` clean with no spec or generated
diff; TestReconcileVersionPersistsAcrossUOW green; TestProxiedLookup green;
`-run 'TestTrackBdVersion|TestAutoMigrateOnVersionBump|TestGetVersionsSince|TestMaybeShowUpgradeNotification|TestInitDoltMetadata'`
green under BEADS_TEST_EMBEDDED_DOLT and TestProxiedServerContext /
TestProxiedServerInfo green under BEADS_TEST_PROXIED_SERVER; TestCorpusGolden
green, so no command's JSON moved.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`bd ready --limit 100` prints "showing 100 of 412", and the 412 came from
nowhere in particular. The direct route computed it inline: unwrap past the
storage decorators, type-assert to storage.ReadyWorkCounter, and fall back to
an unbounded ready query when the assertion missed — twice, once in the --json
branch and once in the text one, with two different fallbacks. The proxied
route could not compute it at all and published no `total` key, so the same
script read a number under one workspace topology and nothing under another.
THE ROLE. issueops.ReadyCounter, reached through store.ReadyCounter() and the
provider's own accessor. It answers a question neither neighbour can: Reader
answers with a PAGE and its verdict is has-more ("did the limit hide
anything"), where this is "how many" — strictly larger, and already published
output, so collapsing the two would change what a shipped surface says. Counter
answers a predicate over one table, and the ready predicate is blocker-aware:
it reads the dependency graph and the wisp tier, which no CountRequest can
describe. Counter's own doc already said the count of ready work would be its
own role for that reason.
It takes issueops.ReadyRequest VERBATIM, the precedent ClaimNextRequest set, so
a listing, a claim and a count ask ONE question of ONE set. Limit and Offset are
ErrValidation for the reason a claim refuses them: a cardinality has no page, so
a limit would answer "how many of the first N" and an offset would subtract the
rows it skipped from the size of a set that still holds them.
THE CONTRACT IS AN IDENTITY, not a resemblance:
CountReady(r).Total == len(Reader.Ready(r with Limit=0).Items)
at every implementation. backend/conformance/ready_counter_contract.go holds
seven cases, each citing the leaf doc by line, run at all three backends with
ZERO parks. They are TWO independent bodies plus an engine check: dolt and
embeddeddolt share internal/workapi/storereadycounter (one indexed COUNT(*) per
plane minus their overlap), and the unit-of-work provider is genuinely separate
code that runs the unbounded ready query and takes its length — which is why
the wisp-tier case is written the way it is, since that is where a COUNT and
the page it sizes are assembled by different arithmetic.
A DEFECT THIS FOUND, and it is not the count's. `bd ready`'s directory-label
default (GH#541) never reached the ReadyClaimer role. claimNextRequest re-ran
the gatherer's own emptiness test against in.filter — and the gatherer had
already written the default INTO that filter, so the test saw a non-empty label
set and skipped. The branch could never fire. In a directory with
`directory.labels` configured, `bd ready --claim` therefore claimed from the
WHOLE ready front while `bd ready` beside it listed only the configured scope:
exactly the "hand an agent work the listing never offered it" that
ReadyClaimer's contract exists to forbid. The gatherer now RECORDS its decision
(readyInput.dirLabels) and both roles read it, so there is one answer instead of
two derivations of it. Caught by writing the count's own test for the same
line, and pinned by cmd/bd/ready_role_request_test.go.
WHAT ELSE CONVERGED. Both routes and both output modes now ask one question
through one accessor: the direct route's two inline epilogues become one call,
and the proxied route's `pagination.total` exists for the first time. The
"showing X of N" text a human reads and the total a script parses are the same
number by construction. cmd/bd no longer names storage.ReadyWorkCounter at all
— the capability is required by the store body's PARAMETER TYPE, so a backend
that cannot size the ready set fails to compile instead of falling back to a
mega-query at runtime.
THE HTTP OPERATION, spec first (per bd-jtp1h's A2 scope decision):
GET /v0/beads/ready:count, capability `ready.count`, answering
`ReadyCount {total}`. It publishes no `limit` and no `sort`: a cardinality has
no page and no order, and the handler sends the listing's own sort default so
the request stays the listing's request rather than one that resembles it. The
filter vocabulary is decoded by ONE function shared with GET /v0/beads/ready
(readyFilters), so the two operations cannot admit different parameters — which
is what the identity rests on over the wire.
`TestCountReadyAndListReadyAdmitTheSameFilters` compares the two predicates
built from one query string. No component here carries allOf and none is
x-go-type-pinned: the pinned seven are canonical Go structs whose JSON encoding
IS the contract, and there is no canonical struct for this number — the CLI
publishes it inside its own stdout envelope, which is not a wire type — so
pinning would weld the body to a CLI presentation type rather than prevent a
drift. The generated output was read to confirm it (a struct with `Total
int64`, not an alias), which is the v2.6.0 trap this document warns about.
httpapi.Config's ROLES database source grows a REQUIRED third member. That is
the sharp edge for the next role commit and is now written down in
engdocs/ADDING_AN_ISSUEOPS_ROLE.md as step 13: a Config carrying the old pair
would bind and then nil-dereference on the first request that reached the new
handler, so Listen refuses it with the same message a half-set pair gets.
USER-VISIBLE, for the wave's changelog pass: proxied `bd ready --json --limit N`
now publishes `pagination.total`; `bd ready --claim` now honours the
directory-label scope on both routes.
Verified: build, vet, gofmt clean; golangci-lint 0 issues; make api-check
(regenerate-and-diff plus the httpapi suite) green; TestReadyCounterContract
7/7 at dolt, embeddeddolt and uow; the httpapi package suite; the direct-route
`bd ready` suites under BEADS_TEST_EMBEDDED_DOLT=1 and the proxied ones under
BEADS_TEST_PROXIED_SERVER=1, including the pagination envelope that now asserts
the total; TestProxiedLookup*; and the ready protocol-corpus tests, which are
byte-identical.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`bd status` (and its `bd stats` alias) had two implementations of the same
command. The direct route asked the store for statistics and, under
--assigned, built an assignee filter, ran a ready-work query and folded
five status counts itself; status_proxied_server.go did all four again
through a unit of work. Both now build an issueops request and ask for the
role, and the difference between the two routes is which accessor answers.
THE ROLE. Its numbers are DEPENDENCY-AWARE — the blocked count reads the
denormalized transitive is_blocked flag and readiness is derived from it —
so no predicate over the issues table describes them and this is its own
role rather than a sixth Counter dimension, which is what issueops/
counter.go already said it would be. Stats and AssigneeStats are born
together because they answer the same question of two sets; they are two
METHODS rather than one with an Assignee field because the assignee answer
fills four fields of the same struct by different definitions, and a
request whose optional string silently changed what a number meant is the
shape this programme exists to remove.
WHAT THE LEAF DOC NOW SAYS OUT LOUD, none of it written down anywhere
before: BlockedIssues counts the graph, not the "blocked" status;
ReadyIssues is arithmetic and NOT the cardinality of `bd ready`;
PinnedIssues overlaps every status bucket so the buckets do not sum to
Total; the workspace-wide answer excludes the wisp tier while the
assignee-scoped one merges it; --no-blocked is a HINT whose only report is
BlockedIssues being nil; and EpicsEligibleForClosure and AverageLeadTime
are structurally always zero, which is why `bd status`'s "Extended:"
branch has never once printed.
CONFORMANCE. backend/conformance/stats_reporter_contract.go holds thirteen
cases, each citing the leaf doc by line, run at all three implementations
with ZERO parks and zero divergences. Unusually for this suite they are
THREE genuine votes: the two stores share the role body (storestats) but
dolt/queries.go, embeddeddolt/statistics.go and domain/db/issue.go each
spell the blocked count and the ready subtraction themselves. Every
workspace-wide case asserts a before/after DELTA — a summary takes no
predicate, so there is no IDFilter to scope it with the way the Counter
contract scopes its cases.
HTTP. GET /v0/beads/stats is added to the Tier-1 document FIRST and the
types generated from it: a `Statistics` schema x-go-type-pinned to
types.Statistics (checked: the pin survives, and the schema is now in the
JSON-tag bijection test), a StatsResponse envelope mirroring the CLI's
--json shape minus `recent_activity`, which no shipped path populates. The
handler calls the same role both CLI routes call. `blocked_count_skipped`
is DERIVED from the answer, never echoed from the request, because the
hint is a hint. httpapi.Config's roles source grows a third field and
requires it with the other two: a source that answers some operations and
faults on others is not a source.
ENFORCEMENT. cmd/bd/status.go and status_proxied_server.go no longer name
types.IssueFilter or types.WorkFilter, so `status` LEAVES the forbidigo
exception list (63 -> 61 of 388 files). The role-constructor depguard list
gains storestats.
TWO USER-VISIBLE CHANGES, both improvements and both small: `bd status
--assigned` reports the underlying failure instead of the bare "failed to
get assigned statistics", identically on both routes; and the proxied
--no-blocked warning now fires from the ANSWER rather than from the route,
so a backend that gains a fast path stops printing it with no edit.
Verified: build, vet, gofmt clean; golangci-lint 0 issues; make api-check
clean (no codegen drift, whole httpapi package green);
TestStatsReporterContract 13/13 at dolt, embeddeddolt and uow;
TestEmbeddedStatus and TestProxiedServerStatus green with their gates set;
TestProxiedLookup green; TestCorpusGolden green.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`bd config` had two implementations of the same four verbs. The direct route
called store.SetConfig/GetConfig/GetAllConfig/DeleteConfig in cmd/bd/config.go;
the proxied route opened its own unit of work and called the config use case in
config_proxied_server.go, then printed the same lines a hundred lines away. Both
now build an issueops request and ask for the role, and the difference between
the two routes is which accessor answers.
THE ROLE. issueops.WorkspaceConfig is the workspace's DURABLE SETTINGS PLANE:
the key-value rows the workspace database holds. It is born with four methods
because read, write, remove and enumerate over ONE keyed namespace are four
shapes of one question — the governing rule forbids appending to a role, not a
role being born whole — and because their promises are statements about each
other: SetSetting's promise is about what a later GetSetting returns, and
UnsetSetting's about what a later ListSettings omits.
The methods are GetSetting/ListSettings/SetSetting/UnsetSetting rather than
Get/List/Set/Unset, and that is not verbosity. Reader already has Get and List,
and the decorator conformance tests drive ONE sentinel that implements every
role at once; two roles with the same method name and different signatures make
that sentinel unwritable. The collision was the design telling us the short
names belong to issues.
ONLY THE KV SLICE IS A ROLE, and the rest is a deliberate no. `bd config show`,
`drift`, `apply` and `validate` are multi-source diagnostics over config.yaml,
environment variables, git config, this plane and server state at once. Three of
those five sources are files on the CLIENT's filesystem, which a server
answering for a remote workspace can never read, so a substrate role claiming to
answer them would be claiming to see something it cannot. `bd config set-many`
is off the role too, for a different reason: it exists to make N keys ONE Dolt
commit, the role writes and commits one setting per call, and
TestProxiedServerConfigSetMany pins the difference. A batched write is a
separate capability, exactly as `bd create --file` stays off Lifecycle.Create.
TWO LIVE DEFECTS FIXED.
1. THE PROJECTION, which is the Q11 user-visible change. Reads of the custom
status and type vocabularies are TABLE-first: they consult custom_statuses
and custom_types and fall back to the config string only when the table is
empty. The store backends have always rewritten the table in the same
transaction as the row; the unit-of-work backend wrote only the string. So
on a team server `bd config set types.custom "session"` reported success,
`bd config get` read it back, `bd doctor` re-verified against the string and
reported all-OK, and `bd create -t session` answered "invalid issue type"
for as long as the workspace lived. Fixed where dab71c5eb fixed it — in the
config repository, so the row and its projection commit together — and
verified by reverting the fix and watching ProjectsCustomStatuses and
ProjectsCustomTypes fail on uow alone.
2. `bd config set-many issue_prefix=x` re-prefixed the workspace. The
single-key verb refuses the prefix in both spellings and points at
`bd init --prefix`, `bd bootstrap` and `bd rename-prefix`; set-many
partitioned its pairs by source and wrote the database ones straight
through, so it never saw that guard. Beads created before the write and
after it disagreed about their own namespace with nothing to reconcile
them. The refusal is now in the role for every caller that goes through it,
and at set-many's front door because it does not.
THE BRIEF'S THIRD PREMISE IS FALSE, and it is worth saying so: "uow SetConfig
skips issue_prefix normalization" is not true at this base.
configSQLRepositoryImpl.SetConfig has trimmed the trailing hyphen since the file
was created (4fcbd5882, verified with git log -L). The normalization half needed
no fix; the custom-table half did, and dab71c5eb is NOT in this base.
WHAT ELSE CONVERGED. The status.custom parse lived in THREE places (both routes
of `bd config set` plus set-many) and is now one; the routing that stays at the
front door — which source owns a key, and whether writing it would leak a secret
into git — stays there, because those are questions about files on this machine.
CONFORMANCE. backend/conformance/workspaceconfig_contract.go holds fourteen
cases run at all three implementations with ZERO parks. Its shape is
deliberately not the issue contracts': there are no rows to seed, so it asserts
PRECEDENCE (which of two writes a later read sees, and whether a refusal leaves
the earlier value standing) and SIDE EFFECTS. Every projection case reads the
TABLE through QueryScalar rather than reading the setting back through the role,
because reading it back through the role is exactly the check that passed on the
backend where nothing took effect. Two independent bodies plus an engine check,
not three votes: dolt and embeddeddolt share
internal/workapi/storeworkspaceconfig.
TWO ASYMMETRIES ARE PINNED RATHER THAN FIXED, because all three backends agree
and closing either is a user-visible change this slice was not approved for.
UnsetSetting does not undo SetSetting's projection, so removing types.custom
leaves the custom types applying (bd-yby99.33); and `bd config unset
issue_prefix` is not refused where `bd config set` is (bd-yby99.34). Both are
stated in the leaf doc and asserted by a case, so neither can drift or be closed
on one backend while the owner decides.
HTTP. GET /v0/beads/config and GET /v0/beads/config/{key}, spec-first, taking
the v0 surface from six operations to eight. A setting whose KEY marks it as
credential-bearing — notion.token is database-backed — is published with
`redacted: true` and NO value: withheld values are omitted rather than masked,
which is the document's own "verbatim or absent" rule, and the CLI is unchanged
because its caller already holds the database while this surface has no
authentication. There is no HTTP WRITE, and that is the honest answer rather
than a hedge: `bd config set` routes most keys to config.yaml or git config
before the database is reached, so a server-side PUT of `export.auto` would
return 200 and land a row nothing reads. `Setting` is the one unpinned response
component, with the reason in the document beside it — the CLI marshals an
ad-hoc map, so there is no canonical struct to pin to, and minting one would
mean changing `bd config get --json` in order to satisfy a rule about not
changing it. All three are recorded in AMBIGUITIES.md as A-cfg-1..3.
ENFORCEMENT. storeworkspaceconfig joins the cmd-bd-role-constructors deny list.
`bd config` never named types.IssueFilter, so there is no forbidigo exception to
remove. engdocs/ADDING_AN_ISSUEOPS_ROLE.md gains what step 12 now costs since
the owner's scope decision: the spec operation, the route row, the Op constant
and operationCodes row, the capability token, and the Config field that a
store-shaped database source must now carry.
Verified: build, vet, gofmt clean; golangci-lint 0 issues;
TestWorkspaceConfigContract green at dolt (14/14), embeddeddolt (14/14) and uow
(14/14); the workapi validator unit tests, the two decorator enumerations, the
root layering pins and internal/jira green; internal/httpapi green and
`make api-check` clean; TestProxiedLookup green; `-run Config` green under
BEADS_TEST_EMBEDDED_DOLT and, under BEADS_TEST_PROXIED_SERVER, green except
TestConfigValidateReadOnlyIsHermetic, which fails identically on a pristine base
worktree under the same filter and passes standalone on both. TestCorpusGolden
green, so `bd config --json` is byte-identical to the committed corpus.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`bd count` had two implementations of the same command. The direct route
built a types.IssueFilter in cmd/bd/count.go, loaded the workspace list
config and applied the --include-infra policy; the proxied route did all
four again in count_proxied_server.go and executed against the use case.
Both now build an issueops.CountRequest and ask for the role, and the
difference between the two routes is which accessor answers.
THE ROLE. Counts are NUMBERS; Reader answers PAGES OF ISSUES. Different
question, so its own role per the governing rule rather than a counted
variant on Reader: a count has no order, no page and no cursor, and a
request type carrying paging fields a count must ignore is the shape that
makes a caller believe --limit 10 bounded the answer. Count and
CountByGroup are two shapes of ONE question and cannot be separated in
practice - the grouped answer carries the scalar Total, because label
buckets overlap and the sum is wrong - so the role is born with both.
WHAT CONVERGED, beyond the duplication:
- the wisp-tier policy. BuildCountFilter is now the single definition of
what `bd count` means, beside BuildListFilter, and the GH#4387
cardinality-parity test moved from cmd/bd to internal/workapi where it
compares the two SHARED builders instead of a CLI helper against one
of them.
- the grouped Total. "use the scalar count, not the sum, because label
buckets overlap" lived in cmd/bd; an HTTP surface adding grouped
counts would have had to rediscover it.
- the config load. It happens inside the role, and only under
IncludeInfra, so a plain count still makes one query.
CONFORMANCE. backend/conformance/counter_contract.go holds twelve cases,
each citing the leaf doc by line, run at all three implementations with
ZERO parks. They are TWO independent votes plus an engine check, not
three: dolt and embeddeddolt both hand back internal/workapi/storecounter,
and the unit-of-work provider is the second body.
ENFORCEMENT. cmd/bd/count.go no longer names types.IssueFilter, so `count`
LEAVES the forbidigo exception list - the hole it needed is closed rather
than merely unused. The reader-constructor depguard rule becomes
cmd-bd-role-constructors and gains storecounter, so it is a list the next
role extends by one line instead of a rule per role.
NO HTTP HANDLER EXISTS for count. `bd serve` publishes /healthz,
/v0/beads/context, /v0/beads/ready, /v0/beads/issues, /v0/beads/issues/{id}
and POST /v0/beads/issues/{id}:claim, and the spec is Tier-1 ratified, so
none was invented.
THE PER-ROLE COST, which no design budgeted, is now written down in
engdocs/ADDING_AN_ISSUEOPS_ROLE.md: twelve steps derived from this commit,
naming the accessor line in internal/storage/storage.go, the hook and
telemetry wrappers, the two store accessors, the unit-of-work source, the
three conformance wirings, the five places each decorator enumeration
lists a role, and the two lint edits. Every later new-role commit follows
it.
Verified: build, vet, gofmt clean; golangci-lint 0 issues;
TestCounterContract green at dolt (12/12), embeddeddolt (12/12) and uow
(12/12); TestEmbeddedCount* and TestProxiedServerCount* green with their
gates set; TestCorpusGolden green, so `bd count --json` is byte-identical
to the committed protocol corpus.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Beads had two implementations of most issue verbs: one for the direct route
(the CLI talking to a store it opened itself) and one for the proxied-server
route (the CLI talking through a unit of work over a running Dolt server).
They drifted — different commit messages, different transaction boundaries,
different refusals, occasionally different answers.
Seven role interfaces now live in the leaf package issueops: Lifecycle,
Reader, ReadyClaimer, BatchCloser, DependencyEditor, Commenter and Relations.
Each is reached only through a store accessor, never a constructor, because
the accessor is where the hook and telemetry decorators add their layers.
Three implementations back every role — dolt, embeddeddolt, and the
unit-of-work provider the proxied route uses. Both routes call the same role
for close, dep add/remove/list, comment, ready --claim and update.
A depguard rule (httpapi-domain-boundary) denies internal/storage/domain from
internal/httpapi, so a handler cannot reach uw.IssueUseCase() past the roles
and open a second front door one lint-clean commit at a time.
Behaviour users will notice, all in the CHANGELOG:
- bd close a b c is one Dolt commit, not three, and --claim-next moved
inside that transaction so it fires only when something landed
- the open-children guard moved into the transaction and its hand-rolled
cmd/bd copy is gone, removing a read-then-write window that made
bd close <child> <parent> depend on argument order
- bd dep add --file honours deferred version commit
- embedded bd comment writes the role's message and author
- dep verb commit messages are the role's on the direct route
Wisp-sourced dependency edges are restored. Moving bd dep add onto the role
had pinned an edge's SOURCE to the issues plane, and the two routes did not
even fail alike: direct refused with "issue <id> not found", proxied threw an
fk_dep_issue violation. The comment justifying the pin claimed the issues
plane was "the only one its unit-of-work sibling can reach" — that was false;
domain.DependencyUseCase declared a full set of wisp twins with no production
caller. All three implementations now route per edge by the edge's own
source. A mixed request stays one transaction: parent-child-first ordering
and the whole-graph cycle gate span both planes, and a refusal rolls back
both. Behind the role, three bulk add verbs collapsed into one source-routed
AddDependencies, so no plane-pinned variant is left to reach for by mistake.
Six Provenance fields with no production caller were deleted rather than
wired — CloseRequest, CloseBatchRequest, ClaimNextRequest, AddCommentRequest,
AddDependenciesRequest, RemoveDependencyRequest. Each role already composes an
id-bearing message, so a caller could only restate the default and make it
unreachable from production. Two are not caller-settable even in principle:
CloseBatchCommitMessage names what LANDED and ClaimNextCommitMessage names the
id the claim WON. UpdateRequest and ReopenRequest keep theirs; commit messages
users see are unchanged.
Verified: build, vet and gofmt clean; golangci-lint 0 issues; protocol corpus
byte-identical under BEADS_PROTOCOL_REQUIRE_DOLT=1; all twelve
DependencyEditor conformance wirings green (four contract functions against
each implementation); TestEmbeddedDepAddWispSource runs bd dep add <wisp-id>
at the front door and was demonstrated RED against the pinned routing first.
Three internal/storage/dolt failures reproduce on pristine origin/main.
Known gaps are enumerated in the PR description rather than left to be found:
comment listing is on no role, bd dep tree and bd dep cycles have no role,
bd create and bd reopen are on Lifecycle only on the direct route, per-edge
line attribution is lost in bd dep add --file, multi-store bd close
--claim-next rides only the first store's batch, and the is_blocked staging gap
(bd-2y9ke, predates this change). Seven of the eight role interfaces now have a
shared conformance contract in backend/conformance, run at all three
implementations; main's Claimer, added in parallel by #5334, is the eighth and
has none yet.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Two claims were true of the function and not of the sentence around it.
"EXECUTION through workapi.FinishPage for `bd list` on both routes" is
mode-scoped and did not say so. The hierarchical --parent tree under
pretty output reaches no epilogue on either route: the direct route
computes a page at list.go, then discards it for getHierarchicalChildren's
recursive walk, and the proxied route returns into
runListProxiedHierarchicalParent before FinishPage is called at all.
Neither sorts, trims or reports has-more. Every other listing - JSON,
plain text, --watch, --ready - does run the epilogue, so the correction
is "in every mode but one", named, rather than a retreat to "shares
something".
FinishPage's own doc said a limit of 0 means "nothing is cut and there
is by definition nothing more". The first half is what the code does; the
second is not. With limit 0 the cut is skipped and the hasMore SEED is
returned unchanged, so a seam that already reported more rows behind an
unlimited request keeps saying so - which is the honest answer, since a
cut that never ran cannot contradict it. The doc now describes that, and
the test case that carried the old wording in its name is split: one case
for "never cut", one new case for a true seed surviving limit 0.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The doc comments claimed the property at the level it was true and
hand-waved the rest. They now say the whole of it, per surface:
- every read the HTTP surface answers goes through the role, and two lint
rules make reaching past it a lint failure;
- `bd show --json` is on the role on BOTH routes now, keeping only its own
id resolution, which has no place on a contract an HTTP client calls;
- `bd ready` and `bd list` are on neither route, and will not be until
there are more roles to route them through — what they share is the
builders (pinned by golden files) and, for list on both routes and ready
on the proxied one, workapi.FinishPage;
- `bd ready`'s DIRECT route shares no epilogue and cannot, because it
publishes a hidden-row total the role has no member for. Said plainly
rather than left out.
claimOnUOW records the claim-path decision instead of leaving it
unexplained: the CAS is already ONE implementation a level below both
surfaces (domain issueUseCaseImpl.claim, which ClaimIssue and
ApplyUpdate's spec.Claim arm are two names for), so there is no claim
logic above it to extract. What is above it is a batch-with-per-id-exit-
codes on one side and a typed 409 on the other, and a function spanning
those would be two halves with one caller each.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Both surfaces already shared CONSTRUCTION — one BuildListFilter, one
BuildReadyFilter, both over the same issueops request types, both pinned
by the builders' golden files. They executed separately: the two Reader
implementations applied the over-fetch/sort/trim/HasMore tail, and each
CLI route applied its own copy. That tail had already drifted twice, and
both times it was the same bug in the same three lines written in two
places — a --ready page under a sort the database cannot express came
back untrimmed from one implementation, and the proxied route answered
`--sort id --limit 5` with every row while the direct route answered
with five.
workapi.FinishPage is now that tail, once. It is called by both
issueops.Reader implementations, by both of `bd list`'s routes, and by
the proxied `bd ready` listing. Nothing about the contract widened: the
epilogue takes rows, an order, a page limit and the seam's own has-more,
and answers with the page and the verdict. A seam that reports has-more
natively seeds it; a seam that does not passes false and lets the
over-fetched row speak.
`bd ready`'s DIRECT route keeps its own epilogue, and the comment in
ready_input.go now says so instead of claiming otherwise: it answers the
strictly larger question "how many rows were hidden" with a second
counting query and publishes the total in its pagination meta, which the
role has no way to express and the CLI cannot stop printing.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`workapi.NewStoreReader` was exported and lived in internal/workapi, which 22
cmd/bd files already import for the builders. It takes storage.DoltStorage — an
interface a command already holds — so it was a one-line drop-in replacement for
`store.IssueReader()` from any front door, and the wrong one: every storage
decorator adds its layer in its OWN accessor (telemetry's reader-level spans, the
hook store's deliberate pass-through), so a command that constructed a reader
directly would get a bare unspanned one and the code would look entirely
ordinary. The old doc comment said "nothing does; the accessor is the door",
which is a promise, not a guard.
It has real callers, so it cannot simply be unexported: dolt.DoltStore and
embeddeddolt.EmbeddedDoltStore both need one shared body for their accessors,
and they are in different packages. So the body moves down to
internal/workapi/storereader instead, where those two are the only importers,
and the cmd-bd-reader-constructor depguard rule keeps cmd/bd out. Nothing about
internal/httpapi changes: depguard matches pkg by prefix, so
httpapi-transport-boundary already denied the subpackage along with its parent.
The two store packages' own NewIssueReader are unexported at the same time. They
had no caller but their own accessor, they are in internal/ so no out-of-tree
consumer can reach them, and leaving them exported would have left the same door
open one package over.
SEEN TO FAIL, on the golangci-lint version CI installs. `bd show --json` switched
from the accessor to the constructor — the exact bypass — compiles and vets
clean:
$ golangci-lint run --config=.golangci.yml --build-tags=gms_pure_go ./...
cmd/bd/show.go:15:2: import
'github.com/steveyegge/beads/internal/workapi/storereader' is not allowed from
list 'cmd-bd-reader-constructor': a command reaches the reader role through
store.IssueReader(), never through the constructor ... (depguard)
exit 1
ErrUnsupported.Op moves with the function, "NewStoreReader" -> "storereader.New",
so the Op still names the function that refused; its test moves with it.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
"Both front doors can only say rd.List(ctx, req)" was false for two of three
operations on the CLI side. `bd ready` and `bd list` still load config, build a
filter and stamp the --max-rows cap on it, on BOTH their routes — the exact
ritual the role exists to make unwritable — and five doc comments asserted
otherwise, including the leaf contract's own.
The gap is real and is not closed by moving MaxRows onto the leaf requests:
those commands consume the FILTER for --claim, --gated, --explain, --mol,
--watch, the hierarchical --parent tree and the text renderings that want
[]*types.Issue rather than a counted page. Routing only their JSON paths
through the role would fork each command in two, which is more drift, not
less. Closing it needs more roles, not more methods on this one.
So every claim now states its scope: the HTTP surface is on the role for all
three operations and machine-checked; `bd show --json` is on the role; the two
paging commands are not, and their protection is one level down — the same
builders over the same request types, pinned by the builders' golden files. The
two sites that still call the builders say why, in place.
Third structural divergence recorded on the parity oracle, which listed only
two: the endpoint always defaults to workapi.DefaultListLimit, while `bd list`
resolves a five-way CLI policy first (explicit --limit, --all, configured
list.limit, piped stdout -> unlimited per GH#4094, agent mode -> 20), so the
shared request-level default is unreachable from the CLI and `bd list --json |
...` swapped for the HTTP call loses rows past 50. The oracle passes an
explicit limit on both sides, so it never saw this.
TestListLimitPolicyIsResolvedBeforeTheRequest pins the policy branch by branch
against a real initialized config — removing the piped branch makes it report
50 where the CLI promises 0.
Two comments still naming the deleted ReadyParams type now name
issueops.ReadyRequest.
storeReader.Ready and storeReader.List had zero coverage: no front door reaches
them (the CLI's paging commands still call the builders directly, and the HTTP
surface goes through the uow reader), so the over-fetch and trim that moved out
of cmd/bd/list.go lived unexercised. They are pinned now — the +1 probe row, the
trim back to the page limit, an exact page reported as complete, an unlimited
query left unlimited, and SQLLimit's two cases — against a fake DoltStorage
that honors the row limit the way a query would.
TestCursorRoundTrips never round-tripped. The fixture's CreatedAt was the zero
time, decodeCursor rejects a zero instant as an empty position, so `ok` was
always false and BOTH assertion branches were dead: the test passed with
encodeCursor broken outright. It now mints from a real instant and asserts the
id and the instant come back exactly; dropping CreatedAt from cursorFor fails it.
Also aligns the nil-store refusal's Op with the constructor it names
(NewStoreReader, matching the store packages' NewIssueReader), which the new
test asserts.
The frozen document says an invalid `metadata_field` key is a 400. It was a
500: the only check lived in the SQL builder, so the failure arrived wrapped in
the storage method's name ("GetReadyWorkWithCounts: invalid metadata key ...")
— a shape nothing above storage can classify — and client typos landed in the
request_error alarm stream. Three doc comments already claimed otherwise,
including the leaf contract's "Keys are validated inside", which no Reader
implementation did.
Both builders now call one validator, so the claim is true of every
implementation of the role rather than of the CLI's flag parsing only. The CLI
keeps its own usage errors: it validates the same input at flag-parse time and
reaches the builder with the keys already checked, so its messages and exit
codes are untouched.
invalidFilterParam gains the two prefixes, and every row of that switch — the
three that were already there included — is now driven end to end by
TestABuilderRefusalIsTheDocumentedBadRequest. `invalid issue type ` was pinned
nowhere before: rewording it in list.go turns ?type=bogus into a 500 and now
fails that test.
Reader is Lifecycle's read counterpart, built as its mirror image: a role in
the leaf `issueops` package, reached through a capability accessor on the
storage seam, implemented at the same six sites. `Storage` gains
`IssueReader() (issueops.Reader, error)` beside `IssueLifecycle()`, and the
governing rule holds — a new capability got a new role and a new accessor,
not four more methods on an existing one.
SUBSUME, NOT COMPOSE. Reader takes the whole high-level request and performs
filter and default construction INTERNALLY, supplying its own ConfigSource
from the store or unit of work it already holds. Under compose both front
doors would each build a ConfigSource, load config, call a builder and execute
— two callers again, which is the topology that shipped a bare IssueFilter to
a viewer and silently served in_progress rows as "ready". Under subsume the
ritual is not callable from a front door: handlers and RunE bodies can only
say rd.List(ctx, req), so the failure mode is unwritable rather than merely
discouraged.
The three read endpoints are implemented against the frozen OpenAPI v0
document and consume the accessor; the 501 stubs and their self-deleting
exemption list are gone. `bd show --json` reaches the same role through the
same accessor, resolving the canonical id first so fuzzy and cross-repo
lookup stay CLI-local.
The workapi builders are re-typed onto the leaf request types, so there is no
second params struct to drift; both recorded goldens replay byte-identical,
which is the proof the re-typing changed nothing.
Load-bearing details:
- `sort` is forwarded EXPLICITLY as priority when absent. The storage layer
reads an empty policy as hybrid, which demotes older high-priority work and
therefore changes the item SET once a limit truncates — while the document
still reads correctly. Pinned by a handler test on the recorded filter and
by the parity oracle's order assertion.
- The parity oracle compares FULL ITEM JSON, not id sets. An id-set oracle
passes while ready ships a bare Issue against the CLI's IssueWithCounts.
- internal/workapi no longer imports internal/storage/uow; it names the slice
of a unit of work it reads through, so the uow provider can implement the
role without closing an import cycle.
- internal/utils' cgo store test moves to an external test package for the
same reason, with its two unexported-symbol cases split out.
Verified: issueops is still a leaf (internal/types + stdlib only); the
protocol corpus is unchanged structurally and behaviourally under
BEADS_PROTOCOL_REQUIRE_DOLT=1; a real `bd serve` answers all six operations
against a real workspace with CLI and HTTP JSON identical field for field.
Correction to bd-ehi's report: it claimed all six divergences between the two
pre-collapse builders are machine-pinned by TestReadyFilterGoldenDivergences.
Five of them are. The sixth - the shared gatherer reporting five usage errors
through HandleErrorRespectJSON where the proxied builder used HandleError - is
not, and cannot be: the golden was recorded with jsonOutput false, where the
two helpers print the same stderr line, so those cases show up as agreements.
The change is observable and worth keeping: the direct route has always used
the RespectJSON variant, so unifying on it leaves that route byte-identical
and gives the proxied one what --json means everywhere else in bd. Reverting
would instead break the direct route. So it is pinned rather than reverted:
- TestGatherReadyInputUsageErrorsRespectJSON asserts, for each of the five,
that a JSON error object lands on stdout and stderr stays empty.
- The proxied integration suite asserts the same end to end for three of
them, which is the route whose behaviour actually changed.
The divergence test's doc comment now says what the golden structurally cannot
see and where that is covered instead, so the next reader does not repeat the
claim.
Agent-Signature: claude-code-opus-5-unknown-reasoning on behalf of CI Bot
`bd ready --offset -1` started exiting 1 with "--offset must be >= 0" outside
proxied mode, where it used to print ready work. The direct RunE only ever
rejected --offset > 0 ("only supported under --proxied-server") and never
looked at the flag again, so a negative value was a no-op there; moving the
proxied gatherer's validation into the shared gatherer handed it to a route
that had never had it.
--offset is a proxied-only flag, so its validation belongs to the proxied
route's RunE, which is where it now runs - before gathering, so it still
precedes the mol-type, metadata and sort checks exactly as it did when it sat
at the top of the gatherer. It keeps HandleError rather than the RespectJSON
variant: this message is the proxied route's alone, and plain stderr text is
what it has always been.
The shared gatherer now takes an offset only when it is positive, which is
what both old builders did with the values that reached them: the direct one
never set Offset at all, and the proxied one had already rejected negatives.
Pinned three ways: a unit test on the gatherer, a live-CLI embedded test that
`bd ready --offset -1` still lists ready work, and a proxied integration test
that the same command line is still rejected there.
Agent-Signature: claude-code-opus-5-unknown-reasoning on behalf of CI Bot
The GH#541 directory label is a configured value, not user input, and both
pre-collapse builders put it on the filter verbatim: they assigned
config.GetDirectoryLabels() to labelsAny *after* NormalizeLabels had run over
the user's sets. Routing it through ReadyParams changed that, because
BuildReadyFilter normalizes the label sets it is given - so a directory.labels
value with stray whitespace silently started matching a different label.
The golden could not catch it: the generator ran with no directory.labels
configured, so the branch was never recorded. It is a real config path, hence
a test that would have - the configured label is one NormalizeLabels visibly
rewrites, and the assertion is against the raw value.
The default's emptiness gate now reads the built filter's label sets rather
than a locally normalized copy. That is the same decision (BuildReadyFilter
normalizes with the same function) and it removes cmd/bd's second normalize
pass along with the "NormalizeLabels is idempotent" hand-wave that justified
it.
Agent-Signature: claude-code-opus-5-unknown-reasoning on behalf of CI Bot
TestGetIssueOrWispKeepsHardErrors did not test what it claimed. Both fakes
hard-errored on GetIssue AND GetWisp, so the pre-fix fall-through resolver
reached the same hard error by the longer route and the test stayed green
under mutation - it pinned the "no not-found decay" half of the fix and
nothing about ordering.
The scenario that discriminates is the asymmetric one: the issue lookup
fails while the id happens to exist in the wisp table. Fall-through answers
that with (wisp, true, nil) - a dead backend reported as a successful read
of a different table. fakeIssueUC grows an issueErr knob for exactly that,
and the new subtest fails against the old semantics.
The store subtest stays and is now documented as what it is: the store
adapter's GetWisp is a hardwired dead end, so that seam has no fall-through
to suppress and cannot discriminate. It pins that the store's hard error
still reaches the caller.
Also unexports IsNotFound. It had no caller outside the package - all six
cmd/bd sites test errors.Is(err, storage.ErrNotFound) against the already
normalized error - and exporting it cut against the design, handing
frontends a second way to read raw seam errors when the point of
GetIssueOrWisp is that they never see one.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Lift the detail view - labels, dependencies with metadata, the three
cardinality counts, the comments-omitted flag, the shallow dependent
rows, and epic progress - into internal/workapi/detail.go behind
BuildIssueDetails + DetailSource, with store and UOW adapters. Both
copies in cmd/bd are deleted: bd show's direct assembly block and
proxiedBuildDetails, along with proxiedGetIssueOrWisp, proxiedCountDeps,
and proxiedCountComments. Fuzzy id resolution, --current, watch mode,
and the array-of-one output envelope stay CLI-local; so do
proxiedListDeps and proxiedGetComments, which feed terminal rendering
rather than the shared shape.
The point of the slice is the correctness fix, not the code motion. The
two storage seams disagree about "no such issue": the store wraps
storage.ErrNotFound, while db.issueSQLRepositoryImpl.Get returns a bare
sql.ErrNoRows that issueUseCaseImpl.get wraps with the id - never
storage.ErrNotFound, and never a (nil, nil) pair. workapi.GetIssueOrWisp
normalizes both shapes, plus nil-issue-with-nil-error, to the
storage.ErrNotFound sentinel, and short-circuits hard errors instead of
retrying them against the wisp table. Putting that in the shared
function - not in a caller - is what stops the next frontend
reintroducing either failure mode: `if err != nil || issue == nil` -> 404
reports a dropped connection as a missing issue, and its mirror image
ships a 500 for one.
Six proxied callers inherit the fix. Most visibly, `bd show <missing-id>`
in proxied mode printed "Error fetching x: get x: sql: no rows in result
set" and gate list answered "issue not found" for any backend failure at
all; both now say what actually happened.
Two behaviour deltas, both in error paths the corpus does not cover:
the proxied JSON path no longer swallows a failed --include-dependents /
--include-comments read (it errors like the direct path always has), and
a proxied lookup that fails for a non-not-found reason reports that
reason. Row streams are collected through storage.Iter on both seams,
so the direct path keeps its be-4d36f2 streaming and the proxied path
gains it; the comment collector now copies each value, per Iter's
documented pointer-reuse contract.
Also deletes shallowDependentsForJSON, which had no production caller
left; its be-4d36f2 guard moves to workapi as
TestBuildIssueDetailsShallowDependents.
Verification: protocol corpus unchanged structurally (no diff under
cmd/bd/protocol vs the base) and behaviourally (TestCorpusGolden green
with BEADS_PROTOCOL_REQUIRE_DOLT=1, before and after);
TestProxiedServerShow{,2,3} 50/50 subtests green with
BEADS_TEST_PROXIED_SERVER=1; TestEmbeddedShow 21/21 green with
BEADS_TEST_EMBEDDED_DOLT=1; TestShow_* green individually;
TestCoverage_ShowUpdateClose green; TestProxiedServer{State,SetState,
Label,Comment,GateList,GateCheck} green. TestShow_IDFlag and
TestCoverage_TemplateAndPinnedProtections fail identically on the base
commit (in-process harness state leakage), and TestCoverage_ShowThread
skips on the base commit for want of a reachable Dolt server.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
First half of the bd-ehi collapse, kept separate so the golden table is
provably generated from the OLD code: this commit adds
internal/workapi/ready.go (BuildReadyFilter, ReadyParams,
DefaultReadyLimit) without touching either of cmd/bd's copies, and records
what BOTH of them produce for 39 command lines into
internal/workapi/testdata/ready_filter_golden.json.
Recording both columns is the point. `bd ready`'s defaults are built twice
today - inline in ready.go's RunE for the direct path, and in
gatherReadyInput for the proxied path - and the golden is what turns "they
look the same" into a fact. They agree on 33 of the 39 cases, including
Status: "open" (the tracked description says only one copy hard-codes it;
that has not been true since ready_input.go was added in 911ff8025). The
six disagreements are pinned by TestReadyFilterGoldenDivergences with the
branch that was kept and why:
- Offset: only gather sets it. The direct RunE rejects --offset before
any filter exists, so this is not observable.
- MaxRows/MaxRowsSource: only the direct path sets them, and only the
direct path can enforce them. Kept in cmd/bd rather than ReadyParams.
- --max-rows -1 / --claim --gated / --offset -1: each rejected by one
builder because the other path's RunE rejects it upstream.
DefaultReadyLimit = 100 is today's CLI default, not a new choice: it is
readyCmd's --limit default at HEAD. 0 still means unlimited, so the builder
does not substitute it.
The generator (cmd/bd/zz_ready_filter_golden_gen_test.go) is scaffolding
and is deleted in the follow-up commit that removes ready.go's inline copy.
It clones readyCmd's real flag definitions rather than re-declaring them,
and its args -> ReadyParams mapping cannot launder a mistake into a false
pass: the golden records the ReadyParams, so a field set in params but not
on the command line makes the replay fail rather than succeed.
Agent-Signature: claude-code-opus-5-unknown-reasoning on behalf of CI Bot
Second half of the extraction. cmd/bd/list_filter.go is gone; the direct
path (list.go), the proxied path (list_proxied_server.go), and the four
other consumers the file had grown (search, search_proxied_server, count,
count_proxied_server, graph_apply) call workapi.BuildListFilter /
LoadStoreListConfig / LoadUOWListConfig / ApplyStatusFilter /
ValidStatusList instead.
listInput now embeds workapi.ListParams rather than copying into it. A
50-field flags -> params mapping would be a silent-swap hazard the compiler
cannot see; embedding makes cmd/bd fill the shared struct directly, so
there is one definition of a list query and nothing to keep in sync. The
CLI-only fields (output format, pager, tree/deps rendering, effectiveLimit,
--repo) stay in listInput, which is why ListParams is a subset and not the
whole thing.
applyStatusFilter and validStatusList are exported rather than kept
unexported as the design sketch had them: search.go, search_proxied_server.go
and graph_apply.go already called them, and leaving them behind in cmd/bd
would have forked the status-parsing rules.
The --limit flag now registers workapi.DefaultListLimit. internal/config's
list.limit viper default keeps its own literal 50 - internal/config cannot
import workapi, because workapi imports internal/config for
GetCustomTypesFromYAML.
Boundary enforcement lands with the package, per the design: a
workapi-frontend-boundary depguard rule denying cobra and net/http under
internal/workapi, and a pr-policy.sh grep for the symbol-level half depguard
cannot express (config.GetDirectoryLabels, os.Getenv). Both were verified to
fail on a deliberate violation and then reverted.
Gates: protocol corpus unchanged (whole cmd/bd/protocol package green with
BEADS_PROTOCOL_REQUIRE_DOLT=1, no testdata diff); TestBuildListFilterGolden
35/35 against the filters recorded from the old builder; TestEmbeddedList
52 subtests and TestProxiedServerList 65 subtests green; count, search and
graph-apply suites green; golangci-lint clean on cmd/bd and internal/workapi
apart from the two pre-existing main.go gosec baselines.
Agent-Signature: claude-code-opus-5-unknown-reasoning on behalf of CI Bot
First half of the bd-fv4 extraction, kept separate so the golden table is
provably generated from the OLD code: this commit adds
internal/workapi/list.go (BuildListFilter, ListParams, ListConfig,
ConfigSource, DefaultListLimit) without touching cmd/bd's copy, records
what cmd/bd's buildListFilter produces for 35 inputs into
internal/workapi/testdata/list_filter_golden.json, and asserts the moved
builder reproduces it byte for byte.
DefaultListLimit = 50 is today's CLI default, not a new choice: both
cmd/bd/list.go's --limit flag and internal/config's list.limit default are
50 at HEAD.
The generator (cmd/bd/zz_list_filter_golden_gen_test.go) is scaffolding and
is deleted in the follow-up commit that removes cmd/bd/list_filter.go. Its
params -> listInput conversion cannot launder a mistake into a false pass:
the golden records the ListParams, so a mis-mapped field there makes the
replay fail rather than succeed.
Agent-Signature: claude-code-opus-5-unknown-reasoning on behalf of CI Bot