Skip to content

ST3: backend — relay + GrpcRelayTransport + presence mirror + select-sandbox #86

Closed

Description

@pdettori

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). Accepts SandboxWorker.Attach; on Hello, validates the bearer-token ↔ sandbox_id binding (§8/§9) and parks the live stream in an in-memory table sandbox_id → stream. Mirrors presence into the existing Redis sandbox pool (writes sandbox_id, labels, capabilities, capacity_max, transport:"grpc"; removes the record on stream close — the live Attach stream is the registration, no separate heartbeat key, no reaper). Routes SandboxExec.Exec/Abort to the parked stream and forwards Chunk/End/ExecError back as stream ExecEvent.
  • GrpcRelayTransport — implements SandboxTransport (ST2); turns one exec() into a SandboxExec.Exec call with stream reassembly + req_id correlation; 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 by record.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.
  • GrpcRelayTransport round-trips read/write/bash/grep through the relay with byte-identical onData streaming to KubectlTransport.
  • 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/.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions