Repository navigation
Fix: let the extension take its two transport tiers separately (#245) - #606
Conversation
`k8sSandboxExtension` runs a two-tier transport on purpose: `fastTransport` (`persistentExecInPod`, ONE long-lived nonce-framed bash) for the small request/response ops, and `streamTransport` (per-call exec) for the ops that need onData/abort. But `opts.transport` overrode BOTH, and `run-leaf.ts` passes exactly that for a leased gRPC record -- so on the gRPC path the fast tier silently did not exist and every read/write/edit/ls/find became a full `SandboxExec.Exec` round trip ending in a fresh `bash -c`, where the kubectl path spent one framed line on an already-running bash. Nothing above the seam could see that difference, let alone choose it. So: - `fastTransport?` / `streamTransport?` on the extension, each resolved through the same three steps -- own override, then the `transport` both-tiers shorthand, then the tier's default. The specific knob wins over the shorthand, or it would be unreachable for every existing caller. - `fastTier` is REQUIRED on `SandboxTransport`, for the reason `ExecResult.truncated` is: optional, a fourth transport omits it and reads as a safe-looking default, which is how this divergence existed unrecorded. - Each transport declares its own tier, and the conformance battery pins the claim against what a caller reads -- the discipline `producerStop` uses, so a fourth transport cannot ship without choosing one. The capacity latch FORWARDS the value rather than asserting one, since it wraps both tiers. - `session_shutdown` now closes BOTH tiers. Closing the fast one was sufficient while the stream tier was the same object or a no-op KubectlTransport; a `streamTransport` that owns something (a GrpcRelayTransport owns its gRPC channel) would have leaked once per session. Guarded on the PRE-WRAP identity because the latch's `watch` allocates a fresh wrapper per call, so post-wrap the two are never identical even under the shorthand. No behavioural change at `run-leaf.ts`, deliberately: naming only `streamTransport` there would let the fast tier fall through to `persistentExecInPod`, which spawns a LOCAL `kubectl exec` -- and a leased pool sandbox is reached over the relay, with no pod this process can exec into. The shorthand stays until a transport that can amortize over the relay exists. What changed is that the fact is now readable rather than implicit. Two of the issue's acceptance items are not delivered, because they are not buildable as specified. A `docker exec`/`podman exec` persistent channel is not a parameterized argv over `persistent-exec.ts`: the harness runs as `User=harness` and nothing in `setup-vm.sh` or the systemd units grants it a container-runtime socket; on the gRPC path the harness need not share a host with the sandbox at all (ADR-0024 has it dialling out over one :443 connection); and on the microVM tier it is meaningless by construction, since a fresh VM serves each tool call. The relay-mediated channel the issue names as "the larger alternative" is the only viable one, and it needs a `sandbox.proto` change -- `rpc Exec` is one command per RPC, with no long-lived shell on the wire. The before/after latency measurement has nothing to measure until that exists. Refs rossoctl#245 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: cwiklik <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Looks good. The per-tier resolution order, the required fastTier on the seam (with the latch forwarding it), and the pre-wrap identity guard for the shutdown close are all sound, and the tests pin each of them. I checked that every production caller of k8sSandboxExtension still uses the shorthand or the defaults, so routing is unchanged, and that each non-test SandboxTransport constructor now declares a tier. Keeping the shorthand at run-leaf.ts is the right call while there is no kubectl path to a leased relay sandbox.
One small suggestion inline about closing the two tiers independently.
| // one object on every existing caller and closing it twice there is pointless work on | ||
| // a path that runs for every session. | ||
| pi.on('session_shutdown', async () => { | ||
| await fastTransport.close(); |
There was a problem hiding this comment.
suggestion: If fastTransport.close() rejects, the stream tier is never closed, which is the leak this hunk was added to prevent. Consider closing each tier independently:
pi.on(session_shutdown, async () => {
try {
await fastTransport.close();
} finally {
if (streamBase !== fastBase) await streamTransport.close();
}
});#245's remaining acceptance item: "a test pins fast-tier availability per transport, so a fourth transport cannot silently ship without one -- the same discipline transport.ts applies to `truncated`." PR #606 landed the two-tier split and the required `SandboxTransport.fastTier` field; the discipline it claimed was only half in place. Two holes, each proven by mutation first. 1. The latch wrapper could answer for what it wraps. conformance.ts said it pinned that "a wrapper (the capacity latch wraps BOTH tiers) cannot quietly answer for the thing it wraps", but the only assertion read the UNWRAPPED object. Hardcoding `fastTier: 'persistent-channel'` in capacity-latch.ts passed all 181 tests. That wrapper is what `extension.ts` hands every tool on a harness turn, so the value a caller actually reads was unasserted. The battery now asserts it through `createCapacityLatch().watch()` as well -- placed in the battery, not in capacity-latch's own tests, because forwarding must hold for whichever transport is latched and this is the only list of all of them. 2. Enrolment itself was unpinned. A required field makes OMITTING the claim a compile error, not DECLARING one and never being held to the battery -- type-correct and unasserted, which is the state this divergence was already in. A fourth transport declaring `persistent-channel` with no conformance file passed everything. fast-tier-coverage.test.ts pins the declaration sites against the enrolments, in the loud-throw source-reading idiom output-cap-coupling.test.ts uses for the Go constants: the correspondence is N declarations against N enrolments, which no type expresses. Its second case guards the guard -- with the battery's assertions deleted, TransportCapabilities.fastTier would become a field every factory fills in and nothing reads. Mutations, all killed; M1 survived before this change: M1 latch hardcodes a tier instead of forwarding 3 tests fail M2 KubectlTransport claims 'persistent-channel' 2 fail M3 battery drops the raw-transport assertion 1 fail M4 battery drops the through-the-latch assertion 1 fail M5 fourth transport declares a tier, never enrols 1 fail, naming it M6 fastTier renamed across src/ loud-throws The reader anchors on the ENCLOSING `export function`, not the file's first: both transport files open with an argv builder, so taking the first export would name a helper no conformance file imports and report a failure that is the reader's own -- worse than no test, since it trains the next person to edit the expectation. Two comments corrected rather than left overclaiming: capacity-latch.ts no longer says the forwarding is "never asserted", and FastTier's doc states that the discipline takes two tests and why each covers only half. Acceptance items 1 and 2 were already satisfied (#606, and 934b613 enrolling persistentExecInPod with `producer-side-cap`). Item 4, measured per-file-op latency before/after on the gRPC path, has no "after" to measure: `rpc Exec` is one command per RPC, so that path still has no fast tier by design (run-leaf.ts:1040-1048 documents why splitting the tiers there would be worse). What changed is that the fact is now readable off the seam. Spec: the transport design's wire-semantics section gains a per-transport fast-tier bullet and table mirroring the existing `producerStop` one, and the test-layer table's Conformance row is corrected from "both" to all three. Fixes #245 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: cwiklik <[email protected]>
Summary
k8sSandboxExtensionruns a two-tier transport on purpose:fastTransport(persistentExecInPod, ONE long-lived nonce-framed bash) for the small request/response ops, andstreamTransport(per-call exec) for the ops that needonData/abort. Butopts.transportoverrode both, andrun-leaf.ts:989passes exactly that for a leased gRPC record — so on the gRPC path the fast tier silently did not exist, and everyread/write/edit/ls/findbecame a fullSandboxExec.Execround trip ending in a freshbash -c, where the kubectl path spent one framed line on an already-running bash.Nothing above the seam could see that difference, let alone choose it. Refs #245.
What changed
fastTransport?/streamTransport?on the extension, each resolved through the same three steps — own override, then thetransportboth-tiers shorthand, then the tier's default. The specific knob wins over the shorthand, or it would be unreachable for every existing caller (all of them settransport).fastTieris REQUIRED onSandboxTransport, for the reasonExecResult.truncatedis: optional, a fourth transport omits it, reads as a safe-looking default — which is exactly how this divergence existed unrecorded. Making it required means the compiler enumerates every place a transport is constructed.producerStopuses: every implementation makes a positive claim, so a fourth cannot ship without choosing one. The battery deliberately does not try to measure cost — that is a claim about N ops, and a scripted fake's process count is the factory's fiction, not the transport's behaviour.fastTierrather than asserting one. It wraps both tiers, so a hardcoded value would make every latched transport claim the same tier and contradict the thing it wraps.session_shutdownnow closes BOTH tiers. Closing the fast one was sufficient while the stream tier was either the same object or a no-opKubectlTransport; astreamTransportthat owns something — aGrpcRelayTransportowns its gRPC channel — would have leaked once per session.Two things worth flagging
No behavioural change at
run-leaf.ts, deliberately. This is the call site the issue names, but naming onlystreamTransportthere would let the fast tier fall through to its default,persistentExecInPod, which spawns a localkubectl exec. A leased pool sandbox is reached over the relay (ADR-0024 has it dialling out over one:443connection, possibly from another cloud) — there is no kubectl path to it and no pod this process can exec into. The shorthand stays until a transport that can amortize over the relay exists. What changed is that the fact is now readable:selected.transport.fastTiersays'per-call-exec'out loud.Two of the four acceptance items are not delivered, because they are not buildable as specified. A
docker exec/podman execpersistent channel is not a parameterized argv overpersistent-exec.ts, for three independent reasons: (a) the harness runs asUser=harnessand nothing insetup-vm.shor the three systemd units grants it a container-runtime socket — nopodman.sock, noSupplementaryGroups, nousermod -aG; (b) on the gRPC path the harness need not share a host with the sandbox at all; (c) on the microVM tier it is meaningless by construction, since #274 gives a fresh VM per tool call. The relay-mediated channel the issue names as "the larger alternative" is in fact the only viable one, and it needs asandbox.protochange —rpc Execis one command per RPC, with no long-lived shell concept on the wire. The before/after latency measurement has nothing to measure until that exists. ADR-0041 sharpens this: it deprecatesKubectlTransportand pod-exec sandboxes, so the transports that have a fast tier are the deprecated ones.Tests
4 new extension tests — tier routing (fast ops reach the fast tier,
bashnever touches it), override precedence over the shorthand, both-tiers close, and single-close under a latch. Plus one conformance case per transport.That last test exists because of a bug in my own first fix: I guarded the double-close on post-wrap identity, but the latch's
watchallocates a fresh wrapper per call, so with a latch supplied the two tiers are never identical even under the shorthand — every latched session would have double-closed. The guard is now on the pre-wrap bases.Counts are not asserted for
ls, which legitimately issues more than one exec (existence probe, then listing) — that is the tool's business. What must hold is that every one went to the fast tier and none leaked.Verification
Rebased onto current
main(7a5fc3ae); the working diff came back byte-identical, andmocactlwent 1462 → 1476 tests picking up #594.pnpm -r typecheckpnpm -r test(+ the 4 packages-rbails before reaching)prettier --check .k8s-sandboxsuiteNo
.goor.protofiles touched, somake lint/gofmt/bufare unaffected.The one failure is
harness/test/context-overlay.test.ts, macOS-only: the test doeschmod -R a-wthenmv, which Linux permits and Darwin refuses. Reproduced identically on the base commit with this work stashed, so it is not from this change and will not fire on CI's Linux runners.Checklist
git commit -s).make lintand the tests for the touched packages pass.make check-links— n/a, no Markdown changed.Assisted-By: Claude