beads/internal/storage/issueops
Steve Yegge 96388ea019
fix(search): order Go-side-sort pages before every trim; honor sortDesc for id (#5639)
* fix(search): order Go-side-sort pages before every trim; honor sortDesc for id

Two live defects, both named-but-deferred in #5587's commit message and
both reachable from bd query '<expr>' --sort id (DefaultQueryLimit means a
bound is always set):

1. sqlbuild.Less ignored sortDesc for "id" — the one Go-side sort key —
   so every merge sort feeding a reversed id page kept the byte-FIRST
   rows. idSrcPage.sortGoSide's doc named this sibling bug explicitly.

2. #5587's fix (a page bound is only ever pushed under an order the query
   can express) covered the union seam only. The per-table seams
   (searchTable/scanFilterIDs, and the counts twin's
   finishSearchCountsPage) received the full matching set — searchWindowFor
   already withholds the page bound — but trimmed it with no sort anywhere:
   measured, 10 rows sort id desc limit 3 answered [000 001 002] where
   [009 008 007] was owed. The store-backed seam (issueops.searchTableInTxT)
   was worse off: it still pushed LIMIT into the leg SQL with no ORDER BY,
   so each leg contributed an arbitrary engine-ordered subset.

Fixes, one per seam, all converging on the same rule:

- sqlbuild.Less: sortDesc now flips the id comparison (byte order, matching
  the SQL the key would render if it could).
- domain/db: new sortRowsGoSide helper (the per-table copy of
  idSrcPage.sortGoSide) runs before finishWindow at searchTable's wide
  path, scanFilterIDs, and finishSearchCountsPage.
- issueops.searchTableInTxT: a Go-side sort leg no longer carries a SQL
  LIMIT; the leg scans the complete matching set, orders it in Go, and
  applies the same EffectiveSearchLimit bound after the order exists
  (goSideSortAndTrim), so cap accounting is unchanged and Pattern B
  hydrates only surviving rows.
- idProjection gains a comparator for the one key its payload can order
  ("id"), removing the merged-id-search landmine the old nil documented.

Tests: red-before-green verified on all three seams. sqlbuild unit test
pins Less; sqlmock tests pin the store-backed leg shape (no LIMIT under a
Go-side sort, bound still pushed under a SQL sort) and the ordered+trimmed
page; the domain/db suite adds per-table membership cases (asc, the
measured desc repro, and a four-route parity check: wisps-empty probe,
SkipWisps, wide path, counts twin must answer one page) plus a reversed
union page fence.

(bd-jao3t, bd-69c1a)

* fix(search): extend the Go-side-sort bound rule to the store-backed counts seam; one LessID comparator

Review round (adversarial pass on PR #5639):

F1 — runFilterSearchQueryInTx (issueops/search_counts.go) had the identical
defect the first commit fixed in searchTableInTxT: LIMIT eff pushed
unconditionally while sqlbuild.OrderBy renders no ORDER BY for "id". This
is the seam bd query '<expr>' --sort id actually reaches on the
store-shaped backends (storequerier → SearchIssuesWithCounts →
SearchIssuesWithCountsInTx), where BuildQueryPlan always pushes a bound —
so the first commit's repro claim held only for the uow/domain-db bodies.
Now the counts leg scans the complete matching set under a Go-side sort
and applies the same eff bound after ordering (goSideSortAndTrim),
leaving merge/trim/cap accounting exactly what the SQL LIMIT handed them.
bd list was already safe here (workapi.SQLLimit zeroes the pushed limit
for --sort id); only the querier path pushed a bound.

F2 — the byte-order id comparison existed in five hand-rolled copies
(Less, idProjection.less, goSideSortAndTrim, sortRowsGoSide,
idSrcPage.sortGoSide) — the exact duplication that let Less drift from
sortGoSide in the first place, and that hid F1's sixth site. All five now
call the one exported comparator, sqlbuild.LessID.

F3 — the ascending per-table suite case is annotated as the weak witness
it is (engine order for a PK-clustered prefix scan tends to be
byte-ascending already); the DESC cases are the red-before-green fences.

New shape test pins the counts legs: under --sort id neither the issues
nor the wisps counts query may carry a LIMIT (red on the previous commit:
the leg query carried LIMIT 3).

(bd-jao3t, bd-69c1a)
2026-08-11 00:24:28 -07:00
..
aggregate.go fix(bd): canonicalize remaining actor==assignee comparisons in claim/heartbeat CAS (ga-v2k49) (#5479) 2026-08-09 17:19:00 -07:00
aggregate_authorize_transfer_test.go fix(bd): canonicalize actor==assignee comparisons in unclaim.go and AuthorizeAssigneeTransferWithPools (#5439) 2026-08-09 11:35:01 -07:00
as_of.go /{cmd,internal}: bd show proxied-server mode 2026-06-17 13:29:24 -07:00
batch_apply.go Add issueops.BatchApplier: one plan, one transaction (#5480) 2026-08-09 06:59:34 -07:00
batch_apply_test.go Add issueops.BatchApplier: one plan, one transaction (#5480) 2026-08-09 06:59:34 -07:00
batching.go /{cmd,internal}: cleanup 2026-05-22 13:04:38 -07:00
batching_test.go fix(storage): preserve mixed issue and wisp reads (#3991) 2026-05-21 06:50:42 -07:00
blocked.go /{cmd,internal}: bd ready proxied-server 2026-06-18 13:00:57 -07:00
blocked_consistency.go feat(events): transactional events journal engine (bd-opisf) 2026-08-09 01:58:17 +00:00
blocked_consistency_test.go feat(sync): tell a stuck dirty working set from a busy one, exit 4 (wy-wub2s) 2026-07-25 17:53:02 -07:00
blocked_merge.go fix(is_blocked): cross-mode full recompute repair for stale is_blocked (bd-6dnrw.37) (#4423) 2026-06-19 23:14:09 -07:00
blocked_state.go feat(events): transactional events journal engine (bd-opisf) 2026-08-09 01:58:17 +00:00
blocked_state_result_test.go feat(storage): one guarded issue-lifecycle surface for the CLI and linked consumers (#5191) 2026-07-31 11:26:38 -07:00
blocking_annotation.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
bootstrap.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
bulk_ops.go feat(events): transactional events journal engine (bd-opisf) 2026-08-09 01:58:17 +00:00
child_id.go /internal/storage: remove dual tx 2026-05-15 12:07:41 -07:00
claim.go fix(bd): canonicalize remaining actor==assignee comparisons in claim/heartbeat CAS (ga-v2k49) (#5479) 2026-08-09 17:19:00 -07:00
claim_next.go feat(workapi,storage): opt-in Brief projection for the list and ready pages (#5554) 2026-08-10 10:45:23 -07:00
close.go feat(events): transactional events journal engine (bd-opisf) 2026-08-09 01:58:17 +00:00
close_batch.go feat(issueops): put every issue capability behind one library surface 2026-08-04 12:27:56 -07:00
close_test.go feat(storage): one guarded issue-lifecycle surface for the CLI and linked consumers (#5191) 2026-07-31 11:26:38 -07:00
commenter.go feat(issueops): put every issue capability behind one library surface 2026-08-04 12:27:56 -07:00
comments.go feat(events): journal read/prune surface with typed truncation (bd-opisf) 2026-08-09 01:58:17 +00:00
commit_pending.go fix(storage): skip empty Dolt commit when nothing is staged (re-port of #4288) (#5403) 2026-08-07 10:32:31 -07:00
compaction.go feat(storage): content-derived ids for events/comments at insert time (bd-ri8bd) (#5150) 2026-07-29 04:33:04 -07:00
config_helpers.go fix(cook/pour): honor declared formula step types instead of squashing them to task (#5520) 2026-08-10 05:36:33 -07:00
config_helpers_test.go feat(storage): one guarded issue-lifecycle surface for the CLI and linked consumers (#5191) 2026-07-31 11:26:38 -07:00
config_metadata.go /{cmd,internal}: bd ready proxied-server 2026-06-18 13:00:57 -07:00
count.go Retire the last three wisp-switch call sites, and bound the wisp-inclusive union reads (ga-2ltro.12, ga-2ltro.7) (#5587) 2026-08-10 17:07:59 -07:00
create.go fix(cook/pour): honor declared formula step types instead of squashing them to task (#5520) 2026-08-10 05:36:33 -07:00
create_batch.go refactor: delete the dead orphan-handling capability (bd-gwryr) (#5497) 2026-08-09 12:03:18 -07:00
create_only_errors_test.go feat(storage): one guarded issue-lifecycle surface for the CLI and linked consumers (#5191) 2026-07-31 11:26:38 -07:00
create_only_guard.go feat(storage): one guarded issue-lifecycle surface for the CLI and linked consumers (#5191) 2026-07-31 11:26:38 -07:00
create_only_guard_test.go feat(storage): one guarded issue-lifecycle surface for the CLI and linked consumers (#5191) 2026-07-31 11:26:38 -07:00
create_test.go test(conformance): pin the missing-parent child-counter skip on a real backend (bd-k4bcj) (#5505) 2026-08-09 13:44:54 -07:00
cycle_report.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
cycle_report_test.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
cycles.go fix(deps): enforce combined cycles across storage paths 2026-07-13 13:50:07 -07:00
cycles_test.go fix(deps): bulk cycle gate blocks only cycles that traverse a new edge (bd-578h9.9) 2026-06-11 15:21:33 -04:00
delete.go feat(events): transactional events journal engine (bd-opisf) 2026-08-09 01:58:17 +00:00
delete_cascade_tables_test.go fix(storage): stage every table a delete removes rows from (#3807) (#5187) 2026-07-31 09:41:33 -07:00
delete_role.go Add DeleteRequest.ExpectedVersion: a compare-and-delete on the named row (#5481) 2026-08-09 07:17:54 -07:00
dep_counts.go /{cmd,internal}: bd show proxied-server mode 2026-06-17 13:29:24 -07:00
dependencies.go Add issueops.BatchApplier: one plan, one transaction (#5480) 2026-08-09 06:59:34 -07:00
dependencies_test.go feat(errors): typed dependency error taxonomy on the public beads package (#4892) 2026-07-18 18:29:07 -07:00
dependency_coordination.go feat(storage): one guarded issue-lifecycle surface for the CLI and linked consumers (#5191) 2026-07-31 11:26:38 -07:00
dependency_coordination_test.go feat(storage): one guarded issue-lifecycle surface for the CLI and linked consumers (#5191) 2026-07-31 11:26:38 -07:00
dependency_editor.go Add issueops.BatchApplier: one plan, one transaction (#5480) 2026-08-09 06:59:34 -07:00
dependency_queries.go fix(storage): total ORDER BY on dependency bulk-loaders (#4749) (#4829) 2026-07-26 11:53:03 -07:00
dependency_queries_test.go fix(storage): total ORDER BY on dependency bulk-loaders (#4749) (#4829) 2026-07-26 11:53:03 -07:00
dependency_tree.go /{cmd,internal}: bd dep proxied-server 2026-06-18 15:44:45 -07:00
dependency_tree_test.go feat(leases): move leases to ephemeral dolt_ignored leases table (bd-lrgn1) 2026-07-17 01:02:29 -07:00
derivedid.go feat(events): transactional events journal engine (bd-opisf) 2026-08-09 01:58:17 +00:00
diff.go /internal/storage/{dolt,embeddeddolt,issueops}: implement methods 2026-03-20 11:46:28 -07:00
edge_counts.go Add issueops.GraphCounter: how many edges, in one named direction (ga-itny5) (#5485) 2026-08-09 11:29:32 -07:00
edge_counts_test.go Add issueops.GraphCounter: how many edges, in one named direction (ga-itny5) (#5485) 2026-08-09 11:29:32 -07:00
edge_role_requests_test.go feat(issueops): put every issue capability behind one library surface 2026-08-04 12:27:56 -07:00
edges.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
epic_closure.go more commands 2026-07-20 14:41:07 -07:00
errors.go feat(issueops): name the two dependency-endpoint refusals (bd-yby99.9) 2026-08-07 19:45:54 +00:00
events.go feat(storage): events + dependents reads, batched blocked, public claim surface (#4926) 2026-07-22 07:41:47 -07:00
execution.go fix(bd): canonicalize remaining actor==assignee comparisons in claim/heartbeat CAS (ga-v2k49) (#5479) 2026-08-09 17:19:00 -07:00
execution_test.go fix(bd): canonicalize remaining actor==assignee comparisons in claim/heartbeat CAS (ga-v2k49) (#5479) 2026-08-09 17:19:00 -07:00
federation.go /{cmd,internal}: wip sync and data EmbeddedDoltStore methods 2026-03-24 12:01:16 -07:00
filters.go refactor(storage): extract shared SQL builders into internal/storage/sqlbuild (bd-6dnrw.46) 2026-06-12 15:56:23 -04:00
filters_test.go fix(filters): Dolt label-filter regression fix — LabelPattern + LabelRegex + JSON truncation hint suppression (#3971) 2026-07-24 00:17:02 -07:00
get_issue.go feat(leases): move leases to ephemeral dolt_ignored leases table (bd-lrgn1) 2026-07-17 01:02:29 -07:00
helpers.go fix(cook/pour): honor declared formula step types instead of squashing them to task (#5520) 2026-08-10 05:36:33 -07:00
helpers_test.go feat(create): add status flag for initial issue status (#4536) 2026-07-05 11:15:48 -07:00
history.go fix(history): coalesce NULL text columns in dolt_history_issues scan (#4912) 2026-07-25 22:30:34 -07:00
identity.go fix(bd): canonicalize remaining actor==assignee comparisons in claim/heartbeat CAS (ga-v2k49) (#5479) 2026-08-09 17:19:00 -07:00
identity_parity_test.go fix(bd): canonicalize actor==assignee comparisons in unclaim.go and AuthorizeAssigneeTransferWithPools (#5439) 2026-08-09 11:35:01 -07:00
journal.go feat(events): journal read/prune surface with typed truncation (bd-opisf) 2026-08-09 01:58:17 +00:00
journal_autoprune.go feat(events): bounded-by-default auto-prune to the retention floors (bd-opisf) 2026-08-09 01:58:17 +00:00
journal_autoprune_test.go feat(events): bounded-by-default auto-prune to the retention floors (bd-opisf) 2026-08-09 01:58:17 +00:00
journal_completeness_test.go feat(events): transactional events journal engine (bd-opisf) 2026-08-09 01:58:17 +00:00
journal_dependencies.go feat(events): transactional events journal engine (bd-opisf) 2026-08-09 01:58:17 +00:00
journal_prune.go feat(httpapi): publish the events journal on the v0 surface (bd-opisf) 2026-08-09 06:01:23 +00:00
journal_prune_test.go feat(events): journal read/prune surface with typed truncation (bd-opisf) 2026-08-09 01:58:17 +00:00
journal_truncation_test.go feat(events): journal read/prune surface with typed truncation (bd-opisf) 2026-08-09 01:58:17 +00:00
journal_vocabulary_test.go feat(events): journal read/prune surface with typed truncation (bd-opisf) 2026-08-09 01:58:17 +00:00
labels.go feat(events): transactional events journal engine (bd-opisf) 2026-08-09 01:58:17 +00:00
lease.go fix(bd): canonicalize remaining actor==assignee comparisons in claim/heartbeat CAS (ga-v2k49) (#5479) 2026-08-09 17:19:00 -07:00
lease_replica_test.go fix(leases): keep node_id off the committed config; tighten the replica guard (wy-jpd3.7) 2026-07-25 02:32:31 -07:00
metadata.go feat(engine): guarded write ops — atomic metadata merge, row-version CAS, typed dep errors + events, bd close delegation (#4911) 2026-07-21 18:13:03 -07:00
metadata_cas.go Add issueops.MetadataCAS: compare-and-set over one metadata key (#5473) 2026-08-09 04:15:34 -07:00
metadata_test.go feat(engine): guarded write ops — atomic metadata merge, row-version CAS, typed dep errors + events, bd close delegation (#4911) 2026-07-21 18:13:03 -07:00
molecule.go /{cmd,internal}: remove depends_on_id 2026-05-19 10:17:49 -07:00
persistence.go feat(events): transactional events journal engine (bd-opisf) 2026-08-09 01:58:17 +00:00
promote.go feat(events): transactional events journal engine (bd-opisf) 2026-08-09 01:58:17 +00:00
provenance.go Add append-only provenance_events log and bd provenance CLI (#4461) 2026-08-07 09:43:20 -07:00
public_claim.go fix(bd): canonicalize remaining actor==assignee comparisons in claim/heartbeat CAS (ga-v2k49) (#5479) 2026-08-09 17:19:00 -07:00
public_claim_test.go fix(bd): canonicalize remaining actor==assignee comparisons in claim/heartbeat CAS (ga-v2k49) (#5479) 2026-08-09 17:19:00 -07:00
public_create.go feat(issueops): name the two dependency-endpoint refusals (bd-yby99.9) 2026-08-07 19:45:54 +00:00
public_create_test.go feat(events): transactional events journal engine (bd-opisf) 2026-08-09 01:58:17 +00:00
public_hydration.go feat(storage): one guarded issue-lifecycle surface for the CLI and linked consumers (#5191) 2026-07-31 11:26:38 -07:00
public_hydration_test.go feat(storage): one guarded issue-lifecycle surface for the CLI and linked consumers (#5191) 2026-07-31 11:26:38 -07:00
public_snapshot.go fix(export): promoted no-history wisps survive import round-trip (bd-r9uce) (#5368) 2026-08-05 12:48:44 -07:00
public_snapshot_test.go fix(export): promoted no-history wisps survive import round-trip (bd-r9uce) (#5368) 2026-08-05 12:48:44 -07:00
ready_work.go feat(ready): WorkFilter.Statuses — multi-status ready work in one query (#4752) 2026-07-26 12:53:23 -07:00
ready_work_counts.go feat(workapi,storage): opt-in Brief projection for the list and ready pages (#5554) 2026-08-10 10:45:23 -07:00
ready_work_test.go feat(ready): WorkFilter.Statuses — multi-status ready work in one query (#4752) 2026-07-26 12:53:23 -07:00
relations.go feat(issueops): put every issue capability behind one library surface 2026-08-04 12:27:56 -07:00
release_role.go Add issueops.Releaser: give a claim back, optionally only a named holder's (#5482) 2026-08-09 07:48:56 -07:00
reopen.go feat(events): transactional events journal engine (bd-opisf) 2026-08-09 01:58:17 +00:00
reopen_test.go feat(storage): one guarded issue-lifecycle surface for the CLI and linked consumers (#5191) 2026-07-31 11:26:38 -07:00
role_requests_test.go feat(issueops): put every issue capability behind one library surface 2026-08-04 12:27:56 -07:00
row_lock_guard_test.go fix(automerge): settled merges must mint a row_lock distinct from both parents (absorbed from #4682) (#5245) 2026-08-02 06:21:35 -07:00
scan.go feat(workapi,storage): opt-in Brief projection for the list and ready pages (#5554) 2026-08-10 10:45:23 -07:00
scan_test.go feat(workapi,storage): opt-in Brief projection for the list and ready pages (#5554) 2026-08-10 10:45:23 -07:00
search.go fix(search): order Go-side-sort pages before every trim; honor sortDesc for id (#5639) 2026-08-11 00:24:28 -07:00
search_counts.go fix(search): order Go-side-sort pages before every trim; honor sortDesc for id (#5639) 2026-08-11 00:24:28 -07:00
search_counts_test.go test(cli,storage): BEADS_MAX_ROWS behavioral + opt-out gate tests (be-x42v) (#4160) 2026-07-24 01:40:36 -07:00
search_goside_sort_test.go fix(search): order Go-side-sort pages before every trim; honor sortDesc for id (#5639) 2026-08-11 00:24:28 -07:00
search_lite_merge_test.go feat(storage): one guarded issue-lifecycle surface for the CLI and linked consumers (#5191) 2026-07-31 11:26:38 -07:00
search_test.go test(cli,storage): BEADS_MAX_ROWS behavioral + opt-out gate tests (be-x42v) (#4160) 2026-07-24 01:40:36 -07:00
stale.go more commands 2026-07-20 14:41:07 -07:00
statistics.go feat(stats): --no-blocked flag skips blocked-count computation; fix Blocked:0 red render (be-nnqp, be-4b63) (#4022) 2026-07-23 23:52:39 -07:00
sweep.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
tree_walk.go Prune each half of a both walk before merging them 2026-08-06 21:46:53 +00:00
tree_walk_test.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
unclaim.go fix(bd): canonicalize actor==assignee comparisons in unclaim.go and AuthorizeAssigneeTransferWithPools (#5439) 2026-08-09 11:35:01 -07:00
update.go fix(bd): canonicalize remaining actor==assignee comparisons in claim/heartbeat CAS (ga-v2k49) (#5479) 2026-08-09 17:19:00 -07:00
update_cas.go fix(bd): canonicalize actor==assignee comparisons in unclaim.go and AuthorizeAssigneeTransferWithPools (#5439) 2026-08-09 11:35:01 -07:00
update_closed_fields_test.go fix(issueops): make a done-crossing generic update close like bd close (#5255) 2026-08-01 15:22:52 -07:00
update_force_close_policy_test.go feat(update): enforce close policy when a status update crosses into done (#5206) 2026-07-31 18:23:06 -07:00
update_mergeops_test.go feat(storage): one guarded issue-lifecycle surface for the CLI and linked consumers (#5191) 2026-07-31 11:26:38 -07:00
update_test.go feat(leases): move leases to ephemeral dolt_ignored leases table (bd-lrgn1) 2026-07-17 01:02:29 -07:00
update_validation_test.go feat(storage): one guarded issue-lifecycle surface for the CLI and linked consumers (#5191) 2026-07-31 11:26:38 -07:00
version.go feat(engine): guarded write ops — atomic metadata merge, row-version CAS, typed dep errors + events, bd close delegation (#4911) 2026-07-21 18:13:03 -07:00
version_commit.go feat(storage): one guarded issue-lifecycle surface for the CLI and linked consumers (#5191) 2026-07-31 11:26:38 -07:00
wake_defers.go feat(events): transactional events journal engine (bd-opisf) 2026-08-09 01:58:17 +00:00
wisp_filter_convert.go feat: add ListWisps method to Storage interface (fix-merge PR #2783) 2026-03-26 19:33:28 -07:00
wisp_routing.go Add append-only provenance_events log and bd provenance CLI (#4461) 2026-08-07 09:43:20 -07:00
wisp_routing_test.go perf(storage): amortize per-ID wisp routing via WispIDSetInTx (#3453) 2026-04-24 13:39:42 -07:00