Skip to content

Client tools cross the remote door to the connection that set them - #2417

Merged
AbirAbbas merged 5 commits into
workstreams/mainfrom
workstreams/l-remote-engine
Nov 5, 2026
Merged

AbirAbbas merged 5 commits into
workstreams/mainfrom
workstreams/l-remote-engine

Conversation

@AbirAbbas

@AbirAbbas AbirAbbas commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Client tools (agents.tools_set, agents.tool_call, agents.tool_result) worked only for a conversation the codeaf app process ran itself. When the app joined a conversation another codeaf host held (the remote door), the holder had no client-tool door. When a chat was held on another computer through the relay, the app answered bad_scope. This change makes client tools cross the remote door. The change is generic, transport-agnostic and additive. The Workstreams plan's L-REMOTE item depends on it.

Remote door (internal/remote)

  • A new Welcome.clientTools capability. With it, a connection sends its whole snapshot of sets with ClientTools.Set. The holder answers calls with ClientTool.Answer. Two new frames carry the calls: clientToolCall, and clientToolEnded for a call that ended without an answer. remote.Version stays 22. An older peer never sends or receives them.
  • A per-conversation ClientToolHub implements session.ClientToolDoor and is keyed by connection. It validates on the holder, including built-ins, cross-connection collisions and the 4-set and 64-tool limits. It routes each call only to the connection that owns the set, and rejects answers from any other connection.
  • When a connection leaves (detach, torn pipe, close or a failed write), the hub drops its sets and settles its pending calls at once with the existing client_unavailable … disconnected answer. A call nobody answers ends at its existing wait with client_timeout. A roaming client re-sends its snapshot after a redial.

App (cmd/codeaf, internal/appwire)

  • On a joined conversation whose holder forwards, agents.tools_set validates locally and forwards the agent's snapshot. The registry commits only after the holder accepts. A holder refusal maps to bad_params; a link failure maps to unreachable. An older holder keeps today's exact bad_scope.
  • Every hold of a joined conversation installs the call handler and pushes the agent's current sets, so a re-join re-attaches.
  • A chat held on another computer stores its sets. They apply once the chat runs here again.
  • A host process without an app gives each conversation the hub. The app hello adds agents.client_tools.remote.
  • Docs: PROTOCOL.md "Client tools", docs/REMOTE.md and the chat manual.

Validation contract → tests

Item Tests
C1 tools_set works on a joined conversation; the tools reach the holder's belt and instructions TestClientToolsRemoteCapabilityAndSnapshot, TestClientToolsRemoteModelBoundary, TestClientToolsRemoteJoinedModelRoundTrip, TestClientToolsRemoteHolderRefusalIsAtomic, TestClientToolsRemoteTransportFailureLeavesRegistry, TestClientToolsRemoteAttachmentUsesCallPath
C2 Calls go only to the connection that set the tools; answers come back on it TestClientToolsRemoteOwnersAndAnswers, TestClientToolsRemoteAnswerBypassesOrderedLane, TestClientToolsRemoteJoinedModelRoundTrip, TestClientToolsRemoteBoundedResult
C3 A dropped connection settles pending calls at once; silence ends at the existing wait TestClientToolsRemoteDisconnectDetachAndClose, TestClientToolsRemoteWaitEndAndAnswerOwnership, TestClientToolsRemoteAppDropSettlesPending, TestClientToolsRemoteAppTurnEnded, TestClientToolsRemoteBlockedSenderDropsExpiredCalls, TestClientToolsRemoteCallDuringPublication
C4 A reconnect re-attaches (redial and re-hold) TestClientToolsRemoteRedialRestoresSnapshot, TestClientToolsRemoteReholdPushesSets, TestClientToolsRemoteEngineOpenings, TestClientToolsRemoteRedialMovesAttachedOwner, TestClientToolsRemoteRedialConversationIdentity
C5 Two connections never answer each other's calls TestClientToolsRemoteOwnersAndAnswers, TestClientToolsRemoteWaitEndAndAnswerOwnership, TestClientToolsRemoteHolderValidationAndAggregateLimits
C6 An older holder is told apart by the welcome flag and keeps bad_scope TestClientToolsRemoteCapabilityAndSnapshot, TestClientToolsRemoteScopeAndElsewhereStorage, existing TestClientToolsAgentLimitsAndScope unchanged
C7 A chat held on another computer stores its sets for when it runs here TestClientToolsRemoteScopeAndElsewhereStorage
C8 Hello feature agents.client_tools.remote TestClientToolsRemoteHelloFeature
C9 Conversations without sets are unchanged TestClientToolsRemoteCapabilityAndSnapshot, TestClientToolsRemoteModelBoundary

Review fixes

A fresh review found three CI blockers and four lifetime/reconnect defects. All are fixed:

  • Each owner connection has one sender, which skips calls already settled or past their wait. A stuck write holds one goroutine, not one per call.
  • Requests use the client's ordinary call path; there is no per-request writer.
  • Each client carries a random owner token. A redial that lands while the old connection is still attached moves the sets to the new connection instead of colliding with itself.
  • A snapshot is replayed only onto the conversation it was acknowledged in.
  • A forwarded call waits for an in-flight publication only as long as its own context allows.
  • Every new lock unlocks from a defer.
  • The chat manual keeps its one bounded section.

CI: no failures of its own. The integration branch's known baseline reds (SYNC7) are unchanged.

🤖 Generated with Claude Code

