Skip to content

feat(mcp): bound the invoice walk's offset at the door - #1265

Merged
chappie-daemon merged 4 commits into
rewrite/mainfrom
factory/040-mcp-offset-bound
Nov 27, 2026
Merged

chappie-daemon merged 4 commits into
rewrite/mainfrom
factory/040-mcp-offset-bound

Conversation

@chappie-daemon

Copy link
Copy Markdown
Collaborator

The MCP door now bounds the invoice walk's skip, so a caller cannot make either backend walk an arbitrarily long prefix.

The bound. pub const MAX_ROWS_PER_SKIP: u64 = 5_000 sits beside MAX_ROWS_PER_PAGE, with the reason in its doc: the skip is linear in the rows it passes (~0.09 µs/key over 20 000 pending rows) and then saturates at the pending set, so an unbounded offset buys a whole index walk for an answer that may be empty — 0.941 ms at offset: 5_000 against 7.936 ms for a served 500-row page, and 1.562 ms at u64::MAX for an empty one. offset_bound sits beside page_bound, both run before any repository call, and the refusal is McpError::Criterion with offset: a walk skips at most 5000 rows, {offset} was given.

Advertised, not just enforced. The argument's inputSchema gains minimum: 0 and maximum: 5000, the property description and the tool description both state the ceiling, and the tools/list snapshot carries the published document. A caller reading only the schema can choose a legal page.

Not a keyset cursor. ADR 0020 D1 records the alternative and its price: a cursor changes a storage trait with six implementors plus the parity fixture and needs a Postgres ORDER BY tie-break that no test here can run. D2 is the number, decided at this door and measured against the relay's clamp rather than derived from it — the architecture lens caught the first draft aliasing nostream_storage::MAX_PAGE_ROWS, which would have let a relay event-page change move an MCP schema. D3 is the door. Each decision carries its cost.

Verified. store_families 19 (base 18), with the existing refusal case extended to 5000 served / 5001 and u64::MAX refused and a new case seeding 5 001 rows that asserts the page at the ceiling is still served; tools_list 5 with a typed pin on the constant; parity_lmdb 52; nostream-mcp 102 tests; workspace 116 targets green; fmt, both clippy passes and release clean. The approver drove the release binary's stdio door: 5001 and u64::MAX refused with the exact text before any store call, 5000 passed through, and {limit: 0, offset: 5001} still answers the limit text.

Storage, services and the daemon are untouched; the Postgres as i64 wrap recorded in the issue is now out of MCP's reach and stays a failed call, not a leak. Eight paths, one empty changeset.

Rust only: no version bump. Closes #N is inert on this repository's integration branch; #1223 is closed by hand with the merge sha.

MAX_ROWS_PER_SKIP is a local 5,000 with its own reason; ADR 0020 D2 records a
door decision measured against MAX_PAGE_ROWS rather than derived from it, and
D1 now prices the cursor's door-side cost and its queue-shift benefit.
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a71834ba-04e3-4044-b010-1ac9c0e96ae1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • 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.

Share

@changeset-bot

changeset-bot Bot commented Nov 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f7255fa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Caps the MCP invoices_list offset at 5,000 before the repository read.

  • MCP invoice lists stop callers from skipping more than 5,000 rows.

Reduced paging depth is intentional: PR author chappie-daemon describes the ceiling and the rejected cursor alternative; ADR 0020 records the cost.

Reviews (1) · Last reviewed commit: "refactor(mcp): hold the skip ceiling at ..." · Reviewed by Greptile

@chappie-daemon
chappie-daemon merged commit 5c6dc91 into rewrite/main Nov 27, 2026
19 checks passed
@chappie-daemon
chappie-daemon deleted the factory/040-mcp-offset-bound branch November 27, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant