Repository navigation
Conversation
… responses Keep main's environment serving and fold in coverage for non-entity reads, response summaries, and MCP tool annotations. Squashed rebase of #5352 onto main.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ad8f674d22
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| latestAbsence( | ||
| serving.source.manifest.tools | ||
| .filter((candidate) => itemTools.has(candidate.name)) | ||
| .flatMap((candidate) => candidate.record_ordinals), |
There was a problem hiding this comment.
Select fallback absences by capture order
When a type has multiple item-view tools and the invoked update/delete tool has no recorded absence, this concatenates ordinals in manifest-tool order and latestAbsence() selects the final element. Manifest tools are sorted by template and method rather than capture chronology, so an older 400/404/410 from the last-sorted tool can be returned instead of the latest recorded absence. Compare the candidate exchanges by ordinal/timeline before choosing one.
AGENTS.md reference: AGENTS.md:L13-L13
Useful? React with 👍 / 👎.
| : stateAnswer( | ||
| serving, | ||
| { exchange, exact: true }, | ||
| written.value, |
There was a problem hiding this comment.
Derive exact_match for document entity responses
When a served document write supplies a query value that differs from the exemplar response's recorded query, the write is still accepted by its path/body model, but this hardcoded value reports replay.exact_match: true. That incorrectly claims all supplied path and query values matched; the other response shapes correctly call selectReplayExchange in writeAnswer(). Compute the exactness for this entity-response branch the same way.
AGENTS.md reference: AGENTS.md:L13-L13
Useful? React with 👍 / 👎.
[Medium impact] The changes affect state-backed environment serving and its MCP callers. Do not merge yet: the gate can expose unproved or unusable writes, and some delete confirmations and page calls are handled incorrectly.
|
| for (const field of Object.keys(evidence.after)) { | ||
| if ( | ||
| Object.hasOwn(body, field) || | ||
| !Object.hasOwn(evidence.before, field) || | ||
| same(evidence.before[field], evidence.after[field]) | ||
| ) | ||
| continue; |
There was a problem hiding this comment.
explainUpdate silently skips new fields the request did not send. For example, book 1 lacks status, book 2 has it, and a PATCH of book 1 returns a new status. A later summary list can confirm the name change, and renders passes because book 2 has every response field. The tool is served, but the captured PATCH then fails because writtenResponse cannot find status on book 1.
Treat new, unsent fields as unexplained unless a rule reproduces them. Check the write's answer against its computed result.
Knowledge Base Used: Analysis environments
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/analysisView/environmentStateWriteExplain.ts
Line: 310-316
Comment:
**Advertised updates can fail**
`explainUpdate` silently skips new fields the request did not send. For example, book 1 lacks `status`, book 2 has it, and a PATCH of book 1 returns a new `status`. A later summary list can confirm the name change, and `renders` passes because book 2 has every response field. The tool is served, but the captured PATCH then fails because `writtenResponse` cannot find `status` on book 1.
Treat new, unsent fields as unexplained unless a rule reproduces them. Check the write's answer against its computed result.
**Knowledge Base Used:** [Analysis environments](https://app.greptile.com/pre/-/custom-context/knowledge-base/morluto/rea/-/docs/analysis-environments.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| const shown = renderStateEntity(entity, view, check.volatile, observed); | ||
| const outcomes = new Map<string, boolean>(); | ||
| for (const [tool, fields] of check.writes) { | ||
| const compared = (fields ?? []).filter( | ||
| (field) => Object.hasOwn(observed, field) || Object.hasOwn(shown, field), | ||
| ); | ||
| if (fields === null || compared.length === 0) continue; | ||
| outcomes.set( | ||
| tool, | ||
| compared.every((field) => same(shown[field], observed[field])), |
There was a problem hiding this comment.
Unproved writes become available
writtenFieldChecks can confirm a write using only volatile fields. renderStateEntity takes those values directly from the follow-up recording, so the comparison always passes.
After repeated initial reads mark count volatile, a PATCH setting count to 5, an unmodelled action, and a read showing count as 0 still confirm the PATCH. The tool becomes available without evidence of its effect. Exclude volatile fields here, as normal confirmation already does.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/analysisView/environmentStateWriteChecks.ts
Line: 471-480
Comment:
**Unproved writes become available**
`writtenFieldChecks` can confirm a write using only volatile fields. `renderStateEntity` takes those values directly from the follow-up recording, so the comparison always passes.
After repeated initial reads mark `count` volatile, a PATCH setting `count` to 5, an unmodelled action, and a read showing `count` as 0 still confirm the PATCH. The tool becomes available without evidence of its effect. Exclude volatile fields here, as normal confirmation already does.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| for (const { collection } of collections) | ||
| for (const id of ids) | ||
| if (state.entity(type, collection, id) !== undefined) | ||
| return { collection, id }; | ||
| return { collection: written, id: ids[0]! }; |
There was a problem hiding this comment.
itemTarget loses the collection spelling once the requested entity is absent. A delete of /api/orgs/%61cme1/books/1 records its effect under the encoded collection. A later 404 from /api/orgs/acme1/books/1 falls back to the plain collection because the deleted entity can no longer be found.
The read never confirms the delete, so the tool stays off the catalog despite confirming evidence. Keep enough collection identity to match absence reads to the deleted target.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/analysisView/environmentStateWriteChecks.ts
Line: 291-295
Comment:
**Equivalent reads miss deletes**
`itemTarget` loses the collection spelling once the requested entity is absent. A delete of `/api/orgs/%61cme1/books/1` records its effect under the encoded collection. A later 404 from `/api/orgs/acme1/books/1` falls back to the plain collection because the deleted entity can no longer be found.
The read never confirms the delete, so the tool stays off the catalog despite confirming evidence. Keep enough collection identity to match absence reads to the deleted target.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| if (PAGE_SIZE_PARAMETERS.has(key)) { | ||
| if (number > 0 || !unboundedZero) size = Math.min(size, number); | ||
| } else if (key === "_start") range.start = number; | ||
| else if (key === "_end") range.end = number; | ||
| } | ||
| const width = Math.min(size, Math.max(range.end - range.start, 0)); | ||
| return Number.isFinite(width) ? width : undefined; |
There was a problem hiding this comment.
A query such as ?page=1 qualifies as paging-only, but pageBound returns no bound without an explicit size or range. If the captured API uses a default page size, an initially full page can become membership: "all". After served creates grow the collection, an exact call to that page returns every held entity instead of its recording.
Keep requested pages with an unknown size on recordings, or establish their bound before treating them as unlimited.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/analysisView/environmentStatePaging.ts
Line: 49-55
Comment:
**Page calls return extra rows**
A query such as `?page=1` qualifies as paging-only, but `pageBound` returns no bound without an explicit size or range. If the captured API uses a default page size, an initially full page can become `membership: "all"`. After served creates grow the collection, an exact call to that page returns every held entity instead of its recording.
Keep requested pages with an unknown size on recordings, or establish their bound before treating them as unlimited.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| #remember(named: ReadonlyMap<string, readonly string[]>): void { | ||
| for (const [type, collections] of named) { | ||
| const known = this.#knownCollections.get(type) ?? []; | ||
| for (const collection of collections) | ||
| if (!known.includes(collection)) known.push(collection); | ||
| this.#knownCollections.set(type, known); |
There was a problem hiding this comment.
Deleted collections keep consuming memory
#knownCollections and the per-collection sequence entries grow outside the state byte limit. An untied create accepts a new parent value. Creating and deleting one entity under successive parents leaves every collection spelling and sequence key behind.
data/get stays small, but memory and later collection searches keep growing until reset or load. Charge this retained bookkeeping to a capacity limit and refuse new keys when it is reached.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/application/environment/environmentStateStore.ts
Line: 171-176
Comment:
**Deleted collections keep consuming memory**
`#knownCollections` and the per-collection sequence entries grow outside the state byte limit. An untied create accepts a new parent value. Creating and deleting one entity under successive parents leaves every collection spelling and sequence key behind.
`data/get` stays small, but memory and later collection searches keep growing until reset or load. Charge this retained bookkeeping to a capacity limit and refuse new keys when it is reached.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| if (typeof value === "string" && value.length >= COPY_MIN_LENGTH) { | ||
| const from = bodyPointerOf(body, value); | ||
| if (from !== undefined) return { field, rule: "copy", from }; |
There was a problem hiding this comment.
Write planning repeats large scans
requestRule starts a fresh bodyPointerOf walk for every non-echoed string field. A request with 100,000 zeros and a response with 8,000 string fields both fit the 256 KiB body limit, yet require about 800 million node visits and repeated allocations before the plan is built. The budget does not charge this repeated work.
Build the shallowest string-to-pointer index once per request and reuse it for all fields.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/analysisView/environmentStateWriteExplain.ts
Line: 113-115
Comment:
**Write planning repeats large scans**
`requestRule` starts a fresh `bodyPointerOf` walk for every non-echoed string field. A request with 100,000 zeros and a response with 8,000 string fields both fit the 256 KiB body limit, yet require about 800 million node visits and repeated allocations before the plan is built. The budget does not charge this repeated work.
Build the shallowest string-to-pointer index once per request and reuse it for all fields.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| const members = (names: readonly string[]): string => | ||
| names.length <= DESCRIBED_MEMBERS | ||
| ? names.join(", ") | ||
| : `${names.slice(0, DESCRIBED_MEMBERS).join(", ")}, … (${String(names.length)} members; all in the state Evidence)`; |
There was a problem hiding this comment.
Long names disable state serving
members limits the number of names, but not their length, and joins captured names without quoting them. One accepted 180 KiB key can appear in both the accepted and required lists. That exceeds the catalog reservation and forces replay even when the read catalog fits. Commas and newlines also make accepted names unclear.
Reuse the byte-bounded, quoted-name formatting used by response summaries.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/application/environment/environmentStateWriteDescription.ts
Line: 9-12
Comment:
**Long names disable state serving**
`members` limits the number of names, but not their length, and joins captured names without quoting them. One accepted 180 KiB key can appear in both the accepted and required lists. That exceeds the catalog reservation and forces replay even when the read catalog fits. Commas and newlines also make accepted names unclear.
Reuse the byte-bounded, quoted-name formatting used by response summaries.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| a departed caller, a server that closes while a download is stalled, the | ||
| response budget, batches and notifications, the card declaration, absent write | ||
| tools, a served query `POST`, the per-mode discovery reservation and a |
There was a problem hiding this comment.
Current behavior loses its docs
The rebase removes still-current notes from the serving and capture guides:
stateIntake.tsstill retains a file whose close failed and blocks later file loads until cleanup succeeds.SazCapture.tsstill reports zero-byte_c.txtand_s.txtmembers asnullwith a limitation.
Restore those baseline paragraphs and the close-retry verification notes. Neither behavior changed with write effects.
Knowledge Base Used: Environment bundle and replay
Prompt To Fix With AI
This is a comment left during a code review.
Path: docs/specs/agent-environments/state-serve/spec.md
Line: 175-177
Comment:
**Current behavior loses its docs**
The rebase removes still-current notes from the serving and capture guides:
- `stateIntake.ts` still retains a file whose close failed and blocks later file loads until cleanup succeeds.
- `SazCapture.ts` still reports zero-byte `_c.txt` and `_s.txt` members as `null` with a limitation.
Restore those baseline paragraphs and the close-retry verification notes. Neither behavior changed with write effects.
**Knowledge Base Used:** [Environment bundle and replay](https://app.greptile.com/pre/-/custom-context/knowledge-base/morluto/rea/-/docs/environment-bundle-and-replay.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Summary
Replacement for fork PR #5600, stacked on the squashed rebase of #5352 (
cursor/rebase-5352,95c8c9d15). Fork force-with-lease tofeat/environment-state-writeswas rejected because the app token cannot update.github/workflows/ci.yml.Problem and expected behavior
#5600 could not merge. After rebase it should still serve write tools only where a later read confirms the effect, on top of current main's serving and the #5352 coverage work.
Change and scope
Merged
pull/5600/headonto the rebased #5352 tip and kept main's state-file close ownership and part-wise JSON measurement. Write plans, the write gate, and served write answers come from #5600. Squashed to one commit whose parent is the #5352 squash. Not a new provider or target-execution capability. Maintainer scope decision: not applicable.Follow the contribution scope.
Contract and boundary impact
Expected effects:
Evidence and regression coverage
npm run typecheckpassed on this tree.environment-servedescription names confirmed write tools.For evidence-bearing changes:
Validation performed
npm run typecheck— passed on the resolved feat(environment): apply evidence-gated write effects to the served state #5600 tree before squash (same tree asad8f674d2).Compatibility, safety, and release
--replay-onlystill replays every tool.This branch contains the #5352 commit plus this one. Merging it into main also lands #5352. The later fidelity branch
cursor/rebase-5699is based on this tip.Author readiness
Human owner: @morluto
Before merge
type(scope): outcome.