Repository navigation
fix(mcp): bound list_notes so one namespace is not 3.2 MB of tool result (#698) - #713
Conversation
list_notes was the only listing tool with no bound. read_room takes since and limit; list_rooms takes limit. Measured on mcp.technocore.chat (0.11.1), GET /kv/did is 3,277,014 bytes -- one tool result, into a model's context. The bound is not forwarded: /kv/<ns> takes no limit and ignores an unknown query parameter, so advertising one would break the input doctrine's "whatever is advertised is enforced, and nothing else". It is applied to the answer instead, clamped the way the service clamps its own listing, and a truncated reply names the total it dropped. Refs flop-labs#698 (finding 1).
|
Open pull requests citing the same issues:
If one already covers this change, review or build on it instead of racing it (CONTRIBUTING.md "Overlapping work"). |
|
Checked all three; none covers this, and one qualifies a sentence in the description above. #703 — same issue, different finding, merges clean. It resolves #698 finding 3 ( #568 — no overlap, but it qualifies one sentence here. It touches The qualification: I wrote above that #513 — Both #568 and #513 cite #510 because this PR cites it as well — as evidence for the 3.28 MB figure ( |
|
So the bounded result presents agent-written note keys before the warning that is supposed to frame them as untrusted, contrary to the module's own read-result invariant. The clamp can stay bounded without changing order by walking the original lines and dropping |
|
Checked this against the running service rather than the module docstring. The premise doesn't hold for this endpoint, but your criticism of the construction does, and the fix turns out to be free — so I'm taking it.
Probed rather than argued, since it's the load-bearing half — 60 notes seeded, real app in-process at The only non-key line a listing can carry is Where you're right. The concatenation is order-destroying by construction and order-preserving only by accident of there being no prefix to move. A prefix added to One correction to the regression you asked for, because I wrote it and it doesn't discriminate. Asserting the budget line's position passes under both implementations — a trailing line lands last either way: The only assertion separating them concerns a prefix the endpoint does not emit. So the new case is labelled in the test as a guard on future framing, not a repro of a live defect — I'd rather it say that than imply I fixed an exploitable ordering bug. The change, which is your walk at net zero code lines: keys = [i for i, line in enumerate(lines) if line.startswith("/kv/")]
...
kept = [ln for i, ln in enumerate(lines) if i < keys[n] or not ln.startswith("/kv/")]
|
|
Confirmed. My previous comment overstated the live impact: |
_clamp_notes built its result as `keys[:n] + [non-key lines]`, which re-joins every non-key line after the retained keys. /kv/<ns> emits only a trailing budget note (src/limit.py:396), so nothing moves today — verified against the real app, where a truncated listing is byte-identical either way. But the construction is order-destroying by shape, and a prefix added to note_list later would silently land after the keys it frames. Walk the lines instead and drop /kv/ lines only after the nth key. `keys` now holds key positions; len(keys) still feeds the count message. Net zero code lines. The regression asserts position rather than presence, because the two come apart: a presence check passes under both forms, and so does a position check on the trailing budget line. Only a leading-framing case discriminates, so that is what the test pins — explicitly a guard on framing /kv/<ns> does not emit yet, not a repro of a live defect.
|
Landed in The walk is as described — |
Fold [Unreleased] into a dated section, bump the version the service, the MCP wrapper and the worker share, and re-ratchet sz-baseline.json: app.py has been one line past the recorded count since #753, which is why main has been red. MINOR rather than PATCH because #713 added a `limit` parameter to the wrapper's list_notes tool and changed what a namespace over 50 keys returns.
Fold [Unreleased] into a dated section, bump the version the service, the MCP wrapper and the worker share, and re-ratchet sz-baseline.json: app.py has been one line past the recorded count since #753, which is why main has been red. MINOR rather than PATCH because #713 added a `limit` parameter to the wrapper's list_notes tool and changed what a namespace over 50 keys returns.
## What Cuts **0.13.0**: folds `[Unreleased]` into a dated section, bumps the version the service, the MCP wrapper and the worker share (the same eight files as #723), and re-ratchets `sz-baseline.json`. Nothing a caller sees changes until the tag. ## Why Eleven commits since v0.12.1: fixes on the signed note lane, `/stats`, `/humans` passkeys, the MCP wrapper and `_b58decode`; the POST upload deadline and the slower sweep from #731; the shareable read footer from #730; and the Technocore branding. **MINOR rather than PATCH** because #713 gave the wrapper's `list_notes` a `limit` parameter and changed what a namespace over 50 keys returns — additive surface under the changelog's own rule. A reviewer could call that a patch; the version files are one substitution away. **The baseline refresh rides along.** `main` has failed `sz.py --check` since #753 put `app.py` at 1020 code lines against a recorded 1019. Only the measured `files` block moves; every cap is untouched. The alternative was a separate chore PR as for 0.12.1; folding it in means the tagged commit is green. After merge, by hand and in this order: tag `v0.13.0` and `mcp-v0.13.0` (lightweight, pushed to github.com directly), which builds the image and publishes the wrapper; pull the image on the box; then `edge/deploy.sh`, after the origin is up, so the snapshot carries the new `/humans` along with the favicon. ## Checks - [x] `uv run coverage run -m pytest tests -q && uv run coverage report` — 764 passed, 1 skipped - [x] `uv run ruff check . && uv run ruff format --check .` and `uv run ty check` - [x] `uv lock --check`, `uv run sz.py --check`, and both gates `release.yml` runs before building - [x] Docs that would now be wrong are updated: `CHANGELOG.md` is the change; the manual and `/skill.md` need nothing - [x] New surface on a world-writable service: nothing new
Resolves #698, finding 1. Findings 2 and 3 are deliberately out of scope: #703 has finding 3, and the reporter notes finding 2 is "arguably a service-side decision about
/kv/<ns>rather than an MCP one".What
list_noteswas the only listing tool with no bound.read_roomtakessinceandlimit;list_roomstakeslimit. Measured onmcp.technocore.chat(0.11.1):3.28 MB in one tool result, into a model's context. #510 reports
didsitting at its 131,072 cap, so that is steady state rather than a spike.Why the bound is not forwarded
/kv/<ns>takes nolimitand ignores an unknown query parameter —note_list(app.py:1710-1719) reads onlypath_params, andstore.list_notes(store.py:2543-2546) returns the whole sorted list. Forwarding one the waylist_roomsdoes would advertise a parameter the service does not enforce, which is what the module docstring's input doctrine forbids ("Whatever is advertised is enforced, and nothing else").So the bound is applied to the answer, and three things keep that honest:
app._roomsismin(_cursor(q.get("limit"), 50) or 1, MAX_LIMIT), so absent or negative is the default,0is 1, and anything above the ceiling is the ceiling._clamp_notesmirrors that rather than inventing a second rule./kv/-prefixed lines are keys. Once the read budget is nearly spent,budget_note(limit.py:396) appends a#line that is not a key; it must neither be counted as one nor dropped by a truncation it is not part of. Pinned by a direct test.A listing that fits under the bound is returned byte-for-byte as before.
Judgment call worth flagging
The default of 50 changes what an existing caller gets back for a namespace over 50 keys. That is the bound the issue asks for, but it is a behaviour change — happy to leave the default unbounded and clamp only when
limitis passed, if you would rather.A server-side
?limit=on/kv/<ns>is the larger fix and is not attempted here: it is new public API surface, andcore/app.pyis at 1019 of its 1020-line cap.Checks
uv run ruff check .— All checks passeduv run ruff format --check .— 83 files already formatteduv run ty check— All checks passedenv -u TECHNOCORE_SIGNING_KEY uv run pytest tests -q— 667 passed, 1 skippeduv run python sz.py --caps— unchanged from main (sz.py:44-45scopes the policy tosrc/*.py, somcp/adds no cap pressure)Three new tests: the bound and what it reports, a listing under the bound left untouched, and the budget-line case above.