diff --git a/backend/conformance/reader_contract.go b/backend/conformance/reader_contract.go index 9832c6bbb..0bb2f55c1 100644 --- a/backend/conformance/reader_contract.go +++ b/backend/conformance/reader_contract.go @@ -2673,6 +2673,263 @@ func RunReaderListWispTypeNarrowsTheAdmittedPlaneRatherThanAdmittingIt(t *testin } } +// RunReaderListBriefDropsTheFreeFormTextAndNothingElse pins +// ListRequest.Brief. It is the SkipCounts case's shape, on the other kind of +// payload, and both halves are load-bearing for the same reason: +// +// - all six free-form fields come back zero-valued on a row that genuinely +// carries each of them, so the knob demonstrably reached the SELECT rather +// than being accepted and dropped; and +// - NOTHING ELSE MOVES. Same rows, same order, same identity fields, same +// counts, same labels, same Parent, same has-more verdict as the identical +// request without the knob. +// +// EVERY ASSERTED FIELD IS SEEDED HEAVY, which is the discipline the sibling +// projection on the detail view had to be sent back for: a case that asserts +// Design and AcceptanceCriteria empty without seeding them passes on a body +// that strips two of the six and leaks four. +// +// IDENTITY IS ASSERTED, not assumed. Brief keeps Title, and the lite SELECT +// deliberately retains the small routing columns beside it; a body that +// stripped the row down to its id would satisfy every emptiness clause above. +// +// IsLitePartial IS THE HALF NO WIRE CONSUMER CAN SEE. All six fields are +// omitempty, so a projected row marshals identically to a genuinely textless +// one — the ambiguity ga-clgh and CommentsOmitted already record. The flag is +// how an in-process caller tells them apart, so a body that blanked the fields +// without setting it would answer correctly and lie about why. +func RunReaderListBriefDropsTheFreeFormTextAndNothingElse(t *testing.T, ctx context.Context, fixture ReaderFixture) { + t.Helper() + subject := readerID(fixture, "lsbrief", "subject") + blocker := readerID(fixture, "lsbrief", "blocker") + dependent := readerID(fixture, "lsbrief", "dependent") + parent := readerID(fixture, "lsbrief", "parent") + label := readerLabel(fixture, "lsbrief") + + for _, id := range []string{subject, blocker, dependent, parent} { + seedReaderIssue(t, ctx, fixture, readerHeavyIssue(id, label)) + } + // The same three edges and one comment the SkipCounts case seeds, so the + // counts and Parent this one holds STILL are nonzero and can be tripwires + // for a projection that suppressed more than the text. + for _, edge := range []*types.Dependency{ + {IssueID: subject, DependsOnID: blocker, Type: types.DepBlocks}, + {IssueID: dependent, DependsOnID: subject, Type: types.DepBlocks}, + {IssueID: subject, DependsOnID: parent, Type: types.DepParentChild}, + } { + if err := fixture.AddDependency(ctx, edge, "seed"); err != nil { + t.Fatalf("seed edge %s -> %s: %v", edge.IssueID, edge.DependsOnID, err) + } + } + if err := fixture.AddComment(ctx, subject, "seed", "so the comment count is nonzero"); err != nil { + t.Fatalf("seed the comment: %v", err) + } + + req := publicops.ListRequest{IDFilter: readerIDFilter(subject, blocker, dependent, parent), SortBy: "created"} + hydrated, err := fixture.Reader.List(ctx, req) + if err != nil { + t.Fatalf("List with the text hydrated: %v", err) + } + hydratedRow := readerRowByID(t, "List with the text hydrated", hydrated, subject) + if hydratedRow == nil { + return + } + assertReaderHeavyPremise(t, "List", hydratedRow.Issue) + if hydratedRow.DependencyCount == 0 || hydratedRow.DependentCount == 0 || hydratedRow.CommentCount == 0 || hydratedRow.Parent == nil { + t.Fatalf("the seeded subject came back with counts (%d, %d, %d) and Parent %v; this case needs all of them populated before it can assert Brief leaves them alone", + hydratedRow.DependencyCount, hydratedRow.DependentCount, hydratedRow.CommentCount, readerParentText(hydratedRow.Parent)) + } + + req.Brief = true + brief, err := fixture.Reader.List(ctx, req) + if err != nil { + t.Fatalf("List with Brief: %v", err) + } + briefRow := readerRowByID(t, "List with Brief", brief, subject) + if briefRow == nil { + return + } + assertReaderBriefRow(t, "List with Brief", briefRow.Issue, hydratedRow.Issue) + + if !slices.Equal(readerPageIDs(brief), readerPageIDs(hydrated)) { + t.Errorf("List with Brief returned %v, want the same page as without it, %v: this knob chooses what is hydrated, never which rows match", + readerPageIDs(brief), readerPageIDs(hydrated)) + } + if brief.HasMore != hydrated.HasMore { + t.Errorf("List with Brief reported HasMore = %v, want %v", brief.HasMore, hydrated.HasMore) + } + for _, got := range []struct { + what string + got, want int + }{ + {"DependencyCount", briefRow.DependencyCount, hydratedRow.DependencyCount}, + {"DependentCount", briefRow.DependentCount, hydratedRow.DependentCount}, + {"CommentCount", briefRow.CommentCount, hydratedRow.CommentCount}, + } { + if got.got != got.want { + t.Errorf("List with Brief returned %s = %d, want %d: Brief bounds a row's TEXT and no aggregate beside it", got.what, got.got, got.want) + } + } + if !readerSameParent(briefRow.Parent, hydratedRow.Parent) { + t.Errorf("List with Brief returned Parent = %v, want %v: Parent is not free-form text and rides the same query", + readerParentText(briefRow.Parent), readerParentText(hydratedRow.Parent)) + } + if !slices.Equal(briefRow.Labels, hydratedRow.Labels) { + t.Errorf("List with Brief returned Labels = %v, want %v: labels are their own opt-out (SkipLabels) and this is not it", briefRow.Labels, hydratedRow.Labels) + } +} + +// RunReaderReadyBriefDropsTheFreeFormTextAndNothingElse is ListRequest.Brief's +// twin on the ready plane. It gets a case of its own rather than an arm because +// the two operations reach the projection through DIFFERENT filters: the +// listing carries types.IssueFilter.Lite and ready carries +// types.WorkFilter.Lite, built by a different builder and read by a different +// hydration helper on each backend. A break in either is invisible from the +// other, and the ready side is the one no route reaches through this role from +// the CLI, so this case is the only thing holding it. +func RunReaderReadyBriefDropsTheFreeFormTextAndNothingElse(t *testing.T, ctx context.Context, fixture ReaderFixture) { + t.Helper() + label := readerLabel(fixture, "rdybrief") + subject := readerID(fixture, "rdybrief", "subject") + dependent := readerID(fixture, "rdybrief", "dependent") + + for _, id := range []string{subject, dependent} { + seedReaderIssue(t, ctx, fixture, readerHeavyIssue(id, label)) + } + // An INCOMING blocks edge only. It leaves the subject itself unblocked, so + // it still qualifies for ready work, while giving its row a nonzero + // DependentCount for the same tripwire the listing case uses. + if err := fixture.AddDependency(ctx, &types.Dependency{IssueID: dependent, DependsOnID: subject, Type: types.DepBlocks}, "seed"); err != nil { + t.Fatalf("seed edge %s -> %s: %v", dependent, subject, err) + } + if err := fixture.AddComment(ctx, subject, "seed", "so the comment count is nonzero"); err != nil { + t.Fatalf("seed the comment: %v", err) + } + + req := publicops.ReadyRequest{Labels: []string{label}, Sort: "oldest"} + hydrated, err := fixture.Reader.Ready(ctx, req) + if err != nil { + t.Fatalf("Ready with the text hydrated: %v", err) + } + hydratedRow := readerRowByID(t, "Ready with the text hydrated", hydrated, subject) + if hydratedRow == nil { + return + } + assertReaderHeavyPremise(t, "Ready", hydratedRow.Issue) + if hydratedRow.DependentCount == 0 || hydratedRow.CommentCount == 0 { + t.Fatalf("the seeded subject came back with DependentCount %d and CommentCount %d; this case needs both nonzero before it can assert Brief leaves them alone", + hydratedRow.DependentCount, hydratedRow.CommentCount) + } + + req.Brief = true + brief, err := fixture.Reader.Ready(ctx, req) + if err != nil { + t.Fatalf("Ready with Brief: %v", err) + } + briefRow := readerRowByID(t, "Ready with Brief", brief, subject) + if briefRow == nil { + return + } + assertReaderBriefRow(t, "Ready with Brief", briefRow.Issue, hydratedRow.Issue) + + if !slices.Equal(readerPageIDs(brief), readerPageIDs(hydrated)) { + t.Errorf("Ready with Brief returned %v, want the same page as without it, %v", readerPageIDs(brief), readerPageIDs(hydrated)) + } + if brief.HasMore != hydrated.HasMore { + t.Errorf("Ready with Brief reported HasMore = %v, want %v", brief.HasMore, hydrated.HasMore) + } + // Ready carries no SkipLabels and no SkipCounts (issueops.readyHydrationFor), + // so an implementation that reached for the listing's hydration helper here + // would drop these along with the text. + if briefRow.DependentCount != hydratedRow.DependentCount || briefRow.CommentCount != hydratedRow.CommentCount { + t.Errorf("Ready with Brief returned DependentCount %d / CommentCount %d, want %d / %d: a ready filter carries no counts opt-out", + briefRow.DependentCount, briefRow.CommentCount, hydratedRow.DependentCount, hydratedRow.CommentCount) + } + if !slices.Equal(briefRow.Labels, hydratedRow.Labels) { + t.Errorf("Ready with Brief returned Labels = %v, want %v: a ready filter carries no label opt-out either", briefRow.Labels, hydratedRow.Labels) + } +} + +// readerHeavyFields is what the two Brief cases seed and assert on: every +// free-form column the lite SELECT drops (issueops.HeavyDropList). It is one +// list so the seed and the assertions cannot fall out of step, which is the +// exact way the sibling projection's first draft went vacuous. +func readerHeavyFields(issue *types.Issue) []struct { + what string + text string +} { + return []struct { + what string + text string + }{ + {"Description", issue.Description}, + {"Design", issue.Design}, + {"AcceptanceCriteria", issue.AcceptanceCriteria}, + {"Notes", issue.Notes}, + {"Payload", issue.Payload}, + {"Waiters", strings.Join(issue.Waiters, ",")}, + } +} + +// readerHeavyIssue is readerIssue with every droppable field carrying text. +func readerHeavyIssue(id, label string) *types.Issue { + issue := readerIssue(id, types.TypeTask, label) + issue.Description = id + " description body" + issue.Design = id + " design body" + issue.AcceptanceCriteria = id + " acceptance criteria body" + issue.Notes = id + " notes body" + issue.Payload = id + " payload body" + issue.Waiters = []string{id + "-waiter"} + return issue +} + +// assertReaderHeavyPremise fails the case when a field it is about to assert +// EMPTY did not arrive populated. Without it, a backend that never round-trips +// one of the six turns this case's clause for that field into a clause that +// cannot fail. +func assertReaderHeavyPremise(t *testing.T, what string, issue *types.Issue) { + t.Helper() + for _, field := range readerHeavyFields(issue) { + if field.text == "" { + t.Fatalf("%s returned the seeded subject with an empty %s; this case needs every field it asserts stripped to arrive populated, or that assertion cannot fail", + what, field.what) + } + } + if issue.IsLitePartial { + t.Fatalf("%s returned the seeded subject with IsLitePartial already set on a full read", what) + } +} + +// assertReaderBriefRow holds a projected row to both halves of the promise: the +// text is gone, the identity is not, and the row says which it is. +func assertReaderBriefRow(t *testing.T, what string, brief, full *types.Issue) { + t.Helper() + for _, field := range readerHeavyFields(brief) { + if field.text != "" { + t.Errorf("%s returned %s = %q, want empty: Brief was accepted and the column selected anyway", what, field.what, field.text) + } + } + if !brief.IsLitePartial { + t.Errorf("%s returned IsLitePartial = false on a projected row: a blank body and a genuinely textless one are indistinguishable without it", what) + } + for _, id := range []struct { + what string + got, want string + }{ + {"ID", brief.ID, full.ID}, + {"Title", brief.Title, full.Title}, + {"Status", string(brief.Status), string(full.Status)}, + {"IssueType", string(brief.IssueType), string(full.IssueType)}, + } { + if id.got != id.want { + t.Errorf("%s returned %s = %q, want %q: Brief drops the free-form text and keeps everything a caller picks a row by", what, id.what, id.got, id.want) + } + } + if brief.Priority != full.Priority { + t.Errorf("%s returned Priority = %d, want %d", what, brief.Priority, full.Priority) + } +} + // readerIssue builds the seed every case starts from: an open, unassigned, // unblocked task that qualifies for ready work. A case that needs it to fail one // of those tests changes the field it means to test and nothing else. diff --git a/backend/conformance/ready_claimer_contract.go b/backend/conformance/ready_claimer_contract.go index 2ddd6ef9c..4aa349554 100644 --- a/backend/conformance/ready_claimer_contract.go +++ b/backend/conformance/ready_claimer_contract.go @@ -73,8 +73,8 @@ type ReadyClaimerFixture struct { CountHistory func(context.Context) (int, error) } -// RunReadyClaimerRejectsLimitOffsetAndEmptyActor pins the deterministic -// request-validation refusals — Limit set, Offset set, Actor empty +// RunReadyClaimerRejectsLimitOffsetBriefAndEmptyActor pins the deterministic +// request-validation refusals — Limit set, Offset set, Brief set, Actor empty // (issueops/readyclaimer.go:15-23 and :7-8) — and the state clause that comes // with them: "a validation failure leaves persistent state unchanged" // (issueops/readyclaimer.go:56). @@ -89,6 +89,14 @@ type ReadyClaimerFixture struct { // (issueops/reader.go:85-100), and only the first of those is what this request // permits. // +// Brief is refused on a sharper version of the same argument. The claim does +// not read its row through the page's query at all — it refetches the winner +// whole and hydrates the cardinalities itself — so the projection has nothing +// to apply to. Accepting it would return a fully-hydrated row, carrying +// IsLitePartial=false, from a request that has ALREADY MUTATED STATE: the one +// field a caller could check to notice would be the field asserting nothing +// went wrong. That is why it is here and not merely documented. +// // The claimable row seeded here is the point of the state half: each refusal // runs against a front that WOULD have yielded it, so an implementation that // validated after claiming fails on the row rather than on the error. @@ -98,7 +106,7 @@ type ReadyClaimerFixture struct { // so a case checking that the refused call also returned a zero result would be // pinning today's implementations rather than the contract. The state // assertions below are the part the contract does promise. -func RunReadyClaimerRejectsLimitOffsetAndEmptyActor(t *testing.T, ctx context.Context, fixture ReadyClaimerFixture) { +func RunReadyClaimerRejectsLimitOffsetBriefAndEmptyActor(t *testing.T, ctx context.Context, fixture ReadyClaimerFixture) { t.Helper() label := fixture.IssuePrefix + "-rcreject" candidate := fixture.IssuePrefix + "-rcreject-a" @@ -123,6 +131,10 @@ func RunReadyClaimerRejectsLimitOffsetAndEmptyActor(t *testing.T, ctx context.Co Actor: "claimer", Filter: publicops.ReadyRequest{Labels: []string{label}, Sort: readyClaimerSort, Offset: 1}, }}, + {"brief", publicops.ClaimNextRequest{ + Actor: "claimer", + Filter: publicops.ReadyRequest{Labels: []string{label}, Sort: readyClaimerSort, Brief: true}, + }}, {"empty actor", publicops.ClaimNextRequest{ Filter: publicops.ReadyRequest{Labels: []string{label}, Sort: readyClaimerSort}, }}, @@ -135,7 +147,7 @@ func RunReadyClaimerRejectsLimitOffsetAndEmptyActor(t *testing.T, ctx context.Co // Unchanged means unchanged: the row a valid request would have won is // still open and unassigned, and nothing was written to history. assertReadyClaimerRowState(t, ctx, fixture, candidate, string(types.StatusOpen), "") - assertReadyClaimerHistoryDelta(t, ctx, fixture, before, 0, "four refused requests") + assertReadyClaimerHistoryDelta(t, ctx, fixture, before, 0, "five refused requests") } // RunReadyClaimerEmptyFrontIsNormal pins the outcome most likely to diverge: a diff --git a/backend/conformance/role_bundle_cases.go b/backend/conformance/role_bundle_cases.go index 9dff1e24f..76114a426 100644 --- a/backend/conformance/role_bundle_cases.go +++ b/backend/conformance/role_bundle_cases.go @@ -519,11 +519,13 @@ var roleContractCases = []roleContract{ RunReaderListKeysetPositionNarrowsWithoutReplacingTheOtherPredicates, RunReaderListIncludeEphemeralMergesThePlanesIntoOneOrder, RunReaderListWispTypeNarrowsTheAdmittedPlaneRatherThanAdmittingIt, + RunReaderListBriefDropsTheFreeFormTextAndNothingElse, + RunReaderReadyBriefDropsTheFreeFormTextAndNothingElse, ), roleCases("ReadyClaimer", "ReadyClaimer() and IssueReader()", oncePerRole, func(b RoleContractBundle) func(t *testing.T) *ReadyClaimerFixture { return b.ReadyClaimer }, - RunReadyClaimerRejectsLimitOffsetAndEmptyActor, + RunReadyClaimerRejectsLimitOffsetBriefAndEmptyActor, RunReadyClaimerEmptyFrontIsNormal, RunReadyClaimerClaimsTheFrontRowAndReturnsThePostClaimState, RunReadyClaimerClaimsAnEphemeralRowTheFilterAdmits, diff --git a/internal/storage/dolt/reader_contract_test.go b/internal/storage/dolt/reader_contract_test.go index e29115860..100693fac 100644 --- a/internal/storage/dolt/reader_contract_test.go +++ b/internal/storage/dolt/reader_contract_test.go @@ -246,6 +246,18 @@ func TestReaderListWispTypeNarrowsTheAdmittedPlaneRatherThanAdmittingIt(t *testi conformance.RunReaderListWispTypeNarrowsTheAdmittedPlaneRatherThanAdmittingIt(t, ctx, fixture) } +func TestReaderListBriefDropsTheFreeFormTextAndNothingElse(t *testing.T) { + fixture, ctx, cleanup := newDoltReaderFixture(t, "rdr") + defer cleanup() + conformance.RunReaderListBriefDropsTheFreeFormTextAndNothingElse(t, ctx, fixture) +} + +func TestReaderReadyBriefDropsTheFreeFormTextAndNothingElse(t *testing.T) { + fixture, ctx, cleanup := newDoltReaderFixture(t, "rdr") + defer cleanup() + conformance.RunReaderReadyBriefDropsTheFreeFormTextAndNothingElse(t, ctx, fixture) +} + // newDoltReaderFixture composes the shared role kit with the reader accessor. // One store per case here rather than one per suite: setupTestStore gives each // test its own copy-on-write branch and costs a fraction of a second, so the diff --git a/internal/storage/dolt/ready_claimer_contract_test.go b/internal/storage/dolt/ready_claimer_contract_test.go index 856119d9f..8cacfbbba 100644 --- a/internal/storage/dolt/ready_claimer_contract_test.go +++ b/internal/storage/dolt/ready_claimer_contract_test.go @@ -7,10 +7,10 @@ import ( "github.com/steveyegge/beads/backend/conformance" ) -func TestReadyClaimerRejectsLimitOffsetAndEmptyActor(t *testing.T) { +func TestReadyClaimerRejectsLimitOffsetBriefAndEmptyActor(t *testing.T) { fixture, ctx, cleanup := newDoltReadyClaimerFixture(t, "rcrej") defer cleanup() - conformance.RunReadyClaimerRejectsLimitOffsetAndEmptyActor(t, ctx, fixture) + conformance.RunReadyClaimerRejectsLimitOffsetBriefAndEmptyActor(t, ctx, fixture) } func TestReadyClaimerEmptyFrontIsNormal(t *testing.T) { diff --git a/internal/storage/dolt/search_counts_parity_test.go b/internal/storage/dolt/search_counts_parity_test.go index da993ecc7..cb0aff6c3 100644 --- a/internal/storage/dolt/search_counts_parity_test.go +++ b/internal/storage/dolt/search_counts_parity_test.go @@ -65,14 +65,17 @@ func TestSearchCountsFilterBeforeJoinParity(t *testing.T) { // Predicate form (nil ids): the form this PR reshapes. The by-IDs // form keeps the plain driver and is unaffected. - newSQL, genArgs := sqlbuild.SearchCountsSQL(sqlbuild.IssuesFilterTables, nil, whereSQL, orderBy, limitSQL, true, sqlbuild.CountsHydration{SkipLabels: tc.filter.SkipLabels}) + hyd := sqlbuild.CountsHydration{SkipLabels: tc.filter.SkipLabels} + newSQL, genArgs := sqlbuild.SearchCountsSQL(sqlbuild.IssuesFilterTables, nil, whereSQL, orderBy, limitSQL, true, hyd) if genArgs != nil { t.Fatalf("predicate form must not generate args, got %d", len(genArgs)) } oldSQL := oldSearchCountsSQL(sqlbuild.IssuesFilterTables, whereSQL, orderBy, limitSQL, true, tc.filter.SkipLabels) - gotNew := runCountsSQL(ctx, t, store.db, newSQL, args) - gotOld := runCountsSQL(ctx, t, store.db, oldSQL, args) + // Both sides scan under the hydration that built them; the old + // builder has no lite form, so this pair is always full-shape. + gotNew := runCountsSQL(ctx, t, store.db, newSQL, args, hyd) + gotOld := runCountsSQL(ctx, t, store.db, oldSQL, args, hyd) if len(gotNew) != len(gotOld) { t.Fatalf("row count: new=%d old=%d", len(gotNew), len(gotOld)) @@ -97,7 +100,7 @@ type countsRow struct { deps string } -func runCountsSQL(ctx context.Context, t *testing.T, db *sql.DB, query string, args []any) []countsRow { +func runCountsSQL(ctx context.Context, t *testing.T, db *sql.DB, query string, args []any, hyd sqlbuild.CountsHydration) []countsRow { t.Helper() rows, err := db.QueryContext(ctx, query, args...) if err != nil { @@ -108,7 +111,7 @@ func runCountsSQL(ctx context.Context, t *testing.T, db *sql.DB, query string, a var out []countsRow seen := make(map[string]bool) for rows.Next() { - iwc, err := issueops.ScanReadyWorkRowWithCounts(rows) + iwc, err := issueops.ScanReadyWorkRowWithCounts(rows, hyd) if err != nil { t.Fatalf("scan: %v", err) } diff --git a/internal/storage/domain/db/issue_search_counts.go b/internal/storage/domain/db/issue_search_counts.go index 31a1c00c2..93dc00b86 100644 --- a/internal/storage/domain/db/issue_search_counts.go +++ b/internal/storage/domain/db/issue_search_counts.go @@ -105,12 +105,19 @@ func (r *issueSQLRepositoryImpl) searchUnionWithCounts(ctx context.Context, quer return domain.SearchCountsPage{Items: out, HasMore: hasMore}, nil } -// hydrationFor reads the two hydration opt-outs off a search filter, matching -// the store-backed path's helper of the same name (internal/storage/issueops). -// Both bodies must read the same pair off the same filter or a caller that set -// one would get different columns from the two backends. +// hydrationFor reads the hydration opt-outs off a search filter, matching the +// store-backed path's helper of the same name (internal/storage/issueops). +// Both bodies must read the same fields off the same filter or a caller that +// set one would get different columns from the two backends. func hydrationFor(filter types.IssueFilter) sqlbuild.CountsHydration { - return sqlbuild.CountsHydration{SkipLabels: filter.SkipLabels, SkipCounts: filter.SkipCounts} + return sqlbuild.CountsHydration{SkipLabels: filter.SkipLabels, SkipCounts: filter.SkipCounts, Lite: filter.Lite} +} + +// readyHydrationFor is the WORK-filter twin, matching +// issueops.readyHydrationFor. See it for why a ready filter carries Lite and +// neither of the other two. +func readyHydrationFor(filter types.WorkFilter) sqlbuild.CountsHydration { + return sqlbuild.CountsHydration{Lite: filter.Lite} } // fetchCountsByIDs hydrates counts rows for explicit IDs via the by-IDs form @@ -129,7 +136,7 @@ func (r *issueSQLRepositoryImpl) fetchCountsByIDs(ctx context.Context, ids []str end = len(ids) } countsSQL, args := sqlbuild.SearchCountsSQL(tables, ids[start:end], "", "", "", includeWispReverseDeps, hyd) - items, err := r.scanCountsQuery(ctx, tables, countsSQL, args) + items, err := r.scanCountsQuery(ctx, tables, countsSQL, args, hyd) if err != nil { return nil, err } @@ -159,12 +166,12 @@ func (r *issueSQLRepositoryImpl) runFilterSearchQuery(ctx context.Context, query //nolint:gosec // G201: SQL fragments are built from hardcoded table names and parameterized filters. func (r *issueSQLRepositoryImpl) runSearchQuery(ctx context.Context, tables filterTables, whereSQL, orderBySQL, limitSQL string, args []any, includeWispReverseDeps bool, hyd sqlbuild.CountsHydration) ([]*types.IssueWithCounts, error) { searchSQL, _ := sqlbuild.SearchCountsSQL(tables, nil, whereSQL, orderBySQL, limitSQL, includeWispReverseDeps, hyd) - return r.scanCountsQuery(ctx, tables, searchSQL, args) + return r.scanCountsQuery(ctx, tables, searchSQL, args, hyd) } // scanCountsQuery runs a prebuilt counts mega-query and hydrates each row, // deduping by issue ID (mirrors issueops.scanCountsRowsInTx). -func (r *issueSQLRepositoryImpl) scanCountsQuery(ctx context.Context, tables filterTables, query string, args []any) ([]*types.IssueWithCounts, error) { +func (r *issueSQLRepositoryImpl) scanCountsQuery(ctx context.Context, tables filterTables, query string, args []any, hyd sqlbuild.CountsHydration) ([]*types.IssueWithCounts, error) { rows, err := r.runner.QueryContext(ctx, query, args...) if err != nil { return nil, fmt.Errorf("search count %s: %w", tables.Main, err) @@ -174,7 +181,7 @@ func (r *issueSQLRepositoryImpl) scanCountsQuery(ctx context.Context, tables fil var out []*types.IssueWithCounts seen := make(map[string]bool) for rows.Next() { - iwc, scanErr := scanReadyWorkRowWithCounts(rows) + iwc, scanErr := scanReadyWorkRowWithCounts(rows, hyd) if scanErr != nil { return nil, scanErr } @@ -212,8 +219,8 @@ func (r *issueSQLRepositoryImpl) optionalTableExists(ctx context.Context, table // scanReadyWorkRowWithCounts delegates to the classic implementation so both // stacks hydrate counts rows identically (same delegation pattern as // scanIssue -> issueops.ScanIssueFrom). -func scanReadyWorkRowWithCounts(rows *sql.Rows) (*types.IssueWithCounts, error) { - return issueops.ScanReadyWorkRowWithCounts(rows) +func scanReadyWorkRowWithCounts(rows *sql.Rows, hyd sqlbuild.CountsHydration) (*types.IssueWithCounts, error) { + return issueops.ScanReadyWorkRowWithCounts(rows, hyd) } // finishSearchCountsPage closes the window runFilterSearchQuery opened. It diff --git a/internal/storage/domain/db/ready_work_union.go b/internal/storage/domain/db/ready_work_union.go index 6b2d92b14..31464b65c 100644 --- a/internal/storage/domain/db/ready_work_union.go +++ b/internal/storage/domain/db/ready_work_union.go @@ -7,7 +7,6 @@ import ( "github.com/steveyegge/beads/internal/storage/dberrors" "github.com/steveyegge/beads/internal/storage/domain" - "github.com/steveyegge/beads/internal/storage/sqlbuild" "github.com/steveyegge/beads/internal/types" ) @@ -119,13 +118,13 @@ func (r *issueSQLRepositoryImpl) getReadyWorkWithCountsUnion(ctx context.Context return domain.SearchCountsPage{Items: nil, HasMore: hasMore}, nil } - issuesByID, err := r.fetchCountsByIDs(ctx, page.issueIDs, issuesFilterTables, wispDepsExist, sqlbuild.CountsHydration{}) + issuesByID, err := r.fetchCountsByIDs(ctx, page.issueIDs, issuesFilterTables, wispDepsExist, readyHydrationFor(filter)) if err != nil { return domain.SearchCountsPage{}, fmt.Errorf("ready work union with counts: hydrate issues: %w", err) } var wispsByID map[string]*types.IssueWithCounts if len(page.wispIDs) > 0 { - wispsByID, err = r.fetchCountsByIDs(ctx, page.wispIDs, wispsFilterTables, true, sqlbuild.CountsHydration{}) + wispsByID, err = r.fetchCountsByIDs(ctx, page.wispIDs, wispsFilterTables, true, readyHydrationFor(filter)) if err != nil && !dberrors.IsTableNotExist(err) { return domain.SearchCountsPage{}, fmt.Errorf("ready work union with counts: hydrate wisps: %w", err) } diff --git a/internal/storage/embeddeddolt/reader_contract_test.go b/internal/storage/embeddeddolt/reader_contract_test.go index a80e09587..4ee7f3bb7 100644 --- a/internal/storage/embeddeddolt/reader_contract_test.go +++ b/internal/storage/embeddeddolt/reader_contract_test.go @@ -235,6 +235,18 @@ func TestEmbeddedReaderListWispTypeNarrowsTheAdmittedPlaneRatherThanAdmittingIt( conformance.RunReaderListWispTypeNarrowsTheAdmittedPlaneRatherThanAdmittingIt(t, ctx, newEmbeddedReaderFixture(t, "rdr")) } +func TestEmbeddedReaderListBriefDropsTheFreeFormTextAndNothingElse(t *testing.T) { + skipUnlessEmbeddedDolt(t) + ctx := t.Context() + conformance.RunReaderListBriefDropsTheFreeFormTextAndNothingElse(t, ctx, newEmbeddedReaderFixture(t, "rdr")) +} + +func TestEmbeddedReaderReadyBriefDropsTheFreeFormTextAndNothingElse(t *testing.T) { + skipUnlessEmbeddedDolt(t) + ctx := t.Context() + conformance.RunReaderReadyBriefDropsTheFreeFormTextAndNothingElse(t, ctx, newEmbeddedReaderFixture(t, "rdr")) +} + // newEmbeddedReaderFixture composes the shared role kit with the reader // accessor. One environment per case: newTestEnv clones a pristine template // into the test's own temp dir, which costs a fraction of a second once the diff --git a/internal/storage/embeddeddolt/ready_claimer_contract_test.go b/internal/storage/embeddeddolt/ready_claimer_contract_test.go index 195eac7c6..e7a0ed352 100644 --- a/internal/storage/embeddeddolt/ready_claimer_contract_test.go +++ b/internal/storage/embeddeddolt/ready_claimer_contract_test.go @@ -8,10 +8,10 @@ import ( "github.com/steveyegge/beads/backend/conformance" ) -func TestEmbeddedReadyClaimerRejectsLimitOffsetAndEmptyActor(t *testing.T) { +func TestEmbeddedReadyClaimerRejectsLimitOffsetBriefAndEmptyActor(t *testing.T) { skipUnlessEmbeddedDolt(t) ctx := t.Context() - conformance.RunReadyClaimerRejectsLimitOffsetAndEmptyActor(t, ctx, newEmbeddedReadyClaimerFixture(t, "rcrej")) + conformance.RunReadyClaimerRejectsLimitOffsetBriefAndEmptyActor(t, ctx, newEmbeddedReadyClaimerFixture(t, "rcrej")) } func TestEmbeddedReadyClaimerEmptyFrontIsNormal(t *testing.T) { diff --git a/internal/storage/issueops/claim_next.go b/internal/storage/issueops/claim_next.go index 11514dd41..7aac20408 100644 --- a/internal/storage/issueops/claim_next.go +++ b/internal/storage/issueops/claim_next.go @@ -31,6 +31,16 @@ func ValidateClaimNextRequest(request publicops.ClaimNextRequest) error { if request.Filter.Offset != 0 { return fmt.Errorf("%w: claim next does not take an offset", storage.ErrValidation) } + // Brief is refused for the reason Limit and Offset are, and the reason is + // sharper here: a claim does not read its row through the page's query at + // all. ExecuteClaimNext refetches the winning row whole (GetIssueInTx) and + // hydrates its counts itself, so the projection has nothing to apply to, + // and a claim that accepted the field would answer a MUTATING request with + // a fully-hydrated row carrying IsLitePartial=false — the caller's only + // signal that it did not get what it asked for, saying it did. + if request.Filter.Brief { + return fmt.Errorf("%w: claim next does not take a projection", storage.ErrValidation) + } return nil } diff --git a/internal/storage/issueops/ready_work_counts.go b/internal/storage/issueops/ready_work_counts.go index 412448784..78e73beef 100644 --- a/internal/storage/issueops/ready_work_counts.go +++ b/internal/storage/issueops/ready_work_counts.go @@ -11,6 +11,22 @@ import ( "github.com/steveyegge/beads/internal/types" ) +// readyHydrationFor reads a ready filter's hydration opt-outs, the twin of +// search_counts.go's hydrationFor. A WORK filter carries only one of the three: +// SkipLabels and SkipCounts are not carried onto the ready arm (see +// runReadyCountsInTx and issueops.ListRequest.SkipCounts), so ready work still +// hydrates labels and cardinalities unconditionally. Lite is carried, because +// it bounds the SIZE of a row the caller asked for rather than dropping a +// number the ready renderings print. +// +// It is one function per filter type rather than one shared read so that the +// asymmetry above is stated in code at the one place it applies, instead of +// being a field quietly absent from a struct literal at four call sites. That +// absence is what left this path on a hardcoded zero value. +func readyHydrationFor(filter types.WorkFilter) sqlbuild.CountsHydration { + return sqlbuild.CountsHydration{Lite: filter.Lite} +} + func GetReadyWorkWithCountsInTx(ctx context.Context, tx *sql.Tx, filter types.WorkFilter) ([]*types.IssueWithCounts, error) { wispDepsExist, err := optionalTableExistsInTx(ctx, tx, "wisp_dependencies") if err != nil { @@ -21,7 +37,7 @@ func GetReadyWorkWithCountsInTx(ctx context.Context, tx *sql.Tx, filter types.Wo if err != nil { return nil, err } - out, err := runReadyCountsInTx(ctx, tx, IssuesFilterTables, filter.Limit, issuePreds, wispDepsExist, sqlbuild.CountsHydration{}) + out, err := runReadyCountsInTx(ctx, tx, IssuesFilterTables, filter.Limit, issuePreds, wispDepsExist, readyHydrationFor(filter)) if err != nil { return nil, err } @@ -41,7 +57,7 @@ func GetReadyWorkWithCountsInTx(ctx context.Context, tx *sql.Tx, filter types.Wo if err != nil { return nil, err } - wisps, err := runReadyCountsInTx(ctx, tx, WispsFilterTables, filter.Limit, wispPreds, true, sqlbuild.CountsHydration{}) + wisps, err := runReadyCountsInTx(ctx, tx, WispsFilterTables, filter.Limit, wispPreds, true, readyHydrationFor(filter)) if err != nil { if isTableNotExistError(err) { return finishReadyWorkWithCounts(out, filter) @@ -128,10 +144,11 @@ func finishReadyWorkWithCounts(items []*types.IssueWithCounts, filter types.Work // For limit <= 0 (unbounded) there is no page to push down, so it runs the // predicate-form mega-query unchanged. // -// Both callers pass the ZERO hydration, so ready work is always fully -// hydrated. types.WorkFilter carries neither opt-out — the projection that -// builds it drops both — and issueops.ListRequest says so where a caller reads -// it: SkipLabels and SkipCounts are not carried onto the ReadyFlag arm. +// Both callers pass readyHydrationFor(filter), which carries Lite and nothing +// else: ready work always hydrates labels and cardinalities, because +// types.WorkFilter carries neither opt-out — the projection that builds it +// drops both — and issueops.ListRequest says so where a caller reads it, +// SkipLabels and SkipCounts are not carried onto the ReadyFlag arm. // //nolint:gosec // G201: whereSQL/orderBySQL/limitSQL are hardcoded fragments; user input rides ? placeholders. func runReadyCountsInTx(ctx context.Context, tx *sql.Tx, tables FilterTables, limit int, preds *readyWorkPredicates, includeWispReverseDeps bool, hyd sqlbuild.CountsHydration) ([]*types.IssueWithCounts, error) { @@ -157,7 +174,7 @@ func runReadyCountsInTx(ctx context.Context, tx *sql.Tx, tables FilterTables, li end = len(pageIDs) } countsSQL, idArgs := sqlbuild.SearchCountsSQL(tables, pageIDs[start:end], "", "", "", includeWispReverseDeps, hyd) - rows, scanErr := scanCountsRowsInTx(ctx, tx, tables.Main, countsSQL, idArgs) + rows, scanErr := scanCountsRowsInTx(ctx, tx, tables.Main, countsSQL, idArgs, hyd) if scanErr != nil { return nil, scanErr } @@ -295,10 +312,15 @@ func sortIssuesWithCountsByPolicy(items []*types.IssueWithCounts, policy types.S } // ScanReadyWorkRowWithCounts scans one row of the counts mega-query -// (sqlbuild.SearchCountsSQL): IssueSelectColumns followed by labels JSON, +// (sqlbuild.SearchCountsSQL): the issue columns followed by labels JSON, // dep/rdep/comment counts, parent ID, and dependency JSON. Exported so the // domain/db stack hydrates counts rows through the exact same code path. -func ScanReadyWorkRowWithCounts(rows *sql.Rows) (*types.IssueWithCounts, error) { +// +// It takes the whole hydration rather than a bool because hyd is what chose +// the SELECT list on the other side: reading the same value here is what keeps +// the two in agreement, where a separately-passed flag could disagree with the +// query it is scanning. +func ScanReadyWorkRowWithCounts(rows *sql.Rows, hyd sqlbuild.CountsHydration) (*types.IssueWithCounts, error) { var labelsJSON, depsJSON sql.NullString var parentID sql.NullString var depCount, rdepCount, commentCount sql.NullInt64 @@ -314,7 +336,11 @@ func ScanReadyWorkRowWithCounts(rows *sql.Rows) (*types.IssueWithCounts, error) &depsJSON, }, } - issue, err := ScanIssueFrom(composite) + scan := ScanIssueFrom + if hyd.Lite { + scan = ScanIssueLiteFrom + } + issue, err := scan(composite) if err != nil { return nil, fmt.Errorf("scan issue with counts: %w", err) } diff --git a/internal/storage/issueops/scan.go b/internal/storage/issueops/scan.go index f92cc2db7..fb52fa9da 100644 --- a/internal/storage/issueops/scan.go +++ b/internal/storage/issueops/scan.go @@ -33,17 +33,10 @@ const IssueSelectColumns = sqlbuild.IssueSelectColumns // IssueSelectColumnsLite must include sqlbuild.LeaseJoin(table) in its FROM // clause, exactly as full hydration does (see issueLiteProjection in // search.go, joinLeases: true). -const IssueSelectColumnsLite = `id, content_hash, title, - status, priority, issue_type, assignee, estimated_minutes, - created_at, created_by, owner, updated_at, started_at, closed_at, external_ref, spec_id, - compaction_level, compacted_at, compacted_at_commit, original_size, source_repo, close_reason, closed_by_session, - sender, ephemeral, no_history, wisp_type, pinned, is_template, - await_type, await_id, timeout_ns, - mol_type, - event_kind, actor, target, - due_at, defer_until, - work_type, source_system, metadata, row_lock, storage_class, - leases.lease_expires_at, leases.heartbeat_at, leases.granted_node` +// The list itself lives in internal/storage/sqlbuild beside IssueSelectColumns, +// shared with the domain/db stack and with the counts mega-query, which renders +// a qualified variant of it. +const IssueSelectColumnsLite = sqlbuild.IssueSelectColumnsLite // HeavyDropList enumerates the columns omitted from IssueSelectColumnsLite. // Test-only: the schema-parity test asserts diff --git a/internal/storage/issueops/scan_test.go b/internal/storage/issueops/scan_test.go index 2ea98148e..11081087a 100644 --- a/internal/storage/issueops/scan_test.go +++ b/internal/storage/issueops/scan_test.go @@ -113,6 +113,46 @@ func TestIssueSelectColumns_LitePlusHeavyEqualsFull(t *testing.T) { } } +// TestIssueSelectColumnsLite_IsFullMinusHeavyInOrder is the ORDER half of the +// guard above, and the set comparison cannot stand in for it. Both lists are +// scanned POSITIONALLY — ScanIssueFrom and ScanIssueLiteFrom bind destinations +// by index, and sqlbuild.SearchCountsSQL now renders a qualified variant of +// each into the counts mega-query — so two columns of the same SQL type can be +// transposed with no membership change at all: the set test stays green, the +// scan succeeds, and every row silently carries one column's value in the +// other's field. Nothing downstream can detect that, which is why it is pinned +// here rather than left to a case that would have to guess which pair moved. +// +// The oracle is the full list itself: deleting the heavy columns from +// IssueSelectColumns, in place, must reproduce IssueSelectColumnsLite exactly. +// That makes the lite list a DERIVATION rather than a second hand-maintained +// copy, so a column added to the full list in the middle cannot be appended to +// the end of the lite one. +func TestIssueSelectColumnsLite_IsFullMinusHeavyInOrder(t *testing.T) { + t.Parallel() + + dropSet := columnSet(HeavyDropList) + var want []string + for _, col := range parseSelectColumns(IssueSelectColumns) { + if _, heavy := dropSet[col]; !heavy { + want = append(want, col) + } + } + + got := parseSelectColumns(IssueSelectColumnsLite) + if len(got) != len(want) { + t.Fatalf("IssueSelectColumnsLite has %d columns, want %d (IssueSelectColumns minus HeavyDropList)", len(got), len(want)) + } + for i := range want { + if got[i] != want[i] { + t.Fatalf("IssueSelectColumnsLite[%d] = %q, want %q.\n"+ + "The lite list must be IssueSelectColumns with the heavy columns removed IN PLACE: both are scanned by\n"+ + "position, so a transposition of two same-typed columns swaps their values on every row without failing\n"+ + "any membership check.\n got: %v\nwant: %v", i, got[i], want[i], got, want) + } + } +} + // TestScanIssueLiteFrom_LeavesHeavyFieldsBlank verifies the happy path for the // lite scan helper: identity/metadata hydrate, the six heavy text columns // remain zero-valued, and IsLitePartial is set so downstream code can detect diff --git a/internal/storage/issueops/search_counts.go b/internal/storage/issueops/search_counts.go index 40bcc388d..8b2e29cdb 100644 --- a/internal/storage/issueops/search_counts.go +++ b/internal/storage/issueops/search_counts.go @@ -100,7 +100,7 @@ func SearchIssuesWithCountsInTx(ctx context.Context, tx *sql.Tx, query string, f // function rather than two field reads at each call site so a path cannot pick // up one of the pair and quietly drop the other. func hydrationFor(filter types.IssueFilter) sqlbuild.CountsHydration { - return sqlbuild.CountsHydration{SkipLabels: filter.SkipLabels, SkipCounts: filter.SkipCounts} + return sqlbuild.CountsHydration{SkipLabels: filter.SkipLabels, SkipCounts: filter.SkipCounts, Lite: filter.Lite} } func runFilterSearchQueryInTx(ctx context.Context, tx *sql.Tx, query string, filter types.IssueFilter, tables FilterTables, includeWispReverseDeps bool) ([]*types.IssueWithCounts, error) { @@ -123,7 +123,7 @@ func runFilterSearchQueryInTx(ctx context.Context, tx *sql.Tx, query string, fil //nolint:gosec // G201: SQL fragments are caller-built from hardcoded shapes func runSearchQueryInTx(ctx context.Context, tx *sql.Tx, tables FilterTables, whereSQL, orderBySQL, limitSQL string, args []interface{}, includeWispReverseDeps bool, hyd sqlbuild.CountsHydration) ([]*types.IssueWithCounts, error) { searchSQL, _ := sqlbuild.SearchCountsSQL(tables, nil, whereSQL, orderBySQL, limitSQL, includeWispReverseDeps, hyd) - return scanCountsRowsInTx(ctx, tx, tables.Main, searchSQL, args) + return scanCountsRowsInTx(ctx, tx, tables.Main, searchSQL, args, hyd) } // scanCountsRowsInTx runs a prebuilt counts mega-query and hydrates each row @@ -132,7 +132,7 @@ func runSearchQueryInTx(ctx context.Context, tx *sql.Tx, tables FilterTables, wh // ready-counts path. // //nolint:gosec // G201: query is builder-produced; user input rides ? placeholders. -func scanCountsRowsInTx(ctx context.Context, tx *sql.Tx, mainTable, query string, args []interface{}) ([]*types.IssueWithCounts, error) { +func scanCountsRowsInTx(ctx context.Context, tx *sql.Tx, mainTable, query string, args []interface{}, hyd sqlbuild.CountsHydration) ([]*types.IssueWithCounts, error) { rows, err := tx.QueryContext(ctx, query, args...) if err != nil { return nil, fmt.Errorf("search count %s: %w", mainTable, err) @@ -142,7 +142,7 @@ func scanCountsRowsInTx(ctx context.Context, tx *sql.Tx, mainTable, query string var out []*types.IssueWithCounts seen := make(map[string]bool) for rows.Next() { - iwc, scanErr := ScanReadyWorkRowWithCounts(rows) + iwc, scanErr := ScanReadyWorkRowWithCounts(rows, hyd) if scanErr != nil { return nil, scanErr } diff --git a/internal/storage/sqlbuild/counts.go b/internal/storage/sqlbuild/counts.go index 1d45f5ffe..2eed5ce11 100644 --- a/internal/storage/sqlbuild/counts.go +++ b/internal/storage/sqlbuild/counts.go @@ -7,6 +7,11 @@ import "fmt" // leases. qualifier (the mega-query FROM includes LeaseJoin("i")). var ReadyWorkIssueColumns = QualifyColumns(IssueBaseColumns, "i.") + ", " + LeaseSelectColumns +// ReadyWorkIssueColumnsLite is the lite counterpart of ReadyWorkIssueColumns, +// selected by CountsHydration.Lite. The scan side is +// issueops.ScanIssueLiteFrom, reached through ScanReadyWorkRowWithCounts. +var ReadyWorkIssueColumnsLite = QualifyColumns(IssueBaseColumnsLite, "i.") + ", " + LeaseSelectColumns + // DepJSONObject renders one dependency row as JSON for JSON_ARRAYAGG // aggregation in the counts mega-query. Field names must match the JSON tags // of types.Dependency. @@ -20,30 +25,51 @@ const DepJSONObject = `JSON_OBJECT( 'thread_id', thread_id )` -// CountsHydration selects which per-row aggregates the counts mega-query -// computes. Both members are opt-OUTs: the zero value hydrates everything. +// CountsHydration selects what the counts mega-query materializes per row. +// Every member is an opt-OUT: the zero value hydrates everything. // -// Neither one changes WHICH ROWS come back or in what order — the aggregates +// None of them changes WHICH ROWS come back or in what order. The aggregates // hang off LEFT JOINs that preserve every driver row, so dropping one drops a -// column's value and nothing else. Each also keeps the projection's SHAPE: -// the scan side (issueops.ScanReadyWorkRowWithCounts) reads the six extra -// columns positionally, so a suppressed aggregate is projected as a constant -// in place rather than removed. +// column's value and nothing else; Lite changes only the driver's own SELECT +// list, and no filter predicate is expressed in the SELECT. // // SkipLabels leaves labels_json NULL, which the scan turns into no labels. // SkipCounts leaves the three cardinalities 0, which a caller must read as // unknown rather than as none — the promise issueops.ListRequest.SkipCounts -// makes above storage. +// makes above storage. Both keep the projection's SHAPE: the scan side reads +// the six extra columns positionally, so a suppressed aggregate is projected +// as a constant in place rather than removed. +// +// LITE IS THE ONE THAT CHANGES THE SHAPE, which is why it is not merely a +// third constant substitution. It swaps ReadyWorkIssueColumns for +// ReadyWorkIssueColumnsLite, so the driver projects six fewer columns and the +// scan must read the matching dest list — ScanReadyWorkRowWithCounts takes the +// whole struct for that reason and dispatches on this field. Substituting +// empty strings in place would have kept one scan path, and was rejected: the +// row would come back with blank free-form text and IsLitePartial=false, which +// is indistinguishable from a genuinely textless row (the ambiguity ga-clgh +// and CommentsOmitted already record). ScanIssueLiteFrom sets the flag. type CountsHydration struct { SkipLabels bool SkipCounts bool + Lite bool } -// SearchCountsSQL renders the counts mega-query: full issue rows aliased "i" -// plus labels JSON, dep/rdep/comment counts, parent ID, and dependency JSON, -// for one table family. The scan side is issueops.ScanReadyWorkRowWithCounts, -// which scans IssueSelectColumns positionally followed by the six extra -// columns in the order projected here. +// IssueColumns returns the driver's SELECT list for this hydration. +func (h CountsHydration) IssueColumns() string { + if h.Lite { + return ReadyWorkIssueColumnsLite + } + return ReadyWorkIssueColumns +} + +// SearchCountsSQL renders the counts mega-query: issue rows aliased "i" plus +// labels JSON, dep/rdep/comment counts, parent ID, and dependency JSON, for one +// table family. The scan side is issueops.ScanReadyWorkRowWithCounts, which +// scans hyd.IssueColumns() positionally followed by the six extra columns in +// the order projected here — so the SAME hydration value has to reach both, and +// is the reason the scan takes the struct rather than being told the shape +// separately. // // There are two forms of the same projection, selected by ids: // @@ -223,7 +249,7 @@ func SearchCountsSQL(tables FilterTables, ids []string, whereSQL, orderBySQL, li ) d ON d.issue_id = i.id %s `, - ReadyWorkIssueColumns, + hyd.IssueColumns(), labelsSelect, countsSelect, driverSQL, diff --git a/internal/storage/sqlbuild/sqlbuild.go b/internal/storage/sqlbuild/sqlbuild.go index 4e42d1c40..9e6496c44 100644 --- a/internal/storage/sqlbuild/sqlbuild.go +++ b/internal/storage/sqlbuild/sqlbuild.go @@ -46,6 +46,24 @@ const IssueBaseColumns = `id, content_hash, title, description, design, acceptan due_at, defer_until, work_type, source_system, metadata, row_lock, storage_class` +// IssueBaseColumnsLite is IssueBaseColumns minus the heavy TEXT columns +// (issueops.HeavyDropList). It lives here rather than beside its scan function +// for the same reason IssueBaseColumns does: the counts mega-query aliases the +// main table and has to qualify the row columns without mangling the leases.* +// references, and that query is rendered in this package. issueops re-exports +// the full list as IssueSelectColumnsLite and pins it against IssueBaseColumns +// with the schema-parity test. +const IssueBaseColumnsLite = `id, content_hash, title, + status, priority, issue_type, assignee, estimated_minutes, + created_at, created_by, owner, updated_at, started_at, closed_at, external_ref, spec_id, + compaction_level, compacted_at, compacted_at_commit, original_size, source_repo, close_reason, closed_by_session, + sender, ephemeral, no_history, wisp_type, pinned, is_template, + await_type, await_id, timeout_ns, + mol_type, + event_kind, actor, target, + due_at, defer_until, + work_type, source_system, metadata, row_lock, storage_class` + // LeaseSelectColumns is the lease overlay for full issue hydration. Leases // live in the ephemeral leases table (bd-lrgn1), not on the issues row, so // every query selecting these must also add LeaseJoin to its FROM clause — @@ -60,6 +78,12 @@ const LeaseSelectColumns = `leases.lease_expires_at, leases.heartbeat_at, leases const IssueSelectColumns = IssueBaseColumns + `, ` + LeaseSelectColumns +// IssueSelectColumnsLite is the lite counterpart of IssueSelectColumns. The +// scan side is issueops.ScanIssueLiteFrom and the same LeaseJoin requirement +// applies. +const IssueSelectColumnsLite = IssueBaseColumnsLite + `, + ` + LeaseSelectColumns + // LeaseJoin returns the FROM-clause fragment that overlays the ephemeral // leases table onto the given issues/wisps table reference (a table name or // alias). LEFT JOIN: rows without a live claim have no lease row and hydrate diff --git a/internal/storage/uow/reader_contract_test.go b/internal/storage/uow/reader_contract_test.go index 2544d81fb..121d4b2ac 100644 --- a/internal/storage/uow/reader_contract_test.go +++ b/internal/storage/uow/reader_contract_test.go @@ -156,6 +156,12 @@ func TestReaderContract(t *testing.T) { t.Run("ListWispTypeNarrowsTheAdmittedPlaneRatherThanAdmittingIt", func(t *testing.T) { conformance.RunReaderListWispTypeNarrowsTheAdmittedPlaneRatherThanAdmittingIt(t, ctx, fixture) }) + t.Run("ListBriefDropsTheFreeFormTextAndNothingElse", func(t *testing.T) { + conformance.RunReaderListBriefDropsTheFreeFormTextAndNothingElse(t, ctx, fixture) + }) + t.Run("ReadyBriefDropsTheFreeFormTextAndNothingElse", func(t *testing.T) { + conformance.RunReaderReadyBriefDropsTheFreeFormTextAndNothingElse(t, ctx, fixture) + }) // Last on purpose: the backend-failure half runs a request on a dead // context, and this backend's provider is shared by every case above it. t.Run("GetMissIsNotFoundAndBackendFailureDoesNotDecay", func(t *testing.T) { diff --git a/internal/storage/uow/ready_claimer_contract_test.go b/internal/storage/uow/ready_claimer_contract_test.go index 354035595..8845b2970 100644 --- a/internal/storage/uow/ready_claimer_contract_test.go +++ b/internal/storage/uow/ready_claimer_contract_test.go @@ -30,7 +30,7 @@ func TestReadyClaimerContract(t *testing.T) { name string run func(*testing.T, context.Context, conformance.ReadyClaimerFixture) }{ - {name: "RejectsLimitOffsetAndEmptyActor", run: conformance.RunReadyClaimerRejectsLimitOffsetAndEmptyActor}, + {name: "RejectsLimitOffsetBriefAndEmptyActor", run: conformance.RunReadyClaimerRejectsLimitOffsetBriefAndEmptyActor}, {name: "EmptyFrontIsNormal", run: conformance.RunReadyClaimerEmptyFrontIsNormal}, {name: "ClaimsTheFrontRowAndReturnsThePostClaimState", run: conformance.RunReadyClaimerClaimsTheFrontRowAndReturnsThePostClaimState}, {name: "ClaimsAnEphemeralRowTheFilterAdmits", run: conformance.RunReadyClaimerClaimsAnEphemeralRowTheFilterAdmits}, diff --git a/internal/types/types.go b/internal/types/types.go index 983e936db..c2a3a2d92 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -1975,11 +1975,19 @@ type IssueFilter struct { // reference columns in WHERE regardless of SELECT shape. Default false preserves // today's behavior at every call site. // - // Backend coverage: honored by the issueops-backed stores (Dolt, embedded - // Dolt). The proxied-server (domain/db) path does not check this field yet - // and always returns fully-hydrated issues with IsLitePartial=false — - // correct results, no lite optimization. Wiring Lite through domain/db is - // deferred to the CLI-wiring follow-up. See engdocs/EXTENDING.md. + // Backend coverage: honored on BOTH stacks for the COUNTED page, which is + // every read that returns IssueWithCounts — issueops.Reader.List on either + // implementation, and so `bd list --json` on both routes and + // GET /v0/beads/issues. It rides the counts mega-query as + // sqlbuild.CountsHydration.Lite, which both seams derive from this field + // through their hydrationFor helper. + // + // The UNCOUNTED search is store-backed only: SearchIssuesInTx selects + // issueLiteProjection from this field, and the domain/db SearchIssues has + // no equivalent, so a caller on that path gets correct rows fully hydrated + // rather than an error. That path serves the text renderings, which print + // no body, so the gap costs bytes off the wire and no correctness. + // See engdocs/EXTENDING.md. Lite bool } @@ -2116,6 +2124,19 @@ type WorkFilter struct { // MaxRowsSource attributes which knob set MaxRows. Expected values: // "--max-rows", "BEADS_MAX_ROWS", or "" (library users with no source). MaxRowsSource string + + // Lite mirrors IssueFilter.Lite for ready work: the heavy TEXT columns + // (description, design, acceptance_criteria, notes, payload, waiters) are + // not selected, and the returned issues carry IsLitePartial=true with those + // fields zero-valued. It bounds the SIZE of a row, never which rows match: + // a predicate that reads a heavy column keeps working, because WHERE is + // independent of the SELECT shape. + // + // Unlike IssueFilter.Lite it is honored on BOTH backends, through the + // counts mega-query's CountsHydration. The two knobs beside it there + // (SkipLabels, SkipCounts) have no WorkFilter counterpart on purpose; see + // issueops.readyHydrationFor. + Lite bool } // StaleFilter is used to filter stale issue queries diff --git a/internal/workapi/list.go b/internal/workapi/list.go index 6132a22be..49cf30dab 100644 --- a/internal/workapi/list.go +++ b/internal/workapi/list.go @@ -329,6 +329,9 @@ func BuildListFilter(in issueops.ListRequest, cfg ListConfig) (types.IssueFilter if in.SkipCounts { filter.SkipCounts = true } + if in.Brief { + filter.Lite = true + } if in.PriorityMin != nil { p := *in.PriorityMin diff --git a/internal/workapi/ready.go b/internal/workapi/ready.go index cd1f3d5a3..073e5f475 100644 --- a/internal/workapi/ready.go +++ b/internal/workapi/ready.go @@ -62,6 +62,7 @@ func BuildReadyFilter(in issueops.ReadyRequest) (types.WorkFilter, error) { IncludeEphemeral: in.IncludeEphemeral, ExcludeTypes: normalizeExcludeTypes(in.ExcludeTypes), HasMetadataKey: in.HasMetadataKey, + Lite: in.Brief, } if in.Priority != nil { @@ -122,6 +123,17 @@ func BuildReadyCountFilter(in issueops.ReadyRequest) (types.WorkFilter, error) { unlimited := 0 counted := in counted.Limit = &unlimited + // Brief is CARRIED, not refused and not cleared, which is the opposite of + // what ClaimNext does with it. A count reads no field of any row, so the + // projection cannot make the number wrong; and the count is not always + // cheap enough for that to be the end of it. The unit-of-work seam has no + // COUNT(*) over the ready predicate and sizes the set by running the + // unbounded page and taking its length (uow/ready_counter.go), so clearing + // the field here would hydrate every heavy column of the whole ready set to + // answer `bd ready --brief`, which is the cost the projection exists to + // avoid and larger than the page it was asked for. Carrying it also keeps + // the count filter what this builder says it is: the listing's filter with + // the PAGE removed, and nothing else removed. return BuildReadyFilter(counted) } diff --git a/internal/workapi/ready_count_test.go b/internal/workapi/ready_count_test.go index 94352b9da..c19a62ef0 100644 --- a/internal/workapi/ready_count_test.go +++ b/internal/workapi/ready_count_test.go @@ -13,9 +13,16 @@ import ( // the predicate the listing runs, with the page taken off. It is asserted // against BuildReadyFilter rather than field by field so a new ReadyRequest // field the count builder forgot to carry shows up as a difference. +// +// Brief is in the fixture because it is the field most likely to be dropped +// here by an author reasoning that a count returns no rows: the store-backed +// counter's indexed COUNT(*) ignores it, but the unit-of-work counter sizes the +// set by running the unbounded page (uow/ready_counter.go), where dropping it +// hydrates every heavy column of the entire ready set. func TestBuildReadyCountFilterIsTheUnboundedReadyFilter(t *testing.T) { priority := 1 request := issueops.ReadyRequest{ + Brief: true, IssueType: "mr", Assignee: "alice", Labels: []string{" alpha ", "alpha"}, @@ -54,6 +61,13 @@ func TestBuildReadyCountFilterIsTheUnboundedReadyFilter(t *testing.T) { if counted.Offset != 0 { t.Errorf("counted filter Offset = %d, want 0", counted.Offset) } + // Asserted absolutely and not only through the comparison above, which + // holds just as well if BuildReadyFilter stops resolving Brief at all: both + // sides would read false together and the projection would be gone from the + // count and the listing at once. + if !counted.Lite { + t.Error("counted filter Lite = false, want true: a request that asked for the projection must not be counted with the full column list") + } } // TestBuildReadyCountFilterRefusesAPage pins the two deterministic refusals the diff --git a/internal/workapi/ready_golden_test.go b/internal/workapi/ready_golden_test.go index 921280663..914cfba01 100644 --- a/internal/workapi/ready_golden_test.go +++ b/internal/workapi/ready_golden_test.go @@ -47,6 +47,14 @@ func loadReadyFilterGolden(t *testing.T) []readyFilterGoldenCase { // running both of them before either was deleted, so a green run here is the // proof that collapsing them into this package changed nothing. // +// EVERY RECORDED FILTER CARRIES "Lite": false, which the old builders could +// not have produced because types.WorkFilter had no such field. The record is +// of what each REQUEST resolves to, and false is what a request that did not +// ask for the projection resolves that field to, so writing it in keeps the +// replay exact rather than weakening it — the same absorption +// types.IssueFilter's MaxRows and SkipCounts had on the listing golden. A case +// that MEANT to set it would fail here, which is the property being kept. +// // It replays the gatherReadyInput column: that is the builder both CLI paths // now share, and it is the one whose output a filter can be built from for // every case (the direct column stops at --max-rows, which stays in cmd/bd). diff --git a/internal/workapi/sort.go b/internal/workapi/sort.go index 597246c07..ecc27ec41 100644 --- a/internal/workapi/sort.go +++ b/internal/workapi/sort.go @@ -64,6 +64,11 @@ func ReadyFilterFromIssueFilter(filter types.IssueFilter) types.WorkFilter { HasMetadataKey: filter.HasMetadataKey, MaxRows: filter.MaxRows, MaxRowsSource: filter.MaxRowsSource, + // Carried, where SkipLabels and SkipCounts are dropped: those two hide + // a number the ready renderings print, and this bounds a body no + // listing prints. Dropping it here would answer `bd list --ready + // --brief` with full rows and nothing to say why. + Lite: filter.Lite, } if filter.IssueType != nil { wf.Type = string(*filter.IssueType) diff --git a/internal/workapi/testdata/ready_filter_golden.json b/internal/workapi/testdata/ready_filter_golden.json index 5fa2bfebf..044890a10 100644 --- a/internal/workapi/testdata/ready_filter_golden.json +++ b/internal/workapi/testdata/ready_filter_golden.json @@ -32,7 +32,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -61,7 +62,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -102,7 +104,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -131,7 +134,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -172,7 +176,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -201,7 +206,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -242,7 +248,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -271,7 +278,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -320,7 +328,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -352,7 +361,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -399,7 +409,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -431,7 +442,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -482,7 +494,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -513,7 +526,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -561,7 +575,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -592,7 +607,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -636,7 +652,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -665,7 +682,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -705,7 +723,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -734,7 +753,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -774,7 +794,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -803,7 +824,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -844,7 +866,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -873,7 +896,8 @@ "HasMetadataKey": "", "Offset": 3, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -913,7 +937,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -942,7 +967,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -982,7 +1008,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -1027,7 +1054,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -1056,7 +1084,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -1096,7 +1125,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -1125,7 +1155,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -1168,7 +1199,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -1197,7 +1229,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -1238,7 +1271,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -1267,7 +1301,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -1308,7 +1343,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -1337,7 +1373,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -1377,7 +1414,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -1406,7 +1444,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -1446,7 +1485,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -1475,7 +1515,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -1535,7 +1576,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -1564,7 +1606,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -1605,7 +1648,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -1634,7 +1678,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -1693,7 +1738,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -1722,7 +1768,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -1762,7 +1809,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -1791,7 +1839,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -1842,7 +1891,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -1875,7 +1925,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -1924,7 +1975,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -1956,7 +2008,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -2005,7 +2058,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -2037,7 +2091,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -2116,7 +2171,8 @@ "HasMetadataKey": "team", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -2145,7 +2201,8 @@ "HasMetadataKey": "team", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -2233,7 +2290,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -2277,7 +2335,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } }, @@ -2338,7 +2397,8 @@ "HasMetadataKey": "", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -2452,7 +2512,8 @@ "HasMetadataKey": "env", "Offset": 0, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } }, "gather": { @@ -2492,7 +2553,8 @@ "HasMetadataKey": "env", "Offset": 2, "MaxRows": 0, - "MaxRowsSource": "" + "MaxRowsSource": "", + "Lite": false } } } diff --git a/issueops/reader.go b/issueops/reader.go index 3988c5d44..0f6f44d02 100644 --- a/issueops/reader.go +++ b/issueops/reader.go @@ -105,6 +105,12 @@ type ReadyRequest struct { // 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. @@ -181,6 +187,33 @@ type ListRequest struct { // hydrated there either way, which costs time and not correctness. SkipCounts 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 diff --git a/issueops/readyclaimer.go b/issueops/readyclaimer.go index 3ce2f4f78..c70bc7b5f 100644 --- a/issueops/readyclaimer.go +++ b/issueops/readyclaimer.go @@ -20,6 +20,12 @@ type ClaimNextRequest struct { // be unclaimable while plenty of other ready work remained. Rejecting the // two fields says that out loud rather than accepting them and quietly // dropping them. + // + // Brief must be unset too, and for the same reason stated once more + // because this one costs a write: the claim refetches its winning row + // whole rather than reading it through the page's query, so the projection + // cannot be applied here, and accepting it would return an unprojected row + // from a request that has already mutated state. Filter ReadyRequest }