Skip to content

Raise the bridge's input limit to fit the server's tool schemas - #15

Open
bablamon wants to merge 3 commits into
prooflinedev:mainfrom
bablamon:fix/input-limit
Open

bablamon wants to merge 3 commits into
prooflinedev:mainfrom
bablamon:fix/input-limit

Conversation

@bablamon

@bablamon bablamon commented Dec 2, 2026

Copy link
Copy Markdown

Problem

The bridge caps an input line at 8,192 bytes. A longer line gets a null-id error and the bridge exits, so the coding agent loses every Proofline tool for the rest of its session until someone restarts it.

That cap is smaller than what the server accepts. ask_codebase allows a 4,000-character question; in a CJK script (3 bytes per character) that is 12,000 bytes, so a question the server would answer never reaches it. The CLI's bridge has the same limit, reported in prooflinedev/cli#144; this npm bridge has it too.

Fix

  • REQUEST_LIMIT is 1 MiB of raw bytes per line, the limit proposed for the CLI's bridge in Raise the MCP bridge's input limit to fit the server's tool schemas cli#145. It fits the longest bounded string in the tool schemas (65,536 characters, at most 768 KiB escaped) with room for the envelope. A call with several large fields, or an unbounded field, can still exceed it, and the README and the constant's comment say so.
  • Past the limit nothing changes. The null-id input error and the exit stay as designed, matching the CLI's choice.
  • frames() copies each piece into a buffer it owns. At 1 MiB, the old copy-on-every-chunk loop would copy a finely split line once per chunk. Collecting views of the chunks instead would keep every chunk alive. An owned buffer grown by doubling keeps copying linear and keeps no input chunk alive, and the line is detached before it is yielded, so nothing extra is held while its request is in flight.

Tests

Test What it checks
a full-length question in a CJK script is relayed and the session continues (new) After the handshake, a 4,000-character question (12,000 bytes) is relayed under its own id, and a ping after it is answered. On main: the bridge exits.
an input line is bounded at 1 MiB (new) A line of exactly 1,048,576 bytes is relayed; one byte more gets the null-id input error, exit 1, and never reaches the server.
a line split into small pieces is relayed whole, and the limit counts the whole line (new) Runs the bridge in-process on input in fixed-size pieces, so the test, not the pipe, decides the split: 7-byte pieces that cut 3-byte characters are reassembled byte for byte, and an over-limit line in 8 KiB pieces is refused before any of it reaches the server.
invalid frames and lifecycle never reach the server (updated) The oversized-frame case uses the new limit.

The test server now joins request bytes before decoding them, so multi-byte characters split across chunks stay intact.

Verification

  • The two stdio tests fail on main and pass on this branch.
  • Mutation checks: moving the limit one byte either way fails a test; checking only the current chunk (end instead of size + end) fails the split-input test; not resetting the size between lines fails 14 tests.
  • npm run check and npm test pass, 16/16, on Windows 11 with Node 24.16.0.
  • End to end against a loopback stand-in server: a 3,600-character CJK question gets its answer, the ping after it is answered, and the bridge exits 0. A 1,048,577-byte line sent in 8 KiB writes is refused, and nothing over 146 bytes reaches the server.
  • Not run here: a symlinked PROOFLINE_MCP_TEST_BIN, since Windows needs Developer Mode for file symlinks. The resolution was checked through a directory junction.

npm run test:package fails on Windows on main as well (spawnSync npm.cmd EINVAL). #13 addresses that, so it isn't changed here.

How I worked

I used Claude Code throughout. I chose this repository because it was the least contested, read the whole bridge, and noticed it shared the 8 KiB limit already reported against the CLI (prooflinedev/cli#144). I reproduced the failure before writing the fix and wrote tests that fail on main. I asked Gemini for an independent security review and tested its claims: three reproduced, but they were low impact, and I left them out of this change. I ran Proofline and CodeRabbit on a review PR in my fork, plus a planted-bug PR scored against an answer key I wrote beforehand. Both caught the planted bug. On the real change they found four valid issues, one of them a regression from my own fix, and I fixed all four.

Proofline review log

Fork review PR: bablamon#1. CodeRabbit reviewed the same PR as a second opinion.

Round Finding Reviewer What I made of it Outcome
1 No findings (quick review) Proofline n/a n/a
2 README promised every schema-valid call fits the cap Proofline Agreed: it fits the longest bounded string, not every call Fixed in f73fe6b, marked fixed
2 frames() yielded before clearing its fragment list, holding them through the HTTP request Proofline Agreed: the generator pauses at yield Fixed in f73fe6b, marked fixed
2 One retained view per input piece while collecting CodeRabbit Agreed: each view keeps its parent chunk alive Fixed in f73fe6b, confirmed resolved
3 The new in-process test failed to load when the test binary is a symlink Proofline Agreed: a regression from f73fe6b Fixed in 0e3cd2c, marked fixed
4 No new findings Proofline, CodeRabbit n/a Merge risk Minimal

Overlap with open PRs

#12, #13 and #14 edit the same files, so they will conflict textually. None of them changes the input limit. #13 also edits frames() to skip blank lines. Whichever lands first, I'll rebase this onto it.

The bridge capped an input line at 8,192 bytes and exited on a longer one,
so the agent lost every Proofline tool for the rest of its session. A
full-length ask_codebase question (4,000 characters) in a CJK script is
12,000 bytes, so a call the server accepts never reached it.

Raise the limit to 1 MiB, the same limit the CLI's bridge proposes for
prooflinedev/cli#144. Past the limit nothing changes: the null-id error and
the exit stay as designed.

Collect a line's chunks and join them once at its newline. At 8 KiB the
per-chunk copy didn't matter; at 1 MiB a line arriving in small chunks
would be copied once per chunk.

The test server now decodes the request body after joining its bytes, so
multi-byte characters split across chunks stay intact.
Review follow-up for the three findings on this pull request.

frames() kept a view of every input chunk in a list until the line ended,
and yielded the joined line before clearing that list. A finely split line
held one view, and its parent chunk, per piece, and the list stayed alive
for the whole HTTP request. Each piece is now copied into a buffer the
bridge owns, grown by doubling so the copying stays linear, and the line is
detached before it is yielded.

The README and the limit's comment said 1 MiB fits any schema-valid call.
It fits the longest bounded string, but a call with several large fields or
an unbounded one can exceed it. Both now describe a raw-byte limit.

Add a test that runs the bridge in-process on input split into pieces of a
fixed size: 7-byte pieces that cut multi-byte characters are reassembled
exactly, and an over-limit line in 8 KiB pieces is refused before any of it
reaches the server. Unlike the stdio tests, it doesn't depend on how the
pipe happens to chunk input.
The in-process test imported bridge.js beside PROOFLINE_MCP_TEST_BIN as
given. When that path is a symlink, such as node_modules/.bin/proofline-mcp
on macOS and Linux, it looked in the link's folder and the whole suite
failed to load. Spawning the binary had always followed the link, so this
was a regression from the previous commit. Resolve the path first.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant