Repository navigation
fix(exec): cut a map reply at the row limit and mark it - #222
Conversation
CouchDB and HBase return a map from a native query: a Mango find gives
{"docs": [...]}, and an HBase scan gives {rowkey: row}. The iq_exec cap
marks only a list reply as truncated, so these two drivers read their
whole reply into memory, and a cut would have looked complete.
Add a cut notice in the context: WithRowCutNotice, NoteRowCut, and the
helper CutAtLimit. A driver whose reply is not a list reads at most the
limit of rows. If the last of them exists, it drops that row, keeps one
row less, and reports the cut. iq_exec then sets truncated for any reply
shape. The WithRowLimit doc states both contracts.
CouchDB applies this to the docs of a find, and a cut reply has no
bookmark. HBase applies it to the rows of a scan and closes the
scanner. Without a limit, both read every row as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Zsolt Gaspar <17578237+zsltg@users.noreply.github.com>
|
@coderabbitai review Generated by Claude Code |
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Query row-cut notice contract internal/query/query.go, internal/query/query_test.go |
The query package adds a context callback and CutAtLimit. Its documentation distinguishes list replies, non-list replies, and single-document replies. Tests cover cut thresholds and callback behavior. |
CouchDB and HBase row-limit handling drivers/couchdb/couchdb.go, drivers/couchdb/mock_test.go, drivers/hbase/hbase.go, drivers/hbase/store_test.go, docs/docs/agents.md |
CouchDB and HBase stop before decoding the limit-th row and report the cut. Tests check row counts and cut behavior. The documentation describes the drivers’ row caps and the uncapped CLI iq exec. |
MCP truncation reporting cmd/mcp_tools.go, cmd/mcp_exec_test.go |
toolExec marks results truncated when result capping or a driver row-cut notice reports truncation. Tests check that map replies remain unchanged and that their truncated status matches the driver notice. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Sequence Diagram(s)
sequenceDiagram
participant toolExec
participant CouchDBStoreQuery
participant HBaseExecScan
participant queryCutAtLimit as query.CutAtLimit
participant rowCutCallback
toolExec->>toolExec: Register row-cut callback
alt CouchDB query
toolExec->>CouchDBStoreQuery: Query with row limit
CouchDBStoreQuery->>queryCutAtLimit: Check row count
else HBase scan
toolExec->>HBaseExecScan: Scan with row limit
HBaseExecScan->>queryCutAtLimit: Check row count
end
queryCutAtLimit->>rowCutCallback: Report row cut at limit
rowCutCallback-->>toolExec: Set atomic cut flag
toolExec->>toolExec: Combine cut flag with result-cap truncation
Possibly related PRs
- zsltg/iq#207: Adds
iq_execitem and byte caps and introducesquery.WithRowLimit. - zsltg/iq#215: Adds native-driver stopping behavior at the
query.WithRowLimitcap.
Merge Risk: 
Minimal · up to 78429
-
No merge-blocking issue was identified.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The description explains the problem, implementation, affected drivers, behavior, tests, documentation, and checks completed or deferred to CI. It provides sufficient detail despite using Summary and Change headings instead of the template's What and why heading.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 8 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
|
CodeScene found execScan at its complexity limit after the cut check. addScanRow now adds one result and reports whether the scan is done. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Zsolt Gaspar <17578237+zsltg@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #222 +/- ##
=======================================
Coverage 96.91% 96.92%
=======================================
Files 154 154
Lines 15187 15214 +27
=======================================
+ Hits 14719 14746 +27
Misses 467 467
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
kivik gives the metadata of a result set only once its rows are read to the end, so a find that the row limit cut gets no bookmark anyway. The cut flag and its early return changed nothing, and the mutation gate found both as escaped. Remove them and say why in a comment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Zsolt Gaspar <17578237+zsltg@users.noreply.github.com>
|
@coderabbitai review Generated by Claude Code |
|
|
@coderabbitai review Generated by Claude Code |
Action performed
|
Summary
CouchDB and HBase return a map from a native query: a Mango find gives
{"docs": [...], "bookmark": ...}, and an HBase scan gives{rowkey: row}. Theiq_execcap marks only a list reply as truncated, so #215 left these two drivers out: a cut map would have looked complete. They still read the whole native reply into memory, and the cap only limited what the agent saw.Change
query.WithRowCutNotice,query.NoteRowCut, and the helperquery.CutAtLimit(ctx, n), which a non-list driver calls after it reads row n.WithRowLimitdoc now states both contracts. A list driver returns up to n rows; the caller asks for one more than it shows. A driver whose reply is not a list reads at most n rows; if the n-th row exists, it drops that row, keeps n-1, and reports the cut.docsof a find. A cut reply has nobookmark, because the driver did not read the reply to its end. The deferred close still releases the result set.scan <table>and closes the scanner.getreturns one row and is unchanged.iq_execinstalls the sink and setstruncatedfor any reply shape when a cut was reported. The byte cap and the list cap do not change.docs/docs/agents.mdnow lists CouchDB and HBase, and says that their map reply comes back withtruncatedset when rows were cut.Checks
make checkmake docsscripts/mutation-gate.sh: left to CI. Locally, the CouchDB test container refused its login ("Account is temporarily locked"), so the baseline run could not start.make cover: left to CImake security: left to CITestRowCutNotice,TestNoteRowCutWithoutSinkDoesNothing,TestNoteRowCutCallsTheSink,TestQueryRowLimit(CouchDB: limit 3 over 5 docs gives 2 docs, no bookmark, the cut, and 3 reads),TestQueryScanRowLimit(HBase: the same, and the scanner closes once),TestMCPExecMarksACutMapReply. They fail without the change.scripts/capabilities.sh: not needed,go.modandgo.sumdid not change🤖 Generated with Claude Code
Summary by CodeRabbit
truncated: truewhen a row limit cuts the results. Rows that fit are retained, and the result data remains unchanged otherwise.iq execremains uncapped and returns the full reply.