fix(pi-fff): cap grep total results with pageSize, clamp context (#768) - #769
fix(pi-fff): cap grep total results with pageSize, clamp context (#768)#769gustav-fff wants to merge 1 commit into
Conversation
ffgrep/fff-multi-grep passed the documented `limit` only as `maxMatchesPerFile`, so matches spread across files could return a full SDK page (default 50) instead of `limit`. Pass `limit` as `pageSize` too, on both grep tools and the fuzzy fallback, so the cap applies to total matches per page; excess stays retrievable via the existing cursor. Also clamp `context` to a bounded non-negative integer so a large value cannot multiply output size past the model window. Closes #768
📝 WalkthroughWalkthrough
ChangesGrep bounds
Estimated code review effort: 2 (Simple) | ~10 minutes Mergeability Score: 🟡 Moderate · up to The change bounds grep output and context, but fuzzy-search pagination can switch behavior on subsequent pages when a cursor is returned, potentially producing missing, duplicate, or changed results. This concrete correctness issue should be fixed or explicitly accepted before merge. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/pi-fff/src/index.ts`:
- Around line 822-823: Prevent fuzzy fallback results from emitting a cursor
that cannot resume the same fuzzy query: update the pagination flow around the
fuzzy search and cursor construction near maxMatchesPerFile/pageSize to either
persist the fuzzy query and mode in the cursor and restore them on the next
request, or suppress nextCursor for fuzzy results. Add a regression test
covering a paginated fuzzy fallback and verifying subsequent requests do not
switch to the normal exact-query picker.grep path.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 54047dbf-799a-4df3-8564-6486b2438eac
📒 Files selected for processing (1)
packages/pi-fff/src/index.ts
| maxMatchesPerFile: pageSize, | ||
| pageSize, |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Do not emit a broken fuzzy cursor.
pageSize can now make the fuzzy fallback return nextCursor. The next request skips the fallback because params.cursor is set, then resumes the normal picker.grep path with the exact query and non-fuzzy mode. It does not replay fuzzyQuery with mode: "fuzzy". The native wrapper also forwards only cursor._offset in packages/fff-node/src/finder.ts Lines 368-386.
Store the fuzzy mode and query with the cursor, or suppress cursors for fuzzy results. Add a regression test.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/pi-fff/src/index.ts` around lines 822 - 823, Prevent fuzzy fallback
results from emitting a cursor that cannot resume the same fuzzy query: update
the pagination flow around the fuzzy search and cursor construction near
maxMatchesPerFile/pageSize to either persist the fuzzy query and mode in the
cursor and restore them on the next request, or suppress nextCursor for fuzzy
results. Add a regression test covering a paginated fuzzy fallback and verifying
subsequent requests do not switch to the normal exact-query picker.grep path.
Closes #768
Root cause
ffgrep/fff-multi-greppass the documentedlimitonly asmaxMatchesPerFile(packages/pi-fff/src/index.ts:774,806,1051pre-fix), never aspageSize. Per the SDK (packages/fff-node/src/fff-api.ts:439-440,545-546),maxMatchesPerFilecaps matches per file whilepageSizecaps total matches per page (default 50). Solimit: 5returns up to a full SDK page when matches are spread across files.contextwas also passed through unbounded — large values multiply output size with no cap.Fix
Pass the effective limit as
pageSize(clamped to 50) alongsidemaxMatchesPerFileon both grep tools and the fuzzy fallback, so the cap applies to total matches per page; the existingnextCursorstill exposes the rest. Clampcontextto[0, 20]via aclampContexthelper.Steps to reproduce
Pre-fix, on
origin/main:Expected: at most 5 matches for
limit: 5.Actual (pre-fix):
54 matches across 14 files for a documented
limitof 5.How verified
Rebuilt
fff-node, ran the same grep with the post-fix options (maxMatchesPerFile: 5, pageSize: 5):Output drops from 54 to a bounded page (page-boundary soft cap) with the remainder reachable via cursor.
bunx tsc --noEmit -p packages/pi-fff/tsconfig.jsonpasses clean; biome reports only pre-existing issues (identical onorigin/main).Automated triage via Gustav. Honk-Honk 🪿
Summary by CodeRabbit