II.
Page overview
Reference · livepage:docs-adr-execution-substrate
ADR: ExecutionSubstrate port, Kubernetes Job default overview
Inspect the raw attributes, linked wiki pages, and inbound or outbound graph edges for page:docs-adr-execution-substrate.
Attributes
nodeKind
Page
sourcePath
docs/adr/execution-substrate.md
sourceKind
repo-docs
title
ADR: ExecutionSubstrate port, Kubernetes Job default
displayName
ADR: ExecutionSubstrate port, Kubernetes Job default
slug
docs/adr/execution-substrate
articlePath
wiki/docs/adr/execution-substrate.md
article
# ADR: ExecutionSubstrate port, Kubernetes Job default
- **Status:** accepted (spec 60 WP-AX-01, run C2)
- **Decision records:** spec 60 C-13h (AX parity rule, gated per area), C-13l (#38 fix-forward), §7.2 (port), §17 G-01/G-02
- **Issues:** a5c-ai/fabric#39 (cancel does not kill the Job), a5c-ai/fabric#38 (callback authentication, shipped separately as the C1 fix-forward)
## Context
The control plane (`@fabricstack/control-plane`) starts every agent run as a Kubernetes `batch/v1` Job. Job creation, status, logs and deletion were methods on the adapters client (`packages/kradle/core/src/adapters-client.js`), called from the dispatch controller. Three problems followed:
1. **Cancel never killed the workload.** The cancel route only patched the run's status to `Cancelled` (a5c-ai/fabric#39). The Job kept running, consumed its budget and could still call back.
2. **The Job status, logs and delete calls addressed the wrong kind.** They asked the resource gateway for `Job`. In the control plane's resource table, `Job` is the aggregated CI kind (`jobs.kradle.a5c.ai`). So `deleteJob` never reached the agent's `jobs.batch` object, and `getJobStatus` read an envelope instead of the Job, so it always reported zeros.
3. **There was no seam for a second substrate.** The AX spike (`docs/specs/platform-gaps/research/ax-kradle-spike.md` §3.2) asks for a port first, so the execution sandbox can move to AX per area once the parity gates close (C-13h).
## Decision
1. **Port.** `packages/kradle/core/src/execution-substrate/` defines `ExecutionSubstrate { render, create, get, watch, suspend, resume, delete }`:
- `render` describes the workload without starting it.
- `create` starts it.
- `get` reports a substrate-neutral state (`Absent`, `Pending`, `Running`, `Succeeded`, `Failed` or `Suspended`) and, on request, the logs.
- `delete` tears the workload down and is idempotent.
`render` is a seventh verb, added to the six of spec 60 §7.2. Dispatch records the workload reference on the run, and persists the run, before the workload exists.
2. **Kubernetes Job default.** `k8s-job` is the only implementation. It wraps the adapters client's `createAgentJob`, `submitAgentJob`, `getJobStatus`, `getJobLogs` and `deleteJob`. It does not support suspend or resume (AX parity row 12; pause/resume is WP-FN-14). It refuses a reference outside the namespace its gateway addresses.
3. **Selection.** `FABRIC_EXEC_SUBSTRATE_DEFAULT` selects the substrate. Unset means `k8s-job`. An unknown value is refused when `control-plane-server` starts, and when a dispatch controller or cancel builds the substrate.
4. **The agent Job is `batch/v1`.** The resource table carries `BatchJob` (`jobs.batch`, core storage, outside snapshots). The adapters client's Job calls use it.
5. **Cancel kills.** `cancelAgentDispatchRun` (`agent-run-cancel.js`) runs in this order:
- It refuses a run that is already `Cancelled`, `Completed` or `Failed` with 409 and changes nothing.
- It writes `Cancelled` as a compare-and-swap from the `resourceVersion` it read. On `Conflict` it re-reads, and a terminal phase written meanwhile wins.
- Only then does it delete the workload through the port. The Job's pods go with it by background cascade.
A failed delete leaves `teardown: pending`. The controllers' reconcile pass (`reconcileCancelledRunWorkloadsPass`, `KRADLE_RUN_WORKLOAD_RECONCILE_INTERVAL_MS`, chart `controllers.runWorkloadReconcileIntervalMs`, default 30 s) deletes the Job of any `Cancelled` run that still has one.
6. **Architecture rule.** `scripts/lib/execution-substrate-boundary.cjs`, run by the architecture boundary gate, rejects a Job create, status, logs or delete call, or a use of the `batch/v1` Job resource key, outside `execution-substrate/` and the two defining modules.
7. **Parity data.** `docs/specs/platform-gaps/roadmap/ax-parity.json` holds the 39 rows of the spike's §3 as data. It validates against `ax-parity.schema.json`, and the C10 and C12 re-audits (WP-AX-06) read it.
## Consequences
- An AX backend (WP-AX-02) adds one case to `createExecutionSubstrate` and one value to `KNOWN_EXECUTION_SUBSTRATES`. Callers do not change.
- The cancel compare-and-swap relies on `patchResourceStatusForOrg(..., { resourceVersion })` raising `code: 'Conflict'` on a stale write. That contract ships with the #38 fix-forward (a5c-ai/fabric#41). Until it merges, the status write is unconditional and the terminal guard is a read-then-write check.
- A Job's pods are removed by the Kubernetes garbage collector after the Job is deleted (background propagation). The deployed flow FL-AX-10 asserts that both are gone within the reconcile interval.
documents
[]
Outgoing edges
None.
Incoming edges
contains_page1
- page:docs·PageBabysitter Docs