fix(mcp): preserve session results within the response limit - #1352
Merged
Merged
Conversation
… readable A durable session's ContextCompactionRecord (summary / retainedTail / details.modifiedFiles) grows without bound; on a long session it alone exceeds MAX_RESULT_CHARS (512 KiB), so boundMcpResult replaced the WHOLE answer with a half-JSON preview and pi_session_get could never reach messages — external clients (e.g. the phone) reported a generic failure and the session was unopenable. Project the compaction record to the compact control-plane shape the tools contract promises (createdAt + details.generation) before bounding, so the transcript survives. Only the external MCP answer is projected; the desktop's own session detail is untouched. Ref: mocode #495 (client-side honest error) / mocode #497 (this root fix).
Apply the compaction projection only when session/get already exceeds the MCP result budget, then recheck the projected answer before truncating. This keeps the original details of ordinary sessions intact while allowing oversized transcript responses to survive. Exercise the real authenticated tools/call response for oversized and under-limit sessions so the public MCP boundary proves both behaviors.
The test now exercises the authenticated local MCP JSON-RPC boundary for large and small session/get responses. Keep the E2E plan accurate about that coverage and the remaining full Electron-to-Host qualification.
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
Supersedes #1346. Preserve the contributor's fix and make compaction projection conditional on the serialized
pi_session_getresult exceeding the MCP response limit. Under-limit responses keep the complete compaction record; oversized responses retry after projecting the large fields, and fall back to the bounded preview only if the projected payload still exceeds the limit.Adds coverage through the authenticated MCP HTTP
tools/callboundary for both oversized and under-limit session results, alongside the bounded-result helper cases. Updates the English and Chinese protocol and E2E specifications.Validation
node --test apps/desktop/test/mcp-control.test.mjs— 10/10 passednode scripts/check-locales.mjs— passednode scripts/check-docs.mjs— passednode scripts/check-pr-base-main.mjs— passed againstorigin/mainate659750486fdgit diff --check— passedThe shared local desktop dependency tree cannot provide a reliable full TypeScript run from this worktree; GitHub CI is required before landing.