# Evidence, Acceptance, and Bounded Recovery This guide describes the opt-in workflow for corpus-backed and other high-risk work. It complements, rather than replaces, the existing [reliability and baseline lint plan](reliability-and-baseline-lint-plan.md). ## Defaults and compatibility - Normal tasks retain `acceptance_profile: none`; they do not invoke a researcher or independent validator. - `recovery.mode` defaults to `off`. No automatic repair or evidence-research follow-up occurs until a new plan snapshots `mode: bounded`. - Existing saved plans load with safe defaults for missing acceptance, evidence, attempt, context, and recovery fields. They keep their persisted recovery policy even when the user configuration later changes. - The retired string verifier remains only as a strict compatibility shim. New agent tools submit typed verification requests; arbitrary shell strings, writes, path escape, and writable formatting are rejected. ## Configure roles and recovery before planning Use the supplied [configuration example](../config.example.yml) as the starting point. A typical profile uses a normal coder route and a read-only Terra/high route for evidence research and acceptance validation: ```yaml roles: coder: { endpoint: copilot, model: gpt-5.6-luna, reasoning_effort: medium } researcher: { endpoint: copilot, model: gpt-5.6-terra, reasoning_effort: high } validator: { endpoint: copilot, model: gpt-5.6-terra, reasoning_effort: high } recovery: mode: bounded semantic_repair_limit: 1 research_supplement_limit: 1 high_reasoning_repair_limit: 1 xhigh_requires_explicit_enable: true ``` AFK snapshots these recovery limits into a new plan. Automatic semantic repair uses the coder model with `high` reasoning effort, never selecting `xhigh`. ## Human-owned profile and evidence setup 1. Create a plan without executing it and review its task IDs. 2. Attach a profile to the specific high-risk task before that task starts. 3. Supply external canonical evidence roots that a human approves. 4. Resume the plan. ```bash afk grillme -d /path/to/project -g "Generate a corpus-backed file" --plan-only afk acceptance-profile project-name --task-id exporter \ --profile corpus_raw_output --evidence-root /path/to/canonical-corpus afk resume project-name --auto-resume ``` The command canonicalizes roots and rejects roots inside the target project. It does not allow the model to select a profile, add a root, or change either after a selected task has begun. A human may correct a profile only when an acceptance preflight stopped before an agent call or declared file change; AFK resets that no-mutation task to pending before it can resume. An agent attempt, a declared file change, or any other failure keeps the profile immutable. An explicit read-only task may use `--profile none --evidence-root ...` to inspect approved external sources without claiming an acceptance profile. AFK also permits a human to add roots after that task escalates solely with `research_insufficient`, provided it made no file changes and had no roots previously. Mutating `none`-profile tasks cannot receive evidence roots. Only `none` and `corpus_raw_output` are enabled today. Registered API, migration, security, and deployment profile names intentionally fail closed until AFK owns a trusted validator for each profile. ## Evidence packets and acceptance For `corpus_raw_output`, a task must receive an immutable evidence packet before the coder can run. When bounded recovery is enabled, AFK asks the read-only researcher for one structured proposal and trusted code validates and serializes it to: ```text ~/.afk-developer/projects//evidence//revision-.json ``` Each packet records approved roots, source-relative paths, literal markers and occurrences, source hashes, bounded excerpts, observed rules, exclusions, raw-output contracts, researcher route/effort, and a fingerprint. Trusted code rejects traversal, missing markers, stale/tampered sources, metadata-only supplements, repeated packets, and invalid contracts. The coder receives only the task contract, selected durable project guidance, completed dependencies, the relevant packet summary, concise review failure, validator findings, and recovery state. It does not receive `last-plan`, all permanent memories, or fading conversation history. Each attempt records its context source IDs, character count, and token estimate. After deterministic review, AFK first performs the trusted raw-output check and then calls the independent validator. For every declared contract, the generated file must match the source-backed bytes exactly. A passing coder-authored test suite alone cannot satisfy this acceptance rule. ## Branches, findings, and recovery Any profiled mutating task requires a clean Git worktree and an AFK-created task branch. If this preflight fails, AFK does not modify the target and does not claim pre-merge validation. On a validator failure, AFK retains the branch and blocks merge. With bounded recovery, the only automatic next actions are: | Condition | One permitted follow-up | |---|---| | New validator finding fingerprint | Coder semantic repair at high reasoning effort | | Missing acceptance evidence | Read-only researcher supplement with a new verified source excerpt | | Repeated fingerprint/evidence, exhausted budget, provider/verifier/tool failure | Escalate for a human | Provider, policy, and verification-tool failures are runner infrastructure failures. They do not consume coder or researcher recovery budget. `afk retry ` displays the manual recovery candidate. A missing-evidence retry runs the researcher before re-invoking the coder. When a bounded automatic budget is exhausted, retry requires `--force-recovery` so the human explicitly accepts the extra attempt. Inspect the retained task branch, findings, and evidence packet before forcing recovery. ## Baseline and state operations Strict lint is the default. For intentional brownfield debt, explicitly create a Ruff baseline before the run, then select baseline mode for that plan: ```bash afk lint-baseline project-name --project-dir /path/to/project afk grillme -d /path/to/project -g "Targeted maintenance" --lint-mode baseline ``` AFK never refreshes an existing baseline during `resume`. If it is absent or incompatible, resume stops with an actionable error. The July auto-resume incident showed why state operations must be bounded. `--auto-resume` stops on an escalation, no runnable tasks, no state progress, or its configured pass cap. Use `afk maintain-state ` only when no other AFK process is active; it prunes duplicate runner state, retains the configured newest session records, and compacts the inactive Cortex database. ## Operator checklist 1. Keep normal work on the default `none` acceptance profile. 2. For corpus work, start from a clean Git worktree and configure external evidence before the task starts. 3. Enable bounded recovery before creating the plan only when one automatic supplement/semantic repair is acceptable. 4. Treat an escalated task as a human review point, not an automatic loop. 5. Before a forced retry, inspect the retained branch, finding fingerprint, evidence revision, and the report's route/usage/context information.