Skip to content

perf(deps): upgrade zod to 4.6.7 to shrink the Host's schema memory - #1110

Merged
iruriQ merged 1 commit into
mainfrom
perf/zod-4-6-host-heap
Nov 24, 2026
Merged

iruriQ merged 1 commit into
mainfrom
perf/zod-4-6-host-heap

Conversation

@BytePioneer-AI

Copy link
Copy Markdown
Owner

Summary

  • The Host loads 20 Harness plugin bundles, and each builds its own zod schemas. A heap snapshot of a cold Host (278 MB including external source strings) showed 30,426 zod schema instances holding about 150 MB, roughly 5.2 KB each in 4.4.3. In 4.6.7 the same schemas keep about 1 KB per instance.
    • The eight ACP-based Adapters (cursor-cli, kimi-code, workbuddy, codebuddy, antigravity, grok, kiro-cli, devin) each hold 10–12.5 MB of schema instances from the ACP SDK, 88.6 MB in total.
  • This PR raises zod from 4.4.3 to 4.6.7 in the root and the nine workspace package.json files that pin it, and changes only the zod entries in package-lock.json.
    • apps/web-ui declares ^4.4.3 in 29 places, so the Web UI now resolves to 4.6.7 too.
    • registry/desktop-extensions is outside the workspace with its own lockfile and stays on 4.4.3.
    • The Claude Code bundle still contains the 4.4.3 copy that @anthropic-ai/claude-agent-sdk inlines. @github/copilot-sdk and @qwen-code/sdk keep their own nested copies, which are not bundled into the plugins.
  • All 21 bundles take zod only from the top-level 4.6.7. Their total size on disk grows from 28.1 MB to 32.2 MB (+15%); the memory numbers below already include that.

Measurements

Isolated Web instance with a throwaway data directory, Node v24.18.0, cold Host, usage statistics not triggered.

Metric Before After
Host footprint, steady (3–8 min after start) 425–428 MB 249–255 MB
Host footprint, startup peak 811 MB 532 MB
Live heap after GC 251 MB 111 MB
V8 heap regions 321 MB 145 MB
External memory 36 MB 59 MB
  • External memory grows because the bundles are bigger and more of them exceed Node's roughly 1 MB external-string threshold. Live heap plus external still falls from 287 MB to 170 MB.
  • The two readings come from slightly different main commits, and the "after" figures are a single run, so treat the difference as an estimate.

zod behavior changes

I read the 4.5.0–4.6.7 release notes and ran 63 zod usage patterns from this repository against both versions. 56 behave identically. The differences that matter here:

Change in 4.5–4.6 Use in this repository Result
z.iso.datetime() / .datetime() rejects times without seconds, such as 06:15Z Five fields: updatedAt, fetchedAt, installedAt, publishedAt, observedAt Every writer found uses toISOString() or GitHub's published_at, both with seconds. A hand-written file that omits seconds would now be rejected.
String length is counted in code points .max() is used widely Strings with emoji can exceed a limit by up to 2× in UTF-16 units before being rejected. .min(1) is unaffected, and .min(n>1) calls were not enumerated.
A strict object given its own __proto__ key reports unrecognized_keys instead of dropping it About 386 strict objects Only inputs that carry such a key change. The Grok test that involves __proto__ passes.
An array over .max() reports only too_big remote-sessions.ts uses too_big to detect an oversized request The check still holds.
toJSONSchema output changed Only the Web UI typert registry wraps it, and nothing outside tests calls it Not exercised.

No other difference showed up: common error messages, z.prettifyError, email and URL acceptance, record keys and recursive JSON schemas all matched.

Supply chain

  • [email protected] is the npm latest, published 2026-10-12, and has an SLSA provenance attestation naming zod's release.yml workflow and commit b500a2ee, the commit tagged 4.6.7. npm audit signatures verified all 818 registry signatures in this lockfile.
  • The 4.6.6 release notes disclose that six malicious commits were pushed to zod's main on 2026-09-21 with a compromised git credential, were reverted the same day, and were never published to npm.

Not included

I also tried building the bundles as ASCII-only to avoid the double-width in-memory copy of their source text, but the bundles still hold 10–100 non-ASCII characters each (regex literals, tagged templates, third-party comments), so Node keeps storing them as UTF-16 and nothing is saved. That change was dropped.

Related issues

N/A

UI Demo

No visual changes: dependency upgrade.

Test plan

These ran before the branch was rebased onto current main; the rebase was clean.

  • npm run build:typescript (tsc -b plus the plugin build): passed.
  • Vitest over packages/shared-contracts/test, packages/protocol-core/test, packages/harness-adapter/test, plus grok-questions.test.ts and renderer-schema-config.test.ts: 65 files, 783 tests passed. No test failed on a changed zod message.
  • Vitest over tests/release (host-bundle, payload, npm-package, lockfile-registry): 102 passed, 1 skipped.
  • After the rebase, npm ci --dry-run confirmed that the lockfile matches every package.json.
  • Not run: the full repository suite, Web UI tests and the other Adapters' tests; CI covers them.

The Host loads 20 Harness plugin bundles, and each builds its own zod schemas.
A zod 4.4.3 schema instance costs about 5.2 KB (30,426 instances held about
150 MB of a 278 MB live heap); 4.6.7 keeps the same schema in about 1 KB.
Cold Host footprint drops from about 428 MB to about 253 MB and the live heap
after GC from 251 MB to 111 MB.

zod 4.6.7 carries an npm SLSA provenance attestation from zod's release
workflow at the commit tagged 4.6.7. The Claude Code bundle still contains the
4.4.3 copy that @anthropic-ai/claude-agent-sdk inlines.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T02:10:47.863119Z 101209f PR opened
🔒 Security Review ✅ Completed 2026-11-24T02:14:16.648530Z 101209f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Chores
    • 更新了内部数据校验依赖的版本。

根项目及多个工作区的 package.json 将 zod 版本从 4.4.3 更新为 4.6.7。

Changes: zod 依赖版本更新

Layer / File(s) Summary
更新 zod 依赖版本
package.json、packages/adapters/*/package.json、packages/harness-broker/package.json、packages/mapping-store/package.json、packages/shared-contracts/package.json、packages/web-server/package.json
这些依赖声明将 zod 版本从 4.4.3 更新为 4.6.7。

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Other

Suggested reviewers: mouzhi, lpmasser

Merge Risk: Minimal · up to 10120 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题“perf(deps): upgrade zod to 4.6.7 to shrink the Host's schema memory”准确描述了主要变更:将 zod 从 4.4.3 升级到 4.6.7,目的是减少 Host 的 schema 内存占用。raw_summary 和 PR 目标都确认了根目录及九个工作区 package.json 中的 zod 版本变更。标题简洁,是单句,没有文…
Description check Passed 描述与变更集相关。它说明了将 zod 从 4.4.3 升级到 4.6.7 的范围(根目录及九个 workspace package.json,仅修改 package-lock.json 中的 zod 条目),给出了内存测量、zod 行为变化的评估、供应链核验以及测试计划。这些内容与 raw_summary 和 PR 目标一致。
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: Title check

Explanation

标题“perf(deps): upgrade zod to 4.6.7 to shrink the Host's schema memory”准确描述了主要变更:将 zod 从 4.4.3 升级到 4.6.7,目的是减少 Host 的 schema 内存占用。raw_summary 和 PR 目标都确认了根目录及九个工作区 package.json 中的 zod 版本变更。标题简洁,是单句,没有文件列表或模糊用语。

Finishing Touches

Generate unit tests (beta)

  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ab1a0df and 101209f.

Files ignored due to path filters: 1

  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing: 10

  • package.json
  • packages/adapters/antigravity/package.json
  • packages/adapters/claude-code/package.json
  • packages/adapters/copilot/package.json
  • packages/adapters/cursor-cli/package.json
  • packages/adapters/zcode/package.json
  • packages/harness-broker/package.json
  • packages/mapping-store/package.json
  • packages/shared-contracts/package.json
  • packages/web-server/package.json

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

Recent review details

Context from checks skipped due to timeout: 8

  • GitHub Check: CodeRabbit
  • GitHub Check: Vitest
  • GitHub Check: Check Linux ARM64
  • GitHub Check: Web Host tests
  • GitHub Check: Check windows-latest
  • GitHub Check: Check macos-26
  • GitHub Check: Check ubuntu-22.04
  • GitHub Check: Static checks
Additional context used

Code guidelines: 2

AGENTS.md — auto-discovered
CLAUDE.md — auto-discovered
Path-based instructions: 3

Source excerpt: `shared-contracts` must remain browser-safe and independent of other Workspace packages.

CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/shared-contracts/package.json
Source excerpt: Harness-specific protocol details must remain inside the corresponding Adapter.

CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/adapters/antigravity/package.json
  • packages/adapters/claude-code/package.json
  • packages/adapters/copilot/package.json
  • packages/adapters/cursor-cli/package.json
  • packages/adapters/zcode/package.json
Source excerpt: Use package public exports for cross-package dependencies.

CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/adapters/antigravity/package.json
  • packages/adapters/claude-code/package.json
  • packages/adapters/copilot/package.json
  • packages/adapters/cursor-cli/package.json
  • packages/adapters/zcode/package.json
  • packages/harness-broker/package.json
  • packages/mapping-store/package.json
  • packages/shared-contracts/package.json
  • packages/web-server/package.json
Additional comments: 1

packages/shared-contracts/package.json: 1

31-31: Data Integrity & Integration

No publishable comment remains. The four current writers in this scope emit seconds, and the GitHub input carries seconds. The remaining question is whether a persisted installedAt value could lack seconds, and that depends on the truncated writer source.

@iruriQ
iruriQ merged commit 1d6a82f into main Nov 24, 2026
4 of 8 checks passed
@iruriQ

iruriQ commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

已核对全仓依赖版本锁定、Zod 变更兼容与供应链审计,内存收益显著且无冲突,已合入 main。

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.

2 participants