Skip to content

perf(rpc): compile Zod request schemas lazily - #17353

Merged
nwparker merged 2 commits into
stablyai:mainfrom
nwparker:nwparker/zod-4.5-compile
Aug 30, 2026
Merged

nwparker merged 2 commits into
stablyai:mainfrom
nwparker:nwparker/zod-4.5-compile

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

Summary

  • upgrade Zod from 4.4.3 to 4.5.0
  • use z.compile() for RPC request parameter schemas with a per-schema WeakMap cache
  • preserve Zod's runtime fallback for transforms and other unsupported schema features
  • add coverage for repeated valid parses, validation errors, and transform output

Why

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 tc
  • pnpm run check:code-quality:changed

@coderabbitai

coderabbitai Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 2 minutes.

View limit details

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9766ec98-aab5-4804-a44f-f2d910550b16

📥 Commits

Reviewing files that changed from the base of the PR and between 252dbd6 and b36646c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • package.json
  • pnpm-workspace.yaml
  • src/main/runtime/rpc/dispatcher-request-parsing.test.ts
  • src/main/runtime/rpc/dispatcher-request-parsing.ts
  • tests/e2e/helpers/paired-client-window-reveal.unit.test.ts

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.

@greptile-apps

greptile-apps Bot commented Aug 30, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR upgrades Zod and makes RPC request-schema compilation lazy and cached while retaining runtime parsing behavior for unsupported schema features.

  • Adds a per-schema WeakMap cache for compiled RPC parameter schemas.
  • Adds tests for repeated parsing, validation errors, and transform output.
  • Updates the dependency manifest, lockfile, and release-age exception.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

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

@pullfrog pullfrog 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.

ℹ️ No critical issues — one scope consideration and a minor test note.

Reviewed changes

  • Lazy compile of RPC request schemas — parseRpcRequestParams now parses through a WeakMap-cached compile(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 compile available, with [email protected] added to minimumReleaseAgeExclude.
  • New tests — dispatcher-request-parsing.test.ts pins 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 ⚠️ behavior changes that apply to every zod schema in the app, while this PR only validates the RPC suite (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 uses z.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?

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

})
})

it('keeps transform output when compilation falls back', () => {

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.

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.

@nwparker
nwparker merged commit 7b86833 into stablyai:main Aug 30, 2026
27 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* perf(rpc): compile Zod request schemas lazily

* test: align window reveal assertion
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