Skip to content

ST5: integration & live gate — cross-transport conformance + end-to-end leaf (Kind → OCP) #88

Closed

Description

@pdettori

ST5 — Integration & live gate: cross-transport conformance + end-to-end leaf

Part of the SandboxTransport epic (see epic #89). Both tracks. Depends on ST3 (backend) and ST4 (worker).

Spec: docs/specs/2026-07-08-sandbox-transport-grpc-design.md §11, §13.3.

Problem

KubectlTransport and GrpcRelayTransport are only safely swappable (driver #2) if they demonstrably satisfy the same SandboxTransport contract, and the remote path only counts as real once a genuine Go worker pod serves a leaf end-to-end over :443.

Goal

Prove equivalence and land the live gate (§11 testing table):

  • Conformance battery — one shared spec run against both KubectlTransport and GrpcRelayTransport: round-trip every op (read/write/bash/grep), abort mid-stream, timeout, reconnect→dedup, output-cap. This is what makes the two transports safely interchangeable. (The battery is authored here and is the same suite ST2 uses to prove its refactor inert.)
  • Manifest-shape test — a vitest that parses the relay + worker Deployment YAML directly (no kustomize in CI), matching the existing manifest-shape pattern.
  • Live gate — a real Go worker pod dialing the in-cluster relay over :443; one leaf end-to-end on Kind, then OCP, following the existing leaf-smoke pattern.

Non-goals (this task)

  • New transport behavior (owned by ST2/ST3) or worker behavior (ST4).
  • The deferred items (mTLS, multi-replica HA, private mesh, extra-language workers, HTTP/1.1 traversal — §13.4).

Acceptance

  • The same conformance suite is green against both transports (identical observable contract).
  • Manifest-shape vitest parses relay + worker Deployment YAML and passes in CI.
  • Live leaf smoke passes with the Go worker → relay :443 path on Kind, then on OCP (gated by the existing live-smoke env vars).

Touches

Shared conformance suite (k8s-sandbox tests, exercised by ST2 + ST3); Go contract tests (ST4); deploy/knative/ relay + worker manifests + smoke drivers (leaf-smoke.sh extension); CI wiring.

Next step

Green here retires the epic's core scope; deferred follow-ups (§13.4) stay tracked in the epic's Deferred section.

Activity

  1. pdettori commented on Jul 10, 2026

    @pdettori
    MemberAuthor

    ST5 scope — integration & live gate

    ST5 is the slice that proves the remote path end-to-end with a real Go worker over the network: worker dials the relay, the harness leases the mirrored grpc record and runs a leaf through GrpcRelayTransport, first on Kind then on OCP. It depends on #87 (ST4, the Go worker) and on #86 (ST3, backend — merged).

    Already landed in ST3 (#86 / PR #93) — do NOT redo

    • Unit-level cross-transport conformance is done. The shared runConformance battery already runs against both transports — runConformance("KubectlTransport", …) and runConformance("GrpcRelayTransport", …) — proving they satisfy the identical SandboxTransport contract. ST5's job is the live analog, not re-proving this at the unit level.
    • Relay Deployment + its manifest-shape vitest exist (deploy/knative/relay-deployment.yaml, single replica, Service on :8443; packages/knative-server/test/relay-deployment.test.ts), wired into the base + OCP kustomizations (OCP overlay already rewrites the relay image to GHCR).
    • Harness dispatch + flag gating (SH_REMOTE_SANDBOX, select-sandbox → GrpcRelayTransport, transport-blind run-leaf) is in and inert when off.

    ST5 deliverables (the live gate)

    1. Worker deploy surface — a worker Deployment manifest for the in-cluster smoke (there is none yet) + a manifest-shape vitest mirroring relay-deployment.test.ts; wire it into the base + OCP kustomizations. (The worker binary/image is ST4: worker — Go reference worker (dial Attach, run/stream/abort, dedup, dual timeout) #87's; ST5 owns its deployment for the gate.)
    2. Reachability + auth wiring — for the Kind/OCP smoke an in-cluster worker can dial the relay ClusterIP sandbox-relay.default.svc:8443 directly (plaintext) — start there, it's the simplest path. The relay needs SH_RELAY_TOKEN/SH_RELAY_TOKEN_<id> + REDIS_URL; the worker Deployment carries the matching Bearer token + its sandbox_id; the harness needs SH_REMOTE_SANDBOX=1 + SH_RELAY_ADDR. The production external-worker path (relay Attach on :443 behind an ingress/Route with TLS, and SandboxExec locked to in-cluster via a NetworkPolicy per spec §9) is a follow-on — decide whether ST5 includes the NetworkPolicy/Route or defers them to a hardening slice.
    3. leaf-smoke.sh relay path — deploy/knative/leaf-smoke.sh has no relay/SH_REMOTE_SANDBOX hooks yet. Extend it (or add leaf-relay-smoke.sh) to: deploy relay + worker, wait for the presence record to appear in the Redis pool (redis-cli HGETALL sh:sandbox:records), run one leaf with SH_REMOTE_SANDBOX=1 so it leases the grpc record, assert the verdict/output, and assert the record is removed when the worker stops.
    4. Live cross-transport gate — run the same leaf workload through the pod path (KubectlTransport, flag off) and the worker path (GrpcRelayTransport, flag on) and assert identical verdicts — the live equivalent of the unit conformance battery.
    5. Kind → OCP progression — green on Kind first, then OCP 4.20 (the repo's live-gate pattern).

    Acceptance gates (spec §10 / §13.2)

    • Flag off ⇒ existing e2e green (path fully inert).
    • Worker connect ⇒ presence record appears in the pool; removed on stream close.
    • A leaf completes end-to-end via the relay (streamed stdout, correct exit code).
    • Relay restart (or worker disconnect) ⇒ in-flight exec fails ⇒ leaf retry re-leases a healthy sandbox (no mid-exec durability).
    • Output-cap truncation and dual-ended timeout exercised against the live worker.

    Starting point

    The Level-2 (full-path) recipe in #87 is the entry point — SH_REMOTE_SANDBOX=1 + SH_RELAY_ADDR + a leased grpc record. Reference material: proto/sandbox/v1/sandbox.proto (§8 semantics), packages/sandbox-relay/src/relay.ts (park/presence/routing), packages/k8s-sandbox/src/grpc-relay-transport.ts (harness-side reqId correlation / Chunk.stream split / dedup / deadline / output cap), and the existing deploy/knative/leaf-smoke.sh as the template to extend.

    Assisted-By: Claude Code

  2. pdettori commented on Aug 26, 2026

    @pdettori
    MemberAuthor

    Status check — code vs. acceptance (as of docs/turn-sse-streaming-spec, 2026-08-26)

    The unit-level equivalence is in place, but the live gate does not exist, and it is blocked on #87 (the worker is a HELLO WORLD stub that runs no commands, so no leaf can complete through the remote path).

    Done ✅

    • Shared conformance battery runs against both transports — same suite, packages/k8s-sandbox/test/conformance.ts, invoked by:
      • transport-conformance.test.ts:39 → runConformance("KubectlTransport", …)
      • grpc-relay-transport.test.ts:55 → runConformance("GrpcRelayTransport", …)
      • Covers: stdout+exit code, streaming stdout/stderr (stderr excluded from stdout), stdin forwarding, non-zero exit, timeout, abort/signal, idempotent close(). (Both run against scripted fakes, not a live backend.)
    • Relay manifest-shape vitest — packages/knative-server/test/relay-deployment.test.ts (single-replica Deployment + Service, entrypoint, kustomization refs).

    Missing ❌

    • No worker Deployment manifest-shape test — only the relay manifest is covered. remote-worker/worker-deployment.yaml / deploy/knative/worker-example.yaml are unparsed by any vitest.
    • No live gate at all. No smoke driver exercises the real worker → in-cluster relay :443 path — leaf-smoke.sh and the other deploy/knative/*.sh contain no RELAY_ADDR / remote-worker / :443 remote path. Nothing runs one leaf end-to-end on Kind, then OCP (§11 / §13.3).
    • Reconnect→dedup and output-cap are not asserted as cases in the shared battery (they're worker-side in ST4: worker — Go reference worker (dial Attach, run/stream/abort, dedup, dual timeout) #87); the cross-transport suite stops at the ops above.

    Blocking dependency

    Even with a smoke driver, an end-to-end leaf cannot run through the remote path today because the #87 worker doesn't execute commands. #87's real bash/timeout/abort must land first.

    Net: transports are proven interchangeable against mocks; the remote half has never executed a real command end-to-end. Remaining: worker manifest test + live leaf smoke (Kind → OCP) on the genuine worker→relay:443 path.

  3. pdettori commented on Aug 27, 2026

    @pdettori
    MemberAuthor

    ST4 is complete — what ST5 inherits

    The Go worker (#87, PR #172) is done: it runs real commands, enforces timeout_s,
    kills process groups on abort, dedups redelivered req_ids, and reconnects while
    preserving its cache. 56 tests, go test -race ./... green in CI.

    The acceptance battery ST4 landed (and its limits)

    All seven of ST4's criteria pass over real gRPC against a real bash, driven by an
    in-process fake relay (remote-worker/internal/relaytest):

    Criterion Test
    read TestContractRead — cat <file>
    write TestContractWrite — base64 -d > <file> on stdin, asserts file bytes
    bash TestContractBash — stdout/stderr on distinct stream enums, real exit 7
    grep TestContractGrepStreamsMultipleChunks — ~149 KiB, ≥2 chunks, each ≤32 KiB
    abort mid-stream TestContractAbortMidStream — asserts a sentinel file stops growing, proving the process group died rather than that reads merely stopped
    timeout TestContractTimeout — sleep 30 at timeout_s: 1 → ExecError{"timeout:1"} in ~1s
    reconnect → dedup TestContractReconnectDedup — drops the stream, reattaches, redelivers; asserts the marker file still holds one line

    Two things ST4 deliberately did not prove, which are ST5's job:

    1. The fake relay is self-authored. It encodes this repo's reading of the wire
      contract, and a double written from the same reading can agree with a misreading.
      ST4 shipped a gated interop test (TestLiveRelayInterop, SH_LIVE_RELAY=1) that
      drives read/write/bash against the real relay via SandboxExec.Exec — but it
      has never been run. It skips without the env var and CI has no relay. Running
      it is the cheapest first step of ST5's live gate.
    2. Cross-transport equivalence is untested. ST4's battery runs only against
      GrpcRelayTransport's worker side. ST5's conformance battery against both
      transports is what actually discharges driver M5: Compaction-checkpoint fast path + budget voter #2.

    Findings from ST4 that bear on ST5 specifically

    • A cache hit re-emits only the terminal frame, never the output chunks. A
      redelivered streaming exec returns its exit code with zero output — a
      redelivered cat file yields exit 0 and empty content. The worker is
      spec-compliant (§8 says "re-emit the cached terminal result", and End has
      nowhere to put output), so this is a contract gap, not an implementation bug.
      ST5's conformance battery should assert whatever behavior you decide is
      correct here, because the two transports will differ:
      KubectlTransport has
      no dedup cache at all, so it re-runs and returns output.
    • gRPC MaxCallRecvMsgSize is unconfigured on the worker's dial. A base64
      write payload over the 4 MiB default kills the whole stream, not just that
      exec, and triggers a reconnect. Worth an explicit max write size in the
      conformance battery, and a decision on both ends.
    • req_id is not unique per worker (see ST4: worker — Go reference worker (dial Attach, run/stream/abort, dedup, dual timeout) #87). ST5 will hit this the moment the
      harness runs more than one replica against a shared sandbox.
    • streaming: false is the proto3 default and was untested over the wire until
      late in ST4. Any conformance battery should drive it explicitly.

    Reachability note for the live gate

    remote-worker/DESIGN.md records that the harness's default-deny egress policy did
    not permit the relay, so with SH_REMOTE_SANDBOX=1 every remote exec was silently
    denied and timed out. deploy/knative/harness-egress-policy.yaml carries the rule
    now; a deployment predating that fix needs the documented patch.

    Assisted-By: Claude Code

  4. pdettori commented on Aug 27, 2026

    @pdettori
    MemberAuthor

    Two things the live gate must handle (found validating the remote path manually)

    I ran the full remote path in a local kind cluster today — leaf → relay → worker pod, no
    kubectl exec in the path (details on #89). Two traps bit me, and both matter for this
    issue's conformance battery and smoke script:

    1. A green run does not prove the remote backend served it. select-sandbox builds
    candidates = [...pods, ...grpcRecs] and leases least-loaded-first, so with idle
    in-cluster sandbox pods present, a pod wins even with SH_REMOTE_SANDBOX=1. My first
    remote run returned a correct-looking verdict that had been produced by an Alpine pod, not
    the worker. So leaf-smoke.sh's relay path must assert which backend executed, not
    just that the leaf succeeded. The cheap way: pick a file that differs between backends —
    the sandbox-N pods are Alpine and the worker image is RHEL, so /etc/os-release gives
    opposite answers and the verdict text names the OS it read.

    2. deploy/knative/relay-deployment.yaml omits SH_RELAY_TOKEN. Relay auth is
    fail-closed, so applying it as-is gives a relay that rejects every Attach. Worth fixing in
    the manifest.

    Operational notes for whoever writes the script: kubectl set env does not work on a
    Knative Service (no kind "Service" is registered) — use a merge patch, and preserve the
    container's volumeMounts or the Knative webhook rejects the patch.

    Already green and not needing repeat work here: the gated SH_LIVE_RELAY=1 interop test
    passes against the real relay, and the shared conformance battery already runs against
    both transports (runConformance("KubectlTransport", …) and
    runConformance("GrpcRelayTransport", …)), including output-cap, transport-side dedup, and
    the dual-ended deadline. So this issue's remaining substance is the live gate itself rather
    than the battery.

    A one-command laptop version of the demo is filed separately as #174.

    Assisted-By: Claude Code

  5. pdettori commented on Aug 28, 2026

    @pdettori
    MemberAuthor

    ST5 complete — the live gate exists, on Kind and on OpenShift

    All three acceptance bullets discharged. Branch: 12 commits; make typecheck, make test (605 passed / 13 skipped) and go test -race ./... green.

    Conformance battery — both per-call transports

    The shared battery now also holds both transports to the output cap, which previously only GrpcRelayTransport enforced: packages/k8s-sandbox/src/exec.ts carried an unbounded buffer behind a TODO(M3) while spec §8 advertised the cap as a seam-level guarantee. The constants moved onto the seam (transport.ts) and the assertion into conformance.ts, so neither transport can regress alone.

    The battery also now asserts the cap stops the producer — client.abort on the gRPC side, child.kill on the kubectl side. That coverage had been deleted as redundant when the cap case moved into the battery, and it was not redundant: with it gone, removing child.kill from exec.ts still passed.

    What this does not establish. There is a third SandboxTransport — persistentExecInPod — it is uncapped, it serves Read/Write/Edit/Ls/Find (extension.ts:53-59), and it is not in the battery. Spec §8, ADR-0024 and transport.ts all claimed a seam-wide guarantee; all three now name the exception. Tracked as #180.

    Manifest-shape vitest

    packages/knative-server/test/worker-deployment.test.ts covers both worker manifests — the third-party copy-and-edit surface and the sed-filled template — and enforces the memory budget that runner.go and the Deployment each described in comments while nothing checked: 2 × effective concurrency × BufferCap ≤ limit, using the concurrency that actually runs rather than only an override. Every assertion was verified to fail against a mutated manifest. The TS↔Go cap coupling is now pinned by a test rather than by prose.

    Live gate — Kind → OCP

    deploy/knative/relay-leaf-smoke.sh: 8/8 on Kind, twice consecutively, and 8/8 on OpenShift (api.rosso1.kubestellar.org, worker image built into that cluster's internal registry — nothing published). Assertions: presence with transport=grpc; the Alpine-vs-RHEL discriminator verified before being relied on; remote Alpine→CLEAR and Red Hat→FLAGGED; presence cleared when the Attach stream closes; a worker disconnect re-leasing a healthy sandbox; the control run on the pod path; the relay removed on teardown.

    Twice on Kind rather than once because the presence assertion was flaky — 3 failures in 5 runs. Cause: a single HGETALL fired immediately after kubectl rollout status, which returns when the pod is merely Running, while registration happens later when the worker dials Attach. The generated worker Deployment has no readinessProbe and shouldn't — its readiness is the Attach stream, which no HTTP/TCP probe can observe. Now a bounded poll.

    The new disconnect assertion carries its limitation inline: with the worker alive a pod also returns FLAGGED for Alpine, so it proves recovery, not routing. That was demonstrated deliberately — commenting out the delete and watching it pass for the wrong reason. The routing proof remains the Alpine/Red Hat pair asserted while the worker is the only lease candidate.

    The three gates the leaf smoke structurally cannot express

    packages/k8s-sandbox/test/live-relay.test.ts (gated on SH_LIVE_RELAY=1) — the leaf's request shape is a grep verdict, so it cannot ask for a sleep, a flood, or a mid-exec kill. Run live against a real relay and a real Go worker, 3/3, each for a checkable reason:

    Case Evidence
    dual-ended timeout rejected timeout:2 in 2009 ms, against a 30 s sleep and a 120 s fallback deadline
    output cap returned 98,323 of 1,000,000 bytes, marker at byte 98,304 = 3×32 KiB against a 2-chunk cap — exactly one chunk of overshoot, confirming the documented asymmetry over real Chunk frames
    worker disconnect rejected worker disconnected 7 ms after SIGKILL, worker built and killed by the test itself

    This is also the only independent check on the hermetic battery, whose fakes are self-authored — a double written from the same misreading of the contract will agree with that misreading.

    Divergences recorded rather than papered over

    Spec §8 gained an "Accepted divergences" section: KubectlTransport applies no default deadline while GrpcRelayTransport always applies 120 s, and the battery cannot see it because its timeout case always passes an explicit timeout (#182); and a bash flood is SIGKILLed but reported to the model as success, because Pi treats a null exit code as non-failing and createPodBashOps discards stdout (#181).

    Fixed along the way

    A truncated read could be written back into a file. Once KubectlTransport gained the cap it became persistentExecInPod's fallback on channel death; readFile discarded exitCode; Pi's Edit is read-whole-file → write-whole-file. So a >8 MiB Edit plus a channel death wrote 8 MiB and the truncation marker back into the source, nondeterministically. readFile now refuses to return content it cannot vouch for.

    Also: req_id uniqueness (#179) — the relay keyed sinks by req_id per sandbox, so a collision detached one caller and interleaved both execs' output, silently.

    Assisted-By: Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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