[PR #5350] [MERGED] perf(environment): index observed-state write cutoffs #6886

Closed
opened 2026-11-01 21:43:50 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/5350
Author: @gensokyo-dev
Created: 10/20/2026
Status: ✅ Merged
Merged: 10/20/2026
Merged by: @gensokyo-dev

Base: main ← Head: gensokyo-dev/state-write-cutoffs-20261020


📝 Commits (1)

  • 27e3d5c perf(environment): index observed-state write cutoffs

📊 Changes

6 files changed (+314 additions, -28 deletions)

View changed files

📝 docs/specs/agent-environments/state-view/verification.md (+39 -1)
📝 src/domain/analysisView/EnvironmentStateExtraction.ts (+30 -15)
📝 src/domain/analysisView/environmentStateRules.ts (+0 -12)
📝 src/domain/analysisView/environmentStateView.test.ts (+58 -0)
➕ src/domain/analysisView/environmentStateWriteCutoffs.test.ts (+86 -0)
➕ src/domain/analysisView/environmentStateWriteCutoffs.ts (+101 -0)

📄 Description

Summary

State extraction reparsed every write root for each read type and repeated the search while assembling output. It now admits one prefix/wildcard index per projection, caches each type’s cutoff (including no match), and derives backed type membership once.

Follow-up to the final performance review on #5319. That PR was merged while this optimization was being validated; this diff is based on current main 3fca2e0ca.

Problem and expected behavior

With 1,000 collection tools and 1,000 unrelated writes, repeated root parsing costs CPU even though the projected state is unchanged. The same completed file-to-state task changed from 1,301 ms warm / 1,300 ms CPU to 624 ms warm / 624 ms CPU, with identical parent IDs and normalized output digests. First-call and process-family memory results are in verification.md; no general memory reduction is claimed.

Change and scope

  • Index write roots once, preserve ancestor/descendant and wildcard matching, and choose the earliest write using the existing timeline owner.
  • Admit index nodes and cutoff/type sets before retaining them; use iterative lookup for deep paths. Keep the 96 MiB representation budget.
  • Cache positive and negative per-type cutoffs within one projection. Remove the superseded linear matcher and repeated output plan scan.

Contract and boundary impact

  • Semantic owner: analysis-view domain, EnvironmentStateExtraction and StateWriteCutoffs.
  • Scope decision: not applicable; routine optimization of existing read-only capture analysis.
  • CLI/MCP contract, providers, formats and installation: unchanged; no new capability or dependency.
  • Evidence and reconstruction: equivalent complete outputs; original ordinals, uncertainty and inference semantics remain intact.
  • Target/cleanup authority: unchanged. All new state is bounded to the projection; no cross-request cache.
  • Generated outputs: regenerated and ignored as usual; no generated catalog or binary committed.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.

Evidence and regression coverage

  • Prefix, parameter, redacted-root and timestamp-order semantics; independent linear matching oracle; 12,000-segment lookup; existing capacity tests.
  • Same authenticated Evidence and complete normalized output digest in the before/after workload.
  • Real Gitea 28.2.0 HAR CRUD/search captures and fresh Chromium scenario capture, including file CLI/default stdio MCP parity and six exact HTTP replays.
  • Model token usage was not measured; no new macOS/Windows or state-serving claim.

Validation performed

  • Relevant domain/application/contracts plus capture validation: 41 files, 508 passed, 3 existing skips.

  • Serial static/build/artifact gate: 11 tasks passed; both selected compiled state CLI/MCP cases passed.

  • Docs/catalog/format checks: 9 tasks passed; architecture guards passed across 1,603 source files; README consistency: 5 tests passed.

  • One CPU/worker throughout; static/build peak process-family RSS 4,745 MiB. No workspace OOM.

  • GitHub CI: all selected lanes passed, including source tests, all five built test shards, portable aggregation, AgentEnv bundle execution and Linux native package verification.

  • Greptile reviewed 27e3d5cd61: 5/5, no actionable findings. Codex cloud review was unavailable because its review quota was exhausted.

  • The separate human-readiness declaration check is intentionally not attested and is bypassed under the operator’s explicit standing instruction.

Compatibility, safety, and release

No public schema, transport default, target authority or write-effect change. Matching and complete output digests are preserved. This optimization uses the existing first-related-recorded-write model and retains its documented inference limitations.

Author readiness

Human owner: @gensokyo-dev

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

Submitted ready under the repository operator’s explicit instruction. Human-review attestations remain unchecked.

Before merge

  • Concrete performance problem and linked original review.
  • Existing read-only scope and authority preserved.
  • Focused conventional title, semantic regression checks and current validation.
  • Owning verification document updated; no secrets or unrelated changes.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/5350 **Author:** [@gensokyo-dev](https://github.com/gensokyo-dev) **Created:** 10/20/2026 **Status:** ✅ Merged **Merged:** 10/20/2026 **Merged by:** [@gensokyo-dev](https://github.com/gensokyo-dev) **Base:** `main` ← **Head:** `gensokyo-dev/state-write-cutoffs-20261020` --- ### 📝 Commits (1) - [`27e3d5c`](https://github.com/morluto/rea/commit/27e3d5cd61cd7d9136b2ae64764f5f7d48fc6b84) perf(environment): index observed-state write cutoffs ### 📊 Changes **6 files changed** (+314 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `docs/specs/agent-environments/state-view/verification.md` (+39 -1) 📝 `src/domain/analysisView/EnvironmentStateExtraction.ts` (+30 -15) 📝 `src/domain/analysisView/environmentStateRules.ts` (+0 -12) 📝 `src/domain/analysisView/environmentStateView.test.ts` (+58 -0) ➕ `src/domain/analysisView/environmentStateWriteCutoffs.test.ts` (+86 -0) ➕ `src/domain/analysisView/environmentStateWriteCutoffs.ts` (+101 -0) </details> ### 📄 Description ## Summary State extraction reparsed every write root for each read type and repeated the search while assembling output. It now admits one prefix/wildcard index per projection, caches each type’s cutoff (including no match), and derives backed type membership once. Follow-up to [the final performance review on #5319](https://github.com/morluto/rea/pull/5319#discussion_r4321115857). That PR was merged while this optimization was being validated; this diff is based on current main `3fca2e0ca`. ## Problem and expected behavior With 1,000 collection tools and 1,000 unrelated writes, repeated root parsing costs CPU even though the projected state is unchanged. The same completed file-to-state task changed from 1,301 ms warm / 1,300 ms CPU to 624 ms warm / 624 ms CPU, with identical parent IDs and normalized output digests. First-call and process-family memory results are in [verification.md](docs/specs/agent-environments/state-view/verification.md); no general memory reduction is claimed. ## Change and scope - Index write roots once, preserve ancestor/descendant and wildcard matching, and choose the earliest write using the existing timeline owner. - Admit index nodes and cutoff/type sets before retaining them; use iterative lookup for deep paths. Keep the 96 MiB representation budget. - Cache positive and negative per-type cutoffs within one projection. Remove the superseded linear matcher and repeated output plan scan. ## Contract and boundary impact - Semantic owner: analysis-view domain, `EnvironmentStateExtraction` and `StateWriteCutoffs`. - Scope decision: not applicable; routine optimization of existing read-only capture analysis. - CLI/MCP contract, providers, formats and installation: unchanged; no new capability or dependency. - Evidence and reconstruction: equivalent complete outputs; original ordinals, uncertainty and inference semantics remain intact. - Target/cleanup authority: unchanged. All new state is bounded to the projection; no cross-request cache. - Generated outputs: regenerated and ignored as usual; no generated catalog or binary committed. Expected effects: - [x] 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. ## Evidence and regression coverage - Prefix, parameter, redacted-root and timestamp-order semantics; independent linear matching oracle; 12,000-segment lookup; existing capacity tests. - Same authenticated Evidence and complete normalized output digest in the before/after workload. - Real Gitea 28.2.0 HAR CRUD/search captures and fresh Chromium scenario capture, including file CLI/default stdio MCP parity and six exact HTTP replays. - Model token usage was not measured; no new macOS/Windows or state-serving claim. ## Validation performed - Relevant domain/application/contracts plus capture validation: 41 files, 508 passed, 3 existing skips. - Serial static/build/artifact gate: 11 tasks passed; both selected compiled state CLI/MCP cases passed. - Docs/catalog/format checks: 9 tasks passed; architecture guards passed across 1,603 source files; README consistency: 5 tests passed. - One CPU/worker throughout; static/build peak process-family RSS 4,745 MiB. No workspace OOM. - [GitHub CI](https://github.com/morluto/rea/actions/runs/39367372967): all selected lanes passed, including source tests, all five built test shards, portable aggregation, AgentEnv bundle execution and Linux native package verification. - Greptile reviewed `27e3d5cd61`: 5/5, no actionable findings. Codex cloud review was unavailable because its review quota was exhausted. - The separate human-readiness declaration check is intentionally not attested and is bypassed under the operator’s explicit standing instruction. ## Compatibility, safety, and release No public schema, transport default, target authority or write-effect change. Matching and complete output digests are preserved. This optimization uses the existing first-related-recorded-write model and retains its documented inference limitations. ## Author readiness Human owner: @gensokyo-dev - [ ] 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. Submitted ready under the repository operator’s explicit instruction. Human-review attestations remain unchecked. ## Before merge - [x] Concrete performance problem and linked original review. - [x] Existing read-only scope and authority preserved. - [x] Focused conventional title, semantic regression checks and current validation. - [x] Owning verification document updated; no secrets or unrelated changes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:43:50 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6886
No description provided.