Skip to content

feat(mcp): bound MemoryDelta results with a limit - #249

Merged
radimsem merged 1 commit into
devfrom
feat/delta-result-limit
Jun 6, 2026
Merged

feat(mcp): bound MemoryDelta results with a limit#249
radimsem merged 1 commit into
devfrom
feat/delta-result-limit

Conversation

@radimsem

@radimsem radimsem commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

Bounds MemoryDelta so a large vault can't blow the LLM context window or overrun the MCP transport in one call — it was the only read tool without a result cap (Search=50, FetchBatch=256, Related=100).

Closes #221.

What changed

  • limit param on DeltaInput (default 500, ceiling 5000, over-asks clamp rather than error). Plumbed HandleDelta → Engine.Delta → GetDiffsSince → qSelectDiffsSince (LIMIT ?).
  • Snapshot-granular cursor preserved (since_snapshot stays a snapshot id — no client contract change). Engine.Delta peeks limit+1 and trims the trailing partial snapshot, so resuming from the hinted since_snapshot is lossless.
  • Tiered note: continuation hint (returned as text, since results are text-only):
    • boundary truncation → Re-call MemoryDelta(since_snapshot=<last complete id>)
    • a single snapshot below the ceiling → raise limit (max 5000)
    • a single snapshot above the ceiling → exact MemoryDiff(from_snapshot_id=…, to_snapshot_id=…) escape hatch (that snapshot is provably the immediate-next one, so the diff is scoped to it alone — no inaccessible tail).
  • Non-positive limit guarded (exported Engine.Delta returns empty instead of panicking).
  • §10 contract docs updated: skills/remind/references/snapshots-diffs.md, docs/versioning.md.

Tests

TestDelta_Limit (fit / trim / boundary / overflow / non-positive guard), TestDeltaTruncationNote (all three note branches), TestHandleDelta_LimitTruncationNote. Full suite, make check-skills, gofmt, and go vet all green.

Review

Project reviewers (go-style-reviewer, mcp-surface-reviewer) clean; Codex review converged over two rounds (caught the >5000-diff inaccessible-tail regression and a non-positive-limit panic, both fixed).

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@radimsem
radimsem merged commit 5d8536d into dev Jun 6, 2026
5 checks passed
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.

[enhancement] MemoryDelta returns unbounded diff results — add a limit to prevent context blow-up

1 participant