Repository navigation
feat(environment): serve an environment manifest as a replay environment - #4975
Conversation
Add rea mcp --http [--host] [--port]: the same server rea speaks over stdio, served over MCP Streamable HTTP on a loopback listener by default, using the SDK's web-standard transport already in the pinned @modelcontextprotocol/server behind a small node:http bridge. One client and one session at a time; DELETE ends the session without running provider teardown, a new client's initialize replaces a session left open, foreign Host headers are refused on loopback binds, and shutdown is signals-only. Stdio stays the default and registered transport; server.json and client registrations are unchanged. Refs morluto#4933 Co-Authored-By: Claude Fable 5.1 <[email protected]>
2457457 to
0d2a474
Compare
…nd shutdown Addresses the automated review findings on the PR: refuse requests once the session slot is closed and join an arming initialize during shutdown; retry failed close stages instead of replaying the rejection; classify loopback binds by address class and add the bind's own hostname to the Host and Origin allowlist; let only a POST with the streamable headers replace an open session; announce the bound URL at every log level; route `mcp -h --http` to the HTTP entry. Co-Authored-By: Claude Fable 5.1 <[email protected]>
0d2a474 to
fec5f44
Compare
…server Addresses the second automated review round: a sessionless POST replaces a session only when its media type proper is application/json, and the server instance is created after the listener binds so a bind failure leaves nothing to clean up and a factory failure releases the listener. Co-Authored-By: Claude Fable 5.1 <[email protected]>
fec5f44 to
0dfc344
Compare
…ailures out of onerror Addresses the third automated review round: loopback is classified from the address the listener bound with the configured name added to the Host and Origin allowlist; scoped IPv6 literals are refused before binding and a URL that cannot be formed closes the listener; listener errors reach onerror only after a successful bind; the MCP runtime keeps its factory owner as the single owner of instance cleanup through `closeInstance: false`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…wn failed Addresses the fourth automated review round: a sessionless POST replaces a session only when its Accept header lists application/json and text/event-stream as exact media ranges, and a session whose transport shutdown rejected stays owned so the next close retries it. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Replaces a comma expression left by the previous commit with plain statements and moves the port release into a small function, so the listener body stays within the lint limits without changing behaviour. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…and keep every Set-Cookie Addresses the fifth automated review round: the instance's shutdown hook runs exactly once even when the listener closes without a live session; the initialize probe no longer awaits cancelling its cloned body, which would wait for the original request to drain; and the node:http bridge passes repeated Set-Cookie values through as an array. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…cleanup Addresses the sixth automated review finding: SIGINT and SIGTERM are recorded from the moment the HTTP entry starts, the lifecycle owner acts on a recorded signal as soon as it registers, and a second signal during startup exits at once. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…mal return Addresses the follow-on finding on the signal latch: the HTTP entry now owns its exit status, so a 0 returned by startup after a recorded signal keeps the signal's 130 or 143 while a real failure still wins; a process test sends the signal as the listening line appears. Co-Authored-By: Claude Fable 5.1 <[email protected]>
… read Addresses the eighth automated review finding: a refused Host or Origin, an unknown route or the startup 503 answered a POST while its body stayed unread on the paused bridged stream; such replies now carry Connection: close so an unread upload cannot keep a socket open. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…d body Addresses the ninth automated review round: a method Fetch refuses, such as TRACE, is answered with 405 instead of escaping the request guard; the unread-body decision now comes from the incoming message's own body declaration, so a GET or HEAD carrying a body closes too; and the regression uses a keep-alive client and checks that the socket actually closes. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Picks up upstream's test-runner configuration and the command-finalization test fixes so the fork lane stops failing on unrelated flaky shards. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…d keep failed hooks retryable Addresses the tenth automated review round: the bridge joins an origin-form request target onto the listener's origin so a network-path target stays a path and absolute-form targets are refused; only a lone initialize can replace an open session; and the shutdown hook records completion only after it returns, so a hook that threw stays eligible for the next close. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Addresses the eleventh automated review finding: dot segments such as `/public/../mcp` were canonicalized to `/mcp` before routing. The bridge now refuses any target whose path differs after parsing, so routing sees exactly the path the client sent. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…regression The previous commit added a second successful route call to the regression but left the single-observation assertion in place. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…to its end Addresses the twelfth automated review finding: bodyUsed only means a body was disturbed, so a route that read one chunk of an upload left the rest paused on a keep-alive socket. The close decision now follows the incoming message's end of stream. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…uard Addresses a thirteenth automated review finding: `application/json;q=0` explicitly refuses JSON, so it no longer counts toward the exact Accept ranges a session takeover requires. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eners A browser on the listener's own page sends Origin with the scheme and the bound port. The SDK validator parses the Origin and compares its hostname with the loopback allowlist, so the port never takes part; this test keeps that true for the MCP endpoint and for composed routes, under 127.0.0.1 and localhost. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in the merged environment manifest view so this branch is tested against current main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
closeAllConnections() ran before close(), so a connection accepted in between missed the forced-close pass and close() could wait for its request timeout. close() now starts first and closeAllConnections() follows immediately, as Node documents. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A route answering HEAD with a body, such as a reused event stream, was piped until EOF although Node discards the bytes, so an endless stream held the request open. A HEAD reply now ends after the headers and cancels whatever body the route attached. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… takeover A comma or semicolon inside a quoted parameter is not a separator, so a header such as application/json;note=", text/event-stream;x=1" holds a single range. The takeover guard split on every comma and found a text/event-stream range the client never sent. Ranges and their parameters are now split outside quoted strings, and q is read from the parsed parameters. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cancelling one branch of a teed body settles only after its sibling is consumed or cancelled, so a HEAD route answering with a clone of a live cached stream left the request handler pending indefinitely. The reply ends after the headers and the cancellation is started, not awaited. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ing body cancellation Readable.fromWeb destroys its source on a client disconnect and waits for the body's cancel(), which for one branch of a teed body settles only when the sibling is consumed or cancelled, so the pipeline never returned. The body is now copied chunk by chunk with backpressure; when the reply closes the copy returns and the cancellation is started, not awaited. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sed before the route resolved The copy raced every read against one pending close promise, which piled up reactions on long streams, and it only noticed a close that happened after it started, so a route resolving after its client left waited forever on an idle body. One close listener now cancels the reader, which also ends a pending read; a reply that is already destroyed cancels at once; drain waits remove their listeners. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The environment-manifest view projects HAR captures only, and replay reads HAR's response fields, but the loader accepted any web network capture format. A hand-paired SAZ, mitmproxy or qlog capture would load and replay empty bodies; it is now refused as invalid input naming the format, before the pair is checked. Co-Authored-By: Claude Opus 5.5 <[email protected]>
On Windows, Node's child.kill() terminates the child outright for SIGINT as well as SIGTERM, so the earlier switch to SIGINT there could not observe a graceful shutdown either. The test now sends SIGTERM and expects 143 on POSIX hosts and is skipped on Windows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@codex review Please review published head |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ad52275d22
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…bound described paths Replay parses a JSON body only when every integer survives exactly; a body with an integer outside JavaScript's safe range, such as an id of 9007199254740993, is returned as its recorded text instead of with other digits. A SIGINT or SIGTERM that arrives while environment-serve reads and authenticates its files now ends startup with a cancelled result before the listener binds, rather than binding and stopping at once. A tool description cuts a captured path longer than 1 KiB at a character boundary and points to the manifest Evidence, matching the list sample budget; the manifest keeps the full path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 130bc4326a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…keep empty queries A captured query name longer than 64 characters is advertised under a short, collision-safe `query_<n>` alias, with the captured name sampled in its description; replay maps the alias back, and the manifest keeps the full name. Replies cut `recorded_path` and `recorded_query` to 1 KiB and set `recorded_line_truncated`, so a megabyte-scale recorded URL is not echoed into every reply; selection still uses the full recorded line. An explicit empty query (`/api?`) keeps its `?` in `recorded_query`. The shared WHATWG URL parser reports it as "", like no query, so the replay exchange reads the delimiter from the recorded URL instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b217929a81
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
# Conflicts: # docs/agent-environments.md # docs/specs/agent-environments/environment-serve/spec.md # src/application/environment/environmentReplay.ts # src/application/environment/environmentTools.ts # src/cli/environmentCommands.ts
|
@codex review Please review the follow-up head |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8c46c5b08b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
@codex review Please retry review of |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a215627ec7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| manifest: EnvironmentManifest, | ||
| records: readonly WebNetworkCaptureRecord[], | ||
| ): ReadonlyMap<number, RecordedExchange> => { | ||
| const byOrdinal = new Map(records.map((record) => [record.ordinal, record])); |
There was a problem hiding this comment.
Index only capture records cited by tools
When a parent capture contains many records that no manifest tool cites (for example, records from other origins or excluded assets), this materializes both a pair array and a Map entry for every record even though exchanges retains only cited ordinals. For large admitted captures, that avoidable full-capture index can create a substantial startup heap spike; collect the cited ordinals first and populate the lookup while scanning only matching records.
AGENTS.md reference: AGENTS.md:L51-L52
Useful? React with 👍 / 👎.
| const supplied = new Map<string, string>(); | ||
| for (const [name, argument] of queryArguments) { | ||
| const value = args[argument]; | ||
| if (typeof value === "string") supplied.set(name, value); | ||
| } |
There was a problem hiding this comment.
Hoist query argument extraction out of exchange scoring
Since scoreExchange is invoked once for every cited record, a tool with many optional query names and many retained records walks the entire argument map and allocates a new supplied map for every candidate, turning one replay into O(records × query names) work even when the caller supplies a single value. Derive the supplied query arguments once in selectReplayExchange and reuse them across candidate scores.
AGENTS.md reference: AGENTS.md:L48-L52
Useful? React with 👍 / 👎.
| for (const [name, value] of iterateUrlQueryParameters( | ||
| exchange.query ?? "", | ||
| )) { |
There was a problem hiding this comment.
Filter unselected query values before decoding
When the supplied query appears after an unrelated parameter with a large percent-encoded value, calling iterateUrlQueryParameters without its selected map makes the generator decode that unrelated value into a full temporary string for every candidate exchange. This defeats the bounded streaming path and can spike heap under concurrent replay; pass supplied as the iterator's second argument so only requested values are decoded.
AGENTS.md reference: AGENTS.md:L51-L52
Useful? React with 👍 / 👎.
Summary
Adds
rea environment-serve <manifest.json> --evidence <capture.json> [--host H] [--port N]: retained-capture replay tools over MCP, the discovery card at/.well-known/agent-env.json, and the/agentenvJSON-RPC stub. No captured application executes; the default REA MCP transport remains stdio. Refs #4933; uses merged #4955.Final head:
a215627ec773074716a75355637ebb98dca0fa37. Original author history and initial readiness declaration are retained, including authorb217929a; integration started from main and was updated through1b3ac942.Problem and expected behavior
A manifest previously had no running replay surface. The command authenticates both Evidence documents and their parent relationship, selects the best retained path/query match, and identifies target content and missing/inexact/truncated facts. It establishes no authorization model or stateful application/reset behavior.
Change and scope
Application owners load/index retained data, derive one argument map for schema and replay, and admit the complete catalog. Discovery uses bounded descriptive samples with omission counts and complete lookup facts retained in Evidence. Long path/query keys have collision-safe aliases; unsafe JSON numbers stay original text; lossy numeric RPC IDs are refused. URL/form parsing has one owner, streaming selected fields and scanning only requested path coordinates.
The server reuses the SDK and HTTP lifecycle owner. Target-content labeling covers standalone cards, initialization, replay and SDK-generated errors. Cancellation reaches the regular-file reader and native DNS/listen startup; a cancelled startup never announces a listener. A 1 MiB conservative serialization reservation admits whole discovery before constructing SDK schemas/binding, returning a non-retryable capacity error on oversized input. Body, recorded-line and content-type truncation remain explicit.
Contract and boundary impact
Expected effects:
Evidence and regression coverage
Negative controls demonstrated rounded numeric bodies, missing pre-initialization card labeling, oversized descriptions, and an old compiled CLI binding after SIGTERM during an Evidence read or paused DNS lookup. The new compiled cases return cancelled/143 without announcing a listener. The capacity regression authenticates an actual projected 10,000-field fixture, asserts those fields exist, then verifies a typed refusal before listening; the initial excluded-HTML fixture attempt failed and is not counted as passing.
Four actually recorded unauthenticated GitHub REST responses were inspected into HAR Evidence and two tools. Ten SDK replays checked body/status/line/provenance, including warm calls, DELETE and session replacement. Card labeling before initialization, argument errors, default stdio, mismatched Evidence, blank names, occupied ports, input digests and SIGTERM/port release passed on the final production build.
Validation performed
Pinned Node 24.18/Linux; heavy tasks used one CPU/worker. Family RSS sums descendants every 50 ms and may double-count shared pages.
ac1e36bf; final head changes only the capacity fixture)Packaged skill build, generated docs/facts/licenses and all five README consistency checks passed. The earlier 512 MiB catalog-worker attempt exhausted that local heap; the bounded isolated rerun above passed. Former native startup cleanup checks passed after updating main. Windows console interrupts, non-loopback deployment and arbitrary third-party enforcement of the advisory catalog notice remain unverified; these checks make no native-analysis claim.
Resource experiments (controlled metadata stress, not newly observed target requests):
--helpruns kept identical stdout: before/final 8.662/10.267 s, CPU 8.531/10.066 s, family RSS 387.57/386.41 MiB. Host caches were not flushed and intervening main updates are included; no startup speedup is established.HAR SHA-256:
f0d98a7bc5e55becb5c0cff2ee0978468463b0d17f81b79d5d21a13c47c9f286. Capture:ev_fe6367745865f768078d918a529bfbee3bcb883342de25aa7869343b4ae1bb8d; manifest:ev_bc2f23ecd9a9358fba1802bfc8f06184271e38be65c7eb65e3258a8ab9cd37ae.Compatibility, safety, and release
Additive retained-data serving; no package/install changes or captured-application execution. All reported review threads have fix/validation explanations and are resolved. Greptile passed on the final head. A fresh Codex review is unavailable because the repository's code-review quota is exhausted; this is not counted as a passing review. Merged by
gensokyo-devat 2026-10-19 19:06:30 UTC as10f1994fe1a0bbddeb846ee8078a80a483a652f1, using the explicit authorization to bypass queued final CI. The preceding production head passed GitHub static/source checks; the final head additionally passed the corrected capacity regression and all local final checks above. Full final CI was queued at merge and is not claimed green.Author readiness
Human owner: @earakely-scale
Before merge
type(scope): outcome.