Skip to content

refactor(rpc): make defineMethod preserve the method name and handler result - #20016

Merged
Jinwoo-H merged 2 commits into
mainfrom
rpc-step2b-define-method
Sep 11, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
rpc-step2b-define-method

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 24 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​207 $\color{#cf222e}{\Huge{\mathbf{−}}}$​47 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​160
Prod 100 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​273 $\color{#cf222e}{\Huge{\mathbf{−}}}$​231 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​42

What

defineMethod erased the two things later migration steps need. RpcMethod.name was string and RpcMethod.handler returned unknown, so nothing downstream could see that status.get is the literal "status.get" or that its handler returns a 22-field object.

defineMethod is now generic over the literal name and the handler's inferred result, returning RpcTypedMethod<TName, TSchema, TResult>. The registry stays erased — RpcMethod, RpcAnyMethod, RpcRegistry and the dispatcher are unchanged — but erasure now happens at one named, commented site (eraseRpcMethods) instead of implicitly by assignment.

Why the diff touches 124 files

The 94 : RpcMethod[] / : RpcAnyMethod[] array annotations were the erasure. With them in place, contextual inference collapsed TName back to string and the change would have been decoration. Deleting them (one line each, 88 files) is what makes the types survive. No handler was annotated or otherwise touched.

DispatcherOptions.methods, PairingOptions.methods and parseRpcRequestParams now accept declarations, which resolved ~607 call-site errors with three signature edits.

Runtime impact: none

eraseRpcMethods returns its argument (return methods as readonly RpcAnyMethod[]). Outside core.ts, the only files gaining a call to it are test files and two test-support harnesses. No production runtime path changed, no handler return value changed, and nothing on the wire changed.

Evidence

Types actually survive, verified by resolving them rather than by inspection:

RpcTypedMethod<"status.get", null, { runtimeId: string; …17 more…; remoteUpdateSupport: RemoteServerUpdateSupport; }>
RpcTypedMethod<"host.wsl.listDistros", null, Promise<string[]>>
RpcTypedMethod<"ssh.getState", ZodObject<{ targetId: ZodString }, $strip>, { state: SshConnectionState | null }>
RpcTypedStreamingMethod<"terminal.subscribe", ZodObject<{ terminal: … }, $strip>>

Mutation results against config/tsconfig.node.json:

Mutation Errors In the contract test
name generic widened back to string 19 5
result widened back to unknown 4 4

Both are type-level failures. vitest stays green under either mutation because expectTypeOf erases at runtime, so pnpm tc is the gate that holds this contract — the new test file is confirmed present in the node project's file list.

Gates

pnpm tc · typecheck:tsc (node + cli + web) · vitest run src/main/runtime/rpc 295 files / 2,503 passed · verify:rpc-params-catalog · check:code-quality:changed 0/0/0 across 124 files · oxfmt --check clean · max-lines ratchet OK (core.ts 199/300).

Known limits

  • Streaming is partial. The literal name and parsed params survive; the emitted value type does not, because emit is an input with no return position to infer from. That needs a separate TEmitted on the spec — a later unit.
  • The params generator is unchanged. Name→schema is now derivable as a type, but the catalog must ship runtime schema values into src/shared where mobile can reach them, so identity mapping stays. What this newly enables is a type-level parity gate asserting RpcParams<M> matches the host's parsed params for every M.

… result

`defineMethod` erased both halves of the contract it was given: the literal
method name became `string` and the handler's return type became `unknown`,
so nothing downstream could name a method or its result in a type.

It is now generic over the literal name, the params schema, and the handler's
inferred result, and the ~611 registered declarations keep those types because
the per-module `RpcMethod[]` annotations — which were the erasure — are gone.
Erasure now happens at one named site, `eraseRpcMethods`, which `buildRegistry`
calls; the registry, the dispatcher, and the wire are unchanged, and the
adapter returns the same array it was handed.

Compile-time only: no handler body, return value, or dispatch path changed.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
@greptile-apps

greptile-apps Bot commented Sep 11, 2026

Copy link
Copy Markdown

Too many files changed for review (124 files, 100 file limit).

Bypass the limit by tagging @greptile-apps to review.

@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

  • Typed defineMethod / defineStreamingMethod — both are now generic over the literal method name and the handler's inferred result, returning RpcTypedMethod<TName, TSchema, TResult> / RpcTypedStreamingMethod<TName, TSchema>, so downstream code can see that status.get is the literal "status.get" and what its handler returns.
  • Single erasure site — eraseRpcMethods (three overloads that preserve the one-shot/streaming split) is the one named, commented place the parsed-params type is dropped; buildRegistry, DispatcherOptions.methods, OrcaRuntimeRpcServerOptions.methods, and parseRpcRequestParams now accept the RpcMethodDeclaration view. The never-param contravariance trick makes typed handlers assignable to declarations with no cast.
  • Annotation removal — ~88 method modules drop their : RpcMethod[] / : RpcAnyMethod[] array annotations so literal names survive; no handler bodies changed.
  • Contract test — core-typed-method-contract.test.ts pins name/result/params inference with expectTypeOf, and the author's mutation testing confirms it is a real gate (name→string = 19 errors, result→unknown = 4 errors under pnpm tc, while vitest stays green since expectTypeOf erases at runtime).

The variance reasoning is sound, the runtime path is untouched (eraseRpcMethods is an identity cast, and the dispatcher still invokes the erased handler with unknown), and the dispatcher/streaming split survives erasure correctly.

One observation for awareness, not a change request: the exported method arrays lost their readonly modifier as a side effect of dropping the annotations — immutability of those module constants is no longer type-enforced. No consumer relies on it, and restoring it cleanly would re-add the very annotations this PR removes, so this is an acceptable tradeoff.

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

@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 0dc4782d-376c-4a9d-b063-099097f721d0

📥 Commits

Reviewing files that changed from the base of the PR and between 1798786 and 99fef2e.

📒 Files selected for processing (124)
  • src/main/runtime/push/push-registration-rpc.test.ts
  • src/main/runtime/rpc/core-typed-method-contract.test.ts
  • src/main/runtime/rpc/core.ts
  • src/main/runtime/rpc/dispatcher-request-parsing.ts
  • src/main/runtime/rpc/dispatcher.ts
  • src/main/runtime/rpc/methods/accounts.test.ts
  • src/main/runtime/rpc/methods/accounts.ts
  • src/main/runtime/rpc/methods/agent-hooks.test.ts
  • src/main/runtime/rpc/methods/agent-hooks.ts
  • src/main/runtime/rpc/methods/agent-session.ts
  • src/main/runtime/rpc/methods/ai-vault.ts
  • src/main/runtime/rpc/methods/artifacts.ts
  • src/main/runtime/rpc/methods/automation-scoped-list-methods.test.ts
  • src/main/runtime/rpc/methods/automations.ts
  • src/main/runtime/rpc/methods/browser-client-file-channel.ts
  • src/main/runtime/rpc/methods/browser-client-host.ts
  • src/main/runtime/rpc/methods/browser-core.ts
  • src/main/runtime/rpc/methods/browser-extras.ts
  • src/main/runtime/rpc/methods/browser-network-tunnel.ts
  • src/main/runtime/rpc/methods/browser-screencast.ts
  • src/main/runtime/rpc/methods/browser-text-rpc-methods.ts
  • src/main/runtime/rpc/methods/client-events.test.ts
  • src/main/runtime/rpc/methods/client-events.ts
  • src/main/runtime/rpc/methods/client-ui.ts
  • src/main/runtime/rpc/methods/clipboard.ts
  • src/main/runtime/rpc/methods/computer-actions.test.ts
  • src/main/runtime/rpc/methods/computer.test.ts
  • src/main/runtime/rpc/methods/computer.ts
  • src/main/runtime/rpc/methods/diagnostics.ts
  • src/main/runtime/rpc/methods/emulator.ts
  • src/main/runtime/rpc/methods/files-mutation-methods.ts
  • src/main/runtime/rpc/methods/files-terminal-artifact-methods.ts
  • src/main/runtime/rpc/methods/files.ts
  • src/main/runtime/rpc/methods/folder-workspace.ts
  • src/main/runtime/rpc/methods/git-commit-message-generation-methods.ts
  • src/main/runtime/rpc/methods/git-diff-methods.ts
  • src/main/runtime/rpc/methods/git.ts
  • src/main/runtime/rpc/methods/github-issue-methods.ts
  • src/main/runtime/rpc/methods/github-project-methods.ts
  • src/main/runtime/rpc/methods/github-pull-request-methods.ts
  • src/main/runtime/rpc/methods/github-pull-request-update-methods.ts
  • src/main/runtime/rpc/methods/github-repo-work-item-methods.ts
  • src/main/runtime/rpc/methods/github.ts
  • src/main/runtime/rpc/methods/gitlab.ts
  • src/main/runtime/rpc/methods/host-capabilities.ts
  • src/main/runtime/rpc/methods/hosted-review.ts
  • src/main/runtime/rpc/methods/index.ts
  • src/main/runtime/rpc/methods/jira.ts
  • src/main/runtime/rpc/methods/linear-agent-access.ts
  • src/main/runtime/rpc/methods/linear-project-create.ts
  • src/main/runtime/rpc/methods/linear.ts
  • src/main/runtime/rpc/methods/mobile-markdown-tab-methods.ts
  • src/main/runtime/rpc/methods/native-chat.ts
  • src/main/runtime/rpc/methods/notifications.ts
  • src/main/runtime/rpc/methods/orchestration.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federated-release-safety.test.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federation-control.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federation-liveness-verdict.test.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federation-methods.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federation-relay.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federation.ts
  • src/main/runtime/rpc/methods/orchestration/gates/gates.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/ask-methods.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/check-methods.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/check-worker-federated-attachment.test.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/message-methods.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/send-methods.ts
  • src/main/runtime/rpc/methods/orchestration/rpc-test-harness.ts
  • src/main/runtime/rpc/methods/orchestration/runs/dispatch-methods.ts
  • src/main/runtime/rpc/methods/orchestration/runs/mutation-request-show.ts
  • src/main/runtime/rpc/methods/orchestration/runs/reset-methods.ts
  • src/main/runtime/rpc/methods/orchestration/runs/runs.ts
  • src/main/runtime/rpc/methods/orchestration/worker/manual-dispatch-observation.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/manual-dispatch-release.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-control.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-list-method.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-methods.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-release-mobile-report.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-release-recovery.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-release.test-support.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-release.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-stop-liveness-verdict.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-stop.ts
  • src/main/runtime/rpc/methods/orchestration/worker/workers-recovery.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/workers.ts
  • src/main/runtime/rpc/methods/pairing.ts
  • src/main/runtime/rpc/methods/plugins.test.ts
  • src/main/runtime/rpc/methods/plugins.ts
  • src/main/runtime/rpc/methods/preflight.ts
  • src/main/runtime/rpc/methods/project-runtime-rpc-methods.ts
  • src/main/runtime/rpc/methods/repo.ts
  • src/main/runtime/rpc/methods/runtime-client-capabilities.ts
  • src/main/runtime/rpc/methods/session-tab-close-methods.ts
  • src/main/runtime/rpc/methods/session-tab-markdown-methods.ts
  • src/main/runtime/rpc/methods/session-tab-mutation-methods.ts
  • src/main/runtime/rpc/methods/session-tabs.ts
  • src/main/runtime/rpc/methods/skills.test.ts
  • src/main/runtime/rpc/methods/skills.ts
  • src/main/runtime/rpc/methods/speech.ts
  • src/main/runtime/rpc/methods/ssh.ts
  • src/main/runtime/rpc/methods/stats.ts
  • src/main/runtime/rpc/methods/status.ts
  • src/main/runtime/rpc/methods/structured-agent-session-hold.ts
  • src/main/runtime/rpc/methods/structured-agent-session-reveal.ts
  • src/main/runtime/rpc/methods/structured-agent-session-status-stream.ts
  • src/main/runtime/rpc/methods/structured-agent-session.ts
  • src/main/runtime/rpc/methods/structured-worker-stop-receipt.test.ts
  • src/main/runtime/rpc/methods/terminal-create-idempotency.test.ts
  • src/main/runtime/rpc/methods/terminal-manifest-characterization.test.ts
  • src/main/runtime/rpc/methods/terminal-orphan.ts
  • src/main/runtime/rpc/methods/terminal.ts
  • src/main/runtime/rpc/methods/terminal/terminal-inspect-process-params.test.ts
  • src/main/runtime/rpc/methods/terminal/terminal-lifecycle-methods.ts
  • src/main/runtime/rpc/methods/terminal/terminal-multiplex-method.ts
  • src/main/runtime/rpc/methods/terminal/terminal-query-methods.ts
  • src/main/runtime/rpc/methods/terminal/terminal-send-method.ts
  • src/main/runtime/rpc/methods/terminal/terminal-subscribe-method.ts
  • src/main/runtime/rpc/methods/terminal/terminal-viewport-methods.ts
  • src/main/runtime/rpc/methods/updater.test.ts
  • src/main/runtime/rpc/methods/updater.ts
  • src/main/runtime/rpc/methods/workspace-ports.ts
  • src/main/runtime/rpc/methods/worktree-catalog-methods.ts
  • src/main/runtime/rpc/methods/worktree.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-pairing-types.ts

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


📝 Walkthrough

Walkthrough

The RPC core now preserves typed method names, parameter schemas, handler results, and streaming distinctions. eraseRpcMethods converts declarations to the erased registry view. Registry, dispatcher, and pairing types accept method declarations. RPC method collections now rely on inferred types. Tests use explicit erasure before method lookup and validate typing, dispatch, streaming behavior, and duplicate registration handling.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 99fef

The typed RPC declaration changes preserve the existing runtime registry and wire behavior, with no unresolved merge-blocking risk identified.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the implementation, rationale, runtime impact, evidence, tests, and known limits. However, it omits required template sections, including the linked issue, visual proof or N/A… Add the missing template sections. Include a linked issue using “Fixes #…”, provide visual proof or write “N/A” with a reason, complete the testing checklist and platform coverage, complete the AI Disclosure section, address Review and Agen…
Docstring Coverage ⚠️ Warning Docstring coverage is 17.39% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 23 functions across 50 files. (74 skipped… 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 summarizes the main change: defineMethod now preserves literal method names and handler result types.
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

Explanation

The description explains the implementation, rationale, runtime impact, evidence, tests, and known limits. However, it omits required template sections, including the linked issue, visual proof or N/A, testing checklist, AI disclosure, review, agent skill boundary, notes, and final checklist.

Resolution

Add the missing template sections. Include a linked issue using “Fixes #…”, provide visual proof or write “N/A” with a reason, complete the testing checklist and platform coverage, complete the AI Disclosure section, address Review and Agent skill upstream boundary, add Notes, and complete the final Checklist.

Full details: Docstring Coverage

Explanation

Docstring coverage is 17.39% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 23 functions across 50 files. (74 skipped: 74 over the file limit.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@Jinwoo-H
Jinwoo-H merged commit 2ecde71 into main Sep 11, 2026
40 checks passed
@Jinwoo-H
Jinwoo-H deleted the rpc-step2b-define-method branch September 11, 2026 05:32
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