Skip to content

perf(agent-state): use the bundled rule files without re-validating them at load - #35768

Merged
nwparker merged 1 commit into
mainfrom
nwparker/orcad-lazy-zod-sites
Oct 29, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/orcad-lazy-zod-sites

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​66 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​66
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​22 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​5

ELI5

Every time Orca's background server starts, it re-checked the 14 rule files that ship inside the app. These rules tell Orca how to read an agent's state from its terminal. Those files never change after the app is built, so checking them on every start wasted about 25 ms. This PR moves that check into a test that runs on every change. At runtime the app uses the files as shipped.

User risk: none expected.

  • Rule files downloaded at runtime, and the user's override file, are still fully checked when loaded.
  • The test fails if the shipped files ever stop matching the rules format, or if the format gains anything that would make checked output differ from the input.

What Changed

Before: agent-state-rules-catalog.ts ran parseAgentStateRuleFiles (zod validation plus a duplicate-id check) over the bundled JSON when the module loaded, on every orcad and desktop start.

After:

  • The bundled JSON is exported as RAW_BUNDLED_AGENT_STATE_RULE_FILES and used as BUNDLED_AGENT_STATE_RULE_FILES through one cast, with a SAFETY: comment that points at the new test.
  • The new agent-state-rules-catalog.test.ts:
    • parses every bundled file and asserts that the output strictly deep-equals the raw JSON (toStrictEqual). That also catches extra keys the schema would strip, and duplicate ids.
    • walks the whole schema and fails on any pipe, transform, default, prefault, catch or coercing primitive, since any of those would let parse output silently differ from the input.
    • checks that the walker itself detects each of those kinds, including a default nested deep inside the real schema (checked by hand by adding one temporarily).
  • Also: corrected a comment from perf(orcad): keep the Codex PATH scan off WSL readiness #35718 in orcad-managed-agent-hooks.ts. Every orcad host, SSH and native Linux as well as WSL, defers the startup Codex lookup until readiness; the gain is on WSL.

Why

Lane CPU profiles (run 40817830493) attribute about 26 ms of orcad startup to this parse, the largest single zod site before readiness.

Alternatives considered:

  • Parse on first use. That would only move the cost onto the first terminal output, because restored terminals classify agent state before readiness.
  • Lazy-loading the ACP and browser-automation schemas. These are statically reachable from the runtime and RPC code that readiness needs, so they can't be deferred without large rewrites.

Linked Issue

N/A (maintainer change)

Visual Proof

N/A: no UI change. Startup work only.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated in agent-state-rules-catalog.test.ts, as described above.
  • Ran pnpm tc, pnpm run typecheck:ci, the changed-code quality gate, the anti-slop lint, the ast-grep tests and gates, and the agent-state, idle-hook, terminal-wait and orcad startup tests (204 passed).

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • SSH and mixed versions: nothing changes on the wire. The rule contents and the download and override paths are unchanged.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…hem at load

orcad spent ~25 ms of every start zod-parsing the 14 checked-in rule files. A test now proves their parse output deep-equals the raw JSON and that the schema can't change output, so the runtime uses them as bundled. Downloaded and override rules keep full validation. Also corrects the Codex-deferral comment: every orcad host defers it, not only WSL.
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Uses the bundled agent-state rules directly instead of parsing them at startup.

  • Orca loads its bundled state rules without rechecking them at startup.
  • The orcad comment clarifies when Codex hooks start.

Reviews (1) · Last reviewed commit: "perf(agent-state): use the bundled rule ..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The agent-state rules catalog now exports imported rule files as a raw array and assigns that array to the bundled rules constant without parsing it at module load. New tests check bundled-file identity, parse equality, and schema behavior. An orcad startup comment now states that all orcad hosts defer startup and identifies the WSL PATH lookup cost.

Priority: Low

Merge Risk: Minimal · up to fe70d

The bundled rules retain their current behavior. The change is ready to merge after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary performance change: avoiding validation of bundled agent-state rule files at load time.
Description check Passed The description is complete and aligned with the template. It explains the change, rationale, alternatives, testing, compatibility impact, and the absence of UI changes. The maintainer-specific Linked…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is complete and aligned with the template. It explains the change, rationale, alternatives, testing, compatibility impact, and the absence of UI changes. The maintainer-specific Linked Issue exception is addressed with N/A. Some broad local command checklist items remain unchecked, but the description records targeted automated validation and is otherwise sufficient.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 3 files.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔇 Additional comments: 1
src/main/orcad/orcad-managed-agent-hooks.ts-42-42: 1

42-42: Minor · Maintainability & Code Quality · Quick win

⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Clarify the startup comment.

The phrase finding codex stats Windows-drive PATH is grammatically incomplete and does not identify the lookup clearly. Rewrite it as:

Proposed fix
-    // Every orcad host defers this; it pays off on WSL, where finding codex stats Windows-drive PATH.
+    // Every orcad host defers this; on WSL, locating Codex on the Windows-drive PATH is expensive.

(raw.githubusercontent.com)


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ec1d0bf2-a2ed-420d-9519-18391c0ff577
Commits

Reviewing files that changed from the base of the PR and between 1279d5f and fe70d54.

Files selected for processing: 3
  • src/main/orcad/orcad-managed-agent-hooks.ts
  • src/main/runtime/agent-state-rules/agent-state-rules-catalog.test.ts
  • src/main/runtime/agent-state-rules/agent-state-rules-catalog.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

@nwparker
nwparker merged commit 83ee93e into main Oct 29, 2026
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant