Skip to content

feat(environment): serve an environment manifest as a replay environment - #4975

Merged
gensokyo-dev merged 74 commits into
morluto:mainfrom
earakely-scale:feat/environment-serve
Oct 19, 2026
Merged

gensokyo-dev merged 74 commits into
morluto:mainfrom
earakely-scale:feat/environment-serve

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

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 /agentenv JSON-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 author b217929a; integration started from main and was updated through 1b3ac942.

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

  • Semantic owner/earliest changed stage: application environment loading, catalog admission and replay; adapters consume those facts.
  • Scope/authority: retained Evidence and the existing inbound listener; same effect class as merged feat(mcp): serve the MCP server over streamable HTTP #4955. See contribution scope; no new target execution, injection, mutation or protection recovery.
  • CLI/MCP: one additive command and per-manifest tools with closed schemas; REA's own MCP inventory/default stdio registration is unchanged. Card field names retain the existing protocol shape.
  • Compatibility: HAR only; loopback default, one active MCP session. Request bodies have the shared 4 MiB bound; JSON-RPC batches admit at most 100 messages.
  • Evidence/cleanup: parent identities, ordinal, match, encoding, body-presence and truncation facts remain visible; complete inputs stay unchanged. DNS/bind cancellation and normal SIGINT/SIGTERM shutdown release owned listeners.
  • Generated/package impact: CLI inventory regenerated and checked; no dependency/install changes. Ignored generated outputs are not committed.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

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.

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

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.

Executed check Result Elapsed / CPU Peak family RSS
Full static/runtime gate (production tree ac1e36bf; final head changes only the capacity fixture) 8 tasks passed 225.607 / 217.296 s 4523.50 MiB
Final source/HTTP/SDK/domain suite 158 tests / 12 files passed 12.074 / 10.907 s 751.00 MiB
Final compiled CLI/MCP/process boundaries 17 tests / 5 files passed 59.393 / 56.972 s 903.93 MiB
Isolated global catalog 10 tests passed, 2 GiB heap cap 21.404 / 20.730 s 1331.09 MiB
Actual API replay workflow Passed, 10 equivalent replays 28.682 / 27.642 s 873.64 MiB

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):

  • Public CLI capture/view/serve, card and eight concurrent SDK lists with 1500 synthetic query names: unchanged 183,798-byte card; before/final elapsed 8.391/9.243 s, CPU 7.991/8.861 s, family RSS 507.27/503.43 MiB. Separate cold processes/caches do not establish a speed or memory gain; this calibrates admission.
  • Selection with 20,001 segments and pairs: first call 14.033/17.238 ms before/after, 20 warm calls 96.544/125.186 ms (94.898/123.495 ms CPU), process max RSS 165.0/162.7 MiB. Bounded retained state costs extra scanning time in this case.
  • Catalog construction/serialization with 10,000 observations/ordinals: 2,128,399/2,945 bytes; first call 15.235/1.584 ms, 20 warm calls 243.826/3.621 ms (240.682/3.652 ms CPU). Whole-process max RSS 127.6/137.1 MiB includes different module imports; no memory reduction is claimed. Capture loading, SDK and extra analyst lookups are excluded.
  • Four fresh --help runs 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.
  • Agent tokens and extra analyst calls remain unmeasured; response bytes are not token counts.

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-dev at 2026-10-19 19:06:30 UTC as 10f1994fe1a0bbddeb846ee8078a80a483a652f1, 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

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

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]>
…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]>
…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]>
earakely-scale and others added 22 commits October 18, 2026 09:18
…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]>
earakely-scale and others added 3 commits October 19, 2026 09:34
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]>
@gensokyo-dev

Copy link
Copy Markdown
Collaborator

@codex review

Please review published head ad52275d2214a1529bffcf4723298014e15b961c on this original PR. It retains author a8382038 and main aacf740a, bounds all three advisory-list formats at their owner, carries the capture trust notice in standalone discovery as well as MCP, and scopes child.kill signal assertions to POSIX. The published-head service/adapter run passed 116 tests; the PR body marks the remaining exact-head build, boundary and real-data reruns as pending rather than passed.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/cli/environmentCommands.ts Resolved
…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]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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
@gensokyo-dev

Copy link
Copy Markdown
Collaborator

@codex review

Please review the follow-up head 0ab4bbde31a98a8ae3bc5362152273c54dd01595. This retains the author's recent commits and fixes the remaining replay precision (including decimal/exponent forms), startup read cancellation, path/query schema aliases, standalone-card provenance and avoidable query/body-key allocations. Relevant source/HTTP/SDK tests: 131 passed; full local built gates are running. No new PR replaces this contribution.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/cli/environmentCommands.ts Resolved
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@gensokyo-dev

Copy link
Copy Markdown
Collaborator

@codex review

Please retry review of ba49f8966678592464c3a568a386f55f166cfc10; the latest automatic run is marked Failed without a completed review. The five previous findings now have owner-level fixes: native cancellation for DNS/listen startup, streaming selected form fields, one-pass selected path coordinates, bounded content-type display, and measured whole-catalog admission before schema construction. 158 relevant source/HTTP/SDK/domain tests and lint passed; full build and compiled CLI/DNS/capacity reruns are in progress. Original author history is retained.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@gensokyo-dev
gensokyo-dev merged commit 10f1994 into morluto:main Oct 19, 2026
13 of 14 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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]));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +96 to +100
const supplied = new Map<string, string>();
for (const [name, argument] of queryArguments) {
const value = args[argument];
if (typeof value === "string") supplied.set(name, value);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +103 to +105
for (const [name, value] of iterateUrlQueryParameters(
exchange.query ?? "",
)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@github-actions github-actions Bot mentioned this pull request Oct 19, 2026
3 tasks done
@morluto morluto added enhancement New feature or request area: setup Setup, packaging, upgrade, install, Doctor, and client registration labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: setup Setup, packaging, upgrade, install, Doctor, and client registration enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants