[GH-ISSUE #1053] [Bug] MCP serialization fails after successful full-ASAR analysis #385

Closed
opened 2026-10-15 18:24:33 +00:00 by bsakaguchi · 3 comments
Owner

Originally created by @N0zoM1z0 on GitHub (Oct 8, 2026).
Original GitHub issue: https://github.com/morluto/rea/issues/1053

Before submitting

  • Searched related issues and PRs, including #623, #723, #746 and #1050.
  • Removed credentials, private paths and target source code.

Area

MCP or agent integration.

Observed behavior

During full-ASAR verification for #746, the real stdio server completed analyze_javascript_application on Notion 7.6.1 and emitted successful terminal progress, but its MCP response failed with Invalid string length. The tool result was marked as an error; the complete analysis was not delivered.

The pinned MCP client SDK was used with a deliberately enlarged 1 GiB read buffer. This distinguishes the observed server serialization failure from the separate default 10 MiB client framing limit. Combined client/server peak RSS was 2,824,601,600 bytes and elapsed time was 146.905 seconds. There was no external timeout or memory stop.

The full Obsidian 1.12.7 CLI result also demonstrates the representation problem: its complete compact Evidence document is 429,165,771 bytes. That CLI output passed streaming JSON validation. This is a CLI observation; a successful full Obsidian MCP transfer was not observed.

Reproduction

  1. Use a development build containing the file-local JavaScript analysis improvements being prepared for #746. The source base is 8d5c88f17cde4ab4fa54c5142f0a45e612619a53; the performance changes are now in #1055 at head 74a55dbda4552dbbe48027385ac3b0031879ae08.
  2. Start the actual stdio server with Node 24.18.0, a 1.5 GiB V8 heap, and a pinned SDK 2.3.1 client.
  3. Connect once, list the canonical tools, and call:
{
  "name": "analyze_javascript_application",
  "arguments": { "input_path": "<caller-selected ASAR>", "format": "asar" }
}
  1. On the shipped Notion artifact below, observe file progress and successful terminal analysis progress followed by an error result containing Invalid string length.

Expected behavior

A completed analysis should be consumable through a documented MCP workflow. If a complete response cannot fit the transport representation, REA should identify that constraint and provide a usable recovery rather than returning an unqualified JavaScript exception. Preserve complete Evidence, exact provenance, caller-selected inputs, and truthful coverage.

Runtime and platform

Node 24.18.0, Linux x64, MCP client/server SDK 2.3.1. Two CPU affinity and below-normal priority. Server heap: 1.5 GiB. Combined client/server RSS guard: 3 GiB. Host memory reserve: 2 GiB. Request deadline: 240 seconds. These are validation conditions, not proposed product limits.

Target and artifact context

  • Notion 7.6.1 app.asar: 8,903,750 bytes; SHA-256 97c41bc14fc0ea8c91cd34f502660963dfdf294d5eb35165ccac9d30963069d4.
  • Official Obsidian 1.12.7 ASAR: 24,060,763 bytes; SHA-256 2b2483b2e1246772e0d25367ec055cbc5047ea2f0091b667c35656678f86d712. Official release artifact.

Both targets were parsed as inert text. No application code was executed.

Interface

MCP.

Earliest failure stage

Transport or result projection.

Relevant output or evidence

Analysis progress: terminal success
Tool response: isError = true
Text: Invalid string length

Analysis or suspected cause

Source inspection of toolResult.ts shows that the same normalized result appears in result and evidence.normalized_result. The candidate is then embedded in both JSON text and structured content. This causes multiple serialized representations of the full payload. The observed server exception establishes that an actual string representation exceeded its limit. UTF-8 output byte counts and Node's UTF-16 code-unit ceiling are different measurements; byte counts alone do not prove the exact stage or threshold. The repeated representations are a source-derived explanation that should be confirmed with per-stage code-unit/allocation measurements. Increasing the client's buffer does not remove the server's single-string constraint.

The result representation also contributes substantial memory and transfer cost before reaching that hard failure. Exact costs should be measured at analysis, Evidence retention, serialization, transport and client parsing separately.

Typed outcome or recovery expected

Evaluate the retained-Evidence and caller-selected view work in #1050, with #723 covering repeated representations. Selected content must have an honest relationship to the complete Evidence record; do not reuse a complete-record digest for different projected content. Keep useful facts inline and expose actual limits and unknowns.

Additional context

This is separated from the #746 algorithm and allocation fix by explicit scope choice: that patch preserves the existing public return contract. This issue tracks the observed hard MCP failure; #1050 tracks the broader result-selection capability. Acceptance should cover real large ASAR analysis, ordinary client settings, invalid/stale references, CLI/MCP equivalence, exact identities, cancellation and cleanup.

Originally created by @N0zoM1z0 on GitHub (Oct 8, 2026). Original GitHub issue: https://github.com/morluto/rea/issues/1053 ## Before submitting - [x] Searched related issues and PRs, including #623, #723, #746 and #1050. - [x] Removed credentials, private paths and target source code. ## Area MCP or agent integration. ## Observed behavior During full-ASAR verification for #746, the real stdio server completed `analyze_javascript_application` on Notion 7.6.1 and emitted successful terminal progress, but its MCP response failed with `Invalid string length`. The tool result was marked as an error; the complete analysis was not delivered. The pinned MCP client SDK was used with a deliberately enlarged 1 GiB read buffer. This distinguishes the observed server serialization failure from the separate default 10 MiB client framing limit. Combined client/server peak RSS was 2,824,601,600 bytes and elapsed time was 146.905 seconds. There was no external timeout or memory stop. The full Obsidian 1.12.7 CLI result also demonstrates the representation problem: its complete compact Evidence document is 429,165,771 bytes. That CLI output passed streaming JSON validation. This is a CLI observation; a successful full Obsidian MCP transfer was not observed. ## Reproduction 1. Use a development build containing the file-local JavaScript analysis improvements being prepared for #746. The source base is `8d5c88f17cde4ab4fa54c5142f0a45e612619a53`; the performance changes are now in #1055 at head `74a55dbda4552dbbe48027385ac3b0031879ae08`. 2. Start the actual stdio server with Node 24.18.0, a 1.5 GiB V8 heap, and a pinned SDK 2.3.1 client. 3. Connect once, list the canonical tools, and call: ```json { "name": "analyze_javascript_application", "arguments": { "input_path": "<caller-selected ASAR>", "format": "asar" } } ``` 4. On the shipped Notion artifact below, observe file progress and successful terminal analysis progress followed by an error result containing `Invalid string length`. ## Expected behavior A completed analysis should be consumable through a documented MCP workflow. If a complete response cannot fit the transport representation, REA should identify that constraint and provide a usable recovery rather than returning an unqualified JavaScript exception. Preserve complete Evidence, exact provenance, caller-selected inputs, and truthful coverage. ## Runtime and platform Node 24.18.0, Linux x64, MCP client/server SDK 2.3.1. Two CPU affinity and below-normal priority. Server heap: 1.5 GiB. Combined client/server RSS guard: 3 GiB. Host memory reserve: 2 GiB. Request deadline: 240 seconds. These are validation conditions, not proposed product limits. ## Target and artifact context - Notion 7.6.1 `app.asar`: 8,903,750 bytes; SHA-256 `97c41bc14fc0ea8c91cd34f502660963dfdf294d5eb35165ccac9d30963069d4`. - Official Obsidian 1.12.7 ASAR: 24,060,763 bytes; SHA-256 `2b2483b2e1246772e0d25367ec055cbc5047ea2f0091b667c35656678f86d712`. [Official release artifact](https://github.com/obsidianmd/obsidian-releases/releases/download/v1.12.7/obsidian-1.12.7.asar.gz). Both targets were parsed as inert text. No application code was executed. ## Interface MCP. ## Earliest failure stage Transport or result projection. ## Relevant output or evidence ```text Analysis progress: terminal success Tool response: isError = true Text: Invalid string length ``` ## Analysis or suspected cause Source inspection of [toolResult.ts](https://github.com/morluto/rea/blob/8d5c88f17cde4ab4fa54c5142f0a45e612619a53/src/server/toolResult.ts) shows that the same normalized result appears in `result` and `evidence.normalized_result`. The candidate is then embedded in both JSON text and structured content. This causes multiple serialized representations of the full payload. The observed server exception establishes that an actual string representation exceeded its limit. UTF-8 output byte counts and Node's UTF-16 code-unit ceiling are different measurements; byte counts alone do not prove the exact stage or threshold. The repeated representations are a source-derived explanation that should be confirmed with per-stage code-unit/allocation measurements. Increasing the client's buffer does not remove the server's single-string constraint. The result representation also contributes substantial memory and transfer cost before reaching that hard failure. Exact costs should be measured at analysis, Evidence retention, serialization, transport and client parsing separately. ## Typed outcome or recovery expected Evaluate the retained-Evidence and caller-selected view work in #1050, with #723 covering repeated representations. Selected content must have an honest relationship to the complete Evidence record; do not reuse a complete-record digest for different projected content. Keep useful facts inline and expose actual limits and unknowns. ## Additional context This is separated from the #746 algorithm and allocation fix by explicit scope choice: that patch preserves the existing public return contract. This issue tracks the observed hard MCP failure; #1050 tracks the broader result-selection capability. Acceptance should cover real large ASAR analysis, ordinary client settings, invalid/stale references, CLI/MCP equivalence, exact identities, cancellation and cleanup.
bsakaguchi 2026-10-15 18:24:33 +00:00
Author
Owner

@N0zoM1z0 commented on GitHub (Oct 8, 2026):

The algorithm/allocation work is now ready in #1055. Its final full Notion CLI result independently validates as complete JSON: 336,236,132 bytes (approximately 321 MiB), including 100,000 semantic nodes and 67,576 unknowns. Duplicating that normalized payload in result and evidence.normalized_result already exceeds this runtime's ordinary single-string representation before text/structured repetition is added. Full Obsidian output also validates at approximately 409 MiB. Both CLI workflows pass on Linux and Windows, with equal graph IDs and counts across platforms.

The real stdio Notion response failure described above remains unresolved by #1055: public transport/return contracts are intentionally preserved in that patch. Continue the compatible retained-Evidence/view design under #1050, and validate the completed investigation through actual client delivery as well as analysis success.

<!-- gh-comment-id:6055420391 --> @N0zoM1z0 commented on GitHub (Oct 8, 2026): The algorithm/allocation work is now ready in #1055. Its final full Notion CLI result independently validates as complete JSON: 336,236,132 bytes (approximately 321 MiB), including 100,000 semantic nodes and 67,576 unknowns. Duplicating that normalized payload in `result` and `evidence.normalized_result` already exceeds this runtime's ordinary single-string representation before text/structured repetition is added. Full Obsidian output also validates at approximately 409 MiB. Both CLI workflows pass on Linux and Windows, with equal graph IDs and counts across platforms. The real stdio Notion response failure described above remains unresolved by #1055: public transport/return contracts are intentionally preserved in that patch. Continue the compatible retained-Evidence/view design under #1050, and validate the completed investigation through actual client delivery as well as analysis success.
Author
Owner

@N0zoM1z0 commented on GitHub (Oct 8, 2026):

Measurement clarification: the reported sizes are UTF-8 output bytes, while Node's single-string limit is measured in UTF-16 code units. Those quantities should not be equated. The real Invalid string length response is observed; repeated result/Evidence/text/structured representations are the source-derived explanation. The follow-up should measure code units and allocations at each serialization stage to identify the exact failed representation. This clarification leaves the CLI validations and observed MCP failure unchanged.

<!-- gh-comment-id:6055610686 --> @N0zoM1z0 commented on GitHub (Oct 8, 2026): Measurement clarification: the reported sizes are UTF-8 output bytes, while Node's single-string limit is measured in UTF-16 code units. Those quantities should not be equated. The real `Invalid string length` response is observed; repeated `result`/Evidence/text/structured representations are the source-derived explanation. The follow-up should measure code units and allocations at each serialization stage to identify the exact failed representation. This clarification leaves the CLI validations and observed MCP failure unchanged.
Author
Owner

@morluto commented on GitHub (Oct 8, 2026):

Verified fixed on main (7a7460f0). a1ed4232 (Refs #1065, #1053) plus 0639a541 and b3f1b4e8 route oversized success/error results through budgeted toolResultEncoding with typed resource_constraint + evidence retention instead of unqualified Invalid string length. src/server/toolResultEncoding.test.ts passes (5/5). Closing per audit; #1050 remains open for general compact views.

<!-- gh-comment-id:6071368941 --> @morluto commented on GitHub (Oct 8, 2026): Verified fixed on main (7a7460f0). a1ed4232 (Refs #1065, #1053) plus 0639a541 and b3f1b4e8 route oversized success/error results through budgeted toolResultEncoding with typed resource_constraint + evidence retention instead of unqualified Invalid string length. src/server/toolResultEncoding.test.ts passes (5/5). Closing per audit; #1050 remains open for general compact views.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#385
No description provided.