From 12556deb0535be4229a1d0a2f04854fa0d2a0d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Mon, 20 Apr 2026 14:49:33 -0400 Subject: [PATCH] Hotfix C4: add invokeInternalTool to worker-message RPC method enum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Production bug — as soon as the CEO agent tries to call the hire_agent or file_approval internal tool introduced by C4 (e2c839b..03864f3), the main process spams: [error] [worker] invalid message payload ZodError: ... with all seven discriminant branches failing. Every branch reports 'invalid_value' on 'type' because zod's discriminated-union validator walks every variant when the discriminant does not match any literal — which happens because the worker sent `{ type: "rpc-request", method: "invokeInternalTool", ... }` and the 'rpc-request' branch's `method: z.enum([...])` only listed five methods: persistMessage / prepareRun / beforeToolCall / afterToolCall / transformContext. 'invokeInternalTool' was missing. Root cause: C4 added the RPC method on both sides of the fence — worker-side caller (hire-agent-tool.ts:133, file-approval-tool.ts:115) and main-side handler (runtime-bridge.ts:565, RpcMethod TS union at line 77) — but forgot to register it in the zod validation schema at worker/entry/types.ts that sits between them. The TS union type would have caught it at compile time if the enum were the single source of truth; right now the enum is duplicated as a zod literal list + a TS union, and C5's compile-time hook contract only covers pi's own hooks, not the RPC message envelope. Fix: add "invokeInternalTool" to the zod enum. One line. Follow-up proposal C5-followup: unify the two duplicated enum definitions by either (a) deriving the TS union from the zod schema via z.infer, or (b) making runtime-bridge.ts import the enum values from worker/entry/types.ts so adding an RPC method requires touching exactly one place. This will be documented in docs/proposals/ once the hotfix lands and the app is known to work end-to-end again. Scope for that cleanup is small (one file edit + one type move) but out of scope for this hotfix because the user is currently unable to run the CEO bootstrap. typecheck green, 529 unit tests green, 8/8 eval green. --- src/main/worker/entry/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/worker/entry/types.ts b/src/main/worker/entry/types.ts index ced960a4..c354b93a 100644 --- a/src/main/worker/entry/types.ts +++ b/src/main/worker/entry/types.ts @@ -53,6 +53,7 @@ export const workerMessageSchema = z.union([ "beforeToolCall", "afterToolCall", "transformContext", + "invokeInternalTool", ]), payload: z.unknown(), }),