beads/internal/workapi
Julian Knutsen 8aaefe2d4f
feat(httpapi): serve bd list's order with sort on listIssues (#5666)
* feat(httpapi): serve `bd list`'s order with `sort` on listIssues

The issue listing served one order, `(created_at DESC, id ASC)`, because the
cursor is a keyset position in it. The spec stated the constraint in its own
words: "the sort order is welded to the cursor contract, and a new order needs
new surface." That welding put the cost on every client wanting `bd list`'s
ordering — the only way to get it was to page the whole result set and sort
locally, which is the one cost on this surface that grows with the project.

Measured against a real `bd serve` over 1400 rows at the 200-row page an HTTP
client actually uses: walk-and-sort is 7 requests plus a client-side
comparator, `?sort=priority` is 1. Both are checked against `bd list --json`
row for row, because the claim that matters is not "fewer requests" but "the
same order".

`sort` takes `created` and `priority` and nothing else. Each value is a keyset
contract — a position shape, a strictly-after predicate, an index — not a
display preference, and both keys are provably total (priority and created_at
are non-null, id is unique) so a page boundary inside a run of equal keys
resolves on id. The seven other orders `bd list --sort` takes have no such key:
`id` is natural-numeric and no database expresses it, `updated` moves on every
write, `closed` is nullable, and status/title/type/assignee are mutable and
unindexed. `priority` here is (priority ASC, created_at DESC, id ASC), which is
both `bd list`'s flagless order and what `--sort priority` produces — a stable
priority sort over the created order is the same sequence — so one served order
retires the walk for both.

Absent `sort` still means `created`, permanently: it is the compatibility
contract for every client written before the parameter existed.

THE CURSOR NOW CARRIES ITS ORDER. This is the half that makes the parameter
safe rather than merely useful, and the obvious implementation gets it wrong.
The token was base64 of `{t,i}` with no binding, so a created-order cursor
replayed under `sort=priority` decoded perfectly and was read as a position in
a different total order — a page that skips and duplicates rows, served with a
200, undetectable by the client. Tokens are now `v2` with an explicit order
member, and decode takes the wanted order as a parameter so a mismatch is
unrepresentable at the seam rather than merely detectable past it. Outstanding
`v1` tokens stay readable as the created-order positions they are, so no
traversal in flight has to restart. This does not contradict "the token carries
no filters": filters select the set, the order decides what the position means.

Storage grows one field. IssueFilter.AfterPriority extends the existing
position; the predicate nests the created one rather than restating it, because
the created/id comparison is only reachable at the cursor's own priority.
Flattening it the way the created predicate's leading-bound trick invites looks
equivalent and is not — it re-delivers rows at the cursor's priority created
after it, which the new conformance walk catches against real Dolt.

NO INDEX MIGRATION, by measurement rather than by omission. A composite
(priority, created_at, id) index was tried on Dolt 2.2.0 against the production
predicate, in both the plain ascending and the mixed-direction spelling Dolt's
DDL accepts: the plan is byte-identical in all three cases, keeping the
single-column priority seek and the TopN. It would have bought write
amplification on every insert and every priority update for no measured change.
The sargability guard pins what is achieved — an IndexedTableAccess range on
idx_issues_priority — and records the measurement to redo if Dolt learns to
stream the composite.

Agent-Signature: claude-opus-5
Co-authored-by: CI Bot <ci@beads.test>

* fix(changelog): drop leftover diff3 conflict marker in sort entry

The rebased adopt-PR head left a stray '|||||||' merge-base marker on the first line of the new `sort` CHANGELOG entry (CHANGELOG.md:381), which `git diff --check` flagged as a leftover conflict marker. Remove only the marker line; the resolved entry content is unchanged. Maintainer fixup for PR #5666 adoption review.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: CI Bot <ci@beads.test>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-27 09:21:12 -07:00
..
storecounter Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
storequerier Converge Offset and MaxRows on all three legs, and fix the panic and the breaker hole under them (#5435) 2026-08-08 11:37:09 -07:00
storereader feat(workapi): opt-in BriefDeps projection for the issue detail view (#5547) 2026-08-10 06:51:41 -07:00
storereadycounter Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
storestats Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
storeversionreconciler Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
storeworkspaceconfig Refuse kv.* point reads on the settings role and stop printing them (#5493) 2026-08-09 11:06:51 -07:00
testdata feat(httpapi): serve bd list's order with sort on listIssues (#5666) 2026-08-27 09:21:12 -07:00
bootstrap.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
bootstrap_test.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
count.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
count_test.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
delete.go Add DeleteRequest.ExpectedVersion: a compare-and-delete on the named row (#5481) 2026-08-09 07:17:54 -07:00
delete_test.go Add DeleteRequest.ExpectedVersion: a compare-and-delete on the named row (#5481) 2026-08-09 07:17:54 -07:00
detail.go feat(workapi): opt-in BriefDeps projection for the issue detail view (#5547) 2026-08-10 06:51:41 -07:00
detail_test.go feat(workapi): opt-in BriefDeps projection for the issue detail view (#5547) 2026-08-10 06:51:41 -07:00
doc.go refactor(show): share issue-detail assembly and normalize not-found (bd-hc1) 2026-07-31 07:58:46 +00:00
list.go feat(httpapi): serve bd list's order with sort on listIssues (#5666) 2026-08-27 09:21:12 -07:00
list_ephemeral_test.go Admit the ephemeral plane from a list request, on the facade and on the wire (#5476) 2026-08-09 05:06:36 -07:00
list_golden_test.go fix(human): respond/dismiss text sources, bd list parity, and proxied-server support (#5333) 2026-08-10 05:36:11 -07:00
list_keyset_test.go feat(httpapi): serve bd list's order with sort on listIssues (#5666) 2026-08-27 09:21:12 -07:00
list_pinned_test.go fix(human): respond/dismiss text sources, bd list parity, and proxied-server support (#5333) 2026-08-10 05:36:11 -07:00
list_status_test.go refactor(list): route both bd list paths through internal/workapi and delete list_filter.go (bd-fv4) 2026-07-31 06:01:48 +00:00
metadata.go fix(workapi): refuse an invalid metadata key where the builders can name it 2026-07-31 18:37:25 +00:00
page.go Converge Offset and MaxRows on all three legs, and fix the panic and the breaker hole under them (#5435) 2026-08-08 11:37:09 -07:00
page_test.go docs(workapi): say where the shared epilogue stops, and what limit 0 does 2026-07-31 23:35:16 +00:00
query.go Merge branch 'facade/wave-3' into facade/wave-4 2026-08-06 21:39:05 +00:00
query_test.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
race_detector_off_test.go feat(issueops): put bd purge and bd prune behind the Sweeper role (bd-pn231) 2026-08-05 16:40:26 +00:00
race_detector_on_test.go feat(issueops): put bd purge and bd prune behind the Sweeper role (bd-pn231) 2026-08-05 16:40:26 +00:00
ready.go feat(workapi,storage): opt-in Brief projection for the list and ready pages (#5554) 2026-08-10 10:45:23 -07:00
ready_count_test.go feat(workapi,storage): opt-in Brief projection for the list and ready pages (#5554) 2026-08-10 10:45:23 -07:00
ready_golden_test.go feat(workapi,storage): opt-in Brief projection for the list and ready pages (#5554) 2026-08-10 10:45:23 -07:00
ready_test.go feat(issueops): add the Reader role and wire both front doors through it 2026-07-31 18:37:25 +00:00
release.go Add issueops.Releaser: give a claim back, optionally only a named holder's (#5482) 2026-08-09 07:48:56 -07:00
release_test.go Add issueops.Releaser: give a claim back, optionally only a named holder's (#5482) 2026-08-09 07:48:56 -07:00
sort.go feat(workapi,storage): opt-in Brief projection for the list and ready pages (#5554) 2026-08-10 10:45:23 -07:00
stats.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
stats_test.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
sweep.go fix(sweep): purge/prune select candidates by tier — a typed wisp is ephemeral however it was minted (#5995) 2026-08-27 05:06:50 -07:00
sweep_test.go fix(sweep): purge/prune select candidates by tier — a typed wisp is ephemeral however it was minted (#5995) 2026-08-27 05:06:50 -07:00
versionreconcile.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
versionreconcile_test.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
workspaceconfig.go docs: the ext-api-store documentation tranche — post-#5516 auth sweep, wave doc coherence, role checklist refresh (#5545) 2026-08-10 08:05:07 -07:00
workspaceconfig_test.go Refuse kv.* point reads on the settings role and stop printing them (#5493) 2026-08-09 11:06:51 -07:00