fix: runtime owns resource-limit defaults; client sends only explicit overrides - #42
Merged
Merged
Conversation
…t overrides The default limits (64 MB memory, 5 s CPU, 30 s wall, 10 bridge calls, 16 MiB export/bridge-payload caps, 1 MiB stdio caps) were filled in client-side in `toWireLimits()` before every Run/Precompile/PrefixRun and shipped as concrete values on the wire. The numbers lived in three places that could drift, and any non-TS client had to re-implement them for safe behavior. Each `ResourceLimits` field is now `Optional<u32>` on the wire: the client sends only what the caller explicitly set, absent means "apply the runtime default", and an explicit `0` still means "no limit" (distinct from absent). Rust resolves absent fields from a single set of `DEFAULT_*` constants in `ipc.rs` — the source of truth. `toWireLimits` is deleted; the public `ResourceLimits` fields become optional to match (call sites take `ResourceLimits` instead of `Partial<ResourceLimits>`), and the duplicate wire-local `ResourceLimits` interface is removed in favor of the public one. Effective behavior is unchanged; defaults are identical. Wire-protocol change (limits payload shape): `@iso4/sandbox` and the `@iso4/v8-*` binaries must ship together. Closes #39.
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.
Closes #39.
Problem
The default limits (64 MB memory, 5 s CPU, 30 s wall, 10 bridge calls, 16 MiB export/bridge-payload caps, 1 MiB stdio caps) were filled in client-side in
toWireLimits()before every Run/Precompile/PrefixRun, so the wire always carried concrete values. The same numbers were documented in three places (TS code,types.tsjsdoc, Rust doc comments) that could drift, and any non-TS client had to re-implement them to get safe behavior.Change
The runtime now owns its own safety posture.
ResourceLimitsfield is nowOptional<u32>(per the existingOptional<T>framing convention). The client sends only the fields the caller explicitly set. Absent → runtime applies its default; explicit0→ limit disabled (distinct from absent).ipc.rs): a single set ofDEFAULT_*constants is the source of truth. A newread_resource_limits()reads the eight optionals and resolves any absent field to its default. Downstream (v8.rs,session.rs) is unchanged — the resolved struct keeps the same0 = no limitsemantics.toWireLimits()(the client-side default-filler) is deleted;options.limitsflows straight through. Encoding uses a newwriteOptionalU32.types.ts):ResourceLimitsfields become optional and call sites takeResourceLimitsinstead ofPartial<ResourceLimits>. The@defaultjsdoc is kept and now documents the numbers the runtime fills in (pointing atipc.rsas the source of truth).ResourceLimitsinterface inipc.ts(identical once the public one went optional) is removed;ipc.ts/client.tsimport the public type. Single source of truth.docs/protocol.md§5.2 updated (encoding, per-field defaults column, absent-vs-explicit-0 semantics).Effective behavior for existing callers is unchanged — the defaults are identical.
Notes
@iso4/sandboxand the@iso4/v8-*binaries must ship together; the changeset bumps all five in lockstep. Protocol version not bumped (pre-v1, per repo owner).minor, consistent with the other pending breaking/notable changes this cycle — adjust if you'd rather it bepatch(consumer-visible behavior is unchanged).Verification
cargo testipc suite green, incl. two new tests — absent limits resolve toDEFAULT_*, and an explicit0is preserved (not replaced by the default).@iso4/sandboxsuite454 passed | 1 skippedagainst a freshly-rebuilt native binary (exercises the new optional wire path end-to-end).typecheck,eslint(0 errors on touched files),cargo fmt --checkall clean.