Repository navigation
perf(rpc): compile Zod request schemas lazily - #17353
Conversation
|
Warning Review limit reachedNext included review available in 2 minutes. View limit detailsLimit details: You’ve used all 10 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
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. Comment |
Greptile SummaryThe PR upgrades Zod and makes RPC request-schema compilation lazy and cached while retaining runtime parsing behavior for unsupported schema features.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| src/main/runtime/rpc/dispatcher-request-parsing.ts | Lazily compiles each RPC parameter schema, caches the compiled schema by identity, and parses requests through it. |
| src/main/runtime/rpc/dispatcher-request-parsing.test.ts | Covers repeated valid requests, preserved validation messages, and transform fallback output. |
| package.json | Updates the root Zod dependency from 4.4.3 to 4.5.0. |
| pnpm-lock.yaml | Resolves Zod 4.5.0 and aligns dependent Playwright package peer snapshots. |
| pnpm-workspace.yaml | Temporarily exempts Zod 4.5.0 from the minimum release-age gate. |
Reviews (2): Last reviewed commit: "test: align window reveal assertion" | Re-trigger Greptile
There was a problem hiding this comment.
ℹ️ No critical issues — one scope consideration and a minor test note.
Reviewed changes
- Lazy compile of RPC request schemas —
parseRpcRequestParamsnow parses through aWeakMap-cachedcompile(schema)instead of the raw schema, falling back to the interpreter when a schema can't be compiled. - Zod 4.4.3 → 4.5.0 — the bump that makes
compileavailable, with[email protected]added tominimumReleaseAgeExclude. - New tests —
dispatcher-request-parsing.test.tspins repeated valid parses, a validation-error path, and transform output.
ℹ️ The zod 4.5.0 bump changes validation semantics app-wide, not just in RPC
compile() itself is safe here — it never throws, returns the schema unchanged for unsupported features, and structurally falls back to the interpreted parser on invalid input, so error reporting is preserved. The compiled codegen also spoofs ctx.addIssue for .transform((v, ctx) => …) and superRefine, which covers Orca's many ctx.addIssue schemas correctly. But the 4.4.3 → 4.5.0 minor bump carries documented src/main/runtime/rpc). Two are worth confirming outside that suite:
z.iso.datetime()/z.iso.datetime({ offset: true })now require seconds and reject minute-precision timestamps. Orca usesz.iso.datetime({ offset: true })in the shared skill-manifest schemas.z.string().min()/.max()/.length()now count Unicode code points rather than UTF-16 code units; record-key/intersection strictness and__proto__stripping also changed.
If the full CI suite (not just the RPC tests) is green and the skill-manifest timestamp change is acceptable, this is fine to merge. The minimumReleaseAgeExclude entry is valid as written (version-specific exclusions are supported since pnpm v10.19.0).
Technical details
# Confirm zod 4.5.0 app-wide behavior changes
## Affected sites
- src/shared/skill-package-manifest.ts:38 — `createdAt: z.iso.datetime({ offset: true })`
- src/shared/skill-bundle-manifest.ts:61 — `createdAt: z.iso.datetime({ offset: true })`
- src/shared/skill-install-contract.ts:23 — `expiresAt: z.iso.datetime({ offset: true })`
- src/shared/skill-bundle-install-contract.ts:28 — `expiresAt: z.iso.datetime({ offset: true })`
- package.json — `zod` `~4.4.3` → `~4.5.0`
## Required outcome
- Confirm no non-RPC validation surface regresses under 4.5.0 (full test suite plus the iso.datetime / code-point-length changes).
## Open questions for the human
- Do any skill manifests or install contracts legitimately carry minute-precision timestamps?DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| }) | ||
| }) | ||
|
|
||
| it('keeps transform output when compilation falls back', () => { |
There was a problem hiding this comment.
This test name claims the transform path "falls back", but a synchronous .transform() actually compiles and runs on the fast path — only async transforms, z.coerce, recursive schemas, and catch callbacks trigger fallback. Consider renaming it and adding one genuine fallback case so the fallback path (the riskiest part of this change) is actually exercised.
* perf(rpc): compile Zod request schemas lazily * test: align window reveal assertion

Summary
z.compile()for RPC request parameter schemas with a per-schemaWeakMapcacheWhy
RPC request validation is a repeated hot path. A representative Zod 4.5 benchmark over 2,000,000 valid parses measured the compiled schema at ~14 ms versus ~215 ms for the interpreted parser (~15x faster in this run). Eagerly compiling all 600+ RPC schemas added about 1 second to module initialization, so compilation is intentionally lazy and cached after first use.
Validation
pnpm exec vitest run src/main/runtime/rpc(206 files; 1,751 passed, 1 skipped)pnpm tcpnpm run check:code-quality:changed