feat(agent): model plane - a hand call's nested model requests are served by the brain that owns it (S31)

Merged
CO
21d ago
+826-0

Summary

Part of #5639. Stacked on #5513 (base feat/s27a-hand-recovery, S27a); this PR shows only its own delta and retargets to main once #5513 merges.

A running call on a hand can now ask the brain that owns it for a model completion (the model plane, design 5.6.3): a model-backed tool on a hand no longer needs a model or credentials of its own.

  • packages/agent/src/execution/plane.ts (new): nested requests between a hand's running call and its brain. A request travels on the parent call's own scope lane and names the parent's execution ID. The brain (createPlaneServer) admits it only while the parent is a live call on that lane (parent_terminal, scope_lane_mismatch, plane_unavailable otherwise), serves each (parent, child request) once and answers a replay from the stored answer, and aborts a parent's open requests when the parent ends. The hand (createPlaneClient) fails a call's open requests once the call ends and forwards an abort.
  • packages/agent/src/execution/plane-model.ts (new): MODEL_PLANE, ModelPlaneRequest (model by provider and ID only, context, maxTokens/temperature/reasoning), serveModelPlane(complete) for the brain and createModelPlaneClient(nested) for a hand tool. The codec keeps only those fields, so a hand can never pick an endpoint, key or header.
  • remote-tool-host.ts: optional planes (absent: every nested request is refused plane_unavailable); ending a call ends its nested requests.
  • remote-executor.ts: HandCall.nested, the call's own nested-request function.

Inert: nothing in the product serves or calls a plane yet, and fused sessions do not touch this code. Out of scope: binding the hand runtime's ctx.model / eval completion() to the plane, durable nested-request records across restarts, and the session plane (S32).

Tests

RED first: the new suites failed with the modules missing (Cannot find module '../../src/execution/plane.ts'), then:

  • bun run --cwd packages/agent test -- test/execution: 8 files, 168 passed (the new model-plane.test.ts 4 + model-plane-admission.test.ts 4).
  • bun run --cwd packages/coding-agent test -- test/hand: 9 files, 31 passed (the HandCall consumers).
  • Mutation proofs, each caught by exactly one case: dropping the lane check, passing the hand's model object through unfiltered, removing the replay answer.
  • bun check -p tsconfig.json: one error, inherited from the base #5513 at ac44a95d53 (remote-hand-ledger.ts(46,3): the ledger's blocked terminal reason vs RemoteTerminalReason); it reproduces on the base with this diff removed and is reported to that PR's owner. No error in this diff's files.

Change fragment: changes/unreleased/5640.md (changelog gate PASS against the base head).


Summary by cubic

Adds the model plane (part of #5639): a running call on a hand can ask the brain that owns it for a model completion, so a model-backed tool on a hand no longer needs a model or credentials of its own.

  • Requests travel on the parent call's scope lane and name the parent execution ID; the brain serves them only while the parent is live on that lane, otherwise refusing with parent_terminal, scope_lane_mismatch, or plane_unavailable. Aborts follow the same lane rule.
  • Each request is served once; a replay gets the stored answer, and a parent's open requests abort when the parent ends. The hand forgets ended calls and fails their open requests.
  • The request codec keeps only the model's provider and ID, context, and sampling options, so a hand can never pick an endpoint, key, or header.
  • createRemoteToolHost() takes optional planes; HandCall.nested carries the call's nested requests. Nothing serves or calls a plane yet.

Since the last summary the branch merged main again; the test fixture now passes the hand's self authority, which the base branch made required.