Repository navigation
Task 6: gated Kind smoke for the leaf-session contract + live-path fixes - #10
Conversation
…Gateway realProduceVerdict used the base pi-ai model directly, ignoring the gateway base URL + Bearer auth that runTurn applies. Against a gateway-backed llm-credentials secret (base-url + auth-token), leaf model calls would hit the wrong endpoint. Extract runTurn's gateway transform into a shared, unit-tested applyModelGateway() helper and use it in both runTurn and runLeaf. Signed-off-by: Paolo Dettori <[email protected]>
Anthropic-compatible gateways (litellm) reject the per-tool extras the direct Anthropic API accepts. Tool-bearing leaf requests failed with 'tools.0.custom.eager_input_streaming: Extra inputs are not permitted' because getAnthropicCompat defaults supportsEagerToolInputStreaming to true for the anthropic provider. When applyModelGateway routes to a gateway baseUrl, disable supportsEagerToolInputStreaming / supportsCacheControlOnTools / supportsLongCacheRetention so convertTools() omits those fields. Verified live: the leaf agent now reads the workspace and submits a valid verdict. Signed-off-by: Paolo Dettori <[email protected]>
…age, scale-to-zero Task 6 of the MVP leaf-session contract. Adds the shared leaf-work PVC, the orchestrator stand-in pod, the /work mount on the harness service, and the gated leaf-smoke.sh driver. setup-kind.sh now enables the Knative persistent-volume feature flags. Verified live on kind sh-knative: MVP spec §7 gates 1-6 all PASS (7/7 checks) — 3 parallel leaves each writing a schema-valid verdict, per-call model routing, structured-output enforcement, idempotent retry, coverage audit, and scale-to-zero. Signed-off-by: Paolo Dettori <[email protected]>
runLeaf registered only submitVerdictExtension, so the agent's read/grep/bash/edit/ write were Pi's native tools and executed inside the credentialed harness pod — violating spec §3 (tools run in the M2/M3 sandbox) and the brain/hands split. Add k8sSandboxExtension() so those tools route into KAGENTI_SANDBOX_POD; the only harness-side tool is submit_verdict. Session cwd is decoupled from workspaceRef (a path inside the sandbox), and buildLeafPrompt now hands the agent the absolute sandbox path to read. Verified live: repo seeded only in sandbox-0, agent produces correct verdicts, nothing executes in the harness pod. Signed-off-by: Paolo Dettori <[email protected]>
Rework leaf-smoke.sh for the brain/hands volume split: inputs/results on the harness /work PVC, the repo seeded ONLY into sandbox-0:/workspace/<run>/repo. Adds Claim 0 (repo present in sandbox, absent on the harness volume) and tightens Claim 2 to require semantically-correct verdicts (i1=FLAGGED, i2/i3=CLEAR) — only achievable by reading the file in the sandbox. Live: 8/8 checks pass on kind. Signed-off-by: Paolo Dettori <[email protected]>
pdettori
left a comment
There was a problem hiding this comment.
Self-review: clean, well-structured PR. The applyModelGateway extraction eliminates real duplication and the brain/hands split (sandbox tool routing) is a meaningful security improvement — agent tools no longer execute in the credentialed harness pod. Shell scripts are solid (set -euo pipefail, jq --arg for safe interpolation, proper gate checks). YAML volume wiring is consistent across all manifests.
Commits: 5, all DCO signed ✓
CI: passing
No must-fix issues. A few suggestions below for future hardening.
| config?: Pick<TurnConfig, "anthropicBaseUrl" | "anthropicAuthToken">, | ||
| ): M { | ||
| const authToken = config?.anthropicAuthToken ?? process.env.ANTHROPIC_AUTH_TOKEN; | ||
| if (authToken && !process.env.ANTHROPIC_API_KEY) { |
There was a problem hiding this comment.
suggestion: ?? process.env.ANTHROPIC_AUTH_TOKEN — the ?? means an explicit empty-string config value suppresses the env-var fallback (unlike ||). If config could ever have "" as a "not set" sentinel, || would be more defensive. Not blocking — just flagging the semantic difference.
There was a problem hiding this comment.
Done in 88e860d — switched authToken/baseUrl resolution from ?? to || so an empty-string config value falls back to the env var. Added a comment marking "" as the not-set sentinel, plus an empty-string-fallback test.
| const authToken = config?.anthropicAuthToken ?? process.env.ANTHROPIC_AUTH_TOKEN; | ||
| if (authToken && !process.env.ANTHROPIC_API_KEY) { | ||
| process.env.ANTHROPIC_API_KEY = authToken; | ||
| } |
There was a problem hiding this comment.
suggestion: This process.env mutation was already in runTurn, but now runs from two call sites (here via runLeaf + the runTurn call below). Consider a brief comment noting this is intentional (Pi SDK reads it at invocation time) so a future reader doesn't "clean it up".
There was a problem hiding this comment.
Done in 88e860d — added a comment marking the ANTHROPIC_API_KEY env mutation as intentional (pi-ai reads it at invocation time) and noting it now runs from both runTurn and runLeaf, so it should not be refactored into a local.
| const m = applyModelGateway(baseModel, { anthropicAuthToken: "tok-only" }) as any; | ||
| expect(m.compat).toBeUndefined(); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
suggestion: Consider an additional edge case — applyModelGateway(baseModel, { anthropicBaseUrl: "https://gw" }) with no token. This validates the "public gateway" path (baseUrl applied, no Authorization header set, compat flags still disabled).
There was a problem hiding this comment.
Done in 88e860d — added the token-less public-gateway case (baseUrl applied, compat disabled, no Authorization header, original headers untouched). Suite now 8 tests.
| # It is long-lived so it pins the WaitForFirstConsumer PVC to the node. | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: |
There was a problem hiding this comment.
nit: alpine:3.20 not pinned to a digest — fine for a local smoke test, but worth a comment if this ever gets promoted beyond Kind.
There was a problem hiding this comment.
Done in 88e860d — added a comment noting alpine:3.20 is a tag (fine for the local Kind smoke) and to pin a digest if this is ever promoted beyond Kind.
… docs - applyModelGateway: use || (not ??) for authToken/baseUrl so an empty-string config value falls back to env instead of suppressing it. - Comment the intentional ANTHROPIC_API_KEY env mutation (read by pi-ai at invocation time; now called from runTurn and runLeaf) so it is not refactored away. - Add token-less public-gateway and empty-string-fallback test cases (8 total). - Note the unpinned alpine:3.20 orchestrator image (pin to a digest if promoted beyond Kind). Signed-off-by: Paolo Dettori <[email protected]>
…state it Review suggestion on f206e8b (clawgenti, turn-handlers.test.ts:109), and it is right: the coupling test passed `newId: () => randomUUID()` itself, so it restated the production wiring rather than exercising it. Switch main.ts:523 to nanoid, ulid or a prefixed id and that test still passes while every real claim 400s -- the dead-letter failure its own comment describes, and a direct contradiction of "the only test that fails when it breaks". The production id factory is now one exported binding, `defaultNewId` in handler-util.ts, following `defaultAuditLog` and `defaultRunKubectl` -- the shape this repo already uses for a production default of an injectable CpDeps field. `depsFromEnv` wires it (the only production CpDeps producer; grepped `packages` and `harness` for another `newId:`), and the three tests that depend on the id's SHAPE inject the same binding instead of rebuilding it: turn-handlers (the coupling test), turn-e2e (claims every turn it submits), and turn-record (`accepts exactly what submitTurn mints`). handler-util.ts rather than beside MINTED_TURN_ID_RE, because `newId` has three shape-dependent consumers and only one is turns: session ids are their own leafSessionId sanitisation (gap rossoctl#10), and `sandboxId` needs 26 random hex and refuses a shorter source. Naming it `newTurnUuid` in turn-record.ts would have put the session and sandbox contract inside the turn module. Verified by mutation: `defaultNewId` -> `nid-${randomUUID()}` fails 8 tests -- the coupling test, all six turn-e2e tests, and the turn-record unit test. Before this commit the same mutation left every one of them green, which is exactly the gap the suggestion identified. Control-plane suite: 1158 passed, 3 skipped against real Redis, no Errors. tsc and prettier clean. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: cwiklik <[email protected]>
Summary
Completes Task 6 of the MVP leaf-session invocation contract — the gated Kind smoke proving the harness can serve as a leaf-session backend for an external orchestrator — and closes the deferred live verifications from the plan (
realProduceVerdictwiring, per-call model boundary, and sandbox tool execution).Plan:
docs/superpowers/plans/2026-06-26-mvp-leaf-session-contract.md· Spec:docs/specs/2026-06-26-mvp-leaf-session-contract-design.mdWhat's here
Task 6 artifacts
deploy/knative/leaf-pvc.yaml— sharedleaf-workPVC (RWO; single-node Kind) for inputs/results.deploy/knative/leaf-orchestrator.yaml— orchestrator stand-in pod mounting/work(also pins theWaitForFirstConsumerPVC).deploy/knative/service.yaml—/workPVC mount on the harness service.deploy/knative/leaf-smoke.sh— gated (LEAF_LIVE_SMOKE=1) driver covering the §7 gates plus a workspace-isolation gate.deploy/knative/setup-kind.sh— enables the two Knative persistent-volume feature flags so the prereq is reproducible.Live-path / correctness fixes (the deferred verifications)
fix(harness): apply LLM gateway auth in runLeaf—realProduceVerdictignored the gateway base URL + Bearer authrunTurnapplies; extracted a shared, unit-testedapplyModelGateway()helper used by both.fix(harness): disable gateway-incompatible tool compat flags— tool-bearing requests 400'd on the litellm gateway (tools.0.custom.eager_input_streaming: Extra inputs are not permitted).applyModelGatewaynow disablessupportsEagerToolInputStreaming/supportsCacheControlOnTools/supportsLongCacheRetentionwhen routing to a gateway. Also hardensrunTurn.fix(harness): route leaf agent tools through the sandbox pod— the merged Task 3runLeafregistered onlysubmitVerdictExtension, so the agent'sread/grep/bash/edit/writewere Pi's native tools and ran inside the credentialed harness pod — violating spec §3 and the brain/hands split. Addedk8sSandboxExtension()so those tools route intoKAGENTI_SANDBOX_POD;submit_verdictis the only harness-side tool. Session cwd is decoupled fromworkspaceRef(a path inside the sandbox), andbuildLeafPrompthands the agent the absolute sandbox path.Volume model (spec §5, brain/hands split)
inputs_ref/result_ref→ harness-mounted/workPVC (trusted NodefsI/O the harness performs).workspace_ref(the repo) → only insandbox-0at/workspace/<run>/repo; the agent reads it via the sandbox tools. The repo is never placed on/work, so a correct verdict is only possible if the agent read the file in the sandbox.Verification — MVP spec §7, live on Kind
sh-knativeLEAF_LIVE_SMOKE=1 bash deploy/knative/leaf-smoke.sh→ 8/8 checks pass, 0 fail:sandbox-0, absent on the harness/workvolumedone; scaled out to 3 concurrent podsfailed, valid →donefailed, no invalidresult_refwrittenGate 7 (resume via M5 checkpoint) is the documented stretch — not separately built here.
Unit tests: full harness suite green (51 passed, 2 live-gated skipped), including new
applyModelGatewaycoverage.Assisted-By: Claude Code