feat(agent,rpc): remote ToolHost and hand executor that run the hand's tool handlers on every call (S27a)
Summary
Part of #5482. Stacked on #5436 (base feat/rt10-loopless-runtime); retarget to main once it merges. Also closes the deferred obligation recorded on #5413 for the remote executor's side.
A session can now run its tool calls on a hand (a tool-execution-only process) instead of in its own process:
packages/agent/src/execution/remote-tool-host.ts:createRemoteToolHost({ transport })is aToolHost. It sends each model-issued call (name and raw arguments) to the hand over the durable-coreTransport, one lane per execution scope, and keeps the loop's side:tool_execution_start/_end, the batch's ordering (sequentialwaits per call), a forwarded abort, and result messages in source order. Each call is sent once; a link that fails before a settle becomes an error result, never a retry.packages/agent/src/execution/remote-executor.ts:createRemoteExecutor({ transport, openScope })is the hand's side. It opens each scope lazily, bound to the scope's root; a later call naming the same scope with another root is refused (scope_binding_mismatch), and so is any execution ID it already accepted (duplicate_execution). What the session says about itself (sessionRef) is never passed to a tool. Tools markedexecutionMode: "sequential"keep their barrier inside the scope.packages/agent/src/execution/remote-protocol.ts: the wire messages (invoke,abort,settled,refused) and a strict decoder.packages/coding-agent/src/modes/rpc/remote-executor-scope.ts:createLooplessHandScopes(configuration)opens each scope on a loopless runtime (#5436) whose cwd is the scope root.
The hand runs its tool handlers for every call (fail-closed)
loopless-execute-grant.tsgains a second closed-allowlist caller,remote-tool-executor. The guard inexecute()is unchanged: a runtime without an issued grant still refuses every call (loopless-execute-guard.test.tsunchanged and green).- A runtime built with that grant runs its own extensions'
tool_callhandlers (permission checks among them) after argument validation and before the tool, andtool_resulthandlers after it, as a session does (loopless-tool-call.ts,loopless-tool-handlers.ts). A block, an abort, or a handler that throws stops the call before the tool runs. - Two runtime facts a session-less runner refused, and that the builtin handlers need, are now bound by the loopless runtime itself (
ExtensionRunner.bindSessionlessFacts):pi.getAllTools()(the permission system resolves extension tools' permission parsers with it) andctx.getLoadedHookSources()(where hook configuration is read). An unbound session-less runner still refuses both.pi.getAllTools()uses one projection shared with the session (core/tool-info.ts, moved out ofAgentSession.getAllTools). - The builtin shell-hooks extension cannot give PreToolUse/PostToolUse hooks their session input on a runtime without a session. There it refuses every call when any tool hook is configured, and does nothing when none is. Forwarding those hooks to the process that owns the session is the two-sided forwarding change.
Inertness
Nothing in the product creates a remote ToolHost or a hand executor yet: no CLI flag, setting, RPC method or worker selects them. Sessions keep their in-process ToolHost. The two edits outside new files only affect runtimes without a session (loopless runtimes), and the getAllTools move is the same projection.
Not in this change (follow-ups on #5482)
- KILL-HAND, MULTI-HAND/MULTI-KILL and FAULT-HAND conformance cases and the win32 process-semantics simulation.
- Split-local equivalence cells and the
extension-contract-unchangedsplit-local case. - Two-phase preparation of a parallel batch on the hand (today each call runs its handlers then its tool as it arrives), tool-name alias resolution and result-image normalization on the hand.
- Two-sided forwarding of handlers that need the session (the shell-hooks extension above).
Tests
test/hand/remote-executor-select.test.ts,test/hand/permission-order-split-local.test.ts,test/hand/varied-session-info.test.ts,test/hand/scope-binding.test.ts(new).- Exact-head gate rows: see the comment below.
KILL
None registered here: the executor adds no durable write. Dispatch-at-most-once is enforced in memory per hand; the KILL-HAND cases come with the follow-up above.
Dead code
None made dead.
Summary by cubic
Adds remote tool execution (part of #5482): a session can now run its tool calls on a hand, a separate tool-execution-only process, instead of in its own process. The session side uses a new remote ToolHost (createRemoteToolHost) and the hand side a matching executor (createRemoteExecutor), linked by the transport protocol in remote-protocol.ts, over the reference transport (createReliableTransport, createInProcessNetwork, localEndpoint) now exported from the package root.
The hand runs its tool handlers for every call (fail-closed)
- Loopless runtimes built with a new
remote-tool-executorgrant now run their extensions'tool_call/tool_resulthandlers around every call, as a session does: a block, an abort, or a handler that throws stops the call before the tool runs. The in-process test harness's grant still runs the tool alone. - The executor opens each scope lazily, refuses duplicate execution IDs and scope root mismatches, and sends each call at most once: a failed link becomes an error result, never a retry. The session reference never reaches a tool.
- The loopless runtime now binds
pi.getAllTools(),pi.getActiveTools()(an empty set), a no-oppi.setActiveTools(), andgetLoadedHookSources()so the builtin permission system, hook loading, and tool-search catalog work without a session; unbound runtimes still refuse them.toolInfoOfshares thegetAllToolsprojection withAgentSession. - The builtin shell-hooks extension refuses every call when tool hooks are configured on a runtime without a session, since those hooks need session input.
Inertness
- Nothing in the product selects the remote ToolHost or starts a hand executor yet; sessions keep their in-process ToolHost.
- The only edits outside new files affect runtimes without a session.