II.
Page JSON
Structured · livepage:docs-adr-execution-substrate
ADR: ExecutionSubstrate port, Kubernetes Job default json
Inspect the normalized record payload exactly as the atlas UI reads it.
{
"id": "page:docs-adr-execution-substrate",
"_kind": "Page",
"_file": "wiki/docs/adr/execution-substrate.md",
"_cluster": "wiki",
"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": "\n# ADR: ExecutionSubstrate port, Kubernetes Job default\n\n- **Status:** accepted (spec 60 WP-AX-01, run C2)\n- **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\n- **Issues:** a5c-ai/fabric#39 (cancel does not kill the Job), a5c-ai/fabric#38 (callback authentication, shipped separately as the C1 fix-forward)\n\n## Context\n\nThe 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:\n\n1. **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.\n2. **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.\n3. **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).\n\n## Decision\n\n1. **Port.** `packages/kradle/core/src/execution-substrate/` defines `ExecutionSubstrate { render, create, get, watch, suspend, resume, delete }`:\n - `render` describes the workload without starting it.\n - `create` starts it.\n - `get` reports a substrate-neutral state (`Absent`, `Pending`, `Running`, `Succeeded`, `Failed` or `Suspended`) and, on request, the logs.\n - `delete` tears the workload down and is idempotent.\n\n `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.\n2. **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.\n3. **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.\n4. **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.\n5. **Cancel kills.** `cancelAgentDispatchRun` (`agent-run-cancel.js`) runs in this order:\n - It refuses a run that is already `Cancelled`, `Completed` or `Failed` with 409 and changes nothing.\n - 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.\n - Only then does it delete the workload through the port. The Job's pods go with it by background cascade.\n\n 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.\n6. **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.\n7. **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.\n\n## Consequences\n\n- An AX backend (WP-AX-02) adds one case to `createExecutionSubstrate` and one value to `KNOWN_EXECUTION_SUBSTRATES`. Callers do not change.\n- 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.\n- 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.\n",
"documents": []
},
"outgoingEdges": [],
"incomingEdges": [
{
"from": "page:docs",
"to": "page:docs-adr-execution-substrate",
"kind": "contains_page"
}
]
}