Skip to content

perf(environment): index observed-state write cutoffs - #5350

Merged
gensokyo-dev merged 1 commit into
mainfrom
gensokyo-dev/state-write-cutoffs-20261020
Oct 20, 2026
Merged

gensokyo-dev merged 1 commit into
mainfrom
gensokyo-dev/state-write-cutoffs-20261020

Conversation

@gensokyo-dev

@gensokyo-dev gensokyo-dev commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-20T04:01:39.538789Z 27e3d5c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issue was found.

Summary

This PR replaces repeated write-root scans with one index per projection.

  • State extraction reuses write cutoffs across read types.
  • State output picks backed types in one pass.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Recorded writes in timeline order] --> B[Build admitted prefix and wildcard index]
  C[Read type] --> D{Cutoff cached?}
  D -->|No| E[Find earliest related write]
  B --> E
  E --> F[Cache write or no match]
  D -->|Yes| G[Use cached cutoff]
  F --> G
  G --> H[Bound initial observations]
  H --> I[Assemble backed types and entities]
Loading

Reviews (1) · Last reviewed commit: "perf(environment): index observed-state ..." · Reviewed by Greptile

@gensokyo-dev
gensokyo-dev merged commit d148ce0 into main Oct 20, 2026
34 of 36 checks passed
@gensokyo-dev
gensokyo-dev deleted the gensokyo-dev/state-write-cutoffs-20261020 branch October 20, 2026 04:16
@github-actions github-actions Bot mentioned this pull request Oct 20, 2026
3 tasks done
earakely-scale added a commit to earakely-scale/rea that referenced this pull request Oct 20, 2026
… 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]>
Deepakdogra07 pushed a commit to Deepakdogra07/rea that referenced this pull request Nov 19, 2026
Index parsed recorded-write roots once per state projection and reuse positive and negative type cutoffs. Preserve wildcard, ancestor/descendant, canonical timeline and Evidence semantics under the existing representation budget.

Follow-up to the final performance thread on morluto#5319, which was merged while this optimization was being validated.

Validated with 508 relevant source tests, compiled state CLI/MCP cases, real Gitea HAR CRUD/search captures and Chromium captures, static/build/docs/catalog gates, and equivalent completed before/after projections.
@morluto morluto added performance Performance regressions, scaling limits, and bounded-resource work 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 performance Performance regressions, scaling limits, and bounded-resource work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants