3.3 KiB
3.3 KiB
Investigation summary: peer Pod handshake
Date: 2026-06-02
Current authority map
ListPods/RestorePodare implemented incrates/pod/src/discovery.rsand are served both as LLM tools and protocol methods from the currently attached Pod's controller. They intentionally start from the caller Pod's visibility set rather than a host-wide Pod universe. Today the visibility set is the caller itself plus spawned children from durable Pod metadata and the live spawned-child registry.- Pod metadata is in
crates/pod-store/src/lib.rsas name-keyed current state (PodMetadata) under the Pod-state root.spawned_childrenis durable current parent/child visibility and delegation state; session JSONL remains the durable explanation for delivered context/history. - The spawned-child registry (
SpawnedPodRegistry) is runtime/current ownership state forSpawnPod,SendToPod,ReadPodOutput, andStopPod. It carries output cursors and delegated scope; it should not be reused for peer visibility. SendToPodincrates/pod/src/spawn/comm_tools.rsis explicitly spawned-child scoped: it looks up onlySpawnedPodRegistry, sendsMethod::Run, and is paired withReadPodOutputcursor semantics. Broadening it would blur child vs peer semantics, so a distinct peer-safe send surface is preferable.- Protocol methods are in
crates/protocol/src/lib.rs; TUI command dispatch is local parsing incrates/tui/src/command.rs, returning typedMethods thatsingle_pod.rssends to the currently attached Pod. This is suitable for a TUI command that asks the current Pod to perform authoritative metadata changes. - Delivered notifications already have an explainable durable path:
Method::Notifyis queued throughNotifyBuffer, rendered as aSystemItem, committed asLogEntry::SystemItem, and then appended to model history. A peer message can reuse that receive-side path without hidden context injection.
Implementation direction
No escalation blocker found. The minimal safe design is:
- Add a
peersfield toPodMetadata, separate fromspawned_children, with serde defaults so no broad migration is needed. - Add a controller-handled
Method::RegisterPeer { name }that validates the target Pod state exists, rejects self, and writes reciprocal peer entries to both Pod metadata records. Normal write failures roll back the first side so successful replies do not leave one-sided visibility. - Extend
ListPodsvisibility with apeerreason sourced fromPodMetadata.peers; keep spawned-child comm registry and child output cursors unchanged. - Add a separate
SendToPeerPodtool backed byPodDiscoveryvisibility. It only sends to visible peers, uses the target's live/restored socket from discovery, and delivers aMethod::Notifymessage labeled with the sender Pod name. It does not read output, stop Pods, grant scope, or useSpawnedPodRegistry. - Add TUI
:peer <name>command that emitsMethod::RegisterPeer { name }to the attached Pod and shows local diagnostics; the controller returns a typed result event for success and normalEvent::Errorfor failure.
Crash-level atomicity for two metadata files is not provided by the existing store, but the implementation can avoid misleading partial state for ordinary validation/write failures and does not require broad schema migration or hidden history changes.