Repository navigation
Description
ST3 — Backend: relay + GrpcRelayTransport + presence mirror + select-sandbox integration
Part of the SandboxTransport epic (see epic #89). Backend track (TypeScript / in-cluster). Depends on ST1 (proto) and ST2 (seam). Behind SH_REMOTE_SANDBOX, off by default.
Spec: docs/specs/2026-07-08-sandbox-transport-grpc-design.md §3, §5, §6, §8, §10, §13.2.
Problem
With the seam (ST2) and the proto (ST1) in place, the harness still can't reach a worker that dials out: something in-cluster must accept the worker's Attach stream and let the harness push commands to it, and select-sandbox must be able to hand back a remote transport.
Goal
Add the in-cluster relay and the harness-side remote transport, keeping matching in the existing pool.
- Relay — new
Deployment, single replica (§6). AcceptsSandboxWorker.Attach; onHello, validates the bearer-token ↔sandbox_idbinding (§8/§9) and parks the live stream in an in-memory tablesandbox_id → stream. Mirrors presence into the existing Redis sandbox pool (writessandbox_id, labels, capabilities,capacity_max,transport:"grpc"; removes the record on stream close — the liveAttachstream is the registration, no separate heartbeat key, no reaper). RoutesSandboxExec.Exec/Abortto the parked stream and forwardsChunk/End/ExecErrorback asstream ExecEvent. GrpcRelayTransport— implementsSandboxTransport(ST2); turns oneexec()into aSandboxExec.Execcall with stream reassembly +req_idcorrelation; enforces the harness-side deadline and the per-exec total-output cap →Abort+[output truncated]on exceed (§8).select-sandbox— leases from the pool (in-cluster pods + mirrored remote records) and returns a transport byrecord.transport:"kubectl"→KubectlTransport,"grpc"→GrpcRelayTransport(sandbox_id)(§6). Pool stays the single source of truth for matching.- Flag: all of the above behind
SH_REMOTE_SANDBOX(§13.2), off by default — no effect until a worker connects.
Non-goals (this task)
- The worker itself (ST4 — Go).
- SPIFFE/mTLS, multi-replica relay HA, private-mesh reachability (deferred, §13.4).
- Any change to the Pi loop,
run-turn, session backend, or leaf queue (§3 "what does NOT change").
Acceptance
- Flag off ⇒ inert: existing e2e green, no relay traffic, kube-exec path unchanged.
- Worker connect → presence record appears in the pool; stream close → record removed.
GrpcRelayTransportround-trips read/write/bash/grep through the relay with byte-identicalonDatastreaming toKubectlTransport.- Relay restart drops parked streams and fails in-flight
Exec→ leaf retry re-leases a healthy sandbox (no mid-exec durability, stated plainly — §6, §10). - Output-cap exceed triggers
Abort+ truncation marker; dual-ended timeout never hangs on a silent worker (§8).
Touches
New relay Deployment + manifests under deploy/knative/; new GrpcRelayTransport (k8s-sandbox package); harness/src/select-sandbox.ts; Redis pool presence mirror (reuses the existing pool/lease store); SH_REMOTE_SANDBOX config plumbing.
Next step
Pair with ST4 (worker) for the ST5 live gate. Backend plan lives locally in docs/plans/.
Activity
docs: register SandboxTransport (ST) track in the milestone registry
feat: add Chunk.stream discriminator to sandbox/v1 proto (ST3, #86)
feat: add PoolRecordStore for grpc sandbox presence (ST3, #86)
feat: add GrpcRelayTransport implementing SandboxTransport (ST3, #86)
test: pin GrpcRelayTransport dedup, output-cap, deadline (ST3, #86)
feat: add sandbox-relay Attach handler + presence mirror (ST3, #86)
feat: add sandbox-relay Exec/Abort routing (ST3, #86)
feat: add sandbox-relay gRPC bootstrap + CI typecheck (ST3, #86)
feat: dispatch grpc records to GrpcRelayTransport in select-sandbox (…
feat: make run-leaf transport-blind for grpc sandboxes (ST3, #86)
feat: add single-replica relay Deployment + manifest test (ST3, #86)
Merge pull request #93 from pdettori/feat/sandbox-transport-relay