fix(runtime): strip module shebang, stream large http responses, reject oversized vm.fetch by content-length#130
Merged
Conversation
…ct oversized vm.fetch by content-length - v8-runtime: strip a leading #!shebang in build_module_source so the patched Claude agent SDK (which begins with #!/usr/bin/env node) parses in guest V8 instead of SyntaxError-crashing the adapter on session/new (host Node strips it; the guest loader did not). - v8-bridge: ServerResponseBridge streams a single res.end(body) to the connection socket in bounded slices (incremental byteLength) instead of buffering the whole body + its serialize/transmit copies, which tripped the isolate heap-limit OOM guard on multi-MB responses. Socket-backed path only; loopback http unchanged. - sidecar: vm.fetch rejects a response whose declared Content-Length exceeds VM_FETCH_BUFFER_LIMIT_BYTES before stalling on a body it cannot stream through the bounded kernel socket buffer; keeps the per-VM configured-limit payload check intact. - limits-inventory: classify DEFAULT_HEAP_LIMIT_MB (policy) and MAX_V8_USERLAND_CODE_BYTES (invariant). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Three runtime fixes (plus a limits-inventory classification) needed to unblock Claude agent sessions and large HTTP responses in the VM.
build_module_sourcenow strips a leading#!shebang line before compiling a module. The patched Claude agent SDK begins with#!/usr/bin/env node; host Node strips it, but the guest V8 module loader did not, so the adapterSyntaxError-crashed onsession/new. Adds a unit test (strip_leading_shebang_matches_node).ServerResponseBridgenow streams a singleres.end(body)on a socket-backed server to the connection socket in 256 KiB slices (computing byte length incrementally), instead of buffering the whole body plus its serialize/transmit copies — which tripped the per-isolate heap-limit OOM guard on multi-MB responses. Socket-backed path only; loopback HTTP is unchanged.parse_kernel_http_fetch_responserejects a response whose declaredContent-LengthexceedsVM_FETCH_BUFFER_LIMIT_BYTESbefore stalling on a body the guest cannot stream through the bounded 4 MiB kernel socket buffer before the request deadline. Uses the hard wire limit, so smaller-but-over-a-configured-limit responses still deliver and hit the existing payload-size check.DEFAULT_HEAP_LIMIT_MB(policy, wired toVmLimits.js_runtime.v8_heap_limit_mb) andMAX_V8_USERLAND_CODE_BYTES(invariant).Testing
cargo clippy --workspace --all-targets -- -D warnings✅cargo fmt --check✅limits_audit2/2 ✅strip_leading_shebang_matches_node✅vm_fetch_kernel_tcp_*tests + http-server tests (incl. normal deliveryaae) ✅ —aaioversized-rejection now passes, no regressions