AbirAbbas added a commit that referenced this pull request Nov 5, 2026
AbirAbbas added a commit that referenced this pull request Nov 5, 2026
@AbirAbbas
AbirAbbas force-pushed the workstreams/l-remote-engine branch from e545761 to 36f0664 Compare November 5, 2026 17:57
AbirAbbas and others added 5 commits November 5, 2026 14:09
A holder that forwards client tools says so in its welcome. A connection
sends its whole snapshot of sets with ClientTools.Set; the holder's
conversation hub puts them on the belt, sends each call to the owning
connection only and takes the answer back with ClientTool.Answer. A
connection that leaves (detach, torn pipe, close, failed write) loses its
sets and its pending calls settle at once with the disconnected answer; a
call nobody answers ends at its existing wait. A roaming client re-sends
its sets after a redial. The protocol version is unchanged: an older peer
never sees the new calls or frames.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
agents.tools_set on a conversation the app joined through another host now
forwards the agent's sets to that holder when it supports it, and the
app pushes them again every time it holds the conversation. Calls come
back as agents.tool_call on the app connection that set them. An older
holder keeps the existing bad_scope refusal. A chat held on another
computer stores its sets and uses them once it runs here again. Hosts
without an app give each conversation the forwarding hub, and the app
hello adds agents.client_tools.remote.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
One sender per owner connection drains its pending calls and skips any
call already settled or past its wait, so a stuck write holds one sender
and no queue. Requests go through the client's ordinary call path. Each
client carries a random owner token: a redial that arrives while the old
connection is still attached moves the sets to the new connection instead
of colliding with itself. A snapshot replays only onto the conversation it
was acknowledged in. A forwarded call waits for an in-flight publication
only as long as its own context and wait allow. Every new lock unlocks
from a defer, and the chat manual keeps its one bounded section.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AbirAbbas
AbirAbbas force-pushed the workstreams/l-remote-engine branch from 36f0664 to f6cbaeb Compare November 5, 2026 19:09
@AbirAbbas
AbirAbbas merged commit 08b6e1e into workstreams/main Nov 5, 2026
8 checks passed
@AbirAbbas
AbirAbbas deleted the workstreams/l-remote-engine branch November 5, 2026 19:45
AbirAbbas added a commit that referenced this pull request Nov 13, 2026
…, agents.set_scope) (#2613)

* Client tools: a client attaches tools to a conversation

Carries #2334 from workstreams/main (e9a571c) onto dev. The workstream
door that commit sat beside is left out, and the collection-held
conversation half is already on dev (#2475).

Co-Authored-By: Claude Mythos 5.2 <[email protected]>

* Client tools: a tool call names the message its turn answers; the answer cutoff is a wait

Carries #2346 (b1a02be) and #2360 (25c6faa) from workstreams/main.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>

* Client tools cross the remote door to the connection that set them

Carries #2417 (08b6e1e) from workstreams/main.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>

* A conversation can be told only about its own work (agents.set_scope)

Carries #2462 (e985a44) from workstreams/main.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>

* changes: one entry for client tools and conversation scope (#2613)

Replaces the five entries carried with the source commits.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>

* Client tools: a call id hashes the whole call, and a call without a provider id gets a random id

The `call` id was sha256(agent, provider call id), with a per-process
counter when the provider gave no id. Provider ids are not unique:
Kimi-family models write their own `name:idx` ids, which repeat after
agents.rewind or compaction, and a faulty server can repeat any id. A
reused id with another tool or other arguments therefore joined the
earlier call's wait or got its saved answer, and never reached the app,
while the app's 30-day table replayed the old answer for the same id.
The counter restarted at every launch, so ids minted without a provider
id came back after a restart.

clientToolCallID now hashes the agent, provider call id, set, tool name
and exact argument bytes, each length-prefixed, and keeps the `ct_` + 64
hex shape. The same call dispatched again keeps its id, joins the pending
wait and gets the saved answer. Without a provider id the id is 32 random
bytes. Calls from a remote holder reach the same door, so they share the
identity.

PROTOCOL.md and the change entry say what `call` is derived from.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Conversation scope: the page and the tasks description stop promising other windows' work

Under `conversation` scope a conversation gets no <elsewhere> block and
its tasks tool lists only its own work, but its system prompt still said
"OTHER codeaf WINDOWS ON THIS PROJECT ARE VISIBLE TO YOU" and the tasks
description still said search includes other windows' live work. The
model could read an empty answer as "nothing else is running here" and
tell the person so.

The page's other-windows line and the tasks description now follow the
stored scope. Under conversation scope the page says the conversation is
told only about its own work and must not conclude nothing else is
running; the tasks description says search reaches only its own work,
even with scope everywhere. A project page and tasks description stay
byte for byte as before.

The scope is read when the agent is made and again at each turn's start.
A changed scope re-renders the page and replaces the tasks tool on the
belt and on a lean shelf, in fresh arrays, so the model sees the change
from the next turn, as the scope already promises. Task nodes keep their
page.

PROTOCOL.md, the tasks manual page and the change entry say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Client tools: a session swap drops the old conversation's sets

A holder shares one ClientToolHub across the initial, fresh and resumed
openings of a remote Session. When another window ran /new or /resume,
Session.swap replaced the agent but left every connection's sets in the
hub, so the replacement conversation got a joined app's tools and
instructions, and its calls went to that app under the old agent's id.
The app then wrote into the old workstream, and its answer was refused
with ErrJoinedGone, so the holder's model was told client_timeout.

Session.swap now calls ClientToolHub.forget before the new agent is
reachable: every connection's sets go, pending calls end with a
clientToolEnded frame so the app stops waiting too, and a joined
connection's snapshot that was already past the session's check is
refused. A following surface may still attach to the open conversation.

PROTOCOL.md, REMOTE.md, the client-tools manual page and the change
entry say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Mythos 5.2 <[email protected]>
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