# Autonomous Supervisor Governance This document defines the runtime governance contract for AFK runs that must progress with minimal human attention. It is deliberately model-neutral: configuration maps responsibilities to endpoints and models; workflow policy never names a provider. ## Authority and recovery The per-run JSONL event stream is the authoritative record. Mutable plan views, counters, status displays, and snapshots are disposable projections. $$ \text{run state} = \operatorname{fold}(\text{valid snapshot}, \text{ordered events}) $$ An event is appended and flushed before its projection is written. A crash after append can only leave a stale projection, which is rebuilt from the log. A crash can leave one torn trailing record; recovery may discard only that incomplete final record before the next append. It must never alter a complete event to reconcile a projection. Each event has a schema version, unique identifier, and monotonically assigned sequence number. Projection application is idempotent by event identifier. An invalid snapshot, a cursor beyond the log, or a missing projection rebuilds from the log. External side effects use separate `effect_intended` and `effect_completed` events keyed by an idempotency key; replay alone never repeats the side effect. ## Counters and retries Worker attempts, mechanical repairs, supervisor decisions, strong-model calls, and human escalations are separate bounded counters. A mechanical recovery consumes only its own budget and returns to deterministic review once. Semantic recovery requires an explicit supervisor decision. No counter is inferred from console text or reset by replay. ## Environment contract Before a worker starts, AFK resolves and fingerprints both the runner and target environment: interpreter path/version, project root, dependency lock or installed-package fingerprint, and validation commands. Runner and target are independent contracts and may legitimately use different interpreter paths, versions, prefixes, and installed packages. There is no ambient interpreter fallback. A missing or unprobeable interpreter blocks immediately; drift from the previously accepted target fingerprint blocks until an explicit repair decision resolves it. Normal plan execution, campaign queue and best-of-N dispatch, and manual retry all call the same preflight boundary. Environment events therefore have the same shape and ordering regardless of which public execution path reached the worker. ## Filesystem hygiene Task ownership is explicit. Files outside a task's declared/observed ownership are not silently deleted. A deterministic hygiene step may move a scoped, hashed set of proven scratch artifacts to quarantine, recording intent and result events. It triggers at most one mechanical re-review; anything remaining is escalated with the artifact hashes and paths. ## Supervisor decisions The supervisor is a routable runtime responsibility, not a synonym for a human operator or a mutable-plan helper. It can only issue typed, pre-validated decisions: bounded retry/repair, environment repair, scoped quarantine, accept/reject a foreman decomposition, replace a task, or escalate to a human. Every decision records inputs, budget impact, validation outcome, and result as events before changing the projection. Foreman children inherit the parent contract, relevant budgets, and a depth limit. Approval requires aggregate exact parent-contract coverage: every item has one owner, while a staged preparatory child may own no item and declare dependencies on earlier siblings. Parent completion requires passing child work and deterministic coherence evidence; human product acceptance remains separate. Deterministic failures carry stable fingerprints over failure kind, diagnostic detail, evidence identity, and relevant file hashes. Automatic execution escalates an unchanged fingerprint as `repeated_failure`; changed evidence remains eligible for bounded recovery. Reviewer display is bounded, but full command output and metadata are retained as per-attempt artifacts outside the target repository. ## Human and vision boundaries Deterministic validation can establish contract conformance. A human alone accepts subjective product qualities such as fidelity, playability, and listening quality. An optional vision route may read only a declared artifact manifest and write factual observations. It cannot accept work, change budgets, or issue supervisor decisions. ## First implementation slice Implemented slices provide the durable event store and pure replay projector, strict environment resolution, scoped scratch quarantine, and deterministic supervisor decomposition approval. Reviewer and typed verification Python commands run through the preflight-resolved target interpreter. The complete environment contract is retained in governance events; a changed target fingerprint on a subsequent run blocks with `environment_drift`. A human can approve one currently verified change with `afk approve-environment-repair --reason ...`; the approval is durable, fingerprint-scoped, and does not guess or repair an environment itself. Existing coarse scheduler events are mirrored into the authoritative log as `run_event_recorded` records. The projection derives terminal task status, the latest task event, and attempt summaries without changing existing terminal output. Future status views can read this projection rather than infer only from the mutable plan. Pending quarantine intents are reconciled at the beginning of a verified run only when the source is absent and the destination is present with the recorded SHA-256. Ambiguous pending states stay visible and untouched: reconciliation never retries a copy or deletes a remaining source file. The status projection separately counts worker attempts, mechanical repairs, supervisor decisions, high-reasoning model calls, and escalations requiring human attention. These are derived from typed event fields and cannot reset merely because a projection is rebuilt. Tasks may declare a product-validation checkpoint for subjective requirements such as fidelity, playability, or listening quality. After deterministic checks and merge succeed, the task blocks until a human runs `afk attest-product-validation --observation ...`. The attestation records the observation and hashes of its declared project artifacts; no model or vision observer can substitute for this human acceptance. `afk observe-product-artifacts ` provides an optional manifest-bounded factual observer. It reads only the task's declared artifacts and records hashes, byte counts, media types, and currently PNG/GIF dimensions. Observation is read-only and cannot modify work, approve a task, attest product quality, or spend any recovery budget. The read-only status view renders pending human checkpoint instructions, artifact manifests, and the exact attestation command. Attested checkpoints show the recorded human observation; this is operational guidance only and never turns the watch view into a mutation surface. `afk friction-report ` derives a read-only operational summary from the governance log: event volume, separated counters, pending effects, environment rejection, and tasks awaiting human product validation. It identifies attention hotspots without adding an LLM interpretation layer. When a `supervisor` route is configured, it may propose only `approve_decomposition` or `escalate` for a pending foreman proposal. Invalid/unavailable proposals fall back to trusted deterministic validation. A model-proposed approval still passes the exact contract-coverage and budget checks before it can be recorded and applied; a model cannot mutate a plan directly.