Repository navigation
perf(agent-state): use the bundled rule files without re-validating them at load - #35768
Conversation
…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.
[Medium impact] The PR appears safe to merge. SummaryUses the bundled agent-state rules directly instead of parsing them at startup.
Reviews (1) · Last reviewed commit: "perf(agent-state): use the bundled rule ..." · Reviewed by Greptile |
Walkthrough
Priority: Merge Risk:
|
There was a problem hiding this comment.
🔇 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 PATHis 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.

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
Files selected for processing: 3-
src/main/orcad/orcad-managed-agent-hooks.tssrc/main/runtime/agent-state-rules/agent-state-rules-catalog.test.tssrc/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.
-
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.
What Changed
Before:
agent-state-rules-catalog.tsranparseAgentStateRuleFiles(zod validation plus a duplicate-id check) over the bundled JSON when the module loaded, on every orcad and desktop start.After:
RAW_BUNDLED_AGENT_STATE_RULE_FILESand used asBUNDLED_AGENT_STATE_RULE_FILESthrough one cast, with aSAFETY:comment that points at the new test.agent-state-rules-catalog.test.ts:toStrictEqual). That also catches extra keys the schema would strip, and duplicate ids.pipe,transform,default,prefault,catchor coercing primitive, since any of those would let parse output silently differ from the input.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:
Linked Issue
N/A (maintainer change)
Visual Proof
N/A: no UI change. Startup work only.
Testing
agent-state-rules-catalog.test.ts, as described above.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
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)