Skip to content

feat(chain): cap JSON-RPC response size before lowering into the guest#309

Open
lgahdl wants to merge 1 commit into
feat/m1-mock-venuefrom
feat/154-chain-response-size-cap
Open

feat(chain): cap JSON-RPC response size before lowering into the guest#309
lgahdl wants to merge 1 commit into
feat/m1-mock-venuefrom
feat/154-chain-response-size-cap

Conversation

@lgahdl

@lgahdl lgahdl commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Closes #154

What

Adds a host-side cap on chain JSON-RPC response bodies so a misbehaving or adversarial node cannot saturate the guest heap via a single large reply.

Changes

  • engine_config.rs: New [limits.chain] TOML section with a response_max_bytes knob (default 1 MiB). Resolver method ModuleLimits::chain_response_max_bytes().
  • host/state.rs: HostState gains chain_response_max_bytes: usize — threaded from config at boot and preserved across restarts.
  • supervisor.rs: Field threaded through LoadedModulebuild_store()HostState construction, at both initial boot and reinstantiation.
  • host/impls/chain.rs: request() applies check_response_cap() after receiving the provider response. Rejection emits a WARN log, increments a dedicated shepherd_chain_response_capped_total metric, and returns ChainError::Fault(InvalidInput). Batch requests inherit the cap via the per-entry request() dispatch path.

Tests

Two new unit tests in host::impls::chain::tests:

  • response_at_cap_is_accepted — body exactly at the cap passes
  • response_over_cap_returns_invalid_input — body one byte over the cap returns InvalidInput

Config

[limits.chain]
response_max_bytes = 1_048_576  # default; 1 MiB

🤖 Generated with Claude Code

https://claude.ai/code/session_01TfSsJPYDQ1GQGbnSVFxATx

@lgahdl lgahdl requested a review from mfw78 as a code owner July 9, 2026 21:41
@lgahdl lgahdl changed the base branch from dev/m1 to develop July 9, 2026 21:59
@lgahdl lgahdl changed the base branch from develop to feat/m1-mock-venue July 9, 2026 22:01
@lgahdl lgahdl force-pushed the feat/154-chain-response-size-cap branch from a8bb9ba to 4acf3ed Compare July 9, 2026 22:03
#154)

Adds a configurable `[limits.chain] response_max_bytes` knob (default
1 MiB) that is enforced host-side in `chain::request()` before the
response string is copied into the guest heap. Oversized responses are
rejected with an `InvalidInput` fault, a `WARN` log, and a dedicated
`shepherd_chain_response_capped_total` metric.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TfSsJPYDQ1GQGbnSVFxATx
@lgahdl lgahdl force-pushed the feat/154-chain-response-size-cap branch from 4acf3ed to fa79d01 Compare July 9, 2026 22:04
@mfw78 mfw78 added the pr-train Part of the current stacked PR train; lands in sequence, do not merge out of order. label Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-train Part of the current stacked PR train; lands in sequence, do not merge out of order.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants