Skip to content

feat(environment): serve writes whose values the application renames or regenerates - #6136

Merged
gensokyo-dev merged 142 commits into
morluto:mainfrom
earakely-scale:feat/environment-write-assigned-values
Oct 22, 2026
Merged

gensokyo-dev merged 142 commits into
morluto:mainfrom
earakely-scale:feat/environment-write-assigned-values

Conversation

@earakely-scale

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

Copy link
Copy Markdown
Contributor

Summary

Refs #4933. Explain and locally serve captured writes where the application stores a create member under another name, replaces a version UUID, or renews nested child UUIDs. No new target execution or remote application writes. Shared domain/application rules serve both CLI and MCP, with retained Evidence ordinals and existing fail-closed checks.

Integrated latest author 7f99adf onto main including #6169. Independent Codex review found two concrete defects, now fixed at the explanation owners: every text occurrence must rebuild an accepted copy, and scalar generation is withheld when its new UUID is shared with another output field. Unsupported scalar/nested links remain unexplained rather than being silently disconnected. Existing nested-only renewal and isolated UUID generation remain supported.

Executed validation

  • 742 related source tests passed, including three new capture→state→serving guards that all fail before the follow-up fixes and pass after them. Existing malformed-body, permission, capacity, state identity, omission and projection tests remain covered.
  • 67 CLI/MCP boundary tests passed on the integrated feature; a final focused rebuild of serving and named schema validity is recorded in the merge follow-up.
  • Full static checks and docs check passed on the integrated feature; final fix-head checks/discovery are recorded in the merge follow-up. Initial final-check formatting failure was corrected, not ignored.
  • Local Codex CLI review reproduced the two findings with in-memory production functions; final targeted source review found no further definite regression. Automated review is not a human attestation.
  • Five immutable public capture datasets (Directus/Homebox/Mealie/Keycloak/Shlink) ran through real compiled CLI and stdio MCP with named schema validation, exact adapter fact/Evidence-ID parity and source-byte SHA-256 checks. The only cross-version Evidence change was Shlink's expected customSlug acceptance + shortUrl template; its unconfirmed write remains unserved, and all served-tool verdicts are unchanged.
  • Complete five-capture fresh-process task: main baseline 26.21 s wall / 41.16 s CPU / 1214 MiB sampled process-family RSS; integrated candidate 23.33 s / 37.59 s / 1173 MiB. One pair with uncontrolled host/filesystem warmth: no speedup claim. RSS is sampled every 500 ms, not an exact peak. No model-token reduction claim or added cache.

Limitations

Public-capture checks cover retained-data analysis, not live application persistence, the author's entire historical 50-capture census, or real provider/Windows behavior. Full historical author experiments remain in docs/specs/agent-environments/write-assigned-values/verification.md and were not independently rerun in full. Scalar UUID relations across output fields are deliberately withheld until a shared generation model can preserve them.

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.

earakely-scale and others added 30 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 <[email protected]>
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 <[email protected]>
… 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 <[email protected]>
…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 <[email protected]>
… 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 <[email protected]>
… 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 <[email protected]>
… 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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
…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 <[email protected]>
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 <[email protected]>
# 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 <[email protected]>
… responses

The environment-state view now holds every non-entity GET read with one
initial request line as a read-only document, infers identity from an
`...Id`/`..._id` field every listed item carries distinctly when no fixed
identity name does, and locates single entities wrapped in a one-element
array (`{"posts":[{...}]}`). Served tool descriptions say what each tool
returns, from its own recorded exchanges, and tools carry MCP annotations
(read-only, destructive, idempotent, closed world). On 44 recorded captures
the state renders 1,016 of 1,258 read tools, up from 710.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-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 <[email protected]>
…-state-coverage

Keep the view's rewritten-type refusal, one-list rule and earliest-sighting
order beside the read-only document and suffix-identity rules: identity is
still inferred only from listed items, and a read that is no list becomes a
document. The two view tests about such reads now expect documents.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t-state-coverage

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 <[email protected]>
…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 <[email protected]>
…ed value

identifies built every value before checking, so a wide first item
followed by many sparse items cost a full scan per suffix-named field.
It now returns at the first missing or repeated value; a regression test
counts reads over a 2,000-field item and 5,000 empty ones.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 <[email protected]>
…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 <[email protected]>
… 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 <[email protected]>
… into feat/environment-state-coverage

Keep main's tool description and change only its environment-state
documents clause to this branch's rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
earakely-scale and others added 7 commits October 21, 2026 22:00
…olatile fields and unchecked calls

A failed item read that is no absence leaves an unknown entity unknown, so
a later usable read still checks its writes. A read showing an unknown
entity again checks no write on a volatile field. An update of an unknown
entity takes its recorded outcome and adds nothing to a built plan. A later
update that does not answer with its entity is observed only by a read
whose view shows every learned clock; without one it is unmodelled.

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

The gate built a later create's path fields from the recorded request path,
while serving fills them from the held collection it selects for that path,
so a read showing the other spelling's parent could confirm a create serving
cannot reproduce. Rules still learn from the recorded path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ds updates write, and keep later members' types

An unmodelled write below an item path names its entity through itemTarget,
and one at or above a collection resolves the held collection, as modelled
writes do, so an encoded spelling no longer hides the entity it changed.
An update's answer counts the fields its rules write, other than increments,
as available, so a field only the update writes no longer makes it
incomplete-entities. A member a later call first stores keeps that call's
JSON type in the body's kinds, which the body check falls back to.

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

A body now records the kinds later calls stored. refinedBody and
conflictsWithPlan, which weigh a later call against the plan, join the
call checks in environmentStateWriteCalls.ts to keep the explanations under
the line limit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…er its object

A replacement claims only the members it wrote or removed, but it now
overwrites every earlier effect under its object, so a merge that wrote
the object it replaces loses its confirmation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Both sides named unmodelled writes as modelled ones do and dropped volatile
fields from members-only checks; this keeps the taint that also resolves
collection-level writes through heldCollection, and one volatile filter.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
earakely-scale and others added 2 commits October 21, 2026 23:17
…rite assigned values

morluto#5600 landed on main as a squash, so this merge takes 3f1f825, the write-plan
commit this branch last merged, as its base.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@earakely-scale
earakely-scale marked this pull request as ready for review October 22, 2026 14:56
@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-22T14:56:24.533262Z
We couldn’t complete this review. Comment @codex review to try again.
7e64c05 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 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 3/5 Tier: plus

[Medium impact] The changes affect the bounded workflow that analyzes and serves recorded environment writes.

Fix the two renewal issues before merging.

Findings

  1. P1 Renewed rows lose their links ▶
  2. P1 Mixed-case renewals are refused ▶
Fix with agent prompt
### Issue 1
src/domain/analysisView/environmentStateWriteGenerated.ts:149-153
An update sending `ownerId: B` can echo `B` into `ownerId` and also replace `rows[0].id` with `B`. `renewedRule` checks the new row ID against other entities, but not against the request or non-renewed output fields. It therefore mistakes the copied ID for a generated one.

The gate supplies recorded `B`, so the plan can pass. Serving instead gives the row an unrelated UUID while keeping `ownerId` equal to `B`, breaking their link. Refuse this plan unless the rules can preserve that link.

### Issue 2
src/domain/analysisView/environmentStateWriteGenerated.ts:119-125
A valid renewal is rejected when one nested field contains both lowercase and uppercase spellings of the same UUID. `paired.renewed` keeps both spellings as separate keys. `fresh` then lowercases their replacement values, so `new Set(fresh).size === fresh.length` fails even when both occurrences correctly renew to the same UUID.

The update becomes `unexplained-change` instead of being served. Check one replacement per lowercase old UUID when testing whether different UUIDs were merged.

---

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

Summary

Adds create rules for renamed values and templates, plus update rules for fresh scalar UUIDs and renewed nested UUIDs.

  • Creates can copy a renamed value and rebuild text that includes it.
  • Updates can regenerate UUIDs in fields and child rows.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Recorded writes and reads"] --> B["Explain copied and generated values"]
  B --> C["Gate uses recorded generated values"]
  C --> D{"Reads agree?"}
  D -- No --> E["Withhold write tool"]
  D -- Yes --> F["Save write plan"]
  F --> G["Served write"]
  G --> H["Copy sent values and rebuild text"]
  G --> I["Generate UUIDs and renew current rows"]
  H --> J["Save changed state"]
  I --> J
Loading

Reviews (3) · Last reviewed commit: "fix(environment): reject unsupported gen..." · Reviewed by Greptile

earakely-scale and others added 3 commits October 22, 2026 08:17
…es a template cannot rebuild

A UUID the call sent anywhere in its body is no fresh `unique` value. Renewal
keys UUIDs in lower case, so one UUID spelled two ways renews alike and is
spelled in each place's own case, and two old UUIDs renewed into one new one
are refused. A copied member whose value also sits in text no template
rebuilds around it is accepted only with its recorded value. The copy and
template helpers move to environmentStateWriteCopies.ts to keep the
explanations under the line limit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	src/application/environment/environmentStateWriteAnswer.test.ts
#	src/domain/analysisView/environmentStateWriteApply.test.ts
#	src/domain/analysisView/environmentStateWrites.test.ts
#	tests/fixtures/environmentStateWrites.ts
Check each text occurrence before accepting variable copied members, and withhold independently generated UUIDs shared with another output field.

Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
@gensokyo-dev
gensokyo-dev merged commit 7ec9b6e into morluto:main Oct 22, 2026
9 of 12 checks passed
@gensokyo-dev

Copy link
Copy Markdown
Collaborator

Merged as 7ec9b6e with original author credit and no coauthor trailer. Final follow-up: 742 source tests; 20 selected serving/schema boundary tests; static/docs checks; discovery of all 2049 tests; and a five-capture compiled CLI/MCP repeat passed. Repeat 23.56 s wall / 38.07 s CPU / 1200 MiB sampled family RSS, no surviving child processes; all ten Evidence IDs match the preceding candidate. Actual merge commit was rebuilt and all 8 selected source/CLI/MCP serving tests passed again. Independent local Codex review found two genuine defects, both fixed and guarded (three fail-before/pass-after production integration tests), then final targeted source review reported no further findings. GitHub CI/Greptile remained running/queued; the readiness job annotation was an Unhandled error: HttpError rather than a source failure. Used the explicitly authorized bypass; unfinished/errored checks are not claimed green. No live third-party apps or remote writes were exercised.

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

5 participants