Skip to content

Keep kinbase_status small enough for MCP clients - #111

Open
shanebarakat wants to merge 5 commits into
mainfrom
fix/kinbase-status-bounded-output
Open

shanebarakat wants to merge 5 commits into
mainfrom
fix/kinbase-status-bounded-output

Conversation

@shanebarakat

@shanebarakat shanebarakat commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What

kinbase_status passed Kinbase's whole status --json document through to the MCP client, including every fact and the full query log. Against the company store (wandercom/sync) that is 92 MB from the CLI and about 192 MB once indented. Claude Code drops the kindex connection on a reply that size, so one call takes every kindex tool down for the rest of the session. An engineer hit this during factory onboarding and his agent reported "the kindex MCP status tool is broken".

read_status now reports facts and events as facts_omitted and events_omitted counts, and adds the query-log window's rows to Kinbase's own query_log_omitted (so it equals query_log_total). If the reply, measured with the same indent=2 the tool sends, is still over 1 MB, the largest remaining section is dropped and named in omitted_for_size. Certification, the other counts and the open Unknowns are unchanged. The kinbase_status docstring now says it returns counts and points to kinbase_explain for records. read_status has no other caller.

Verification

  • Real store, wandercom/sync: reply goes from 191,821,657 bytes to 210,941 bytes.
  • Reproduced the drop by calling kinbase_status from Claude Code (connection closed, kindex server gone); the same call over raw stdio returns, so the size is the cause.
  • Tests: test_read_status_reports_bulk_lists_as_counts, test_read_status_drops_the_largest_section_past_the_size_bound and test_read_status_bound_is_measured_as_the_tool_sends_it (fails on compact measurement, passes with indented). Full suite: 4961 passed, 4 skipped; package byte-compiles on Python 3.10.

Not changed

kinbase status --json itself still emits everything; the CLI has no transport limit. Unknowns (~135 KB here) are kept as-is.


See it in action
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@adaptcom adaptcom Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confidence Score: 5/5

Summary

Bounds kinbase_status MCP replies: facts/events/query-log become *_omitted counts and oversize sections are dropped and named, measured with the indent=2 the tool sends. Low risk; 107 kinbase and mcp_lite tests pass.

Important Files Changed

File Overview
src/kindex/kinbase.py read_status emits omitted counts and enforces MAX_STATUS_BYTES on indented JSON
src/kindex/mcp_server.py kinbase_status docstring promises counts and omitted_for_size
tests/test_kinbase_acceptance.py Three new tests: counts, largest-section drop, indent-measured bound
CHANGELOG.md Unreleased Fixed entry matches shipped behaviour

Reviewed 528566c...8206359 · ↻ Re-run review · View in Adapt

Comment thread src/kindex/kinbase.py Resolved
Comment thread src/kindex/kinbase.py Resolved
Comment thread src/kindex/kinbase.py Resolved
Comment thread CHANGELOG.md Resolved
@shanebarakat shanebarakat added the Factory PR opened by the Factory label Nov 9, 2026

@adaptcom adaptcom Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at head de29845 (base main 63aad55; the merge of main is included and touches nothing in this path).

Checked

  • Fresh venv with the kinbase and mcp extras: tests/test_kinbase_acceptance.py 59/59, the 10 kinbase tests in tests/test_mcp_lite.py pass. Disabling the size loop fails test_read_status_drops_the_largest_section_past_the_size_bound, so the bound is pinned.
  • _query only ever returns a dict (refusal envelopes included), so the new status.get/pop calls are safe on every path; a refusal document has no list values and passes through untouched.
  • query_log_omitted after dropping the window equals query_log_total, matching Kinbase's own window-plus-counts shape. CI test green on this head.

One item from the first review (it was in the review body, not a thread, so it was not part of the resolved set) is still open, inline below. Nothing else new; the compact-vs-indent=2 measurement gap is already noted in the other thread.

Comment thread src/kindex/kinbase.py Resolved
@shanebarakat

Copy link
Copy Markdown
Contributor Author

@adaptcom review

kinbase status --json carries every fact and the full query log. Against the
company store that is ~190 MB once indented, and Claude Code drops the kindex
connection on it, taking every kindex tool down for the session. Report the
three bulk lists as counts; certification, counts and Unknowns are unchanged.
facts and events become facts_omitted and events_omitted, distinct from
Kinbase's own event_count and trusted_fact_count. The query-log window's
rows are added to Kinbase's query_log_omitted instead of a count that read
as a total. Past 1 MB the largest remaining section is dropped and named in
omitted_for_size, so a list outside the three known ones cannot reproduce the
dropped connection.
kinbase_status replies with json.dumps(indent=2), roughly twice the compact
size the 1 MB bound was measured on, so a reply could reach about 2 MB before
anything was dropped. Measure the indented form.
@shanebarakat
shanebarakat force-pushed the fix/kinbase-status-bounded-output branch from 7909f2b to 6bdbdb3 Compare November 17, 2026 23:27
@shanebarakat

Copy link
Copy Markdown
Contributor Author

Re the finding in #111 (review) (kinbase.py:378, bound measured on compact JSON while kinbase_status replies with indent=2): fixed in 6bdbdb3. read_status now measures json.dumps(status, indent=2), the same form kinbase_status sends (mcp_server.py, return json.dumps(result, indent=2)), so the 1 MB bound applies to the actual reply. test_read_status_bound_is_measured_as_the_tool_sends_it uses a payload that fits the bound compact but not indented; it fails on the old measurement and passes now.

Also rebased onto main (0.54.2). The only conflict was CHANGELOG.md: this entry stays under [Unreleased], above the new [0.54.2] section. Main did not touch read_status or kinbase_status.

@shanebarakat

Copy link
Copy Markdown
Contributor Author

@adaptcom review

@shanebarakat

Copy link
Copy Markdown
Contributor Author

Re the finding in #111 (review) (tests/test_kinbase_acceptance.py:667, three blank lines before the next test): fixed in 8206359, one blank line removed. Whitespace only.

@shanebarakat

Copy link
Copy Markdown
Contributor Author

@adaptcom review

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Factory PR opened by the Factory

Development

Successfully merging this pull request may close these issues.

1 participant