fix: prevent 414 error and error log flooding#3
Open
mengfanbo123 wants to merge 2 commits into
Open
Conversation
- Truncate search query to 500 chars in both MCP and OpenCode plugin clients to prevent URL length exceeding nginx default 8KB limit - Add safeErrorMessage() in MCP client to truncate HTTP error response body to 200 chars, preventing error logs from filling the terminal - Add shortError() in MCP tools.ts to truncate all catch block error messages - Add sanitizeContent() to strip XML tags and truncate large content before sending to server (max 30000 chars) - Truncate firstMessage in OpenCode plugin autoRecallHook to 500 chars Root cause: OpenCode plugin's autoRecallHook sends entire user messages (including subagent prompts) as search query parameter, which after URL encoding exceeds nginx's large_client_header_buffers limit, causing 414. The MCP client then includes the full HTTP error response body in the Error message, which floods the OpenCode terminal window.
…uffer CJK chars URL-encode ~9x: 500 chars → ~4500 bytes > nginx 4K buffer. 200 chars → ~1800 bytes, safe under nginx default 4K and 16K.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two critical bugs that cause the omem MCP server and OpenCode plugin to fail when memory content is large:
Bug 1: 414 Request-URI Too Large
The
autoRecallHookin the OpenCode plugin sends the entire user message (which can include long subagent prompts) as theqquery parameter in the search URL. After URL encoding, this exceeds nginx's defaultlarge_client_header_bufferslimit (8KB), causing HTTP 414 errors.Fix: Added
MAX_QUERY_LENGTH = 500constant andtruncateQuery()function in both clients. All search queries are now truncated to 500 characters before making the API request. Also addedsanitizeContent()to strip XML tags from content before sending, reducing payload size.Bug 2: Error log flooding the terminal
When an HTTP error occurs, the MCP client includes the full response body in the Error message. Combined with tools.ts catch blocks that propagate this, a single 414 error can dump hundreds of KB into the OpenCode terminal window, making it unusable.
Fix:
safeErrorMessage()in MCP client that truncates error response bodies to 200 charactersshortError()in tools.ts that truncates all catch block error messages to 200 charactersBug 3: Large content causing server errors
Large content strings sent to the store/ingest APIs can cause embedding failures (500 errors).
Fix: Added
MAX_CONTENT_CHARS = 30000andsanitizeContent()to strip XML tags and truncate content before sending.Files Changed
plugins/mcp/src/client.ts— Added query truncation, content sanitization, error message truncationplugins/mcp/src/tools.ts— AddedshortError()for all 14 catch blocksplugins/opencode/src/client.ts— Added query truncation and content sanitizationplugins/opencode/src/hooks.ts— TruncatedfirstMessagein autoRecallHook to 500 charsplugins/mcp/package.json— JSON formatting onlyplugins/opencode/package.json— JSON formatting onlyTesting