Skip to content

perf(rpc): restore compiled Zod request schemas without override - #17374

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

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

Conversation

@nwparker

@nwparker nwparker commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Restore the Zod 4.5 compiled request-schema fast path from #17353 after #17368 reverted it for the dependency age exception.

This keeps lazy identity-cached compilation with normal-parser fallback for unsupported schemas, but does not add a zod minimumReleaseAgeExclude override.

The repository age gate may block installs until [email protected] reaches the configured three-day age.

ELI5

RPC requests are checked against a recipe. The first request now turns that recipe into a fast checker and remembers it by schema identity; later requests reuse it instead of rebuilding the checker. Schemas that Zod cannot compile keep using the existing runtime parser.

Performance Measurement

Reproduce on Node with Zod 4.5.0 using one representative request schema and 2,000,000 valid safeParse calls. Warm both paths before timing steady state and compare schema.safeParse with one-time compile(schema).safeParse:

node --input-type=module <<'EOF'
import { z, compile } from 'zod'

const schema = z.object({
  requestId: z.string().min(1),
  count: z.number().int().nonnegative()
})
const pool = Array.from({ length: 64 }, (_, count) => ({ requestId: `req-${count}`, count }))
const iterations = 2_000_000

for (const [name, parser] of [
  ['interpreted', schema],
  ['compiled', compile(schema)]
]) {
  let cursor = 0
  let sink = 0
  let escaped
  const parseOnce = () => {
    const result = parser.safeParse(pool[cursor++ & 63])
    sink += result.success ? 1 : 0
    escaped = result
  }
  for (let i = 0; i < 20_000; i += 1) parseOnce()
  const start = performance.now()
  for (let i = 0; i < iterations; i += 1) parseOnce()
  console.log(name, performance.now() - start, 'ms', sink, escaped?.success)
}
EOF

The predecessor's representative Zod 4.5 run recorded approximately 215 ms interpreted versus 14 ms compiled: about 15× faster and 93.5% less validation time. Exact timing varies by host and JIT state. Deterministically, repeated requests incur one lazy compile/cache miss per schema and then reuse the compiled parser; startup does not eagerly compile the 600+ RPC schemas.

User-Facing Trade-offs

None observed for RPC callers. Unsupported schemas (transforms, async refinements, and other compiler refusals) automatically use the existing runtime parser; valid output and error formatting remain unchanged. The dependency-age note above is an install-time repository constraint, not a runtime behavior change.

@coderabbitai

coderabbitai Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The production Zod dependency now targets version 4.5.4. The workspace excludes this version from the minimum release-age rule. RPC parameter schemas are compiled once per schema instance and cached in a WeakMap. New tests cover repeated parsing, fallback validation errors, and transformed output.

Merge Risk: 🔵 Low · up to b51bf

The RPC validation optimization retains the existing parser fallback, but the PR also exempts Zod 4.5.4 from the three-day dependency release-age gate, creating a bounded supply-chain risk. The change is mergeable with explicit owner awareness, or after removing the exception or documenting an equivalent approval control.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the implementation, rationale, performance result, and trade-offs, but it omits several required template sections and checklist information. Add completed What Changed and Why sections, provide the required Linked Issue entry with an issue reference, add Visual Proof with exactly N/A and a reason because this is not a UI change, document Testing and platforms, complete AI Disclo…
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (2 skipped: 2 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: restoring compiled Zod request schemas for RPC performance without adding an override.
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

Resolution

Add completed What Changed and Why sections, provide the required Linked Issue entry with an issue reference, add Visual Proof with exactly N/A and a reason because this is not a UI change, document Testing and platforms, complete AI Disclosure when applicable, and complete the Review, Agent skill upstream boundary, Notes, and Checklist sections.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI

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 to 4.5.4 and restores lazy, identity-cached compilation of RPC request schemas.

  • Routes request validation through a per-schema compiled-parser cache.
  • Adds tests for repeated parsing, validation errors, and transformed output.
  • Updates the dependency lockfile and temporarily exempts Zod 4.5.4 from the release-age gate.

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains in the eligible follow-up review scope.

No blocking failure remains.

Important Files Changed

Filename Overview
src/main/runtime/rpc/dispatcher-request-parsing.ts Adds lazy compilation and WeakMap caching before RPC parameter validation.
src/main/runtime/rpc/dispatcher-request-parsing.test.ts Adds coverage for repeated valid requests, validation-error formatting, and transform output.
package.json Upgrades the root Zod dependency from 4.4.3 to 4.5.4.
pnpm-lock.yaml Locks Zod 4.5.4 and updates dependent peer-resolution snapshots.
pnpm-workspace.yaml Temporarily excludes Zod 4.5.4 from the three-day minimum-release-age gate.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[RPC request] --> B{Method has params schema?}
  B -- No --> C[Return undefined params]
  B -- Yes --> D{Compiled parser cached?}
  D -- Yes --> E[Reuse compiled parser]
  D -- No --> F[Compile schema]
  F --> G[Cache by schema identity]
  G --> E
  E --> H[safeParse request params]
  H -- Valid --> I[Return parsed value]
  H -- Invalid --> J[Return invalid_argument response]
Loading

Reviews (2): Last reviewed commit: "chore(deps): pin zod 4.5.4 and except it..." | 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 new issues found.

Reviewed changes

This run reviewed the full four-file diff: the zod bump to ~4.5.0, the restored lazy compile() fast path in dispatcher-request-parsing.ts, and the new test file.

  • zod 4.5.0 bump — package.json and pnpm-lock.yaml move zod from ~4.4.3 to ~4.5.0, which is what makes the compile named export available (absent in 4.4.3).
  • Lazy identity-cached compilation — getCompiledParams compiles each request schema once in a module-level WeakMap, then parses through the cached schema. Unsupported schemas (async transforms/refinements, z.xor(), recursion, z.coerce.*, .catch(callback)) eject back to the original parser via zod's own compile() fallback, and without { strict: true } no throw path exists, so no try/catch is needed.
  • Regression tests — the new test file pins parse output, custom validation-error message preservation, and transform output through the compiled path.

ℹ️ Merge is time-gated by the dependency age gate

[email protected] is younger than the repo's three-day minimumReleaseAge, so pnpm install (and CI) will keep failing until it ages — this PR intentionally does not re-add the minimumReleaseAgeExclude override from #17353. Nothing in the diff needs to change; the merge is blocked on calendar time, not on this code.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

4.5.4 is the first release fixing isRecursiveSchema (upstream 84e416f, stablyai#6500),
which compile() calls on every schema — on 4.5.0 it fired .default() factories
at compile time. Verified: compile-time factory calls 0 on 4.5.4, 1 on 4.5.0.
@nwparker
nwparker force-pushed the nwparker/zod-4.5-compile-no-override branch from 457b681 to b51bfa3 Compare August 31, 2026 06:40
@nwparker

Copy link
Copy Markdown
Contributor Author

Rebased onto main and repinned zod 4.5.4 (was 4.5.0), with a version-scoped release-age exception.

Why 4.5.4, not 4.5.0: 4.5.4 is the first release containing the upstream fix to isRecursiveSchema (commit 84e416f, colinhacks/zod#6500) — the exact function compile() calls on every schema this PR newly compiles. On 4.5.0, isRecursiveSchema walks for (const key in def) and def.defaultValue is an enumerable getter, so compiling a schema fires every .default(fn)/.prefault(fn) factory once at compile time. Verified against the installed tree:

compile-time default-factory calls: 0   # 4.5.4
compile-time default-factory calls: 1   # 4.5.0

Exception added to pnpm-workspace.yaml, pinned to the exact version and dated so it can be reaped:

minimumReleaseAgeExclude:
  - [email protected]
  - [email protected]

Local verification: pnpm install clean, lockfile passes the supply-chain policy check with only [email protected] excluded (0 residual 4.5.0 refs, integrity sha512-sC95tT5i…), pnpm tc exit 0, dispatcher-request-parsing.test.ts 3/3 pass.

Two follow-ups worth tracking separately:

  1. Reap the exception after 2026-09-01T17:55Z — the repo already churns these entries (chore(deps): remove pdfjs-dist release exception #17372/chore(deps): restore pdfjs-dist release-age exception until it ages out #17385/chore(deps): pin the pdfjs-dist release-age exception to 6.3.289 #17389 did exactly that for pdfjs-dist); leaving it silently weakens the gate for zod indefinitely.
  2. The headline measurement overstates the general case. Measured on a representative 3-field RPC param schema, 500k parses run 251 ms interpreted vs 22 ms compiled — 0.46 µs saved per request — and the speedup falls to ~2.2× on a 25-field schema. compile() costs ~0.54 ms per schema because it eagerly builds a second generated function for the assertOnly path that nothing here calls, so break-even is ~1,175 requests to a single method. That is a clear win for the hot methods and a small net loss on the long tail of one-shot ones. Worth a follow-up that compiles on the Nth call rather than the first.

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 951d0d5e-78e3-4e01-90fb-6f83c2e6e493

📥 Commits

Reviewing files that changed from the base of the PR and between d641d87 and b51bfa3.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • package.json
  • pnpm-workspace.yaml
  • src/main/runtime/rpc/dispatcher-request-parsing.test.ts
  • src/main/runtime/rpc/dispatcher-request-parsing.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Comment thread pnpm-workspace.yaml
# zod 4.5.4 was published 2026-08-29T17:55Z; it clears the 3-day gate on 2026-09-01T17:55Z.
minimumReleaseAgeExclude:
- [email protected]
- [email protected]

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.

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

printf '%s\n' '--- repository conventions ---'
for f in /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/*/*.md; do
  [ -f "$f" ] && { head -5 "$f"; case "$f" in *pnpm*|*workspace*|*dependency*|*supply*|*security*) cat "$f";; esac; }
done
printf '%s\n' '--- workspace configuration ---'
cat -n pnpm-workspace.yaml
printf '%s\n' '--- relevant change summary ---'
git diff --stat -- pnpm-workspace.yaml
git diff -- pnpm-workspace.yaml

Repository: stablyai/orca

Length of output: 10060


🌐 Web query:

pnpm minimumReleaseAgeExclude configuration semantics

💡 Result:

The minimumReleaseAgeExclude configuration in pnpm allows users to bypass the minimumReleaseAge restriction for specific dependencies, ensuring they can be installed immediately regardless of their publication time [1][2]. This setting is useful for trusted internal packages or when immediate access to a new release is required [3]. Semantics and Usage: - Scope: The setting accepts a list of strings [1][2]. Entries can specify package names, glob patterns (e.g., @myorg/*), or specific versions (e.g., [email protected]) [3][1][2]. - Versioning: For specific version exclusions, you can provide single versions or use a disjunction (||) to list multiple versions for a package [1][2]. - Pattern Matching: It supports glob patterns, allowing for broad exclusions such as an entire organization's scope [4][3][1]. - Configuration Layer: It is primarily configured in pnpm-workspace.yaml (or global config files) [5][3]. CLI flags are also available for per-invocation overrides (--minimum-release-age-exclude) [6]. Key Technical Notes: - Behavior with Multiple Entries: When providing multiple exact-version entries for the same package, it is recommended to use a single disjunction (||) entry to ensure consistent behavior across different pnpm operations [7]. - Evolution: The setting was introduced in v10.16.0 [1][2][8]. Pattern support was added in v10.17.0, and specific version support followed in v10.19.0 [1][2]. - Related Settings: This setting operates in conjunction with minimumReleaseAge, which defines the age threshold (in minutes) for package installation [1][2][8]. As of pnpm v11, minimumReleaseAge defaults to 1440 minutes (one day) [3].

Citations:


Security Misconfiguration (CWE-693)

Reachability: External · Exploitability: Difficult

Keep the Zod release-age gate enabled.

Remove [email protected] from minimumReleaseAgeExclude. This entry bypasses the three-day dependency-age control before September 1, 2026, at 17:55 UTC.

@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 new issues found.

Reviewed changes

This run reviewed the incremental delta since the prior Pullfrog review (457b681a): the zod pin moved from ~4.5.0 to ~4.5.4, and a release-age-gate waiver was added. The dispatcher-request-parsing.ts and test-file changes are unchanged from the prior review.

  • zod ~4.5.4 pin — package.json and pnpm-lock.yaml move zod from ~4.5.0 to ~4.5.4; the @stablyai/playwright* peer references in the lockfile follow.
  • Release-age waiver — pnpm-workspace.yaml adds [email protected] to minimumReleaseAgeExclude (exact version, matching the resolved lockfile entry), unblocking installs now that [email protected] is younger than the three-day gate.

ℹ️ PR title and description now contradict the diff

The title (...without override) and body (does not add a zod minimumReleaseAgeExclude override, block installs until [email protected] reaches the configured three-day age) still describe the pre-waiver state. The diff now adds - [email protected] to minimumReleaseAgeExclude and pins [email protected], so update the title/body before merging to keep the merged commit description accurate.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit c09810b into stablyai:main Aug 31, 2026
29 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…blyai#17374)

* perf(rpc): compile Zod request schemas lazily

* chore(deps): pin zod 4.5.4 and except it from the release-age gate

4.5.4 is the first release fixing isRecursiveSchema (upstream 84e416f, stablyai#6500),
which compile() calls on every schema — on 4.5.0 it fired .default() factories
at compile time. Verified: compile-time factory calls 0 on 4.5.4, 1 on 4.5.0.
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