Skip to content

fix(context-mcp): cap the context socket's line buffer - #138

Merged
zooidbot merged 1 commit into
mainfrom
fix/137-context-socket-line-cap
Oct 13, 2026
Merged

zooidbot merged 1 commit into
mainfrom
fix/137-context-socket-line-cap

Conversation

@zooidbot

Copy link
Copy Markdown
Collaborator

Closes #137

Repro: connect to an agent context socket and send bytes with no newline; the data handler in startDaemonSocketServer appends to buf forever. Reproduced as a unit test: before the fix the connection stays open past the 2s deadline.

Fix: after draining complete lines, if the unterminated remainder exceeds MAX_LINE_LENGTH (1 MiB, counted in characters of the utf8-decoded string) the server drops the buffer, replies {ok:false,error:"request line too long"} and closes the connection. Lines under the cap are untouched. Param validation stays with #136.

Tests: new line length cap tests in daemon-socket.test.ts (oversized line closes with error; a near-cap line still gets served). The first fails without the fix.

Knowledge impact: none

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@zooidbot zooidbot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewed against #137's acceptance criteria: all three are met. No blocking findings.

  • The cap check runs on every data event after the line loop. The handler is async, so a later chunk can arrive while an earlier handleLine is still awaiting. That later event still runs the check, so the buffer stays bounded at the cap plus one chunk. Good.
  • Counting characters instead of bytes (≤ ~3 MiB worst case per connection) is fine for this issue.
  • Non-blocking, out of scope: the number of connections per socket is still unbounded. The validation work in #136 is the natural place to look at that if it matters.

Merging once CI is green.

🤖 Generated with Claude Code

@zooidbot
zooidbot merged commit ee90b1a into main Oct 13, 2026
2 checks passed
@zooidbot
zooidbot deleted the fix/137-context-socket-line-cap branch October 13, 2026 21:04
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.

context socket: unbounded line buffer lets an agent exhaust daemon memory

1 participant