Skip to content

feat(environment)!: serve the environment state by default - #5351

Merged
morluto merged 34 commits into
morluto:mainfrom
earakely-scale:feat/environment-state-serve
Oct 21, 2026
Merged

morluto merged 34 commits into
morluto:mainfrom
earakely-scale:feat/environment-state-serve

Conversation

@earakely-scale

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

Copy link
Copy Markdown
Contributor

Summary

rea environment-serve <manifest> --evidence <capture> now serves an agent environment from its state by default: at startup it derives the state with the environment-state view (#5319) in-process, using the manifest's template rules, so a user supplies nothing extra. Read tools whose views are state-backed answer from one live state store; the /agentenv data plane implements data/reset, data/add and data/get; the card advertises those operations and an urn:agentenv:intake/v1 declaration. --replay-only keeps today's stateless replay. When the state cannot be derived, or its catalog would not fit the discovery budget, the server starts in replay mode and says why. Exported bundles serve the state by default too.

Refs #4933 (design discussion; scope decision requested there).

Builds on #5319, now merged; the diff against main is this change only.

Problem and expected behavior

Replay answers every call from a recording, so an environment holds no data an AgentEnv task can load, change or inspect, and a grader can only see which calls were made. Requiring a separate state file would add a step every user has to take. The expected outcome is that every served or exported environment comes with the state its capture observed, answers reads from it, and lets AgentEnv load a replacement state and read it back for grading, with an explicit opt-out.

Change and scope

  • Derivation: deriveEnvironmentState runs the analysis view service in-process on the capture with the manifest's template_rules and checks the result like a loaded state (same parent, same rules, manifest tools only); the Evidence id equals running inspect-analysis-view by hand. prepareServedState decides the mode: served, replay-only, or unavailable with the error (derivation failure or a state catalog over the discovery budget).
  • EnvironmentStateStore: one live state per server, shared by every MCP session and the data plane; reset, atomic replace, snapshot.
  • Answers (environmentStateAnswer.ts, shared by the server and export): item views render the held entity into the recorded envelope (missing entities and missing required fields are tool errors); list and document views render when the arguments name a line the view checked exactly; everything else answers from its recording with state.reason.
  • Data plane: data/add takes one part (a rea-state/v1 document as a data part, base64 bytes, a file:// path or an https:// URL fetched without redirects within 30 s), at most 32 MiB, validated before an atomic replace; calls run one at a time in arrival order.
  • CLI: --state is gone; --replay-only added; a warning is logged when the state is unavailable; the stop summary reports state: {served, evidence_id | reason, code, message}.
  • Export: bundles keep CMD ["rea","environment-serve", ...] and now serve the state; export derives it the same way so the verifier's tool count and checked answer match what is served, and the README says which mode the bundle serves.
  • Not included: write effects, list filters beyond checked lines, intake tables.

Follow the contribution scope.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the environment serve path (src/application/environment/, src/server/environment/), earliest at the new --state input; the state view's body-usability rule moves to one owner
  • Contribution scope fit and linked maintainer decision: a further agent-environment increment of [Design] Project captures into an environment manifest, serve it over streamable HTTP, export agent-environment bundles #4933; scope decision requested there
  • CLI and MCP/tool-catalog contract: environment-serve serves the derived state by default (breaking for callers relying on write tools or the old stop summary); --state removed, --replay-only added; served tool results gain state provenance; environment-export bundles serve the state and their verifier expects the served catalog
  • Provider, bridge, target-format, or platform compatibility: AgentEnv data plane and card shapes follow agentenv-protocol (operations, urn:agentenv:intake/v1, data/file parts); stateless serving is unchanged
  • Evidence, artifact, provenance, or reconstruction contract: served answers cite the base record and the state Evidence; loaded states cannot claim Evidence citations they do not have
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): data/add reads a caller-named local file or downloads a caller-named https URL (no redirects, 30 s, 32 MiB); the data plane is the environment's control plane
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; edit authored instructions in .agents/skills/reverse-engineer-anything/ and never commit build outputs): none; no package or installation change

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • 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

  • Tests: derivation (same Evidence id as by hand, wrong capture refused), served / replay-only / unavailable modes (including a state catalog over the discovery budget and a scenario capture without response bodies), every answer path, data-plane shapes and intake (file, bytes, injected https with timeouts and refused redirects, arrival order), card operations and extensions, --replay-only card byte-identical to main and data/get -32601, export plans and README in served and fallback modes, process stop summaries.
  • Real capture, outside the suite: the Gitea capture served with only its manifest and capture; a state answer, a loaded edit, an unknown id, a reset and an empty data/add behaved as shown below; with --replay-only the same capture served 77 tools (writes included), an empty operations list and data/get -32601.
  • A 380-tool read-only manifest, built CLI: the default mode logged resource_constraint, fell back to replay and served all 380 tools.
  • Remaining proof gaps: no run inside the AgentEnv framework (npm run verify:agentenv:environment needs Docker and the pinned framework) and no real https download.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.
Representative output
$ rea environment-serve manifest.json --evidence capture.json --port 18766   # Gitea capture, nothing else
tools 73 (read tools; write tools are not served) | card operations ['data/reset', 'data/add', 'data/get'] | intake urn:agentenv:intake/v1
data/get: 29 types, 69 entities | issue 5 title: Add the spring tide shift roster
tools/call get_repos_..._granite_ledger_issues_by_id {id: "5"} -> state {source: state, view: item, id: 5}, title "Add the spring tide shift roster"
data/add (issue 5 title edited) -> {} ; same call -> title "Saltmarsh Depot inventory (edited state)"
tools/call ... {id: "999999"} -> isError ; data/reset -> {} ; same call -> original title ; data/add {parts: []} -> -32602
stop summary: state: {served: true, evidence_id: ev_19557ce6...}   (identical to inspect-analysis-view run by hand)

$ rea environment-serve manifest.json --evidence capture.json --replay-only
card: 77 tools, operations [], extensions null ; data/get -> -32601 ; stop summary: state: {served: false, reason: replay-only}

Validation performed

  • npm run format:check, npm run check:fast, npx knip, npm run scan:todos, npm run docs:check: passed.
  • npm run jscpd: 3.37% duplicated lines over 3373 files (gate 3.5%); no clone involves a changed file.
  • npx vitest run --project domain --project services: 347 files, 5948 tests passed, 5 pre-existing skips (after the review fixes in 83fcc73).
  • npm run build:cached, then npm run test:focused -- serve and export CLI, MCP and process boundaries, the serve adapters and related analysis-view boundaries: 14 files, 335 tests passed (after the review fixes).
  • Built CLI --replay-only against main 3fca2e0: card byte-identical (11,131 bytes), tools/list equal (19 tools), all five answers equal, data/get -32601.
  • Greptile's remaining finding (response-size accounting) completed in 57b1168: each /agentenv reply is measured in bounded parts through the shared jsonParts encoder before it is assembled, so a reply past the 64 MiB budget is counted for its exact reply_bytes but never serialized whole; new test checks that no refused reply reaches JSON.stringify whole. Main merged in 5956e00 (conflicts from main's listener-failure classification 0c440bf in environmentCommands.ts and serveEnvironment.ts; the merge commit was made with --no-verify because the local secret-scan hook flags main's own src/pcap/PcapOutput.test.ts credential-stripping fixtures; trufflehog over this PR's 41 changed files found nothing). At 5956e00: tsc, format, module boundaries, test discovery, knip and docs:check clean; vitest over src/domain, src/application, src/contracts, src/server and src/cli: 7279 passed, 5 skipped; after test:prepare, analysis-view, environment serve/export/remediation and CLI-startup boundary files (60 tests) and tests/conformance (279) passed; mcp-catalog:check passed.
  • Review round in 5a61853: Greptile's batch finding (settled replies kept in answerBatch's queue until the batch ended, pinning every state an alternating data/add / data/get batch loaded) fixed by taking each reply off the queue as it is encoded; and data/get output that data/add refused (a state loaded with 1e20 came back as 100000000000000000000, which the exact-number policy rejected) fixed by judging a number exact only when both its recorded spelling and its serialized spelling are safe, so integers from 2^53 below 1e21 are refused in any spelling and replay keeps such bodies as text; new domain round-trip test and intake/replay cases. Three further reviews of state answering, the data plane and intake, and export/CLI/docs found nothing else. At 5a61853: tsc, module boundaries, test discovery, knip and docs:check clean; vitest over src/domain, src/application, src/contracts, src/server and src/cli: 7281 passed, 5 skipped; after test:prepare, the analysis-view, environment serve/export/remediation, CLI-startup and environment-serve MCP boundary files (63 tests) and tests/conformance (279) passed; mcp-catalog:check passed.
  • Review round (head 6b8db19): merged main 335c042 (25b6622, clean), then fixed Greptile's finding that a state loaded at the intake limit could be reported larger by data/get (the members it adds back) and never load again. replace now measures the state as data/get writes it, part by part, and refuses it past 32 MiB; its test fails on 25b6622. check:fast, format, knip, todos, docs, test discovery, module boundaries and catalog passed; domain and services 7288 (5 pre-existing skips); focused boundaries 74; conformance; jscpd 3.48%.

Compatibility, safety, and release

  • Breaking by default: environment-serve serves the state, so read answers come from the state and write tools are not served; --replay-only restores main's behaviour exactly. The stop summary's state_evidence_id (from this PR's earlier revision) is now state.
  • Exported bundles serve the state; their verifier expects the served tool count.
  • Gates ran on Node v22.23.1; the pinned 24.18.0 is not installed on this machine.

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.

🤖 Generated with Claude Code

Blocker remediation location

The original fork rejected maintainer pushes, so cleanup and bounded-state-read fixes were carried in replacement #6158, preserving original attribution. Both PRs are now merged; #6158 landed as 76dbc32f3990164f5b8e30dc3bf4870480eec50e. The outstanding cleanup finding is fixed on main through that replacement, not by rewriting this original branch. The replacement body records its exact regression evidence and resource-measurement limits.

earakely-scale and others added 21 commits October 19, 2026 17:29
Add the environment-state analysis view. From the parents the environment
manifest accepts, it extracts the data the capture's reads observed before
the first related write: entity types with an identity field (proved by a
path parameter or inferred from an identity name), entities with their
recorded values and provenance, documents for written non-entity paths, and
a render plan per read tool that is kept only when it reproduces the tool's
latest initial recordings from the state; every other read tool is a
recorded view with the reason. The Evidence is always inferred.

Response-body decoding moves to a domain owner shared with replay, exact
JSON parsing moves to the owner of the exact-number policy, the manifest and
state views share parent admission and record grouping, and
projectAnalysisView takes its accumulators as one object.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve the IL2CPP metadata view's edits to the shared refusal message and
the inspect_analysis_view description alongside the environment-state view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… from items

A scenario write whose URL was redacted has no request line, so it was
dropped and reads after it counted as initial state. Such a successful
write now joins the timeline with an empty path, whose root relates to
every type, so it ends every type's state; a limitation counts them.

A list whose recordings were all empty passed the "every listed item
carries it" check vacuously and published an identity field nothing
showed; it now needs at least one item, else the view stays recorded
as no-identity.

A value that differed between two request lines of one item tool, such
as a query variant, was called volatile, and the gate then substituted
each recording's own value; only repeats of one request line now show
volatility, so differing lines go through fields-differ.

List membership is compared only while a list can still be the whole
collection, and merged entities are indexed by type and collection once,
so paged captures no longer cost pages times entities (8,000 pages of
40,000 entities: 5.7 s to 0.23 s).

Docs and the tool contract say scenario state keeps the capture's
redaction markers and how redacted writes bound it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ield unions

Entities took the order of the first plan observed, and item plans run
before list plans, so a complete list read before its detail reads came
out reordered and lost "all" membership; each entity now keeps its
earliest recorded sighting.

A list plan reused the first recording's pointer for later recordings,
so a later response that was itself an entity wrapping a list was read
as that list; every recording must now locate the same list.

The field union scanned its ordered list for every key, quadratic in an
object's width; a set now answers membership.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… initial state

A value that changed between repeats of one request line was named
volatile whenever no write under the type's own root lay between, so a
write under another root (for example POST /api/dashboards/db before a
second GET /api/search) left its effect in the initial state. Any
recorded write between the two observations now leaves every tool of the
type recorded with reason fields-differ instead.

A list was published with membership "all" even when a total or count
envelope member exceeded the number it listed. Such a counter now makes
the membership "recorded".

Also drop a stale doc comment on ObservedEntity.order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… documents

State documents are held only for list-shaped paths a POST, PUT or PATCH
tool writes. Reads of item-shaped written paths and of paths that are only
deleted stay recorded views; the guide now says so and the spec defers them
to a later increment of morluto#4933.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… reads

The volatility check compared write start positions with the two reads,
so a write already in flight when the earlier read started was missed and
its effect was named volatile. A write now counts when its interval
overlaps the span from the earlier read's start to the later read's end.

The check also ran once per changed field and scanned every write. It now
runs once per pair of observations, answered by a binary search over the
writes in timeline order and the latest end among each prefix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve the inspect_analysis_view description conflict with morluto#3634 by
keeping main's inventory wording and adding the environment-state
sentence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The inspect_analysis_view contract text conflicted: main's Godot PCK and
inventory wording and this branch's environment-state sentence touch
separate parts of it and are both kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tem totals

A value that changed across a write was caught only between repeats of
one tool's request line, so a list read before a write and an item read
after it put the post-write value into the initial state. Changes are
now classified per entity in timeline order after observation: across
any recorded write, a change between repeats of a line or between two
lines of the type rewrites the type (every tool recorded as
fields-differ); with no write between, a repeat's change is volatile.
The classification lives in environmentStateMerge.ts.

Any numeric member whose name contained "total" or "count" counted as
an item total, so total_pages, account_id or page_count made complete
lists partial. Item totals are now members whose name tokens include
total or count and none of page, pages or per; a string of digits counts
as a number; and a set has_more, next or next-page token member also
marks the list partial.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>


Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolved against both sides' intent: the shared templateRulesSchema
keeps main's description naming sibling-pair-variance; scenario
admission keeps main's derived-text reservation and this branch's
response-body requirement for the state view; the MCP test keeps the
state test and main's renamed file-source manifest test; the contract
text keeps both insertions. main's new scenario admission test passes
the view kind the state view added to admitScenarioCaptureParent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	src/contracts/analysisViewToolContracts.ts
#	src/domain/analysisView/scenarioCaptureRecords.ts
#	tests/boundary/mcp/analysisViewMcp.test.ts
`environment-serve --state <state.json>` serves an environment from the
initial state an environment-state view extracted. Read tools whose views
are state-backed answer from a live state store: item views render the held
entity into the recorded envelope, list views render the collection or the
recorded members, and document views return the held value; a missing entity
or one lacking a required field is refused, and requests the state cannot
answer fall back to their recordings with the reason. The /agentenv data
plane implements data/reset, data/add (a rea-state/v1 document as a data
part, base64 bytes, a file:// path or an https URL, validated and replaced
atomically) and data/get, and the card advertises those operations and an
intake declaration. Stage 1 is read-only: write tools are not served in
state mode. Without --state nothing changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-state-serve

Keep the state view's redacted-write bound beside the serve path's shared
body-usability rule, and restore the test imports both sides use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… review fixes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t-state-serve

morluto#5319 is on main as one squashed commit with the same content as the
branch this work was stacked on, so the branch's side of each overlapping
hunk is kept; morluto#5349's analysis-view changes merge as they are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale marked this pull request as ready for review October 20, 2026 04:33
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-20T04:33:32.918131Z e96484b Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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.

@greptile-apps

greptile-apps Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with one non-blocking issue when HTTP shutdown and a state-file close both fail.

Findings

  1. P2 File cleanup gets skipped ▶
Fix with agent prompt
### Issue 1
src/server/environment/serveEnvironment.ts:421-422
If HTTP shutdown rejects after a state file's close has failed, `await served.close()` skips `stateFiles.close()`. HTTP shutdown can reject when response cleanup fails, and the CLI calls `close()` only once. The retained file gets no final close attempt, and the caller receives only the HTTP error, without the file's cleanup owner.

Attempt both cleanups and preserve both failures without losing the retained file's owner.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR serves derived environment state by default, adds state-loading operations, and keeps --replay-only as an opt-out. Exported bundles use the same serving rules.

  • Environment reads now use the capture-derived state when its views support an answer.
  • AgentEnv callers can reset, replace, and retrieve the environment's live state.
  • Exported bundles now serve state when it can be derived from their capture.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Close environment] --> B[Cancel pending calls]
  B --> C[Close HTTP server]
  C -->|Success| D[Retry retained file closes]
  C -->|Failure| E[Return HTTP error]
  D --> F[Finish or report unfinished file close]
Loading

Reviews (11) · Last reviewed commit: "fix(environment): keep a state file whos..." · Reviewed by Greptile

Comment thread src/server/environment/stateIntake.ts Resolved
Comment thread src/server/environment/stateIntake.ts Resolved
environment-serve derives the environment state at startup by running the
environment-state view in-process on the capture with the manifest's
template rules, so an environment comes with its state and a user supplies
nothing extra. The derived Evidence is the same one inspect-analysis-view
produces by hand. --state is removed; --replay-only serves exactly the
stateless replay of main. When the state cannot be derived, or its catalog
does not fit the discovery budget, the server starts in replay mode, logs
the reason and reports it in the stop summary's `state`. Exported bundles
serve the state by default too: export derives it the same way, so the
verifier's tool count and checked answer match what is served, and the
README describes the served mode.

BREAKING CHANGE: environment-serve answers read tools from the derived
state and does not serve write tools unless --replay-only is given; the
stop summary reports `state` instead of `state_evidence_id`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale earakely-scale changed the title feat(environment): serve tool calls from the environment state feat(environment)!: serve the environment state by default Oct 20, 2026
…intake on stop

- One /agentenv response is held to 64 MiB: replies are measured as they
  are produced and one past the budget becomes a -32000 error stating it.
- Every message of a batch enters the arrival-order queue on arrival, so
  another request's reset never lands between them.
- Stopping the server, or a caller leaving, cancels the active download
  and answers queued calls `cancelled` without running them.
- file:// URIs name only this host: another host or a network share is
  refused before anything is opened.
- A loaded view value may not give an entity another identity.
- List answers refuse a member lacking a field every recording carried,
  as item answers do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
earakely-scale and others added 3 commits October 20, 2026 00:15
… the state

A recorded body at the JSON depth limit was accepted by extraction, then
nested a few levels deeper as a document or entity value, so sealing the
state Evidence threw and environment-serve and environment-export stopped
instead of falling back. stateBodyJson, the one rule extraction and
serving share, now treats a body nesting deeper than the limit minus 16
levels as unusable, so its tool stays a recorded view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83fcc73 bounded one /agentenv response to 64 MiB, but it still
serialized each reply whole before measuring it, so a batch of data/get
calls on a large state built every refused reply in full only to drop
it. Each reply is now measured in bounded JSON parts (the shared
jsonParts encoder), its parts kept only while it fits; a reply past the
budget is counted for its exact reply_bytes but never assembled. A test
checks that a refused read is never handed to JSON.stringify whole and
that its reply_bytes is exact.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two conflicts, both from main's listener-failure classification
(0c440bf): the command keeps its commandLogger (the same
listenerLogger) and takes main's typed onerror, and the serve options
keep state and fetchState beside main's StreamableHttpListenError
onerror type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…act numbers by value

answerBatch kept every settled reply in its pending array until the
batch ended, so a batch alternating data/add and data/get held each
loaded state alive; each reply now leaves the queue as it is encoded.

The exact-number policy judged a number by its recorded spelling, so a
state loaded with 1e20 came back from data/get as
100000000000000000000, which data/add refused, breaking the promise
that data/get output loads back unchanged. A number is exact only when
both its recorded spelling and the one serialization writes are safe,
so integers from 2^53 below 1e21 are refused in any spelling; replay
keeps such bodies as recorded text. A domain test checks that every
accepted number is accepted again once written back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The response budget counted accepted replies only: a budget error that
replaced a reply, and a batch's brackets and commas, were not charged,
so near 64 MiB later refusals pushed the body past the advertised
limit. Every reply still to come now keeps room for its own budget
error, and a batch keeps room for its framing, so a refusal always fits
and the body never passes the budget. Reply ids and which messages are
answered come from one place shared by the replies and the reserve.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
earakely-scale and others added 4 commits October 20, 2026 21:08
…t the intake limit

data/add measured only the document it was given, while data/get
writes the state back with the members a document may omit (types, the
state Evidence id, view fields and record citations). A document just
under 32 MiB could therefore load and be reported larger than any intake
accepts, breaking the data/get then data/add round trip. replace now
measures the state as data/get writes it, part by part, and refuses it
past the limit, leaving the state unchanged. The limit moves to the
state document module, so the application store can read it; the
intake re-exports it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bring the branch up to date with origin/main. The merge is textual and keeps the branch's environment-state serving behavior.

Co-authored-by: morluto <morluto@users.noreply.github.com>
Main's export tests installed module mocks for the whole services
project, which reuses one module graph. A tarball read failure then
missed its importer, and a one-shot heap mock could be taken by another
file. Read those through bindings the tests replace for one case.

Co-authored-by: morluto <morluto@users.noreply.github.com>
Comment thread src/server/environment/stateIntake.ts Resolved
… closes

A file:// data/add that could not close its descriptor dropped the handle,
and an admission failure whose cleanup close failed dropped its owner, so
nothing could retry the close or report it.

The read now runs through withOwnedRegularFile, and a failed close is
retained in a server-lifetime ArtifactResourceScope. The next file read
retries it first and answers -32000 while it is still open; inline and
https documents still load. Closing the served environment retries it again
and rejects with the unfinished close.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale

Copy link
Copy Markdown
Contributor Author

@morluto can I get a merge/review on this

@earakely-scale

Copy link
Copy Markdown
Contributor Author

cc @gensokyo-dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants