Skip to content

feat(environment): give more write tools a state target - #6385

Merged
morluto merged 52 commits into
morluto:mainfrom
earakely-scale:feat/environment-state-targets
Oct 24, 2026
Merged

morluto merged 52 commits into
morluto:mainfrom
earakely-scale:feat/environment-state-targets

Conversation

@earakely-scale

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

Copy link
Copy Markdown
Contributor

Summary

Across the 50 published capture-built environments, 91 of 195 write tools got no state target. The gate refused them before weighing any evidence, because their path named no state type, item or document. We traced each of the 91 to its cause in the recordings and the code. This PR fixes the five largest shared causes:

  1. Read-only POSTs (lookups, read-only RPC tunnels, session refreshes) were planned as writes.
  2. Entities created by a write the gate doesn't model failed the first read that showed them.
  3. Creates whose path is not the read path (POST /Playlists, read as /Items/{Id}) had no target, and their entity leaked into the initial state.
  4. A type whose reads disagree across an unrelated write stayed replayed.
  5. Variant request lines (?counts=true, ?expand=, ?fields=), which show the same entities in another form, failed the whole view.

Over the same captures, served write tools go from 46 to 61 and no-state-target from 91 to 61. No served write and no state-backed read view is lost, and every served write tool applies.

Refs #4933. One commit per cause; each commit's tests fail on the commit before it. The spec is docs/specs/agent-environments/state-targets/.

Problem and expected behavior

  • Read-only calls. A POST stops counting as a state write, and is replayed, when any of these holds:

    • its response repeats the read of its path that finished last before it began, with no write between;
    • it tunnels only read operations;
    • its path's last meaningful word names a lookup;
    • it renews a session.

    It stays a write when a related read line changes across one of its calls, or finds its entity gone after it; a read overlapping the call counts on neither side. For example, Grafana's query-history stays a write.

  • Adopted entities. A write that no built plan models, or one redirected or unanswered, can create an entity the gate's copy never held. When a successful item read later shows that entity, the gate puts it into the copy, and later writes to it are checked as usual. An entity a modelled write touched is never taken back.

  • Linked creates. A POST whose path names no state type becomes a create into the type whose item read first names an id its response returned, before any other tool's write, as long as the id is new. Its observation is a read of an id its response returned, in an envelope too. Serving creates in that read's collection, for the recorded path arguments in either spelling. If a type's reads only show such an id once the POST began, the POST ends that type's initial window; a list read shows its listed entities' own ids, not those they nest.

  • Rewrite cuts. When a type's reads disagree across a write under another root, its initial window ends at the earliest write within the change, and the state is extracted again. When both cuts apply, the earlier wins.

  • Variant lines. A read line that shows the same entities in another form is a variant.

    • It is either an extra query parameter that adds or drops members, or it conflicts with a base line on a shared entity.
    • It leaves the view's checks and the entity observations.
    • Item and list views name it with the query keys that pick it out (projected_query_keys).
    • A call matching those keys replays its recording, so it does not show served writes.
    • A 400, 404 or 410 on such a line is still evidence.

    A learned filter role whose name matches no field needs two agreeing values.

Change and scope

  • Self-contained:
    • new modules: environmentStateQueryCalls.ts, environmentStateWriteAdoption.ts, environmentStateWriteLinks.ts, environmentStateRewrites.ts and environmentStateVariants.ts;
    • small hooks in the extraction, the write simulation, the gate, list queries, the view schema and serving.
  • Not included:
    • item actions (/{type}/{id}/archive);
    • bulk writes at a collection path;
    • templating literal ids by value;
    • envelope masking;
    • making a value that differs between two request lines volatile. This contradicts the spec's distinct query strings, and it made 11 recorded reads answer otherwise than replay.
  • Scope: analysis of existing Evidence, and serving from it, inside the existing boundary. No target execution.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the environment-state analysis view (src/domain/analysisView/), then serving.
  • Contribution scope fit and linked maintainer decision: extends the existing state and write-gate model; not applicable.
  • CLI and MCP/tool-catalog contract:
    • item and list views gain an optional projected_query_keys, and list views may now carry projected_record_ordinals;
    • a replayed answer can carry the provenance reason variant;
    • read-only POSTs leave the write plans and stay in the served catalog as reads;
    • the catalog check passes.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract:
    • States whose views, plans or initial windows change get new Evidence ids.
    • Supplied states keep loading.
    • The Grafana and Mailpit initial states no longer hold the dashboard and message their captures created, so those environments should be rebuilt.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

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

Measurements. All 50 published captures, one commit at a time on main.

  • The served smoke rebuilds each manifest with the tree under test and applies every served write tool.
  • The serving check answers every recorded read made before the capture's first write through state serving, and compares it with the recording.
  • The serving check reads no records from the five browser-scenario captures (Art Institute collection, LoC photos, Lychee, PhotoPrism, Pinry), so its read counts cover 45 apps; their 41 views count among the state-backed views.
Step Write tools Served No state target State-backed read views Recorded reads matching
main 195 46 91 1,098 1,833 of 1,886
read-only POSTs 189 46 84 1,104 1,911 of 1,964
adoption 189 47 84 1,104 1,911 of 1,964
linked creates 189 48 80 1,105 1,911 of 1,964
rewrite cuts 189 51 77 1,110 1,922 of 1,975
variant lines 189 61 61 1,150 2,068 of 2,126
review fixes 189 61 61 1,151 2,075 of 2,133
third round 189 61 62 1,151 2,075 of 2,133

Newly served write tools:

  • Grocy product delete;
  • Jellyfin item delete;
  • Tandoor recipe create, update and delete;
  • Baserow row create, update and delete;
  • Keycloak user delete;
  • Miniflux category create and update;
  • PocketBase create, update and delete;
  • Vikunja task delete.

Of the 40 views that variant lines make state-backed, 146 of 151 recorded reads made before the first write match. The other five are Sentry projects, which replay the first of several differing recordings, as before.

Review round. The 10 Greptile and Codex threads are fixed in three commits, each finding with a test that fails without it:

  • read-only POSTs: body-level batch wrappers, the last path segment's write word, redirected or unanswered calls, and a veto resolved over all candidates;
  • adoption and linked creates: adopted entities are charged to the budget, a linked create holds only for its exemplar's path arguments, and short identity-named ids link with a guard;
  • variant lines: a field selection replays unless the state shows it exactly, and a list's fields line is set aside before the identity proof.

No write verdict changes; one NocoDB records list becomes state-backed (7 of 7 recorded reads match).

A second round fixed 8 more threads in three commits, again each with a test that fails without it: the write gate now skips exactly the reads serving replays; an earlier list or collection read showing a returned id vetoes a linked create; an RPC batch reads only when every entry names a read operation; a planning pass a rewrite cut discards is released from the budget; and no unbounded array is spread into call arguments. No measurement changes.

A third round fixed 9 more Codex and Greptile threads in one commit, each with a test that fails without it:

  • read-only POSTs: a repeated read must have finished before the call began, the veto compares reads that finished before and began after the call and counts a recorded absence as a change, and findAndModify-style operations stay writes;
  • adoption and links: a redirected or unanswered write lets a later read adopt what it made, a read still running when a POST began counts as after it, a list read's ids are its listed entities' own, and a linked create's read must come before any other tool's write;
  • budget and selections: line shapes are charged as they are built, and a fields=* list line is whole.

Mailpit's send, a linked create that was never observed, loses its target, because other writes ran before the read naming its id. No served write, read view or matching read changes.

A fourth round fixed the 6 threads the bots raised on that push, in one commit, each with a test that fails without it:

  • a linked create is observed only in a read of an id its response returned, envelopes included, and serving takes its recorded path values in either spelling;
  • a read-only POST compares the read that finished last before it began;
  • a list read also shows a suffix-named identity (projectId) distinct across its entities;
  • an entity's first sighting comes from the lines left after variant lines are dropped, so a plain list in another order keeps whole membership;
  • the pairwise variant pass stops at a work limit, leaving every line checked.

No verdict, read view or recorded read changes. A purge of temporary files removed 32 of the local captures, so this round was measured on captures restored from the published datasets. Where a local copy survived they are byte-identical; Baserow's, Grocy's and Keycloak's published captures predate the ones in the table. On that set, the previous head and this one both give 187 write tools, 62 served (smoke 62 of 62), 1,151 views and 2,085 of 2,155 recorded reads matching.

A fifth round, after main 6a34be41 was merged, fixed Greptile's 3 threads in one commit, each with a test that fails without it:

  • a list read counts a suffix-named field such as projectId as its entities' ids only when no id-named field identifies them, so a foreign key beside id cuts no window;
  • a read-only POST is compared with the read that finished last among those no other write follows, so a consuming call stays a write;
  • a linked create's source path values compare as spelled on both sides, so no spelling is decoded twice.

Nothing changes on the restored captures.

A sixth round fixed 5 more Greptile and Codex threads in one commit, each with a test that fails without it:

  • a linked create's source values compare segment by segment, so a template naming two parameters alike refuses a changed first one;
  • serving fills a linked create's path fields with its arguments decoded once, as the gate learned them;
  • the read-only check reads each related line's records once per call;
  • member signatures are JSON arrays, so a member name holding the separator still conflicts, and the variant work limit counts line pairs as well as entities.

Nothing changes on the restored captures.

A seventh round, after main 96ea32b7 was merged, fixed 4 more Greptile and Codex threads in one commit, each with a test that fails without it:

  • an item line first recorded after a write that names a new shaping parameter and shows other members is a replayed variant, like an initial one;
  • an item only a replayed line showed, which the state never started with, answers with its own recording;
  • a linked create fills its path fields from its exemplar's path decoded once, whichever accepted spelling the call sends;
  • each membership change span is charged against the budget.

WordPress's post create moves from side-effect to unconfirmed, still unserved: its only later read asks for context=edit, which shows the edit representation, so it is now replayed rather than checked.

An eighth round, after main 3e7e102a was merged, fixed 6 more Greptile and Codex threads in two commits, each with a test that fails without it:

  • item lines first recorded after a write are decided once variants are dropped, against the lines left, so a later ?include=shelf beside a dropped ?expand=shelf replays, and a later ?fields=id,name that keeps the identity replays too;
  • a linked create's earlier-read checks count only reads finished before the call began, so a list still running when it began no longer refuses the link;
  • each replay key is charged against the budget, and a rewrite span's earliest write is found by bisection.

Nothing changes on the restored captures.

A ninth round, after main b7ebccf8 was merged, fixed 5 more Greptile and Codex threads in one commit, each with a test that fails without it:

  • an item only a replayed line showed replays only while no served create has added to its type, so a created and deleted item stays missing;
  • a linked create's earlier item-read veto checks only the candidate's type or collection, and an item read answered with JSON null shows no id;
  • late lines' member names are charged before they are kept, and the read-only check passes once over each write-free stretch.

Nothing changes on the restored captures, session replay included (2,764 of 3,022 session reads matching).

A tenth round, after main a2235b09 was merged, fixed 3 more Greptile threads in one commit, each with a test that fails without it: a linked create passes over an item read naming its id that shows no item; repeated reads for read-only POSTs are found in one sweep; and a creation cut keeps and charges only the ids some creation returned. Nothing changes on the restored captures.

Three serving cases an independent review flagged were fixed before this PR:

  • a paged Paperless list now answers all five documents;
  • a PocketBase item without expand now answers without it;
  • a NetBox filter learned from one line is not adopted.

End-to-end rebuilds. Five published environments last built on 10-18 were re-recorded on disposable Linux VMs and rebuilt with this branch.

  • Recording: each write tool got two scratch objects, and every write was read back at once by item and by whole list. Updates and deletes also ran on a seeded entity.
  • Results: each passed smoke, retrieval and write evals, and was published.
Environment Served write tools Retrieval (gpt-oss / GLM) Write tasks (gpt-oss / GLM)
Grocy product create, update, delete 12/12 / 12/12 3/3 / 3/3
Mattermost post create, update, delete 12/12 / 12/12 3/3 / 3/3
Baserow row update, delete 12/12 / 12/12 3/3 / 3/3
Keycloak user delete 12/12 / 12/12 1/1 / 1/1
Grafana folder delete 12/12 / 12/12 1/2 / 2/2
  • Grafana: its initial state holds no dashboard or folder the capture created. The gpt-oss write miss is a provider rejection of the model's tool call.
  • Mattermost: POST /channels/{id}/members/ids replays as a lookup, and its channel, members and pinned reads answer from state.
  • Gaps these rebuilds expose, still unserved:
    • Keycloak's user create: its list shows access as a summary while its item shows the full map, and a created entity carries only the item's values;
    • Baserow's row create: a position sequence written as a decimal string, 5.0000…;
    • Grafana's folder create and rename: server-generated ids, URLs and versions.

Tests, each failing on the commit before:

  • read-only rules and their guard;
  • adopting an entity a write with no plan made, and not one a modelled write touched;
  • linked creates, and the creation cut with its two guards;
  • rewrite cuts and their composition with the creation cut;
  • variant list and item lines, by added, dropped and conflicting members;
  • a variant call that replays while the plain call answers from state;
  • a 404 on a variant line still confirming a delete;
  • single-line filter roles.

Nine existing view tests that asserted a rewritten type stays fields-differ now assert the cut and re-plan.

Remaining proof gaps:

  • After a write that is not served, a state-backed read can disagree with a recording made after that write (for example, a 404 right after a replayed create). This follows the existing rule.
  • Variant-line calls replay, and do not show served writes.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.

Validation performed

Run on macOS with Node v22.23.1, on the branch with main a2235b09 merged.

  • npm run -s check:fast (no new oxlint warnings in the changed files), npm run -s format:check, npx knip, npm run -s scan:todos, npm run -s docs:check, npm run -s verify:test-discovery, npm run -s verify:module-boundaries, npm run -s mcp-catalog:check and npm run jscpd (3.59%): passed.
  • npx vitest run --project domain --project services: 9393 passed, 6 pre-existing skips, and 10 failures that main has on its own (javascriptStaticAnalysis.mapEndpoints, javascriptStaticAnalysisReturnedInvocation, FridaInstrumentationService).
  • npm run -s test:prepare, then the 8 focused boundary files (environment serve and export CLI, serve and served-writes MCP, analysis-view CLI and MCP, compact input schema, tool schema validity): 90 passed.
  • The census on the restored captures, with the serving check passing a repeated query value as an array and a full session replay: unchanged by this round.
  • CI tests that fail on main itself are listed in the earlier rounds above; the agentenv bundle job failed once on a Docker Hub 502 and passed on the next run.

After merging main 3d4f5565 and then 2968d1e9, both without conflicts, into c166a694:

  • The static gates above: passed; npm run jscpd: 3.52%, main's own level.
  • npx vitest run --project domain --project services at 3d4f5565: the same 148 failing tests as main 3d4f5565 on this machine (Node v22.23.1, below main's new ^22.23.4 floor), none new. The boundary failures (clientConfigurationEnvironment and one analysisViewCli inventory test) fail on main too.
  • At c166a694: typecheck and format passed, the environment tests passed (1013), and the 8 focused boundary files passed (91). The census, served smoke, initial serve check and session replay are unchanged: 187 write tools, 62 served (smoke 62 of 62), 59 without a state target, 1,151 views, 2,085 of 2,155 initial reads and 2,764 of 3,022 session reads matching.
  • CI on c166a694: every build and test job passed.

After the four performance review threads on c166a694 (9614465f, checks recorded in 53b2966c):

  • The variant pass indexes lines by the entities they show and compares only lines sharing one; read-only decisions keep each body's canonical digest, taken once inside its charged parse; the creation cut skips reads at or after the write that ends the initial reads; adoption looks up a target only after an unplanned write.
  • Each of the 7 new tests failed on c166a694 with the old accessors wired as production wired them (work counts, a budget charge, and body access outside a lease); the test I/O now hands bodies through withBody, so the files' other tests no longer run against the old interface.
  • The static gates above passed (npm run jscpd: 3.53%); npx vitest run --project domain --project services: 9814 passed, 6 skipped, none failed; the environment boundary projects: 100 passed; the 8 focused boundary files: 91 passed.
  • Every census, serving-check and session-replay row equals the previous head's (62 served, 2,085 of 2,155 initial reads, 2,764 of 3,022 session reads). On a synthetic list plus 1,000 items read plainly and with ?expand=, the variant pass falls from 401 ms to 2 ms and the state build from 659 ms to 216 ms.

After the reviewer's second performance suggestion (3dd85f21), main d87e73f2 (f55c7315, and the same merge pushed by the reviewer, f151988a) and the round's checks (dee4dd75), at 3608c5aa, on macOS with Node v24.22.1 and main's locked dependencies:

  • The write gate lists a type's collections only when the path's own collection holds no id, and the variant pass parses base lines once (and not at all when it finds no variant). Both new tests fail on 53b2966c; the other 180 tests in their files pass there.
  • The static gates above passed (npm run jscpd: 3.58%); npx vitest run --project domain --project services: 9852 passed, 6 skipped, none failed; the environment boundary projects: 101 passed; the 8 focused boundary files: 93 passed. Every census, serving-check and session-replay row equals the previous head's.
  • The reviewer's synthetic capture (a list, then 1,000 items read plainly and with ?expand=): 259–264 ms against main's 244–247 ms, from 378–397 ms (Node v22.23.1, medians of seven warm runs).
  • The 50 captures' environment-state and environment-manifest views in one process: 2.96 s wall, 3.82 s CPU, 540 MiB peak RSS, against main d87e73f2's 2.61 s, 3.41 s and 516 MiB (warm medians of three runs; cold within 2%). The environment-state view takes 2,093 ms against 1,791 ms and its results grow from 3.69 MB to 3.84 MB; agent tokens were not measured.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Views gain optional members, and existing states load unchanged.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new inputs; reads retained Evidence only.

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

earakely-scale and others added 6 commits October 22, 2026 12:22
A POST that repeats the latest read of its path, tunnels only read
operations, names a lookup in its path's last meaningful word, or renews
a session no longer counts as a state write: it is replayed, does not cut
initial windows, and does not end observation searches. A tool stays a
write when a related read line changes across one of its calls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…first shows it

A successful item read of an entity the gate's copy never held, after a
write no built plan models, puts the entity into the copy instead of
failing the read, so later writes to it are checked as usual. An entity a
modelled write touched is never taken back.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… under

A POST whose path names no state type becomes a create into the type
whose item read first names an id its response returned, when the id is
new to the state; serving creates in that read's collection. A successful
POST that returned an id a type's reads only show after it also ends that
type's initial window, so entities a capture created stay out of the
initial state.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…isagree across

When a type's reads disagree across a write under another root, the
type's initial window now ends at the earliest write within that change
and the state is extracted again, instead of leaving every view of the
type replayed. The cut composes with the creation cut; the earlier wins.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…form

A read line that shows the same entities in another form, by an extra
query parameter that adds or drops members, or conflicts with a base
line on a shared entity, is a variant: it leaves the view's checks and
the entity observations, the view names it with the query keys that pick
it out, and a call matching those keys replays its recording. A filter
role whose name matches no field needs two agreeing values.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@earakely-scale
earakely-scale marked this pull request as ready for review October 22, 2026 19:33
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

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-24T06:11:46.592642Z
We couldn’t complete this review. Comment @codex review to try again.
3608c5a New commits
ℹ️ 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.

@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with a non-blocking performance concern remaining in repeated-call analysis.

Summary

The PR gives more recorded write tools a state target while keeping unsupported reads on replay.

  • POST calls that only read stay reads in captured environments.
  • Later reads add entities made by writes the state did not model.
  • Creates on one path can target the type where their returned ID appears.
  • Changed reads end a type's initial state at the write between them.
  • Reads in another representation replay their captured answers.
  • State-view contracts and capture examples describe the expanded serving rules.

The previous-review ancestry check passed, but the merge bases differed. This review therefore used the full PR diff. Supersession could not be checked on GitHub because authentication was unavailable. No new security issue was established from the changed paths; no runtime verification was performed.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Capture[Recorded calls] --> Classify[Separate reads from writes]
  Classify --> Extract[Build initial state]
  Extract --> Cut[Apply creation and rewrite cuts]
  Cut --> Variants[Separate variant reads]
  Variants --> Gate[Check recorded write effects]
  Gate --> Serve[Serve confirmed writes]
  Variants --> Replay[Replay variant reads]
Loading

Reviews (12) · Last reviewed commit: "docs(environment): record the tenth revi..." · Reviewed by Greptile

@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: 28c3ae97a9

ℹ️ 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".

earakely-scale and others added 5 commits October 22, 2026 14:37
…incomplete

Body-level container operations are skipped like query ones, a lookup is named only
by the path's last literal segment and never alongside a write word, a tool with a
redirected or unanswered call is not reclassified, and the mutation veto is resolved
over all candidates at once so another read-only call cannot explain a read change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…it exactly

Serving tests a field selection before any variant key: a projection value a replayed
read gave, or one no checked line gave other than `*`, replays. A list sets aside a
line asking for some fields only before the identity proof, and a dropped variant's
membership change no longer rewrites the type.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e recording shows

An adopted entity is charged against the view's budget like a created one. A linked
create holds only for its exemplar's path arguments: serving refuses others and the
gate counts such a call as unmodelled. A response's identity-named id links at any
length, but a short one only to a type read before the call.

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: 6656816dd6

ℹ️ 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".

earakely-scale and others added 5 commits October 22, 2026 16:33
…gain

A rewrite cut clears the first pass, so the budget rewinds to a checkpoint taken after
the write cutoffs and created ids before the state is extracted again. Rewrite spans are
charged and appended without spreading them into an argument list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… read only whole batches

A linked create is rejected when an earlier list of its type or read of its collection
showed the returned id. Body ids are walked without spreading children into an argument
list. An RPC call reads only when every operations entry names an operation of its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Serving's replay decision moves to the domain as replayReason, and the write gate uses it:
a read serving replays can neither approve nor veto a write, and a read of every field
beside a replayed selection is checked. A selection read missing a required field is
still skipped, since part of an entity can neither confirm nor check it.

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: 197b1a3d8b

ℹ️ 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".

earakely-scale and others added 3 commits October 22, 2026 18:36
…ence that rules out other causes

- A read-only POST repeats only a read that finished before it began; the veto compares
  the latest read finished before a call with the first begun after it, and counts a
  recorded absence on one side as a change. `modify` and `replace` are write words.
- A redirected or unanswered write lets a later item read adopt the entity it may have made.
- A creation cut counts a read still running when the POST began as after it, and a list
  read shows its listed entities' own ids, not those they nest.
- A linked create's item read must come before any other tool's write.
- Line shapes are charged to the budget as they are built.
- A `fields=*` list line is whole, not a field selection.

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

ℹ️ 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".

earakely-scale and others added 3 commits October 23, 2026 13:22
… earlier reads, and bound late lines and read-only stretches

- An item only a replayed line showed replays only while no served create has
  added to its type, so a created and deleted item stays missing.
- A linked create's earlier item-read veto checks only reads of the candidate's
  type or collection that show the item, so another type's id does not hide it.
- An item read answered with JSON null shows no id to a creation cut.
- Late lines' member names are charged before they are kept.
- The read-only check precomputes nearest writes and passes once over each
  write-free stretch per path, skipping lines whose reads all agree.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
earakely-scale and others added 4 commits October 23, 2026 14:17
…reads once and keep only returned ids for creation cuts

- A linked create passes over a later item read naming its id whose body shows
  no item, such as JSON null, and links the next one.
- Read-only repeated reads are found in one sweep: each path's reads wait by
  end time until a call's start passes them, and a write clears them.
- A creation cut keeps, and charges, only the shown ids some creation returned.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@kaoru0822-kitauji kaoru0822-kitauji left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review of c166a69 (correctness, performance, and the composability/evidence principles). I found no correctness defects in the new read-only, adoption, link, rewrite or variant logic. I traced the counterexamples I could think of (overlapping reads, redirected calls, short ids, envelope ids, field selection *), and the existing tests cover them.

Findings are inline. All are performance or budget-accounting issues, and only the first is measured. AGENTS.md (Performance) asks for before/after timing, CPU and peak memory when a change affects analysis cost. This PR adds several passes over the timeline (read-only detection with a veto loop, creation limits, variant lines, a possible second planning pass after a rewrite cut), but the PR body and verification.md report coverage counts only. A cold/warm timing of the 50-capture sweep on main vs this branch would close that gap.

Note: the Validate author declaration check fails on this head. That is the human-owner readiness declaration, which only you can complete; it isn't something a reviewer can fix.

Codex couldn't review this head: the retrigger returned "usage limits reached".

🤖 Generated with Claude Code

earakely-scale and others added 2 commits October 23, 2026 20:19
…parse each compared body once

The variant pass indexes a tool's lines by the entities they show and compares only lines that share one, charging
the index to the budget while it is held; the pairwise work limit still decides when a tool keeps every line checked.
Read-only decisions keep each response body's canonical digest, taken once while its parse is charged, across calls
and veto passes. The creation cut no longer parses reads at or after the write that ends the initial reads, and reads
the ids a body shows inside its lease. Adoption looks up a read's target only after an unplanned write before it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@earakely-scale

Copy link
Copy Markdown
Contributor Author

@morluto this is ready for review. It merges cleanly with main (2968d1e9 is merged) and every review thread is resolved. The only red CI job is tests/boundary/providers/native/nativePlistFileCleanup.test.ts, which main fails on its own (run 40056434325 at 7f70797b). #6897 builds on this PR.

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Follow-up performance check on 53b2966, on behalf of the repo owner. Thanks for adopting the variant change. 9614465 brings the 1000-item capture (each item read plainly and with ?expand=shelf) from 835 ms to ~431–447 ms. I profiled what remains against main's merge-base 2968d1e (265–292 ms; Node 24.22.1, macOS arm64, warm single runs, wall time of servedFrom).

Where the remaining ~150 ms goes

  1. ~90 ms: the write gate's itemTarget → SimulatedState.ofType (O(N) per read, O(N²) per capture). Main refuses this capture's item view (recorded, fields-differ), so its gate never checks those reads. This PR serves the view, so the gate now checks all 1000 reads, and each check calls itemTarget up to three times (#resynced, #check, checkItemRead). itemTarget builds state.ofType(type).map(...) eagerly as an argument to matchingTarget, even though matchingTarget returns on its first check whenever the path's own collection holds the id, which is the common case. The cost is pre-existing code that this PR now exercises at scale. Making the collections argument lazy keeps results identical and skips the scan on that path.
  2. ~50 ms: the variant pass re-parses query strings. withoutVariants calls replayKeys(unkeyed…, [record.query]) once per found variant, and each call re-parses every base line's query with URLSearchParams and scans baseValues per value. That is V × L parses. Parsing the base lines once (keyBase: values per parameter as Sets, plus the parameters every base line names), reusing it for every variant and swapping found.includes for a Set gives the same keys.

Result with the patch below: 286–299 ms vs main's 265–292 ms, i.e. parity within noise, while serving a view main refuses. With the patch applied on 53b2966, all 41 environment / web-network analysisView and src/application/environment test files pass (1160 tests), and npm run check:fast and npm run format:check pass.

I'm leaving this as a suggestion rather than pushing: environmentStateWriteChecks.ts is outside this PR's diff, and you're actively iterating.

Patch (git apply on 53b2966)
diff --git a/src/domain/analysisView/environmentStateVariants.ts b/src/domain/analysisView/environmentStateVariants.ts
index da5918930..e6b6ba049 100644
--- a/src/domain/analysisView/environmentStateVariants.ts
+++ b/src/domain/analysisView/environmentStateVariants.ts
@@ -273,19 +273,42 @@ const isVariant = (
   [...conflictingLines(mine, shown)].some((line) => base.lines.has(line)) ||
   (namesNewParameter(record.query, base) && showsOtherMembers(mine, base));
 
+/** What replay keys are found against: every value each base line gave a parameter, and the parameters every base line names. */
+interface KeyBase {
+  readonly values: ReadonlyMap<string, ReadonlySet<string>>;
+  readonly everywhere: readonly string[];
+}
+
+/** Parse the base lines' queries once, for any number of replayed lines. */
+const keyBase = (base: readonly (string | null | undefined)[]): KeyBase => {
+  const baseValues = base.map(queryValues);
+  const values = new Map<string, Set<string>>();
+  for (const line of baseValues)
+    for (const [name, given] of line) {
+      const seen = values.get(name) ?? new Set<string>();
+      values.set(name, seen);
+      for (const value of given) seen.add(value);
+    }
+  const everywhere = [...values.keys()].filter(
+    (name) =>
+      !PAGING.has(name.toLowerCase()) &&
+      baseValues.every((line) => line.has(name)),
+  );
+  return { values, everywhere };
+};
+
 /** The keys that tell replayed lines from base lines: a parameter or value only replayed lines give, or a parameter every base line names that one leaves out. */
 export const replayKeys = (
   base: readonly (string | null | undefined)[],
   replayed: readonly (string | null | undefined)[],
   retain: (bytes: number) => void = () => undefined,
+): ReplayKey[] => keysAgainst(keyBase(base), replayed, retain);
+
+const keysAgainst = (
+  { values: baseValues, everywhere }: KeyBase,
+  replayed: readonly (string | null | undefined)[],
+  retain: (bytes: number) => void,
 ): ReplayKey[] => {
-  const baseValues = base.map(queryValues);
-  const named = new Set(baseValues.flatMap((values) => [...values.keys()]));
-  const everywhere = [...named].filter(
-    (name) =>
-      !PAGING.has(name.toLowerCase()) &&
-      baseValues.every((values) => values.has(name)),
-  );
   const keys = new Map<string, ReplayKey>();
   const add = (key: ReplayKey): void => {
     const id = JSON.stringify([
@@ -302,14 +325,10 @@ export const replayKeys = (
     const values = queryValues(query);
     for (const [name, given] of values) {
       if (PAGING.has(name.toLowerCase())) continue;
-      const unseen = given.filter(
-        (value) =>
-          !baseValues.some(
-            (other) => other.get(name)?.includes(value) === true,
-          ),
-      );
-      if (!named.has(name)) add({ name });
-      else for (const value of unseen) add({ name, value });
+      const seen = baseValues.get(name);
+      if (seen === undefined) add({ name });
+      else
+        for (const value of given) if (!seen.has(value)) add({ name, value });
     }
     for (const name of everywhere)
       if (!values.has(name)) add({ name, absent: true });
@@ -408,13 +427,14 @@ export const withoutVariants = (
   const release = facts.checkpoint();
   const found = variantLines(plan.latest, facts.shapeOf, facts.retain);
   release();
-  const unkeyed = plan.latest.filter((record) => !found.includes(record));
+  const variant = new Set(found);
+  const base = keyBase(
+    plan.latest
+      .filter((record) => !variant.has(record))
+      .map((line) => line.query),
+  );
   const variants = found.filter(
-    (record) =>
-      replayKeys(
-        unkeyed.map((line) => line.query),
-        [record.query],
-      ).length > 0,
+    (record) => keysAgainst(base, [record.query], () => undefined).length > 0,
   );
   const lines = new Set(variants.map(requestLine));
   const latest = plan.latest.filter(
diff --git a/src/domain/analysisView/environmentStateWriteChecks.ts b/src/domain/analysisView/environmentStateWriteChecks.ts
index 7526160d6..17c97e6fd 100644
--- a/src/domain/analysisView/environmentStateWriteChecks.ts
+++ b/src/domain/analysisView/environmentStateWriteChecks.ts
@@ -240,12 +240,13 @@ const matchingTarget = (
     readonly ids: readonly string[];
     readonly written: string;
   },
-  collections: readonly string[],
+  /** Read only when the path's own collection holds no id, since listing them walks the type's entities. */
+  collections: () => readonly string[],
   held: (collection: string, id: string) => boolean,
 ): { readonly collection: string; readonly id: string } | undefined => {
   for (const id of path.ids)
     if (held(path.written, id)) return { collection: path.written, id };
-  const ranked = [...new Set(collections)]
+  const ranked = [...new Set(collections())]
     .flatMap((collection) => {
       const verbatim = segmentMatch(segmentsOf(collection), path.read);
       return verbatim === undefined ? [] : [{ collection, verbatim }];
@@ -278,12 +279,12 @@ export const itemTarget = (
   return (
     matchingTarget(
       path,
-      state.ofType(type).map((entity) => entity.collection),
+      () => state.ofType(type).map((entity) => entity.collection),
       (collection, id) => state.entity(type, collection, id) !== undefined,
     ) ??
     matchingTarget(
       path,
-      removed.map((target) => target.collection),
+      () => removed.map((target) => target.collection),
       (collection, id) =>
         removed.some(
           (target) => target.collection === collection && target.id === id,

🤖 Generated with Claude Code

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

On behalf of the repo owner, I pushed f151988: a merge of latest main (d87e73f) into this branch, with no conflicts and no other changes. Your last push was over two hours ago, so I wasn't racing you.

Why: the red required checks on the previous head came from main, not this PR. They were native plist tests (plistSourceFormat, nativePlistFileCleanup) and later stale fixtures (AppleDispatchMetadata.failure, packageTarListing, deferredRuntime, the webpack export-key acceptance test). main fixed them in the plist commits, #6945 and #6951. A rerun would reuse the old merge ref, so the branch needs main merged in.

Validation (local, Node 24.22.1): 41 environment / web-network analysisView and src/application/environment test files (1167 tests) pass; so do npm run check:fast and npm run format:check.

🤖 Generated with Claude Code

earakely-scale and others added 4 commits October 23, 2026 22:55
… holds no id, and parse variant base lines once

The write gate's item target lists the type's held collections, and the removed targets', only when the path's own
collection holds none of its ids, so a served item view's reads no longer walk every entity of the type. The variant
pass parses the base lines' queries once for all the variants they key, and not at all when it found none.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@earakely-scale

Copy link
Copy Markdown
Contributor Author

@morluto this is ready for review: CI is green at 3608c5aa, every review thread is resolved, and it merges cleanly with main.

@kaoru0822-kitauji thanks for the follow-up: both changes are in 3dd85f21 (the variant pass also skips the parse when it finds no variant). The 1,000-item capture now takes 259–264 ms against main's 244–247 ms, and the PR body and verification.md report the 50-capture sweep's wall time, CPU and peak memory against main.

@morluto
morluto merged commit 977c972 into morluto:main Oct 24, 2026
40 of 42 checks passed
@morluto morluto mentioned this pull request Oct 25, 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