Repository navigation
Conversation
…rpretation An operation family declares its method, compatible reader, acceptance policy and interpretation barrier once. The send classifies only a fulfilled envelope; transport rejection stays on the promise channel as the original error object, so the cutover and delivery-unknown predicates keep working and a Promise.all group still fails fast. Multi-request families go through a post-barrier combinator that awaits every raw request and then interprets in declared order. No production call site is migrated: this lands as self-contained machinery so runtime behaviour is provably untouched. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…arsed one The RpcOperation descriptor typed its params with RpcParams, which is z.output — the shape the handler receives after parsing. A field with .default(x) is required there, so a sender that legitimately omits it failed to typecheck. z.input is not the fix: the params builders parse with z.unknown() so a hostile client cannot crash the dispatcher, which collapses every requiredString/OptionalString field to `unknown`. RpcSendParams takes each channel where it is honest — key optionality from zod's own `optin` marker, value types from z.output — by walking the schema from the generated catalog, so it cannot drift from the dispatcher. 21 of 611 methods change, all by letting a sender omit a key the host already defaults. Type-level only: no runtime code, no wire change, and the params contract stays a type-only import so no client can parse a coercing schema. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
There was a problem hiding this comment.
ℹ️ One latent correctness nit in the new
RpcSendInputtype — otherwise a clean, well-fenced, type-level refactor.
Reviewed changes
RpcSendParams/RpcSendInput(src/shared/rpc-contract/rpc-send-params.ts) — a new derived send-side params type that takes key optionality from zod's_zod.optinmarker and value types fromz.output.- Mobile send signatures (
mobile/src/transport/rpc-operation.ts) —runRpcOperation,captureRpcOperationSettlement, andstartRpcOperationnow typeparamsasRpcSendParams<Method>. - Compile fences (
mobile/src/transport/rpc-operation-compile-fence.ts) — five new type-level fences, including a catalog-wideRpcParams<M> extends RpcSendParams<M>invariant and a sole-unknown-method guard. - Catalog comment — the generator and generated catalog both now point senders at
RpcSendParams.
The derivation approach (key optionality from optin, value types from z.output) is sound and matches zod v4's own $InferObjectInput/$InferObjectOutput internals; I verified SendOptionalSchema equals zod's OptionalInSchema, that classic ZodObject exposes shape, and that .superRefine()/.refine() return this so the object-branch comment holds. The RpcParams extends RpcSendParams fence direction is correct — it proves nothing a sender could previously build becomes illegal.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| * tuple, lazy, intersection) fall through to z.output, which is what shipped before. | ||
| */ | ||
| export type RpcSendInput<Schema> = | ||
| Schema extends z.ZodOptional<infer Inner> |
There was a problem hiding this comment.
ZodExactOptional is structurally assignable to z.ZodOptional in zod v4, so this branch also matches .exactOptional() and types it T | undefined — but exactOptional forbids undefined as a value (only absence or the inner value is valid), so the send type over-admits an object the host would reject. No catalog method uses .exactOptional() today, so this is latent, and the catalog-wide fence only guards the opposite (RpcParams extends RpcSendParams) direction.
Technical details
# `RpcSendInput` over-admits `undefined` for `.exactOptional()`
## Affected sites
- src/shared/rpc-contract/rpc-send-params.ts:41 — `Schema extends z.ZodOptional<infer Inner>` also matches `ZodExactOptional` (classic `ZodExactOptional<T>` is assignable to `ZodOptional<T>`), appending `| undefined` where `exactOptional` forbids it.
## Required outcome
- A `.exactOptional()` field types as `field?: T` (no `undefined`), matching what the host accepts.
## Suggested approach (optional)
- Add a `Schema extends z.ZodExactOptional<infer Inner> ? RpcSendInput<Inner> : ...` branch above the `z.ZodOptional` branch. Verified locally: `{ x: undefined }` currently compiles against `z.object({ x: z.string().exactOptional() })`.3ff035c to
f0965e9
Compare
|
Superseded — this work is already in #20018 via Branch kept, not deleted. |

Stacked on #20018. Base is
rpc-step2c-operation, so the diff here is only the send-side type. Independent of #20026, which is also stacked on #20018.The bug this fixes
The descriptor typed outgoing params with
RpcParams<M>, which isz.output— the shape the handler receives after parsing. Wrong for a sender in both directions: a field with.default(x)is required in the output type, so a sender that legitimately omits it fails to typecheck.z.inputis not the fix either, and the generated catalog already says why:requiredStringisz.unknown().transform(...), so its input admits anything.repo.setBaseRefunderz.inputis{ repo: unknown; ref: unknown }— no safety at all.Approach: derive, don't declare
RpcSendParams<M>walks the schema and takes each of zod's two channels where it is honest:optinmarker — thez.inputrule, the one that understands.defaultand.optionalz.output— the post-coercion contract the builders declare in their pipe targetLeaves fall back to
z.output, i.e. today's behaviour.Rejected (a), teaching the builders an input type: only 9 of 113
.unknown()sites insrc/shared/rpc-contract/live inrpc-param-primitives.ts. The other ~104 inline thez.unknown().transform().pipe()pattern directly — 11 inworktree-params.tsalone — so builder annotations would leave all of those fields atunknown.Rejected (b), a parallel generated catalog: needs a runtime zod→TS-source serializer for 611 entries, far more surface to drift, same result.
Resolved types
repo.setBaseRef— sender must pass realstrings (z.inputgaveunknown)files.searchPaths— sender may now omitquery/limit;z.outputhad both requiredworktree.ps— unchanged, still narrowui.get(params: null) —void, unchangedSafety
A catalog-wide compile fence proves
RpcParams<M> extends RpcSendParams<M>for all 611 methods — the send type never tightens the parsed shape, so nothing a sender could legally build before becomes illegal.Across all 611, exactly one method degenerates to
unknown:plugins.panelAction, whose schema literally isz.unknown().Blast radius is small and one-directional: every changed method changes by letting a sender omit a key the host already defaults.
Mutations
z.outputTS2739: Type '{ worktree: string; }' is missing … query, limitz.inputTS2578 Unused '@ts-expect-error'(theworktree: 42andlimit: 'ten'rejections go dead) and aTS2322widening.parseon a params schemaThe second mutation is the interesting one: falling back to
z.inputdoesn't just lose precision, it silently kills two pre-existing fences that were catching wrong-typed fields.Gates
pnpm tc·typecheck:node|cli|web· mobile typecheck · mobile test 530 files / 4,372 passed ·vitest run src/main/runtime/rpc276 files / 2,379 passed ·verify:rpc-params-catalog·check:code-quality:changed0 new findings across 13 files · max-lines ratchet ·oxfmt --check·oxlint0.Type-level only. No runtime change, no wire change, no product call site migrated.