* feat(httpapi): wire-shape signal — wire_revision, floor header, golden digest, param tokens
S0 of the HTTP role-parity program: give a client a single place to learn
whether this build's wire shape has moved under it, and give CI a gate that
catches an undocumented move.
- GET /v0/beads/context reports wire_revision (bumps only on a non-additive
response-shape change) and min_client_wire_revision. An optional
Bd-Wire-Revision request header lets a client declare the revision it was
built for; checkWireRevision refuses a declared revision below the floor
with 400 invalid_argument/reason=wire_revision_unsupported and a
min_wire_revision field, on every route but /healthz (wireRevisionExempt) —
including the identity handshake, where catching the mismatch is cheapest.
Absent header is today's behavior; malformed value is invalid_value, never
wire_revision_unsupported. The floor lives in Server.minClientWireRevision
(defaulting to the MinClientWireRevision constant) so a test can raise it.
- internal/httpapi/wireshape: a golden digest over every response's every
content-type schema (including application/problem+json) across the whole
spec, keyed by schema+member. TestWireShapeDigest fails closed when a
member's JSON name or type changes without wire_revision bumping to match;
regenerate with `go run ./internal/httpapi/wireshape/cmd/gendigest`.
- GET /v0/beads/issues' `sort` parameter now carries the issues.listSort
capability token, the same convention `capabilities` entries use.
TestNewParameterOnExistingOperationHasABehaviorToken requires every new
parameter on an existing operation to carry one, checked against a
write-once grandfather baseline (testdata/pretoken_parameters.json) of
parameters that predate the rule; TestUntokenedParameterRuleFires proves
the checker itself against a synthetic fixture.
- Docs: engdocs/design/bd-serve-v0.md gets a "The wire-shape signal" section;
CHANGELOG.md gets an Added entry.
Live-mutated and reverted three RED demonstrations during development:
retyping api_version in the spec failed TestWireShapeDigest; short-circuiting
checkWireRevision's floor comparison failed
TestWireRevisionBelowFloorRefusesEveryEnforcedRoute; adding an untokened
query parameter to listIssues failed
TestNewParameterOnExistingOperationHasABehaviorToken. All three now pass
against the unmutated tree.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(httpapi): rename issues.listSort to issues.list.sort, harden token rule
Opus review of 12c5144ca (HIGH-1, MEDIUM-5):
- Rename the capability token issues.listSort -> issues.list.sort to match
bd-enterprise's client (httpstore/wire/handshake.go:121, DESIGN.txt S4e),
and widen capabilityToken to accept an optional third segment.
- untokenedParameters() now requires the extracted token to be one
Capabilities() actually serves, not just backtick-shaped text. This
catches real false positives that existed in the spec already
(workapi.DefaultReadyLimit, status.custom) which only shape-matched the
old regex; they're added to the pretoken baseline as genuinely
pre-existing untokened parameters.
- Extend the rule to request body members (new
testdata/pretoken_request_body_members.json baseline) and exempt
brand-new operations via a frozen testdata/pretoken_operations.json
snapshot.
- Add TestPretokenBaselinesNeverGrow pinning all three baseline sizes so
a future change can't hand-add an exemption instead of a token.
- Update spec prose for the widened rule scope.
go test ./internal/httpapi/... and the reviewer's pmut.py all pass as
expected: plain/bogus modes go RED, reuse (real-but-unrelated token) stays
green, matching the review's literal ask ("a token must be one advertised
by Capabilities()").
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(wireshape): close four digest-coverage gaps, add gendigest write guard
Opus review of 12c5144ca (HIGH-2, MEDIUM-4). The digest only tracked
Type/Format/Enum/Required on direct properties, missing:
- nullable: true (never read at all)
- array item shape (Issue.labels items string->integer was invisible;
only object-shaped items got recursed into)
- additionalProperties value shape (IssueCount.groups)
- request bodies entirely (Compute() only walked responses, so
DeleteIssuesRequest.expected_version string->integer, the other half
of #6053, was invisible)
Also added defensive oneOf flattening alongside the existing allOf merge
(dormant today -- grep confirms this spec uses oneOf nowhere -- but no
longer silently invisible if that changes).
Extracted the golden-vs-computed comparison into wireshape.Compare(),
shared by TestWireShapeDigest and the new wireshape.SafeToWrite(), which
gendigest now calls before writing: it refuses to overwrite golden.json
with changed/removed entries unless the candidate's wire_revision is
strictly greater than the existing golden's. Pure additions always write.
TestSafeToWrite exercises both guard directions.
golden.json is regenerated. This single regen is a one-time exception to
the new guard, done by writing the digest directly rather than through
gendigest: confirmed via a throwaway diff (not checked in) that every one
of the 57 "changed" entries differs only in the NEW fields the wider walk
now populates (ItemType/ItemFormat/Nullable/AdditionalProps*) -- every
pre-existing Type/Format/Required/Enum value is byte-identical. Nothing on
the wire changed; the measurement got more precise. Bumping
CurrentWireRevision for this would have written a false "the protocol
changed here" entry into the revision history table. Going forward, any
REAL change the guard now reports uses the normal bump-then-regenerate
path, same as before.
Verified against the reviewer's mut.py: nested_type, nullable,
nullable_issue, array_items, addlprops, request_body and format all go RED
on TestWireShapeDigest, each reverted after confirming.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(httpapi): make bd_version wire_revision inference advisory
Opus review of 12c5144ca (HIGH-3). The spec told a client inferring
wire_revision from bd_version to use the release cutoff >= 1.3.0, and said
nothing about what happens when that inference is wrong -- which it
demonstrably is for real builds already in the field:
- main builds up to commit b3ef65c85 report bd_version 1.2.2 (below any
1.3.0 cutoff) while already sending the string-typed revision/
expected_version shape (#6053).
- 1.3.0-rc.N pre-release builds sort BELOW the release cutoff 1.3.0 under
plain string comparison despite already carrying the string shape.
- The bd-enterprise compatibility line at d3ab32773462 reports bd_version
1.1.0 while also sending strings.
Moved the cutoff to >= 1.3.0-rc.1 (compared as semver-with-prerelease,
which at least captures the rc builds), documented both named exceptions
inline, and made the whole inference explicitly ADVISORY: a client must
accept revision/expected_version as either a string or a number whenever
wire_revision is absent (or probe directly) rather than let the inferred
value choose a decoder, and must never refuse solely because the inferred
revision is 0. Mirrored into engdocs/design/bd-serve-v0.md.
This is spec/doc prose only -- there is no server-side inference code to
change, since this server always sends wire_revision directly; the
inference is guidance for clients reading a pre-signal server's response
(this server, past builds, or an unrelated implementation).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(httpapi): LOW-7/8/9/10 review follow-ups for wire-revision signal
LOW-7: WireRevisionUnsupported now also sets Problem.wire_revision (this
server's CurrentWireRevision) and Problem.bd_version on the
wire_revision_unsupported refusal, alongside the existing
min_wire_revision, so a client logging the refusal has this server's
full self-description without a second /v0/beads/context call.
LOW-8: gazelle + make bazel-sync add the BUILD.bazel entries the prior
commits were missing: wire_revision.go/wire_revision_test.go in
internal/httpapi's srcs, new BUILD.bazel files for wireshape and
wireshape/cmd/gendigest, and a testdata glob on httpapi's go_test so
the pretoken_*.json baselines are visible under `bazel test`. Verified
with `bazel build //internal/httpapi/...` and
`bazel test //internal/httpapi/... --test_env=BEADS_TEST_SKIP=dolt`
(both green) and `python3 tools/bazel/go_srcs.py --check` (clean).
LOW-9: narrowed CHANGELOG.md and engdocs/design/bd-serve-v0.md to
describe the digest's actual final coverage (format/enum/required/
nullable, array items, additionalProperties, request bodies, $ref/
allOf/oneOf recursion, the SafeToWrite revision-bump guard) and the
token rule's actual final shape (three pinned baselines, request-body
members, Capabilities()-membership validation, new-operation
exemption) instead of the original, narrower claims.
LOW-10: Bd-Wire-Revision now parses via a strict decimal-only
parseStrictNonNegativeInt (no leading '+', no leading zero except a
bare "0") instead of strconv.Atoi alone, so two different header
bytes can no longer name the same revision. New malformed-header test
cases: "+1", "01", "007".
Regenerated apigen/types.gen.go (make api-gen) for the new Problem
fields and wireshape/testdata/golden.json (go run
.../wireshape/cmd/gendigest) for the two new additive Problem members;
the latter wrote cleanly through SafeToWrite itself, since both are
pure additions.
go test ./... and bazel test //internal/httpapi/... both green.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(httpapi): re-review LOW follow-ups — retirement test, gendigest -init, docs
1. TestRetiredRevisionsStayBelowTheFloor pins the PRESENCE guarantee the
wire_revision property doc relies on: CurrentWireRevision >= 2 (so 0
and 1 stay permanently retired) and MinClientWireRevision <=
CurrentWireRevision (so this build's own floor never refuses every
request against itself).
2. gendigest now refuses to create a golden.json that does not exist yet
unless run with -init. Previously a missing file (moved testdata,
wrong path, accidental delete) was indistinguishable from a real first
run and silently wrote a fresh golden with no revision history checked
against anything. writeGolden() is extracted out of main() so this is
covered directly: TestWriteGoldenRequiresInitWhenMissing,
TestWriteGoldenInitCreatesWhenMissing,
TestWriteGoldenIgnoresInitWhenGoldenExists (the existing-golden path is
still governed only by SafeToWrite, -init or not).
3. Narrowed the two remaining stale claims that still described the
digest's original, narrower coverage: the wire_revision property's
prose in openapi.v0.yaml (regenerated into apigen/types.gen.go via
make api-gen) and wireshape/doc.go now both list nullable, array item
shape, additionalProperties value shape, request bodies, and
$ref/allOf/oneOf recursion, plus the new -init guard.
go test ./internal/httpapi/... and make api-check both green;
bazel test //internal/httpapi/... (httpapi, wireshape, and the new
gendigest test target) green; python3 tools/bazel/go_srcs.py --check
clean.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* feat(wireshape): cover operation parameters in the wire-shape digest
The digest previously walked only response and request-body schemas, so a
type, enum, required, or removal change on one of the spec's 138 operation
parameters (123 query, 14 path, 1 header) passed the gate silently — the
open item from PR review on #7182.
Each parameter is now recorded as its own Entry, keyed by
"param:"+operationId / location+":"+name (operation-scoped, not
schema-scoped, since two operations' same-named parameter are independent
wire contracts), capturing type, array item shape, enum, required, style,
explode and default. Adding a parameter stays additive; removing,
retyping, narrowing its enum, or changing required/style/explode/default
now trips SafeToWrite exactly like a response or request-body change.
Verified against the live spec: retyping listIssues' `limit` query
parameter from integer to string now fails TestWireShapeDigest (confirmed
red, then reverted — not part of this commit). golden.json regenerated via
gendigest; the new parameter entries are a pure addition, no wire_revision
bump needed. Added TestParameterMutationsAreCaught (remove/retype/narrow-
enum against real golden entries) and updated wireshape's doc.go, the
`wire_revision` spec prose, and the CHANGELOG to describe the new
coverage.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(wireshape): review fixes — stale-golden and lowered-revision arms, effective param serialization, digest boundary
Maintainer fixup from the adopt-pr review loop (iterations 1 and 2), on
top of e17ba924f.
- goldenDrift (A, I): TestWireShapeDigest's comparison moves into a
goldenDrift helper. An addition alongside a moved wire_revision no
longer passes with a stale golden: it asks for a regenerate, as a
changed or removed entry after a bump already did. Every message now
names response/request-body members AND parameters, and TestGoldenDrift
pins each arm. This takes only the test half of the stranded fixup
(adopt-pr/bd-47kdge/stranded-fixup-528cd6095); its doc half, which says
parameters are outside the digest, is false since e17ba924f and is not
replayed (J).
- Lowered wire_revision (D): a CurrentWireRevision LOWER than the
golden's is a wrong constant, not a stale golden, so goldenDrift says to
restore it instead of regenerating, and SafeToWrite (so gendigest)
refuses any write at a lower revision, whatever the entries.
- Effective style/explode (B): walkParam records style and explode with
OpenAPI 3.0's defaults filled in (form for query/cookie, simple for
path/header; explode defaults to style == form). Adding `explode: false`
to a query array that relied on form's implicit explode is now a
changed entry, while spelling out a default changes nothing.
testdata/golden.json is regenerated with -init: 111 parameter entries
change only in style/explode (96 to form/true, 15 to simple), 828
entries before and after, wire_revision stays 2. The golden is new in
this PR and unreleased, so this needs no bump.
- TestWalkParam (H): a package-internal table test
(wireshape_internal_test.go) pins every field walkParam extracts,
through a computeFrom(document, revision) seam that Compute now wraps:
per-location defaults, $ref'd parameters and items, format, nullable and
default, content parameters, and the nil returns.
TestEffectiveSerializationIsCompared pins B end to end through Compare
and SafeToWrite. BUILD.bazel embeds the library in the go_test, which is
gazelle's own output.
- Required inputs and the digest boundary (C, E, F; docs only): all five
prose surfaces (openapi.v0.yaml's wire_revision description and the
regenerated apigen/types.gen.go, wireshape/doc.go, CHANGELOG.md,
engdocs/design/bd-serve-v0.md) now say that a new REQUIRED request
input is recorded as an ordinary addition and needs its own review,
that value constraints and member-level composition are outside the
digest, and that object and content parameters are recorded only as
their container. bd-serve-v0.md also gains the parameter coverage it
was missing.
- G: a brand-new operation is permanently exempt from the
capability-token rule; its own review decides its capability story.
- Iteration 2 (nit): walkParam's comment now says that the location
default it records as a `content` parameter's style and explode is a
placeholder, since OpenAPI 3.0 applies style and explode only to a
parameter described by `schema`. All 138 operation parameters in the
spec use `schema`, so the golden does not change.
Validated: go test ./internal/httpapi/... (gms_pure_go), make api-check,
go vet for linux/windows/darwin, gofmt, git diff --check, gazelle on the
package (no drift), make bazel-sync-check, and bazel test
//internal/httpapi/wireshape/... in the local processwrapper sandbox
(2 of 2 pass). Overlay mutation probes: dropping the added-after-bump
arm, the lowered-revision arm, SafeToWrite's lowered check, or the
effective-default fill each turns the new tests red.
Iteration 2 changes only that comment; go test
./internal/httpapi/wireshape/... (gms_pure_go), go vet, gofmt and git
diff --check pass again.
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* feat(count): add Counter scope fields (S8) — ParentID, NoParent, ExcludeTypes, ExcludeStatus
Extends issueops.CountRequest with ParentID, NoParent, ExcludeTypes and
ExcludeStatus, closing the gap where bd count could not express the
filters bd list already has, forcing downstream consumers like gc to
fall back to listing everything just to get a count.
- issueops.Counter: four new CountRequest fields, documented against the
List equivalents they mirror (ParentID/ExcludeTypes) or newly define
(NoParent, ExcludeStatus has no List counterpart). Status "all" is
pinned as equivalent to unset, matching BuildListFilter's own "all" and
preserving count/list cardinality parity (the role's reason to exist).
- internal/workapi.BuildCountFilter: maps the four fields onto the one
types.IssueFilter builder all three storage legs (dolt, embeddeddolt,
uow) already share via internal/storage/issueops and sqlbuild, so no
per-leg storage code was needed.
- cmd/bd: --parent, --no-parent, --exclude-type, --exclude-status flags.
- HTTP: adds parent/no_parent/exclude_type/exclude_status to GET
/v0/beads/issues:count, behind the new issues.count.scope behavior
token (routes.go), wired in reads.go's countFilters, documented in
openapi.v0.yaml with per-parameter tokens and an extended capabilities
description. gendigest confirms a byte-identical golden.json: query
parameters are outside the wire-shape digest's scope, so this is a
zero-diff, no-revision-bump change as expected.
- backend/conformance: four new Counter contract cases (ParentID scoping,
NoParent's edge-only semantics vs ParentID's edge-or-dotted-id match,
ExcludeTypes composing with include_infra's own exclusions, and
ExcludeStatus), run identically against all three storage legs via a
new CounterFixture.AddDependency hook shared with ReaderFixture.
Verified: go build ./...; go test ./internal/httpapi/... ./internal/workapi/...
./issueops/... and the Counter contract on all three legs (dolt via
testcontainers, embeddeddolt, uow via local dolt binary); make api-gen
(additive-only apigen diff) and make api-check; go vet and golangci-lint
clean; gofmt clean; gazelle diff empty (no new files/imports). Mutation
testing: dropping issues.count.scope from behaviorCapabilities turns
TestCapabilitiesAdvertiseEveryImplementedOperation,
TestSpecCapabilityVocabularyMatchesTheRouteTable and
TestNewParameterOnExistingOperationHasABehaviorToken red; no-op'ing
ExcludeStatus in BuildCountFilter turns
TestBuildCountFilterExcludeStatusTakesNamesAsWritten and the
embeddeddolt ExcludeStatusNarrowsThePredicate conformance case red. Both
reverted and reconfirmed green.
Deviation: DESIGN.txt's literal text would make count --status all an
ErrValidation; shipped behind a test and a doc comment instead, since
"all" already means "every status" on both count and list and rejecting
it would break the count/list parity this role exists to guarantee.
S3/S4 note: no OSS HTTP client exists yet to enforce capability-token
skew. A doc comment on CapIssuesCountScope in routes.go specifies the
required behavior once one lands: check issues.count.scope against the
cached handshake capabilities and refuse locally with a typed
ErrUnsupported{Capability} before sending any of the four new params to
an older server.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(count): S8 review follow-ups — refusal parity, exclude-status validation, doc fixes, parity tests
Addresses the Opus review's six required changes for S8 (bd count scope
fields):
1. BuildCountFilter now refuses ParentID+NoParent together as ErrValidation,
matching bd list's CLI refusal wording; wired through the role, the CLI,
and invalid_argument classification in internal/httpapi/reads.go.
2. Status:"all" is documented in DESIGN.txt as every status, matching List's
no-filter reading (count/list cardinality parity) — a coordinator decision
recorded in beads-design/DESIGN.txt, outside this worktree.
3. ExcludeStatus names are now validated against the workspace vocabulary
(built-in statuses plus workspace-custom ones); an unknown name is
ErrValidation instead of a silent no-op, since a typo here would overcount.
4. Fixed openapi.v0.yaml and issueops/reader.go doc claims about bd list
--parent's default tree-walk vs. the one-level role answer that bd count
--parent agrees with (confirmed by tracing list_show_filter_modes.go); fixed
an Oxford-comma nit in routes.go and the spec.
5. Added storage-level count == len(List) parity tests for ParentID, NoParent
and ExcludeTypes (List has no ExcludeStatus counterpart), plus wisp-child
and closed-child contract cases, across all three backends (dolt,
embeddeddolt, uow). CounterFixture gained a List hook for this.
6. Extended the routes.go skew note: gc's ErrCountUnsupported fallback to List
is now named explicitly, with a note that S3/S4 must add a skew test that
masks the token and asserts the fallback fires.
Also fixed RunCounterExcludeStatusNarrowsThePredicate's now-stale "unrecognized
status excludes nothing" assertion to expect ErrValidation instead.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(count): PR #7199 review follow-ups — exclude-status config load, ParentID doc swap
Addresses bee's REQUEST-CHANGES on gastownhall/beads#7199 (S8):
1. BLOCKER: storecounter.filter and uow.countFilter only loaded the
workspace list config when IncludeInfra was set, so BuildCountFilter's
ExcludeStatus validation refused a workspace's own custom status unless
the caller also passed the unrelated IncludeInfra flag. Both legs now
load the config when IncludeInfra OR len(ExcludeStatus) > 0, with
comments corrected to say so. Added leg-level regression tests (the
conformance fixture cannot drive a workspace-configured custom status)
on embeddeddolt and uow, reproducing the reviewer's CLI repro directly,
plus an HTTP-level probe in cmd/bd's real-Dolt proxied count test.
2. issueops.ReadyRequest.ParentID's comment had been overwritten with the
one-level direct-children wording that belongs to ListRequest.ParentID;
Ready actually walks all descendants via GetDescendantIDsInTx (GH#3396).
Restored the descendants comment on ReadyRequest.ParentID and moved the
one-level explanation to ListRequest.ParentID, which had none.
Verified: make api-check; dolt-server, embeddeddolt and uow Counter
contract legs (BEADS_TEST_DOLT_SERVER=local with a pinned dolt binary for
uow; Docker for the dolt-server leg); the new proxied HTTP exclude_status
probe (BEADS_TEST_PROXIED_SERVER=1).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* chore(wireshape): add the countIssues scope parameters to the wire-shape golden
#7182 now digests operation parameters. The four new issues:count parameters
(parent, no_parent, exclude_type, exclude_status) are additive entries, so no
wire_revision bump is needed; regenerated with gendigest.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* test(conformance): register the S8 count-scope cases with RunRoleContracts (adopt-pr #7199)
The PR adds nine RunCounter* contract cases to counter_contract.go and wires
them into the three in-tree TestCounterContract legs, but not into the
Counter row of roleContractCases. TestRoleContractCasesCoverEveryContractCase
derives the expected set from source, so it fails on the PR head, and an
external backend running RunRoleContracts would never see the new cases.
Register them in source-declaration order (after
RunCounterAnUnknownStatusMatchesNothing), which the same guard enforces.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(count): correct the S8 scope docs the review found wrong (adopt-pr #7199)
Comment and spec-description fixes only; no behavior change. Review-loop
iterations 1 and 2 of the #7199 relaunch.
- ListRequest.ParentID (issueops/reader.go) said "DIRECT children only
... the same one-level clause". The sqlbuild clause has two arms and
neither walks: the parent-child edge arm stops at one level, but the
dotted-prefix arm (`id LIKE CONCAT(?, '.%')` for rows with no
parent-child edge) reaches every edge-less dotted id at any depth, which
RunReaderListParentReachesEveryDescendantAndOnlyItsOwn pins with an
edge-less X.1.1. State both arms, and say the CLI tree view re-runs the
clause against the store once per level (findAllDescendants calls
SearchIssues, not the role). Document ListRequest.NoParent, which had no
doc. The contributor's ReadyRequest.ParentID text is kept; only its
cross-reference to this field changes from "one-level" to "non-walking".
- CountRequest.NoParent (issueops/counter.go) and the count flag comment
(cmd/bd/count.go) said NoParent counts rows with "neither" an edge nor a
dotted prefix. Its SQL checks only the edge table, so an edge-less X.1
is counted by both --parent X and --no-parent, as bd list lists it.
- RunCounterExcludeStatusNarrowsThePredicate's header said an
unrecognized name "excludes nothing rather than failing" while its body
asserts ErrValidation. The header now matches the body.
- The OpCountIssues entry in problem.go's operationCodes said the role has
"exactly one reachable refusal". It has three: an invalid metadata key,
an unrecognized exclude_status name, and parent with no_parent (named
no_parent), all classified by invalidFilterParam. The code set is
unchanged.
- BuildCountFilter's header said cfg is "only read under IncludeInfra".
It is also read to validate ExcludeStatus against the workspace's
custom statuses, which is why both callers load it when ExcludeStatus is
non-empty.
- The countIssues `parent` description in openapi.v0.yaml carried the
same one-level claim as ListRequest.ParentID; it now states both arms.
types.gen.go is regenerated (make api-gen); make api-check passes.
Review fixes (iteration 2), still comment and spec text only:
- The iteration-1 problem.go rewrite called all three count refusals
ErrValidation. Only the exclude_status and parent-with-no_parent
refusals wrap issueops.ErrValidation (internal/workapi/count.go). The
metadata-key refusal is ValidateMetadataFilters' plain fmt.Errorf
chain, so errors.Is(err, ErrValidation) is false for it; it reaches the
wire as a 400 only because invalidFilterParam matches message prefixes.
The comment now says that, so a later move to typed errors cannot trust
it and demote the metadata-key refusal to a 500. The sentinel itself is
not added here: ValidateMetadataFilters is shared with the list and
ready builders.
- invalidFilterParam's comment on the count rows pointed at the
metadata-key rows as "above"; they come after it in the switch.
- The countIssues `parent` description said the CLI tree mode walks
"every edge-linked descendant". findAllDescendants re-runs the full
two-arm predicate per level, so it also descends through edge-less
dotted ids; it now says "every descendant reachable through either
arm". types.gen.go is regenerated; make api-check passes.
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* chore(wireshape): re-record the count scope params under the base's param digest (adopt-pr #7199)
The base branch (feat/wire-revision-signal, #7182 be1f0bad72) now digests
the effective style/explode of scalar query parameters. This PR's golden
entries for countIssues query:parent and query:no_parent were written by
the old algorithm, so after the base refresh TestWireShapeDigest reported
them as "changed without a wire_revision bump".
No bump is owed: all four count-scope entries (parent, no_parent,
exclude_type, exclude_status) are additions this PR introduces and are
absent from the base golden. golden.json was reset to the base copy and
regenerated with `go run ./internal/httpapi/wireshape/cmd/gendigest`. The
result is four pure additions against the base (+35/-0); parent and
no_parent gain "style": "form" and "explode": true, and wire_revision
stays 2.
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* ci: place the PR's new embedded counter test in the shard manifest
TestCounterExcludeStatusAcceptsAWorkspaceCustomStatusWithoutIncludeInfra,
added to internal/storage/embeddeddolt in f23bf5ddbf, is a new top-level
embedded storage test. The 15-shard block of
.github/scripts/embedded-storage-test-shards.txt must list every
discovered test exactly once. Without the entry,
TestStorageEmbeddedShardManifestGeneratorNotStale (scripts/) fails, both
on the reviewed head 89a387de6c and on the merge. CI never ran the check
on this PR: pr.yml runs only for PRs based on main, release/** or
hotfix/**, and this PR was based on feat/wire-revision-signal until the
retarget.
Generated with
`python3 scripts/ci/gen_embedded_storage_shard_manifest.py 15 --weights=duration --write`.
The incremental write adds this one line, in shard 4, and moves no other
test.
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.local>
700 lines
36 KiB
Go
700 lines
36 KiB
Go
package issueops
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
// IssueWithCounts is one row of a work page: the issue plus its relationship
|
|
// cardinalities.
|
|
type IssueWithCounts = types.IssueWithCounts
|
|
|
|
// IssueDetails is one issue with its labels, edges and cardinalities.
|
|
type IssueDetails = types.IssueDetails
|
|
|
|
// MolType classifies a molecule.
|
|
type MolType = types.MolType
|
|
|
|
// WispType classifies an ephemeral record.
|
|
type WispType = types.WispType
|
|
|
|
// ReadyRequest describes one ready-work query.
|
|
//
|
|
// It is a HIGH-LEVEL request, not a filter: normalization, alias expansion,
|
|
// validation and defaulting all happen inside the implementation. A caller
|
|
// that wants ready work says what it wants, never how the query is shaped —
|
|
// which is the whole reason two front doors cannot answer this question
|
|
// differently.
|
|
type ReadyRequest struct {
|
|
// IssueType restricts the type. Only shorthand alias expansion is applied
|
|
// (mr, feat, mol, enhancement, dec, adr); an unrecognized type matches
|
|
// nothing rather than failing. Setting it drops the default type
|
|
// exclusions, ExcludeTypes included.
|
|
IssueType string
|
|
// Assignee restricts to one actor. Unassigned wins over a stale Assignee.
|
|
Assignee string
|
|
// Unassigned restricts to rows with no assignee.
|
|
Unassigned bool
|
|
|
|
// Labels must ALL be present; LabelsAny requires at least one;
|
|
// ExcludeLabels must be absent. All three are raw: normalization happens
|
|
// inside.
|
|
Labels []string
|
|
LabelsAny []string
|
|
ExcludeLabels []string
|
|
// LabelPattern is a glob and LabelRegex a regular expression, both matched
|
|
// against labels.
|
|
LabelPattern string
|
|
LabelRegex string
|
|
|
|
// Priority is an exact priority. It is a pointer because 0 is a real
|
|
// priority: a value-plus-flag pair would let one half be filled in without
|
|
// the other, and P0 has already been lost that way once.
|
|
Priority *int
|
|
|
|
// ParentID restricts to ALL TRANSITIVE DESCENDANTS of one issue, not just
|
|
// its direct children: internal/storage/issueops/ready_work.go calls
|
|
// GetDescendantIDsInTx(ctx, tx, *filter.ParentID, 0), the recursive walk.
|
|
// GH#3396: this used to be a one-hop subquery against the dependency
|
|
// table, so grandchildren were silently dropped despite this comment and
|
|
// the help text both promising "descendants (recursive)" — do not
|
|
// mistake this for ListRequest.ParentID's non-walking clause, which is a
|
|
// DIFFERENT query (PR #7199 review: an earlier pass here wrongly copied
|
|
// that one-level wording onto this field).
|
|
ParentID string
|
|
// MolType restricts to one molecule type.
|
|
MolType *MolType
|
|
|
|
// IncludeDeferred admits rows whose defer_until is still in the future;
|
|
// IncludeEphemeral admits wisp-plane rows.
|
|
IncludeDeferred bool
|
|
IncludeEphemeral bool
|
|
|
|
// ExcludeTypes names types to exclude. Entries may be comma-separated;
|
|
// splitting and alias expansion happen inside. Ignored when IssueType is
|
|
// set.
|
|
ExcludeTypes []string
|
|
|
|
// MetadataFields is a top-level metadata equality filter and
|
|
// HasMetadataKey a top-level key-presence filter. Keys are validated
|
|
// inside.
|
|
MetadataFields map[string]string
|
|
HasMetadataKey string
|
|
|
|
// Sort is the ready ordering: hybrid, priority or oldest. Empty resolves to
|
|
// hybrid at the storage layer, which no front door should rely on — both
|
|
// surfaces send a concrete policy, because hybrid demotes older
|
|
// high-priority work and therefore changes the item SET once Limit
|
|
// truncates.
|
|
Sort string
|
|
|
|
// Limit bounds the page. Nil means the shared ready default; 0 means
|
|
// unlimited. It is a pointer so that "unset" and "explicitly unlimited"
|
|
// stay distinguishable, which is what lets one constant serve both
|
|
// surfaces.
|
|
Limit *int
|
|
// Offset skips the first N matching rows, on EVERY implementation. The
|
|
// page a caller receives is the rows at positions [Offset, Offset+Limit)
|
|
// of the answer the same request returns unpaged, in the same order.
|
|
//
|
|
// WHERE the skip happens is not a backend's choice either. One seam
|
|
// renders OFFSET and one renders LIMIT without it, so both bodies reach
|
|
// past the skipped rows and drop them in the shared page epilogue
|
|
// (internal/workapi.FinishPageAt) — which is also the only sequence that
|
|
// is right for a sort SQL cannot express, since that order first exists
|
|
// after the fetch.
|
|
//
|
|
// An Offset past the end of the result set is an empty page and a nil
|
|
// error, not a failure: a pager that walks off the end has its answer.
|
|
//
|
|
// A ready request carries no keyset position, so there is no portable way
|
|
// to page ready work. A caller that must page across backends pages a
|
|
// ListRequest instead — see ListRequest.Offset.
|
|
Offset int
|
|
|
|
// Brief drops the free-form text from every row: Description, Design,
|
|
// AcceptanceCriteria, Notes, Payload and Waiters come back zero-valued and
|
|
// the row carries types.Issue.IsLitePartial. See ListRequest.Brief, which
|
|
// is the same knob on the other operation and carries the full contract.
|
|
Brief bool
|
|
}
|
|
|
|
// ListRequest describes one issue-list query.
|
|
//
|
|
// Like ReadyRequest it is high-level: the default
|
|
// status/pinned/template/gate/infra exclusions, type validation, status
|
|
// parsing and limit defaulting are all applied inside.
|
|
//
|
|
// PINNED is TWO exclusions rather than one, because a row can be pinned two
|
|
// unrelated ways and each is hidden by its own predicate. The `pinned` STATUS
|
|
// is one of the statuses the default status exclusion covers, alongside
|
|
// `closed`; the separate Pinned FLAG — a marker on a row of any status — is
|
|
// hidden by a predicate of its own. A row carrying either is absent from a
|
|
// default listing, and the knob that takes each back off is a different one:
|
|
// see Status for the first and PinnedFlag for the second.
|
|
type ListRequest struct {
|
|
// Status selects statuses; one name, or a comma-separated OR set. Setting
|
|
// it REPLACES the default exclusions rather than fighting them.
|
|
//
|
|
// It replaces the STATUS ones only. The pinned-flag predicate survives it,
|
|
// so `pinned` and `hooked` are the two spellings that also drop that
|
|
// predicate — every other status narrows to unflagged rows.
|
|
Status string
|
|
// IssueType is validated against the workspace vocabulary — unlike
|
|
// ReadyRequest.IssueType, which matches nothing rather than failing.
|
|
IssueType string
|
|
Assignee string
|
|
TitleSearch string
|
|
SpecPrefix string
|
|
// IDFilter is a comma-separated id set.
|
|
IDFilter string
|
|
|
|
Labels []string
|
|
LabelsAny []string
|
|
ExcludeLabels []string
|
|
LabelPattern string
|
|
LabelRegex string
|
|
|
|
TitleContains string
|
|
DescContains string
|
|
NotesContains string
|
|
ExternalContains string
|
|
ExternalRef string
|
|
|
|
CreatedBefore *time.Time
|
|
CreatedAfter *time.Time
|
|
UpdatedAfter *time.Time
|
|
UpdatedBefore *time.Time
|
|
ClosedAfter *time.Time
|
|
ClosedBefore *time.Time
|
|
DeferAfter *time.Time
|
|
DeferBefore *time.Time
|
|
DueAfter *time.Time
|
|
DueBefore *time.Time
|
|
|
|
EmptyDesc bool
|
|
NoAssignee bool
|
|
NoLabels bool
|
|
SkipLabels bool
|
|
// SkipCounts suppresses the CARDINALITY hydration exactly as SkipLabels
|
|
// suppresses the label one: DependencyCount, DependentCount and
|
|
// CommentCount come back ZERO, and a caller must read a zero as UNKNOWN
|
|
// rather than as none. Nothing else about the page moves — the rows, their
|
|
// order, Parent and the has-more verdict are what they would have been —
|
|
// because this chooses what is HYDRATED, never which rows match.
|
|
//
|
|
// It is here for the renderings that print a page without those three
|
|
// numbers. Each is its own aggregate join, and the reverse-blocker one is
|
|
// the expensive member: it joins on an expression the embedded engine's
|
|
// planner cannot index, which is the per-call cost that makes a counted
|
|
// page the wrong shape for a listing that shows no counts.
|
|
//
|
|
// Like SkipLabels it is NOT carried onto the ReadyFlag arm; the counts are
|
|
// hydrated there either way, which costs time and not correctness.
|
|
SkipCounts bool
|
|
|
|
// IncludeComments populates every row's Issue.Comments with that issue's
|
|
// full comment bodies, and is the LIST twin of GetRequest.IncludeComments.
|
|
// Like SkipLabels and SkipCounts it chooses what is HYDRATED, never which
|
|
// rows match: the rows, their order, Parent and the has-more verdict are
|
|
// what they would have been.
|
|
//
|
|
// IT IS OPT-IN BECAUSE IT COSTS A QUERY PER ROW, which is the same reason
|
|
// the detail view's twin is. A page of 50 is 50 comment reads; a listing
|
|
// asking for the whole store is that many. Nothing hydrates comments
|
|
// unless a caller asks.
|
|
//
|
|
// WHY THE KNOB EXISTS AT ALL (be-73x). comment_count has always been on
|
|
// the row and the bodies never were, so a caller searching a LISTING for
|
|
// text that lives in a comment gets a well-formed, non-empty, WRONG answer
|
|
// — the rows that match are simply absent, and no error, no zero and no
|
|
// short count marks them. That is the failure this knob exists to make
|
|
// answerable, which is why the unhydrated rows also carry
|
|
// types.IssueWithCounts.CommentsOmitted rather than staying silent.
|
|
//
|
|
// IT APPLIES TO BOTH ARMS, ReadyFlag included, and is neither carried nor
|
|
// refused by it: hydration runs in the shared page epilogue after the
|
|
// query, so it is not a filter the ready query has to be able to express.
|
|
//
|
|
// A row whose comments could not be read is an ERROR, not a short list.
|
|
// The detail view's IncludeComments makes the same promise for the same
|
|
// reason: a caller that asked for the rows gets them or gets told.
|
|
IncludeComments bool
|
|
|
|
// Brief suppresses the FREE-FORM TEXT the way SkipLabels suppresses labels
|
|
// and SkipCounts the cardinalities: Description, Design,
|
|
// AcceptanceCriteria, Notes, Payload and Waiters are not selected and come
|
|
// back zero-valued. Nothing else about the page moves — the rows, their
|
|
// order, Parent and the has-more verdict are what they would have been —
|
|
// because this chooses what is HYDRATED, never which rows match. A
|
|
// predicate over a heavy column (DescContains, NotesContains, EmptyDesc)
|
|
// keeps selecting exactly the rows it selects today: WHERE is independent
|
|
// of the SELECT shape.
|
|
//
|
|
// A BLANK FIELD IS AMBIGUOUS ON THE WIRE and the row says so in process:
|
|
// all six are omitempty, so a projected row marshals identically to a
|
|
// genuinely textless one, and the row carries types.Issue.IsLitePartial to
|
|
// tell them apart for an in-process caller. That flag is json:"-", so a
|
|
// wire consumer distinguishes them by having asked — the same shape the
|
|
// repo has already argued about twice (ga-clgh/CommentsOmitted, #5550).
|
|
//
|
|
// UNLIKE SkipLabels and SkipCounts it IS carried onto the ReadyFlag arm,
|
|
// and onto ReadyRequest.Brief beside it. Those two drop a NUMBER the ready
|
|
// renderings print; this drops a body no listing prints, so carrying it is
|
|
// what makes `--ready` and `bd ready` answer the same request the same way.
|
|
//
|
|
// It is the storage layer's types.IssueFilter.Lite / types.WorkFilter.Lite
|
|
// under the name the CLI and the MCP integration already use for a
|
|
// projection (bd show --brief-deps, the MCP's brief).
|
|
Brief bool
|
|
|
|
// Priority is exact; PriorityMin and PriorityMax bound a range. All three
|
|
// are pointers for the same reason ReadyRequest.Priority is.
|
|
Priority *int
|
|
PriorityMin *int
|
|
PriorityMax *int
|
|
|
|
// PinnedFlag and NoPinnedFlag select on the Pinned FLAG, which is not the
|
|
// `pinned` status — see this type's own doc for why there are two of them.
|
|
//
|
|
// PinnedFlag answers with the FLAGGED rows and only them, at any status: it
|
|
// drops the default status exclusions on the way, so a closed pinned row —
|
|
// which a default listing hides twice over — is in that answer.
|
|
//
|
|
// NoPinnedFlag asks for the UNFLAGGED rows, which a default listing already
|
|
// answers with. Its work is holding that predicate in place where AllFlag
|
|
// or a pinned/hooked Status would otherwise have dropped it, so on a
|
|
// default listing it changes nothing and on those it narrows.
|
|
//
|
|
// On the ReadyFlag arm neither applies: that set decides pinned for itself,
|
|
// which is why PinnedFlag is refused there and NoPinnedFlag merely accepted
|
|
// (see AllFlag).
|
|
PinnedFlag bool
|
|
NoPinnedFlag bool
|
|
IncludeTemplates bool
|
|
IncludeGates bool
|
|
IncludeInfra bool
|
|
// IncludeEphemeral admits the EPHEMERAL PLANE — the wisps TABLE, which a
|
|
// default listing does not read at all — and admits nothing else.
|
|
//
|
|
// WHAT IS IN THAT PLANE is not only true ephemerals. The wisps table holds
|
|
// every row the durable plane does not: wisps proper (ephemeral = 1) AND
|
|
// no-history rows, which live there with ephemeral = 0. Both arrive
|
|
// together, because this selects a TABLE rather than testing a column.
|
|
//
|
|
// False, the zero value, is the listing every caller has today: the durable
|
|
// issues table alone. True merges the wisps table IN ADDITION, so under the
|
|
// same filters the answer is a SUPERSET of the false answer. It never
|
|
// narrows, and it never becomes ephemeral-only.
|
|
//
|
|
// IT IS NOT THE SAME MECHANISM AS ReadyRequest.IncludeEphemeral, despite
|
|
// the shared name and the shared "admit in addition" reading, and the
|
|
// difference is observable. The ready query reads BOTH planes either way
|
|
// and its flag adds a per-ROW predicate (ephemeral = 0) when unset; this
|
|
// one selects which TABLES are read at all. So a no-history row — in the
|
|
// wisps table with ephemeral = 0 — is already in a DEFAULT ready answer and
|
|
// is absent from a default listing until this flag is set. Match the two
|
|
// fields for intent, never for row-level equivalence.
|
|
//
|
|
// IT IS A PLANE KNOB, NOT A TYPE KNOB — the difference from the three
|
|
// fields above it. Each of those takes a TYPE exclusion back off; this
|
|
// takes none off, so an ephemeral row whose type a default listing already
|
|
// excludes stays excluded. THAT INCLUDES THE INFRA TYPES, which is the
|
|
// combination most likely to surprise: the configured infra vocabulary
|
|
// (agent, role and message by default) is excluded by TYPE, so ephemeral
|
|
// agent/role/message rows need IncludeInfra as well as — or instead of —
|
|
// this. IncludeInfra does BOTH, which makes it strictly wider; what this
|
|
// field alone reaches is the ephemeral rows of the types a listing already
|
|
// shows.
|
|
//
|
|
// THE MERGED ANSWER IS ONE ORDER. Both planes are ordered together by
|
|
// SortBy as if they were a single table — not the durable rows followed by
|
|
// the ephemeral ones — so a Limit truncates the merged order rather than
|
|
// one plane's. Both implementations produce it (one merge-sorts two ordered
|
|
// legs, the other ORDERs a SQL union), and the keyset position
|
|
// (AfterCreatedAt/AfterID) is applied to BOTH legs, so a paged walk over
|
|
// the merged order drops no row and repeats none.
|
|
//
|
|
// The caveat that walk inherits is the one every multi-page walk already
|
|
// has, and this does not deepen it: a page is not a snapshot. A row written
|
|
// — or, for a wisp, compacted away — between two pages is seen or missed
|
|
// according to where it falls relative to the position, and the ephemeral
|
|
// plane merely turns over faster than the durable one.
|
|
//
|
|
// On the ReadyFlag arm it is CARRIED rather than dropped; see that field.
|
|
IncludeEphemeral bool
|
|
// IncludeAllTypes lifts every default suppression that hides a bead from a
|
|
// listing on account of WHAT IT IS: the three type knobs above (templates,
|
|
// gates, infra types) AND the ephemeral plane, so the wisps table is read
|
|
// too. Frontends whose contract is "never hide a bead" — `bd human list`,
|
|
// where a human label is an explicit request for a person's attention —
|
|
// set this one field instead of enumerating the knobs and then drifting
|
|
// from them when a fourth suppression lands.
|
|
//
|
|
// IT IS THE UNION OF THOSE FLAGS, NOT A NEW MECHANISM. Setting it is
|
|
// equivalent to IncludeTemplates + IncludeGates + IncludeInfra +
|
|
// IncludeEphemeral; it narrows nothing and admits nothing they cannot.
|
|
// Both the type suppressions and the plane decision live in workapi's
|
|
// applyTypeSuppressions, which this flag skips entirely — so a suppression
|
|
// added there is lifted here automatically, which is the whole point.
|
|
//
|
|
// IT SAYS NOTHING ABOUT STATUS. The done/frozen exclusions and the pinned
|
|
// default are a separate axis and still apply; --status (including "all")
|
|
// is how a caller lifts those.
|
|
IncludeAllTypes bool
|
|
// ExcludeTypes entries may be comma-separated; splitting happens inside.
|
|
ExcludeTypes []string
|
|
|
|
// ParentID restricts to one issue's children through one SQL clause, the
|
|
// same one CountRequest.ParentID compiles to
|
|
// (internal/storage/sqlbuild/filter.go): a parent-child dependency edge
|
|
// onto ParentID, OR, for a row with no parent-child edge at all, an id
|
|
// under ParentID's dotted prefix ("X.1", "X.1.1"). NEITHER ARM WALKS. The
|
|
// edge arm stops at one level, so a grandchild with an edge of its own is
|
|
// not in the answer, while the prefix arm reaches every edge-less dotted
|
|
// id at any depth (backend/conformance/reader_contract.go pins that arm).
|
|
// It is NOT the recursive descendants walk — that is ReadyRequest.ParentID
|
|
// above, a DIFFERENT field on a different request, backed by
|
|
// GetDescendantIDsInTx (GH#3396); on the ReadyFlag arm this field crosses
|
|
// to that query and resolves recursively there.
|
|
// The recursive tree that `bd list --parent X` renders by DEFAULT comes
|
|
// from cmd/bd/list_show_filter_modes.go's findAllDescendants re-running
|
|
// this clause against the store once per level and accumulating the
|
|
// results client-side, not from this field answering a deeper question.
|
|
// --flat, --json and --format skip that walk and return exactly this
|
|
// field's answer, which is why the flat listing is the invocation that
|
|
// agrees with `bd count --parent X`'s cardinality.
|
|
//
|
|
// NoParent restricts to rows with no parent-child dependency edge. It has
|
|
// no dotted-id arm, so an edge-less "X.1" matches BOTH ParentID X and
|
|
// NoParent. The ReadyFlag arm refuses it; see that field.
|
|
ParentID string
|
|
NoParent bool
|
|
MolType *MolType
|
|
// WispType matches the wisp_type COLUMN, which both tables carry. It is
|
|
// therefore a predicate and not a plane selector: it does not admit the
|
|
// ephemeral plane, and on a default listing — where that plane is
|
|
// suppressed — it narrows the durable rows to those whose wisp_type
|
|
// matches, which no ordinary durable row has. The combination that answers
|
|
// with rows is IncludeEphemeral (or IncludeInfra) plus this, and it is
|
|
// lawful rather than refused: the two compose as an ordinary AND, admitting
|
|
// the plane and then narrowing it to one classification.
|
|
WispType *WispType
|
|
|
|
DeferredFlag bool
|
|
OverdueFlag bool
|
|
|
|
// MetadataFields is a top-level metadata equality filter and
|
|
// HasMetadataKey a top-level key-presence filter. Keys are validated
|
|
// inside, as they are for ReadyRequest.
|
|
MetadataFields map[string]string
|
|
HasMetadataKey string
|
|
|
|
// AllFlag drops the default status exclusions.
|
|
//
|
|
// ReadyFlag switches the query to the blocker-aware ready set. It does NOT
|
|
// simply add a blocker predicate to this listing: that query reads a
|
|
// narrower filter vocabulary than this request can describe, and only part
|
|
// of the request reaches it.
|
|
//
|
|
// WHAT IT CARRIES: Status/Statuses (an explicit --status is the
|
|
// intersection; AllFlag and `--status all` still take the open default),
|
|
// IssueType, all five label forms, Assignee, NoAssignee,
|
|
// the exact Priority, ParentID, MolType, WispType, MetadataFields,
|
|
// HasMetadataKey, the type exclusions (ExcludeTypes, and with them
|
|
// IncludeGates and IncludeInfra), IncludeEphemeral — the ready query has an
|
|
// ephemeral gate of its own, so the plane bit crosses intact and
|
|
// IncludeInfra's plane half crosses with it — Limit, Offset and the MaxRows
|
|
// cap with its attribution. SortBy and Reverse
|
|
// still apply, because the display order is applied to the page after the
|
|
// query rather than inside it.
|
|
//
|
|
// WHAT IT REFUSES: every other filter here is one the ready query cannot
|
|
// carry, so combining it with ReadyFlag returns ErrValidation naming the
|
|
// fields rather than answering a wider question than was asked. That is
|
|
// IDFilter, TitleSearch, SpecPrefix, the four *Contains fields,
|
|
// ExternalRef, every Created/Updated/Closed/Defer/Due bound, DeferredFlag,
|
|
// OverdueFlag, EmptyDesc, NoLabels, NoParent, PinnedFlag, PriorityMin,
|
|
// PriorityMax, and the keyset position. There is no fallback: no
|
|
// combination of the two silently widens the answer.
|
|
//
|
|
// TWO THINGS THE READY SET DECIDES FOR ITSELF, which no field here
|
|
// overrides. It never returns pinned issues, which is why NoPinnedFlag is
|
|
// accepted and PinnedFlag refused. And it applies no template predicate at
|
|
// all, so this request's default template exclusion does not reach it and
|
|
// IncludeTemplates changes nothing here: a template is left out of a
|
|
// ReadyFlag listing only when its issue type is one the ready query
|
|
// already excludes. SkipLabels and SkipCounts are likewise not carried —
|
|
// labels and cardinalities are hydrated either way, which costs time and
|
|
// not correctness.
|
|
AllFlag bool
|
|
ReadyFlag bool
|
|
|
|
// SortBy names the display order and Reverse inverts it. A sort the
|
|
// database cannot express (natural-numeric id order) is resolved inside by
|
|
// fetching the full result set and trimming, so no caller has to know
|
|
// which sorts those are.
|
|
SortBy string
|
|
Reverse bool
|
|
|
|
// Limit bounds the page the caller RECEIVES. Nil means the shared list
|
|
// default; 0 means unlimited. The row limit actually pushed into the query
|
|
// is derived from it inside the implementation, together with the
|
|
// over-fetch that detects truncation.
|
|
Limit *int
|
|
// Offset skips the first N matching rows, on EVERY implementation, and the
|
|
// page is the rows at positions [Offset, Offset+Limit) of the answer the
|
|
// same request returns unpaged. See ReadyRequest.Offset for where the skip
|
|
// is applied and why that is not a backend's choice either.
|
|
//
|
|
// THE PORTABLE WAY TO PAGE IS THE KEYSET POSITION below,
|
|
// AfterCreatedAt/AfterID: every implementation honors it, and it does not
|
|
// skip or repeat rows when the result set changes underneath a walk.
|
|
// Offset is here for the surfaces that already published it.
|
|
Offset int
|
|
|
|
// AfterCreatedAt and AfterID carry a decoded keyset position in the
|
|
// (created_at DESC, id ASC) order. The opaque token that encodes them is a
|
|
// transport concern and never reaches this contract.
|
|
//
|
|
// AfterPriority EXTENDS that position to the (priority ASC, created_at
|
|
// DESC, id ASC) order — the order SortBy="priority" and the empty default
|
|
// render — and is honored by every implementation, on BOTH tier legs, the
|
|
// same way the pair above is. It is the same position and not a second
|
|
// one: AfterCreatedAt alone decides whether one was supplied, so a
|
|
// priority with no instant is ignored exactly as an AfterID with no instant
|
|
// is.
|
|
//
|
|
// SET IT ONLY UNDER THE ORDER IT NAMES. A priority position under
|
|
// SortBy="created" positions in an order the ORDER BY does not render, and
|
|
// the page that comes back is a walk through rows neither side agrees on.
|
|
// The order the request asks for and the order the position was minted in
|
|
// are one decision; the transport above this contract is what keeps them
|
|
// from drifting.
|
|
AfterCreatedAt *time.Time
|
|
AfterID string
|
|
AfterPriority *int
|
|
|
|
// MaxRows is a DEFENSIVE CAP rather than a page. It bounds how many rows
|
|
// the query may match before the whole answer is refused; 0 disables it.
|
|
// A request whose result set exceeds it comes back as
|
|
// *internal/storage/issueops.ErrTooManyRows — carrying the count observed,
|
|
// the cap, and MaxRowsSource's attribution — and NO PAGE. That is the
|
|
// difference from Limit, whose overflow is an ordinary truncated page with
|
|
// HasMore set. It is a circuit breaker for a caller that would rather fail
|
|
// than wait. The type is named here rather than left as "an error" so a
|
|
// caller can tell the cap firing from any other failure with errors.As;
|
|
// this leaf does not import it, and no answer depends on that.
|
|
//
|
|
// EVERY IMPLEMENTATION HONORS IT, and they agree on when it fires: when
|
|
// the query matched more rows than the cap allows AND the window the
|
|
// request asked the query to TOUCH could have exceeded it. THAT WINDOW IS
|
|
// Limit+Offset, NOT Limit. A row Offset skips is a row the query matched,
|
|
// so an offset walks a caller toward the breaker and never past it: a cap
|
|
// of Limit+Offset or looser never fires, because a query bounded to that
|
|
// many rows cannot break it, and one more row of offset is what flips the
|
|
// same request to a refusal. The two seams size that window through one
|
|
// function (internal/storage/issueops.SearchProbeLimit) so they cannot
|
|
// disagree about the boundary.
|
|
//
|
|
// Unlike SkipCounts and SkipLabels it IS carried onto the ReadyFlag arm.
|
|
MaxRows int
|
|
// MaxRowsSource attributes the cap to whatever knob set it — "--max-rows",
|
|
// "BEADS_MAX_ROWS", or empty for a library caller — and that attribution is
|
|
// what the refusal text reads back. It decides no answer: a request is
|
|
// refused on MaxRows alone, and this only decides how the refusal reads.
|
|
MaxRowsSource string
|
|
}
|
|
|
|
// GetRequest describes one issue-detail lookup.
|
|
type GetRequest struct {
|
|
// ID is the exact canonical id. There is no fuzzy, prefix or substring
|
|
// resolution here: an interactive affordance that can resolve to a
|
|
// different issue than the caller named has no place on a contract two
|
|
// front doors share. The issue-to-wisp fallback DOES happen inside.
|
|
//
|
|
// THAT FALLBACK NEEDS NO PLANE ORDER, and this contract deliberately
|
|
// states none: no LOCAL WRITE PATH can make an id resident in both planes,
|
|
// so the state an order would arbitrate is not reachable by writing
|
|
// through this library. Every local write path closes it. A guarded create
|
|
// probes BOTH tables before inserting
|
|
// and answers ErrAlreadyExists for an id either one already holds. Every
|
|
// batch create — import, a graph apply, a cooked formula, a markdown
|
|
// import — refuses on top of that an id already resident in the SIBLING
|
|
// table, skipping the row rather than hard-failing only on the
|
|
// auto-import recovery path, which leaves the resident row alone.
|
|
// Promotion and demotion insert into the target plane and delete from the
|
|
// source inside ONE transaction, so their dual-presence window never
|
|
// commits. This is why the implementations are free to probe the planes in
|
|
// either order, and why they in fact differ — a documented non-issue
|
|
// rather than a latent divergence (bd-yby99.22).
|
|
//
|
|
// TWO CAVEATS ARE WORTH CARRYING, and the second is the load-bearing one.
|
|
//
|
|
// First: the graph-apply path served by a unit-of-work provider gets its
|
|
// refusal from a preflight ABOVE storage rather than from the create
|
|
// guard, so a future caller that reached the graph-apply use case directly
|
|
// would be the thing that made this reachable.
|
|
//
|
|
// Second, and NOT closed by anything here: REPLICATION. The durable plane
|
|
// merges from a remote on pull, the ephemeral tables are dolt-ignored and
|
|
// local-only, and no post-merge check reconciles the two — the collision
|
|
// guard is reachable only from the create path. So a clone holding a wisp
|
|
// whose id another clone promoted to durable receives that id into the
|
|
// issues plane while its own wisp row survives. That needs a deterministic
|
|
// id to collide at all, which explicit-id creates and the identically
|
|
// minted infra wisps supply. It is a REAL residual path, it is outside
|
|
// this library's reach, and the resulting state is worse than an
|
|
// unspecified plane order: the merge-based lookups behind ready and search
|
|
// hard-error for the whole store. A plane order here would not rescue it.
|
|
//
|
|
// So the honest statement is the scoped one — no local write path reaches
|
|
// dual residency, replication can, and a caller that hits it has a
|
|
// corrupt store rather than an ordering question (bd-yby99.22).
|
|
ID string
|
|
// IncludeDependents and IncludeComments populate the two expensive row
|
|
// lists. Both default off: the detail view carries counts, and a caller
|
|
// that wants the rows asks for them.
|
|
IncludeDependents bool
|
|
IncludeComments bool
|
|
|
|
// BriefDeps reduces each dependency to its identity-and-shape fields.
|
|
BriefDeps bool
|
|
}
|
|
|
|
// IssuePage is one page of work. Ready and List share it deliberately: both
|
|
// surfaces of both operations emit IssueWithCounts today, and a leaner page
|
|
// type for ready would drift at the field level the moment anything compared
|
|
// the two.
|
|
type IssuePage struct {
|
|
// Items is the page, in the operation's order. Never nil for a successful
|
|
// call.
|
|
Items []*IssueWithCounts
|
|
// HasMore reports that the limit truncated the result.
|
|
HasMore bool
|
|
}
|
|
|
|
// Reader describes guarded issue queries: the read counterpart of Lifecycle,
|
|
// and — like Lifecycle — a role with its own accessor. A new capability gets a
|
|
// new role interface and its own accessor; never append a method here.
|
|
//
|
|
// Each method takes the whole request and performs filter and default
|
|
// construction INTERNALLY. A caller of this interface can only say
|
|
// rd.List(ctx, req): the four-step ritual of building a config source, loading
|
|
// config, building a filter and executing it is not reachable through it.
|
|
// Implementations never mutate caller-owned request values.
|
|
//
|
|
// WHERE THAT IS ENFORCED, precisely, because the difference matters:
|
|
//
|
|
// - The HTTP surface is on the role for all three of its issue reads, and
|
|
// two lint rules make writing a filter there a lint failure rather than a
|
|
// review comment. THE CLAIM at the bottom of this comment names them, and
|
|
// names what they cover and what they do not.
|
|
//
|
|
// - `bd show --json`'s DETAIL VIEW is on the role on BOTH routes: the direct
|
|
// one reaches it through store.IssueReader(), the proxied one through the
|
|
// unit-of-work provider's accessor. Its ALTERNATE views are not, and are
|
|
// not the same question: --refs, --children, --thread and --as-of each
|
|
// answer with their own shape, which this contract does not describe and
|
|
// no HTTP operation serves. --short is not either; it prints one line from
|
|
// the issue, not a detail view.
|
|
//
|
|
// The shared implementation behind the store accessor
|
|
// lives in internal/workapi/storereader, which the
|
|
// cmd-bd-role-constructors depguard rule keeps out of cmd/bd: the
|
|
// accessor is where each storage decorator adds its layer, so a command
|
|
// that constructed a reader directly would get an unspanned one. `bd show`
|
|
// keeps its own id RESOLUTION — fuzzy ids, cross-repo routing, --current —
|
|
// and hands this contract the canonical id it resolved, because an
|
|
// affordance that can answer with a different issue than the caller named
|
|
// has no place on a contract an unattended HTTP client also calls.
|
|
//
|
|
// - `bd list` IS, on both routes, for its PAGE — every output mode but the
|
|
// two named next. --json and every text rendering call List below and
|
|
// nothing else; --ready is not a route of its own on either side, it is
|
|
// ReadyFlag, and picking the ready query from it is this role's job.
|
|
// The two exceptions consume the FILTER as a VALUE and no page can express
|
|
// either: --watch re-runs it on a ticker, and the hierarchical --parent
|
|
// tree re-parents a copy of it at every level. What is NOT an exception,
|
|
// though it looks like one, is the whole-graph dependency-record load
|
|
// behind --format and the pretty tree: that is a different question from
|
|
// both this role's and BlockingAnnotator's, so those renderings take their
|
|
// page from here and load the graph beside it.
|
|
//
|
|
// The other thing `bd list` used to do here was the per-page blocking
|
|
// decoration, which is issueops.BlockingAnnotator's on both routes now —
|
|
// its own role, because it is a DERIVED annotation over ids a page already
|
|
// chose rather than a page.
|
|
//
|
|
// - `bd ready` is NOT, on either route, and will not be until there are more
|
|
// roles to route it through. It consumes the FILTER itself for --claim,
|
|
// --gated, --explain and --mol. Two of its questions HAVE left the filter
|
|
// behind, each for the role that owns it: --claim is ReadyClaimer's, and
|
|
// the published total is ReadyCounter's, on both routes.
|
|
//
|
|
// WHAT `bd ready` DOES SHARE, stated exactly, because "not on the role" is not
|
|
// the same as "unprotected":
|
|
//
|
|
// - CONSTRUCTION. Every route, and both implementations of this interface,
|
|
// build from these same request types through the same two builders in
|
|
// internal/workapi, which the builders' golden files pin.
|
|
// - EXECUTION, on the PROXIED route only. The direct route keeps an epilogue
|
|
// of its own and cannot give it up: it answers the strictly larger question
|
|
// "how many rows did the limit hide" and publishes the total in its
|
|
// pagination meta, where this role answers only "were any hidden".
|
|
// Collapsing them would change one surface's published output. That second
|
|
// question is not off-role, though — it is ReadyCounter's, which both
|
|
// routes now ask through their own accessor, over this same ReadyRequest;
|
|
// what stays outside this role is the PAGE's epilogue, not the count beside
|
|
// it.
|
|
//
|
|
// THE CLAIM, stated once and in full so it can be checked sentence by
|
|
// sentence. SHARED: all three issue reads on the HTTP surface go through this
|
|
// role, so does `bd show --json`'s detail view on both its routes, and so does
|
|
// `bd list`'s page on both of its — in every mode but --watch and the
|
|
// hierarchical --parent tree, which take the filter instead. `bd ready` is not
|
|
// on it and shares instead the request types above, the two builders in
|
|
// internal/workapi that their golden files pin, and workapi.FinishPage on its
|
|
// proxied route only. ENFORCED,
|
|
// and by what: depguard (httpapi-transport-boundary) denies internal/workapi
|
|
// from every non-test file of internal/httpapi, so no builder is callable
|
|
// there, and a forbidigo rule denies naming types.IssueFilter or
|
|
// types.WorkFilter there at all, so no filter is writable there either — both
|
|
// are directory-scoped with no per-file exception, so a file added to that
|
|
// package tomorrow is covered the moment it exists. That same forbidigo rule
|
|
// covers cmd/bd deny-by-default with 59 named exceptions, so the files
|
|
// implementing `bd list` and `bd show` cannot write a filter, and neither can
|
|
// a file they are split or renamed into unless the new name lands on that
|
|
// list. NOT ENFORCED: the rule forbids NAMING those types, not holding a
|
|
// value, so the property is "no filter is written there", not "every filter
|
|
// there came from a builder"; test files are exempt from both rules, because
|
|
// the oracles hold filters in order to inspect them; `bd ready`'s files are
|
|
// among the 59, since its listing and --claim are handed the filter itself and
|
|
// the blocked-issue views in those files name one directly, so it is guarded by
|
|
// the builder and the golden files and not by the linter;
|
|
// cmd/bd/list_show_filter_modes.go is among them too and STAYS there — the
|
|
// count did not drop with this flip, because that file is where `bd list`'s
|
|
// two filter-consuming modes and `bd show --current` live and all three still
|
|
// need to name the type;
|
|
// GET /healthz and GET /v0/beads/context are not issue queries and are on no
|
|
// role; `bd ready`'s direct route and `bd list`'s hierarchical tree run
|
|
// epilogues of their own; and none of this is a merge gate — the rules run in
|
|
// `make ci-pr-lint` on every pull request and aggregate into the ci-gate job,
|
|
// but main carries no branch protection beyond deletion and non-fast-forward,
|
|
// so no check is GitHub-required and a red gate binds by convention.
|
|
//
|
|
// Closing the rest needs more roles (a claim role, an explain role), not more
|
|
// methods here.
|
|
type Reader interface {
|
|
// Ready returns unblocked open work in the requested policy's order.
|
|
Ready(ctx context.Context, req ReadyRequest) (IssuePage, error)
|
|
// List returns issues under the request's filters, in the requested
|
|
// display order.
|
|
List(ctx context.Context, req ListRequest) (IssuePage, error)
|
|
// Get returns one issue's detail view. A miss — for both the issue and the
|
|
// wisp table — is ErrNotFound; a backend failure passes through unchanged
|
|
// and never decays into not-found.
|
|
Get(ctx context.Context, req GetRequest) (*IssueDetails, error)
|
|
}
|