fix(review): address round-3 delta review items (be-x42v.4 round 4)
Converging: four small items adjudicated from round-3 delta reviews. 1. internal/storage/issueops/search.go, search_counts.go: round 3's trim-before-cap fix landed in finishReadyWorkWithCounts but not on the sibling bd list search paths. `bd list --include-infra --limit 2 --max-rows 5` (3 durable + 3 wisps) exited 2 in both output modes even though the delivered page is 2 rows, since --include-infra disables the default SkipWisps escape hatch so the wisps merge actually runs. Reproduced live: "6 found, --max-rows=5 exceeded" on the pre-fix code. Mirrored the ready remedy: trim to filter.Limit (guarded by Limit>0) before EnforceMaxRowsCap in searchInTx's four exit points (added a trimToSearchLimit helper) and in finishSearchIssuesWithCounts (swapped the cap/trim order). Fixed search_counts.go's doc comment, which still asserted the old cap-before-trim rationale and directly contradicted ready_work_counts.go's. Single-source results are unaffected (a lone query never exceeds Limit when Limit>0, so the trim there is a no-op); Limit=0 and genuine Limit>MaxRows overage still error. Added IncludeInfraMergedUnderLimit_NoError (both bd list output modes) to TestEmbeddedMaxRowsList. 2. cmd/bd/ready.go: the round-3 fix that exempts proxied `ready --claim` from rejectMaxRowsUnderProxiedServer also skipped resolveMaxRows entirely for that branch, so `--max-rows -1` was silently accepted under proxied claim (every other command, direct or proxied, rejects it with exit 1). Still call resolveMaxRows in the claim-exempt branch for its validation side effect, ignoring the resolved cap for the claim itself. Reproduced live (claim succeeded instead of failing) on the pre-fix code. Added claim_rejects_invalid_max_rows_flag to ready_proxied_integration_test.go. 3. cmd/bd/find_duplicates.go, cmd/bd/max_rows.go: find-duplicates resolved --max-rows twice under proxied mode (once to build its filter, again inside rejectMaxRowsUnderProxiedServer), doubling the malformed-env stderr warning. Split rejectMaxRowsUnderProxiedServer into itself plus a new rejectResolvedMaxRowsUnderProxiedServer(maxRows int) that takes an already-resolved value; find_duplicates.go now calls the latter with its existing resolved maxRows instead of re-resolving. 4. internal/storage/issueops/claim.go: added a comment sentence noting the unbounded-scan trade-off per the adjudication note — parity with pre-PR main and correctness-first (preserves claim's existing fairness/ordering across the ready set); a bounded, paged scan is a deliberate follow-up, not folded in here. Verified: go build/vet clean; full MaxRows-named + FilterHasZeroMaxRows + BypassesBeadsMaxRows + WithFetchOneExtra sweep passes in both dolt-server and BEADS_TEST_EMBEDDED_DOLT=1 modes (including the two new regression tests); full TestProxiedServerReady suite (~211s) passes with BEADS_TEST_PROXIED_SERVER=1; internal/storage/issueops unit tests pass; broader TestList|TestWatch|TestGraph|TestDepTree|TestReady|TestClaim| TestFindDuplicates sweep clean except the same pre-existing unrelated ICU-header build failure noted in prior rounds. Both new regression tests (item 1 and item 2) reproduce the reported failure on the pre-fix code via git-stash and pass after. Agent-Signature: claude-sonnet-medium on behalf of maphew
This commit is contained in:
parent
247dd809cc
commit
77227aa67b
8 changed files with 139 additions and 16 deletions
|
|
@ -121,7 +121,11 @@ func runFindDuplicates(cmd *cobra.Command, _ []string) error {
|
|||
}
|
||||
|
||||
if usesProxiedServer() {
|
||||
if err := rejectMaxRowsUnderProxiedServer(cmd); err != nil {
|
||||
// maxRows was already resolved above (to build filter); reject using
|
||||
// that value directly instead of re-resolving via
|
||||
// rejectMaxRowsUnderProxiedServer, which would call resolveMaxRows a
|
||||
// second time and double any malformed-env warning it emits.
|
||||
if err := rejectResolvedMaxRowsUnderProxiedServer(maxRows); err != nil {
|
||||
return err
|
||||
}
|
||||
return runFindDuplicatesProxiedServer(rootCtx, filter, status, method, threshold, limit, model)
|
||||
|
|
|
|||
|
|
@ -45,6 +45,16 @@ func rejectMaxRowsUnderProxiedServer(cmd *cobra.Command) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return rejectResolvedMaxRowsUnderProxiedServer(maxRows)
|
||||
}
|
||||
|
||||
// rejectResolvedMaxRowsUnderProxiedServer is rejectMaxRowsUnderProxiedServer
|
||||
// split out for callers that have already resolved the cap for their own
|
||||
// purposes (e.g. to build a filter) and would otherwise call resolveMaxRows
|
||||
// a second time — resolveMaxRowsEnvOnly emits a stderr warning on a
|
||||
// malformed BEADS_MAX_ROWS every time it runs, so a second resolve doubles
|
||||
// that warning under proxied mode (be-x42v.4 round-4 follow-up).
|
||||
func rejectResolvedMaxRowsUnderProxiedServer(maxRows int) error {
|
||||
if maxRows > 0 {
|
||||
return HandleErrorRespectJSON("--max-rows / BEADS_MAX_ROWS is not supported in proxied-server mode")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -602,6 +602,46 @@ func TestEmbeddedMaxRowsList(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
// be-x42v.4 round-4 follow-up: the round-3 fix to
|
||||
// finishReadyWorkWithCounts (trim to Limit before EnforceMaxRowsCap)
|
||||
// wasn't mirrored onto the sibling bd list search paths
|
||||
// (searchInTx in search.go, finishSearchIssuesWithCounts in
|
||||
// search_counts.go), which still capped the pre-trim merged
|
||||
// issues+wisps set. `--include-infra` disables the default SkipWisps
|
||||
// escape hatch, so the wisps merge actually runs. limit=2, cap=5, 3
|
||||
// durable + 3 wisp issues: each leg's query is independently bounded
|
||||
// by EffectiveSearchLimit, so the merge can produce up to 6 rows
|
||||
// pre-trim (>cap=5) even though the delivered page (trimmed to 2) is
|
||||
// well within the cap. Covers both bd list output modes (opus's live
|
||||
// repro found both non-JSON and --json tripping the false cap error).
|
||||
t.Run("IncludeInfraMergedUnderLimit_NoError", func(t *testing.T) {
|
||||
mDir, _, _ := bdInit(t, bd, "--prefix", "mrii")
|
||||
for i := 0; i < 3; i++ {
|
||||
bdCreate(t, bd, mDir, fmt.Sprintf("Durable infra %d", i), "--type", "task")
|
||||
}
|
||||
for i := 0; i < 3; i++ {
|
||||
bdCreate(t, bd, mDir, fmt.Sprintf("Wisp infra %d", i), "--type", "task", "--ephemeral")
|
||||
}
|
||||
|
||||
out, code := bdRunRaw(t, bd, mDir, nil, "list", "--include-infra",
|
||||
"--limit", "2", "--max-rows", "5")
|
||||
if code != 0 {
|
||||
t.Fatalf("expected exit 0 (delivered page under cap despite pre-trim merge overage), got %d\n%s", code, out)
|
||||
}
|
||||
if strings.Contains(out, "too many rows") {
|
||||
t.Errorf("delivered-page-under-cap should not emit cap error:\n%s", out)
|
||||
}
|
||||
|
||||
outJSON, codeJSON := bdRunRaw(t, bd, mDir, nil, "list", "--include-infra", "--json",
|
||||
"--limit", "2", "--max-rows", "5")
|
||||
if codeJSON != 0 {
|
||||
t.Fatalf("expected exit 0 under --json (delivered page under cap despite pre-trim merge overage), got %d\n%s", codeJSON, outJSON)
|
||||
}
|
||||
if strings.Contains(outJSON, "too many rows") {
|
||||
t.Errorf("delivered-page-under-cap under --json should not emit cap error:\n%s", outJSON)
|
||||
}
|
||||
})
|
||||
|
||||
// be-x42v.4 follow-up (review MUST-FIX 5): the initial query under
|
||||
// `bd list --watch` must surface a cap violation with exit 2, same as
|
||||
// non-watch `bd list`. Before the fix, watchIssues logged the error to
|
||||
|
|
|
|||
|
|
@ -58,6 +58,16 @@ This is useful for agents executing molecules to see which steps can run next.`,
|
|||
if err := rejectMaxRowsUnderProxiedServer(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// Still validate --max-rows/BEADS_MAX_ROWS here even though
|
||||
// the resolved cap is ignored below: resolveMaxRows is also
|
||||
// where a malformed value (e.g. --max-rows -1) is rejected
|
||||
// with exit 1, and skipping it entirely for the claim-exempt
|
||||
// branch would silently accept a usage error that every
|
||||
// other command (direct or proxied) rejects.
|
||||
if _, _, err := resolveMaxRows(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return runReadyProxiedServer(cmd, rootCtx)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -788,6 +788,21 @@ func TestProxiedServerReady2(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
// be-x42v.4 round-4 follow-up (codex P2): the claim-exempt branch above
|
||||
// must still validate --max-rows via resolveMaxRows even though it
|
||||
// ignores the resolved (positive) cap — otherwise a malformed value
|
||||
// like -1 is silently accepted under proxied `ready --claim`, unlike
|
||||
// every other command (direct or proxied).
|
||||
t.Run("claim_rejects_invalid_max_rows_flag", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
p := newSharedProxiedProject(t, bd, "rcim")
|
||||
bdProxiedCreate(t, bd, p.dir, "Claim invalid max-rows seed")
|
||||
out := bdProxiedReadyFail(t, bd, p, "--claim", "--max-rows", "-1")
|
||||
if !strings.Contains(out, "must be non-negative") {
|
||||
t.Errorf("expected --max-rows usage-error rejection, got: %s", out)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("reject_bulk_ready_under_max_rows_flag", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
p := newSharedProxiedProject(t, bd, "rbmf")
|
||||
|
|
|
|||
|
|
@ -216,6 +216,14 @@ func ClaimReadyIssueInTx(
|
|||
// to claim" whenever that narrow window is unclaimable, even with
|
||||
// plenty of other ready work available. Clear the cap fields so
|
||||
// GetReadyWorkInTx never returns ErrTooManyRows either.
|
||||
//
|
||||
// This is parity with pre-PR main (which never bounded the claim scan)
|
||||
// and correctness-first: an unbounded scan preserves claim's existing
|
||||
// fairness/ordering guarantee across the whole ready set. A paged scan
|
||||
// that stays bounded while still walking past unclaimable rows is a
|
||||
// reasonable follow-up, but it's a genuine behavior change (not a
|
||||
// MaxRows-cap fix) and is deliberately deferred rather than folded in
|
||||
// here.
|
||||
claimFilter.Limit = 0
|
||||
claimFilter.MaxRows = 0
|
||||
claimFilter.MaxRowsSource = ""
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ func searchInTx[T any](ctx context.Context, tx DBTX, query string, filter types.
|
|||
return nil, fmt.Errorf("search wisps (ephemeral filter): %w", err)
|
||||
}
|
||||
if len(results) > 0 {
|
||||
results = trimToSearchLimit(results, filter.Limit)
|
||||
if capErr := EnforceMaxRowsCap(len(results), filter.MaxRows, filter.MaxRowsSource); capErr != nil {
|
||||
return nil, capErr
|
||||
}
|
||||
|
|
@ -139,6 +140,7 @@ func searchInTx[T any](ctx context.Context, tx DBTX, query string, filter types.
|
|||
// must enforce the cap itself; skipping it here would let SkipWisps
|
||||
// callers (e.g. bd list's default filter) silently bypass MaxRows.
|
||||
if filter.SkipWisps {
|
||||
results = trimToSearchLimit(results, filter.Limit)
|
||||
if err := EnforceMaxRowsCap(len(results), filter.MaxRows, filter.MaxRowsSource); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -162,6 +164,7 @@ func searchInTx[T any](ctx context.Context, tx DBTX, query string, filter types.
|
|||
// exceed the cap (the merge path below enforces it at line ~74;
|
||||
// this early return must enforce it too, or the cap is silently
|
||||
// skipped whenever the wisps table is empty).
|
||||
results = trimToSearchLimit(results, filter.Limit)
|
||||
if err := EnforceMaxRowsCap(len(results), filter.MaxRows, filter.MaxRowsSource); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -189,11 +192,19 @@ func searchInTx[T any](ctx context.Context, tx DBTX, query string, filter types.
|
|||
}
|
||||
}
|
||||
|
||||
// Apply the defensive cap on the merged result set. searchTableInTx already
|
||||
// over-fetches by one (LIMIT MaxRows+1) so this check is sufficient — but
|
||||
// when issues and wisps are merged, the combined count can exceed the cap
|
||||
// even though neither leg did individually. Check after merge so the cap
|
||||
// reflects the row count actually returned to the caller.
|
||||
// Apply the defensive cap on the merged, delivered result set. Each leg
|
||||
// (issues, wisps) is independently bounded by EffectiveSearchLimit, so
|
||||
// the merged pre-trim count can exceed the cap even when filter.Limit
|
||||
// itself does not — e.g. Limit=2, MaxRows=5, 3 rows in each table merges
|
||||
// to 6, which would trip MaxRows even though the page actually handed
|
||||
// back to the caller (trimmed to Limit=2) is well within the cap.
|
||||
// Trimming before the cap check (mirrors GetReadyWorkInTx's
|
||||
// mergeReadyWisps, which trims before its caller's EnforceMaxRowsCap
|
||||
// runs) avoids that false positive; a single-source result never
|
||||
// exceeds Limit when Limit>0 in the first place, so this trim is a
|
||||
// no-op there and a genuine overage still fires (Limit=0, or
|
||||
// Limit>MaxRows overage that survives the trim).
|
||||
results = trimToSearchLimit(results, filter.Limit)
|
||||
if err := EnforceMaxRowsCap(len(results), filter.MaxRows, filter.MaxRowsSource); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -201,6 +212,18 @@ func searchInTx[T any](ctx context.Context, tx DBTX, query string, filter types.
|
|||
return results, nil
|
||||
}
|
||||
|
||||
// trimToSearchLimit truncates results to filter.Limit (when set, Limit>0)
|
||||
// before the caller-facing MaxRows cap check runs. Every searchInTx exit
|
||||
// path routes results returned to the caller through this before
|
||||
// EnforceMaxRowsCap — see the comment above the final merge check for why
|
||||
// (be-x42v.4 round-4 follow-up, mirrors finishReadyWorkWithCounts).
|
||||
func trimToSearchLimit[T any](results []T, limit int) []T {
|
||||
if limit > 0 && len(results) > limit {
|
||||
return results[:limit]
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
// searchTableInTxT runs a filtered search against a specific table set
|
||||
// (issues or wisps) under the given projection.
|
||||
//
|
||||
|
|
|
|||
|
|
@ -156,21 +156,34 @@ func scanCountsRowsInTx(ctx context.Context, tx *sql.Tx, mainTable, query string
|
|||
|
||||
// finishSearchIssuesWithCounts is the single terminal hook every
|
||||
// SearchIssuesWithCountsInTx exit path routes through: it sorts the merged
|
||||
// result, enforces the defensive MaxRows cap (be-x42v) on the row count
|
||||
// actually assembled — mirroring searchInTx's terminal EnforceMaxRowsCap
|
||||
// calls — and only then applies the caller-facing Limit trim. Checking the
|
||||
// cap before the Limit trim matters: runFilterSearchQueryInTx sizes its SQL
|
||||
// LIMIT via EffectiveSearchLimit (cap+1 when Limit is absent or looser than
|
||||
// the cap) specifically so overage is still visible here before Limit
|
||||
// silently truncates it away.
|
||||
// result, applies the caller-facing Limit trim, and only then enforces the
|
||||
// defensive MaxRows cap (be-x42v) on the delivered count — mirroring
|
||||
// searchInTx's trimToSearchLimit-before-EnforceMaxRowsCap ordering and
|
||||
// finishReadyWorkWithCounts in ready_work_counts.go.
|
||||
//
|
||||
// Trim-before-cap matters for the merged (issues+wisps) case:
|
||||
// runFilterSearchQueryInTx sizes each leg's SQL LIMIT independently via
|
||||
// EffectiveSearchLimit(filter.Limit, filter.MaxRows), so the merged
|
||||
// pre-trim slice can hold up to ~2x that per-leg bound — e.g. Limit=2,
|
||||
// MaxRows=5, 3 rows in each table merges to 6, which would trip MaxRows
|
||||
// even though the page actually handed back to the caller (trimmed to
|
||||
// Limit=2) is well within the cap. Checking the cap against the delivered
|
||||
// count instead avoids that false positive.
|
||||
//
|
||||
// This does not weaken cap enforcement for a single-source result: a lone
|
||||
// query's LIMIT is already bounded to at most max(Limit, MaxRows+1), so its
|
||||
// result never exceeds Limit when Limit>0 and the trim is a no-op there —
|
||||
// only the two-source merge can produce more rows than Limit pre-trim, and
|
||||
// a genuine overage (Limit=0, or Limit>MaxRows overage that survives the
|
||||
// trim) still fires.
|
||||
func finishSearchIssuesWithCounts(items []*types.IssueWithCounts, filter types.IssueFilter) ([]*types.IssueWithCounts, error) {
|
||||
sortSearchIssuesWithCounts(items, filter.SortBy, filter.SortDesc)
|
||||
if filter.Limit > 0 && len(items) > filter.Limit {
|
||||
items = items[:filter.Limit]
|
||||
}
|
||||
if err := EnforceMaxRowsCap(len(items), filter.MaxRows, filter.MaxRowsSource); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if filter.Limit > 0 && len(items) > filter.Limit {
|
||||
return items[:filter.Limit], nil
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue