[GH-ISSUE #6236] [Performance] Reduce integer-validator allocation after MCP materialization #3798

Closed
opened 2026-10-31 00:44:09 +00:00 by bsakaguchi · 2 comments
Owner

Originally created by @gensokyo-dev on GitHub (Oct 22, 2026).
Original GitHub issue: https://github.com/morluto/rea/issues/6236

Before submitting

  • Searched open/closed issues and PRs; this follows up existing PR #4360 rather than duplicating its implementation.
  • Reviewed contribution scope; this changes existing schema construction without adding target effects, providers or public contracts.
  • No credentials or private target data included.

Area

MCP or agent integration

Current limitation

On main@0b7213c89, many canonical validators still use z.number().int(). An executed Linux probe with the locked Zod 4.4.3 shows a ZodNumber retaining a separate ZodNumberFormat check, whereas z.int() constructs the format directly. Both project the same basic integer JSON Schema. Deferred MCP startup (#4424) avoids loading this graph during discovery but still materializes it at first analysis use.

Existing #4360 reports older macOS measurements. NOT_ENOUGH_INFO: current Linux completed-task allocation/CPU/latency impact has not yet been measured; those historical numbers do not establish the current result.

Desired outcome and success criteria

Complete #4360 against latest main, reducing unnecessary validator allocation only where behavior is preserved. Compare actual SDK discovery and completed public-artifact investigations before/after, including cold/warm context estimates, elapsed/CPU time and peak process-family memory. Preserve byte-identical advertisements in compact/full profiles, parsed values/errors, bounds/defaults/refinements, caller choices and Evidence. Keep CLI/MCP on their existing shared schema owners.

Expected interaction with targets

Read existing files or captured data. No new target interaction or authority; public Rust metadata tasks use existing static analysis.

Boundaries and observed compatibility constraint

An executed Incur 0.6.1 parser probe accepts --limit 2 with z.number().int() but rejects it as a string with z.int(). Installed incur/src/Parser.ts coerces only constructor name ZodNumber. Retain existing CLI option and shared-input coercion exceptions; do not globally replace integer declarations. No installer, target mutation, new cache, output contract or advertised capability change.

Verification available so far

Executed dependency-boundary probes and source review. After normalizing the intended integer construction and formatting, all 175 files in original #4360 are AST-token equivalent to its main merge base. Proposed checks: port onto current main, full numeric/error and advertised-schema parity, real CLI numeric options, bounded domain/conformance tests, and independent-oracle real SDK task measurements. Real external-provider behavior and actual model token usage remain unverified.

References

Originally created by @gensokyo-dev on GitHub (Oct 22, 2026). Original GitHub issue: https://github.com/morluto/rea/issues/6236 ### Before submitting - [x] Searched open/closed issues and PRs; this follows up existing PR #4360 rather than duplicating its implementation. - [x] Reviewed contribution scope; this changes existing schema construction without adding target effects, providers or public contracts. - [x] No credentials or private target data included. ### Area MCP or agent integration ### Current limitation On `main@0b7213c89`, many canonical validators still use `z.number().int()`. An executed Linux probe with the locked Zod 4.4.3 shows a `ZodNumber` retaining a separate `ZodNumberFormat` check, whereas `z.int()` constructs the format directly. Both project the same basic integer JSON Schema. Deferred MCP startup (#4424) avoids loading this graph during discovery but still materializes it at first analysis use. Existing #4360 reports older macOS measurements. **NOT_ENOUGH_INFO:** current Linux completed-task allocation/CPU/latency impact has not yet been measured; those historical numbers do not establish the current result. ### Desired outcome and success criteria Complete #4360 against latest main, reducing unnecessary validator allocation only where behavior is preserved. Compare actual SDK discovery and completed public-artifact investigations before/after, including cold/warm context estimates, elapsed/CPU time and peak process-family memory. Preserve byte-identical advertisements in compact/full profiles, parsed values/errors, bounds/defaults/refinements, caller choices and Evidence. Keep CLI/MCP on their existing shared schema owners. ### Expected interaction with targets Read existing files or captured data. No new target interaction or authority; public Rust metadata tasks use existing static analysis. ### Boundaries and observed compatibility constraint An executed Incur 0.6.1 parser probe accepts `--limit 2` with `z.number().int()` but rejects it as a string with `z.int()`. Installed `incur/src/Parser.ts` coerces only constructor name `ZodNumber`. Retain existing CLI option and shared-input coercion exceptions; do not globally replace integer declarations. No installer, target mutation, new cache, output contract or advertised capability change. ### Verification available so far Executed dependency-boundary probes and source review. After normalizing the intended integer construction and formatting, all 175 files in original #4360 are AST-token equivalent to its main merge base. Proposed checks: port onto current main, full numeric/error and advertised-schema parity, real CLI numeric options, bounded domain/conformance tests, and independent-oracle real SDK task measurements. Real external-provider behavior and actual model token usage remain unverified. ### References - PR #4360: https://github.com/morluto/rea/pull/4360 - Deferred startup: https://github.com/morluto/rea/pull/4424 - Performance requirements: https://github.com/morluto/rea/blob/0b7213c89056a8e3a9e2bb785be210c8393d2899/AGENTS.md#performance
bsakaguchi 2026-10-31 00:44:09 +00:00
Author
Owner

@XinwangTao commented on GitHub (Oct 22, 2026):

赞同以 z.int() 替代 z.number().int() 的方向:Zod 4.4.3 下两者映射相同的 integer JSON Schema,但 ZodNumber 额外保留 ZodNumberFormat 独立实例确实有分配开销。特别认同你标注的边界——不能全局替换:Incur 0.6.1 按 constructor name ZodNumber 做字符串 coercion,这条约束必须在回归测试里锁死(--limit 2 传字符串的场景)。建议度量基线同时覆盖 CLI 数值选项和 MCP 首次 materialization 两条路径,只测 schema 构建不测实际任务容易漏掉内存峰值差异。

<!-- gh-comment-id:6332718805 --> @XinwangTao commented on GitHub (Oct 22, 2026): 赞同以 z.int() 替代 z.number().int() 的方向:Zod 4.4.3 下两者映射相同的 integer JSON Schema,但 ZodNumber 额外保留 ZodNumberFormat 独立实例确实有分配开销。特别认同你标注的边界——不能全局替换:Incur 0.6.1 按 constructor name ZodNumber 做字符串 coercion,这条约束必须在回归测试里锁死(--limit 2 传字符串的场景)。建议度量基线同时覆盖 CLI 数值选项和 MCP 首次 materialization 两条路径,只测 schema 构建不测实际任务容易漏掉内存峰值差异。
Author
Owner

@XinwangTao commented on GitHub (Oct 22, 2026):

Glad #4360 is in — switching canonical validators to z.int() where behavior is preserved is a clean win, and keeping the Incur 0.6.1 coercion exception (constructor-name-based ZodNumber string coercion) scoped is exactly right. Two follow-ups worth considering: first, the issue itself flags NOT_ENOUGH_INFO on current Linux allocation/CPU/latency impact — a post-merge measurement on a completed public-artifact investigation would make the perf claim concrete; second, consider adding a short comment at the shared schema-construction site warning future refactors not to blanket-replace integer declarations, so the coercion exception doesn't silently regress.

<!-- gh-comment-id:6336221749 --> @XinwangTao commented on GitHub (Oct 22, 2026): Glad #4360 is in — switching canonical validators to z.int() where behavior is preserved is a clean win, and keeping the Incur 0.6.1 coercion exception (constructor-name-based ZodNumber string coercion) scoped is exactly right. Two follow-ups worth considering: first, the issue itself flags NOT_ENOUGH_INFO on current Linux allocation/CPU/latency impact — a post-merge measurement on a completed public-artifact investigation would make the perf claim concrete; second, consider adding a short comment at the shared schema-construction site warning future refactors not to blanket-replace integer declarations, so the coercion exception doesn't silently regress.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#3798
No description provided.