Commit graph

5 commits

Author SHA1 Message Date
matt wilkie
fbdf7badbc Merge remote-tracking branch 'upstream/main' into pr-4095-fix 2026-07-13 20:39:27 -07:00
Steve Yegge
67ccdbfd44 fix(ready): honor --label-any on the ready/claim path (wy-jpd3.2)
BuildReadyWorkWhere emitted clauses for --label (AND-set) and
--exclude-label but none at all for --label-any, so the OR-set filter was
silently dropped by `bd ready` and `bd ready --claim` on every backend
(with or without --parent), while `bd list`/`bd search` honored it.

On an atomic claim the silent drop is dangerous rather than merely wrong:
a worker fencing itself to its own lane
(`bd ready --claim --label-any lane-a --parent epic-1`) would claim
another lane's issue and believe it was fenced. Reproduced on current
main: the new conformance case claims a lane-b issue when lane-a was
requested.

Emit an OR-set membership clause (same shape as the list path in
sqlbuild/filter.go) that AND-combines with Labels, ExcludeLabels and the
parent filter. All claim paths (Dolt, embedded-Dolt, sqlkit SQL family)
funnel through ClaimReadyIssueInTx -> GetReadyWorkInTx ->
BuildReadyWorkWhere, so the single seam fixes every backend.

Tests: a SQL-shape unit test in sqlbuild, plus a behavioral conformance
case (ClaimReadyIssueLabelFilters) asserting the claim is fenced by the
OR-set alone, AND-combined with --label and --parent, and — the safety
property — that an exhausted lane claims NOTHING rather than falling back
to unfenced ready work.
2026-07-12 07:58:22 -07:00
Julian Knutsen
fb527d034a
perf(ready): page-push ready-work counts and size the total with cheap COUNT(*)s (#4679)
`bd ready --json` had two O(N) hotspots on main. The counts mega-query's
reverse-blocker `rc` subquery keys on COALESCE(depends_on_issue_id, …), an
expression the pure-Go GMS analyzer cannot auto-index, so it re-scanned its
whole materialization once per candidate — O(candidates × blockers). And the
"Showing X of N" total re-ran that entire mega-query UNBOUNDED just to size N.

Changes:
- Generalize one counts builder: sqlbuild.SearchCountsSQL now takes an optional
  `ids []string`. Empty ids = the predicate form (unchanged callers); non-empty
  ids = the page-pushed form that constrains the driver and every count
  subquery to the page, bounding rc by the page instead of the full graph.
  Removes the drifted SearchCountsSQL/SearchCountsByIDsSQL duplication; the
  projection order is defined once and DepTargetExpr is used throughout.
- issueops.runReadyCountsInTx resolves the ready-ID page with the cheap indexed
  ID query, then hydrates counts constrained to those IDs, CHUNKED by
  sqlbuild.QueryBatchSize so large pages stay within backend placeholder limits
  (no quadratic fallback, no wasted ID pass). The page order is restored so the
  result is byte-identical to the unbounded ORDER BY … LIMIT.
- issueops.CountReadyWorkInTx sizes N with indexed COUNT(*)s over the ready
  predicate for the issues AND wisps families, minus the wisp-wins overlap —
  identical to len(GetReadyWorkWithCounts(Limit=0)) even when wisps exist, with
  no mega-query fallback.
- Add ReadyWorkCounter to internal/storage beside the other optional
  capabilities; DoltStore and EmbeddedDoltStore implement CountReadyWork.
  cmd/bd/ready.go zeroes the limit at the call site and unwraps to the
  capability via storage.UnwrapStore, falling back to the unbounded query only
  when a store predates it.
- Extract the shared scan/dedupe loop (scanCountsRowsInTx).
- Conformance tests: page counts byte-identical to unbounded, and
  CountReadyWork == len(unbounded), with fixtures for wisps and a page that
  spans the chunk boundary.

Co-authored-by: Test User <test@test.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-08 18:07:41 -07:00
matt wilkie
8ad064a961 Merge upstream/main into PR 4095
Resolve ready-work ordering against current main after upstream moved the shared ordering into sqlbuild. Priority ready work now breaks same-priority ties with created_at ASC, and regression coverage checks both the shared helper and ClaimReadyIssue.

Agent-Signature: codex-gpt-5.5-high on behalf of matt wilkie
2026-07-08 12:59:23 -07:00
Steve Yegge
1f8f1fff31 refactor(storage): extract shared SQL builders into internal/storage/sqlbuild (bd-6dnrw.46)
Move all pure SQL-text builders shared by issueops (classic) and
domain/db (proxied) into one package; both stacks now delegate, so
ready/filter/counts query semantics can no longer drift (Seam A).
Execution orchestration stays per-stack per the extract-don't-unify
decision. Canonical SQL text is classic's; the only proxied-side text
deltas are IN-list whitespace.

Adversarial re-review (bd-6dnrw.47) verified all 10 attack items with
no production divergence, and adds an import-boundary test pinning the
layering (domain must never import issueops/sqlbuild) plus a single-use
constraint note on LabelSearchPlan.MergeInto. Follow-ups filed:
bd-emrs2 (+1-overfetch convention), bd-kzeme (IN-helper consolidation).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 15:56:23 -04:00