# Goals, steering and completion

What zelk does between "the model ended its turn" and "the run ended".
Everything here folds from the log: counters, evidence
and reports survive crashes and replay to the same decisions.

## Goals

- Every run has a goal. By default it is the request that began the run; each
  new request is a new **revision**.
- `SetGoal(text)` (≤ 4,000 characters) sets an explicit goal that survives new
  requests and compaction (the summary restates it). `ClearGoal(false)` reverts
  to the request; `ClearGoal(true)` abandons the goal: the completion check no
  longer applies and the report says `not_met`. Only the host sends these; the
  model has no tool for them.
- Changing or reverting a goal while a model call is in flight invalidates
  that turn's report. A normal ending already proposed for the previous revision
  is discarded; another model turn sees the new revision first. Hard limits and
  interrupts still terminate the run.

## Steering

`Steer(run, text)` adds input to the run that began at `run` (the `RunID` the
host saw). If that run is still going, the text joins its next model turn and
the run can't finish before a model turn has seen it. If the run has ended, or
is ending, the steer is rejected. Either way a `SteerOutcome` record follows the
acceptance, so steering never silently lands in another run. A steer pending
when a run is forced to end (budget, turns, interruption) starts the next run.

## Verification evidence

The `Verify` tool runs a check with the Bash tool's shell and records
`EvidenceRecorded`: command, exit status, whether it completed, the bounded
tail of its output and the **mutation generation** it ran at. The model
supplies none of it.

- Host checks come from `WithVerify(Check{Name, Command}...)` (`-verify
  NAME=COMMAND` in the CLIs) and run by name;
  their command is fixed. The model may register its own by giving a new name
  and a command; the report labels it `model`. That command
  is decided as the `Bash` command it is ([permissions](/internals/permissions/)), so
  a check can't run what the session would refuse the shell.
- A model command that hides its own failure is refused, never evidence:
  `|| true`, a trailing `exit 0`/`true`, `set +e`, `/dev/null` with an ignored
  status, `echo`-only commands, test skip/filter flags, and a command whose
  exit status can only come from commands that succeed whatever the files
  hold (`cat`, `wc -l`, `ls`, a pipeline ending in `tee` without pipefail),
  followed through `&&`, `||`, `;`, pipelines, subshells, `set -e` and
  `pipefail` by `bashparse.Deciders`; a script it can't follow is let through. This is a guard against
  the obvious, not a proof: hosts that need checks they trust configure them.
- Plain `Bash` runs never become evidence.

**Which checks apply.** Each session records its verification contract at
creation. In run-local sessions, evidence has no scope and host checks apply
to every run. A check the model
registers with Verify confirms what its own run did. It
applies only to that run; afterwards it is history, not an obligation. So a
check that confirmed a file existed cannot block a later request to delete
it, and a question answered after a code change is not sent back for checks
of the earlier request. A model check that fails or goes stale within its
run still sends that run back.
Scoped sessions apply host invariants and the active work’s acceptance
requirements. Each observation records the workspace, producing run and work
revision. See [requirement ownership](/internals/requirements/).

**Claims.** The unsupported-claim heuristic needs evidence, not
applicability, and it needs Verify: a session the host offered no Verify
(no checks of its own and no required verification) checks with Bash and
says how in its report's requirements, so its prose claims aren't judged. When no check applies to a run, a claim that checks passed is
supported if every observation the workspace hasn't changed since passed. An answer about earlier tests is accepted until the next change, and a stale or failed observation still leaves the claim unsupported.

Each claim is judged on its own against the checks observed
since the workspace last changed. A claim that names checks ("examples-tests
passed") needs every check it names to have passed; one that names none ("the
tests passed") needs some observed check to have passed; a sentence saying a
check doesn't pass is no claim. One failed check thus no longer refutes true
claims about the others: it sends the run back by itself, as a check without
passing evidence. A real subagent run took three reports because its true
claims about two passing checks were flagged beside a third that failed.

A claim is read in the prose alone. Inline code is left out,
since it names commands and files rather than verdicts, and a sentence saying a
check was refused, denied, blocked or skipped is no claim that it passed. A
run's disclosure that "`git clean` and `git rm` were refused", beside a
mention of tests, used to read as "tests … clean" and cost two continuations.

A possible writer (a running background process or an unsettled child) leaves
freshness `unknown`, which the report records with its reason, and claims rest on the checks
observed. A policy that requires verification still treats `unknown` as
unverified.

**Freshness.** Starting any tool call that isn't trusted read-only increments
the generation (Verify itself excepted). A built-in `Bash`
command the read-only allowlist accepts doesn't: a `git status` after the
last Verify used to leave passing evidence stale. Evidence from an older generation is
`stale`; while a background process runs, freshness is `unknown`. Changes made
outside zelk (editors, other sessions) aren't visible: there is no tree hash
yet.

**Background checks.** A check longer than the Verify limit runs with
`Verify{check, run_in_background: true}`. Verify validates it as
it validates any check, starts it as a process of the `check` lifetime and
returns at once; `ProcessStarted` carries a `CheckRun`: the evidence ID (the
starting Verify's effect ID), the check, its source and the generation it
started at. Each later Verify of that check waits up to the Verify limit; if
the check ended, it records one `EvidenceRecorded` with that ID, at the
start generation, which ends the process. The reducer refuses a check that
isn't its running Verify call's, starts at another generation, contradicts
the host's checks, or runs twice under one name; refuses other evidence for
a check while it runs.

- *Freshness.* The evidence is for the workspace when the check started: an
  edit or shell command while it runs advances the generation, so the
  evidence arrives stale. Read, Grep, Glob and ProcessList don't.
- *Other writers.* Verify refuses to start a check beside another running
  background process. A process, child or continued subagent started while
  it runs taints it, as does one the generation can't see at its start;
  tainted evidence never passes, and the report's unverified list says to
  run it again with nothing else running.
- *Completion.* While a check runs, the completion check sends the run back
  (`completion.Input.Running`), whatever the policy requires: the model is
  told to call Verify for it.
- *Endings without a result.* A kill (ProcessKill, or the execution ending)
  or a check the registry no longer holds (the host restarted; the next
  Verify records it `Lost`) ends it as evidence that didn't complete.
- *Not under scoped verification*, whose requirement-owned evidence has no
  background form yet, nor without a completion check (`WithoutCompletion`),
  where nothing would hold the run open.

A host that dies without cleanup, or crashes between starting the check and
logging it, doesn't leave it running in the local environment: like every
local process, it has a guard that kills its group when the host dies.
A descendant that leaves the process group escapes, as it escapes ProcessKill.

## The report step

A run ends through `ReportOutcome`, a harness tool the loop handles itself:
the model states the goal `met`, `partial`, `not_met` or `blocked` (with
`blocked_by`), a `summary` that becomes the run's final text, and what is
`open`. The run ends once the turn's other calls have results: no model turn
follows a report, so ending this way costs nothing extra. The call is the
model's final message, the summary its text: asked instead to report in the
same turn as a final message in text, the model never did (0 of 41 reports
in the Terminal-Bench rerun) and ended on the text, so most runs paid a
continuation for the report alone. A summary left out still falls back to
the final message, when there is one.

The system prompt says once how a run ends. A session with `ReportOutcome`
is told to finish with the call, whose summary is the final message; a
session without it is told to reply with its report. An earlier prompt said
both, a reply first and then the call, and the tool's `summary` argument
allowed a third way: in the overhead check the model replied in text and was
sent back in 11 of 27 runs.

The tool's schema requires `requirements` for every status, though only a
`met` report must list any. While the schema marked it optional, 7 of 27
`met` reports left it out, were refused, and were sent again whole, summary
included.

A rejected report names every problem with it at once and asks for the
whole report again, keeping the fields that were right: told of one
problem, a model fixed that field and dropped a valid one, and was rejected
again.

A `met` report may also name checks it `left`: failing
checks the model left as they were, each with a reason, such as a test that
fails on a bug the task doesn't touch. The completion check judges the run
without them, and the run's report keeps them in `left` beside the real
verdict, which stays `failed`. A report is refused, and the model goes on,
when a left check has no reason, isn't a check whose latest evidence failed
in the workspace as it is now, or passed earlier in the same run: a check the
run saw pass and then fail is one the run broke. The state records the run
each check last passed in (`passed_runs`) for that. The guard can't tell a
pre-existing failure from one the run caused before it first ran the check;
the reason the model gives is shown to the user, and a dishonest one is the
report the tool description calls the worst outcome. Hosts that scope
verification to requirements refuse `left`. A live run showed the need: a
model told to leave an unrelated failure alone did, and every run ended
incomplete because the check it ran still failed, while Claude Code reports
such a failure and stops.

- `blocked` ends the run `blocked`; `partial` and `not_met` end it
  `incomplete`, with that goal status. A `partial` or
  `not_met` report is first sent back, as a continuation, while the run has
  continuations left and no soft limit is wrapping it up: zelk allows
  a run to stop short only to ask, when blocked, or out of budget, and `blocked`
  says which constraint or missing thing it is. The note says nothing stops
  the run and points at `blocked`. Live runs showed the need: models gave up
  mid-work, with no limit, error or constraint in the way, through a report
  that cost nothing while a `met` faced every check. Once the continuations
  are used the report stands. The report stands at once in
  a run zelk refused a call of: a constraint stopped it, and sending the
  report back drove a live run to change code the user hadn't asked about.
- A `partial` with nothing `open` whose requirements name one `not_checked`,
  each with why, stands at once and ends the run `unverified`, its own
  outcome: the work is done as far as the model can tell, and what is
  missing is a way to check, not work. A `met` with a `not_checked`
  requirement is recorded as that `partial`. The three endings of finished
  work sit side by side:

  | Outcome | Means | `zelk exec` exit |
  |---|---|---|
  | `success` | done, every requirement confirmed | 0 |
  | `unverified` | done, with a requirement nothing here could confirm | 3 |
  | `incomplete` | work left undone, or claims and checks that don't hold | 1 |

  It used to end `incomplete`, which told a host that ran on a machine
  without, say, a GPU that work was left undone when none was.
- `met` goes through the completion check below. A report the check sends
  back no longer stands: the model works on and reports again.
- A turn that ends without a report is sent back, as a continuation: a run
  never succeeds on silence. The first live runs showed why: a model that
  declined an impossible task ended its turn, and the run counted as a
  success. This is the default for libraries, `zelk exec` and one-shot runs.
  A continuation sent only for the missing report asks for
  the report rather than more work: the summary is what the user reads, so it
  asks for the complete answer, keeping what the model already wrote, and says
  reporting needs no further tools. "Keep working toward the goal" led a model
  that had answered in text to run more tools and report a short summary, and
  the answer never reached the user. The final text stays the report's
  summary when the reporting turn has none: a reply before a report can be
  narration ("Let me look."), which the reducer can't tell from an answer.

**Conversational completion.** In a conversation, requiring a report costs a
model call on every greeting and question, and a report-only continuation
invited models to invent checks. In one real session a model ran
`Verify("printf 'Hi\n'")` after "Hi". `WithConversationalCompletion()`,
used by the TUI and `zelk acp`, offers no `ReportOutcome` and records
`RequireReport: false`. The model's final answer ends the run, and the system
prompt says so. Everything else in finalization still applies: a check that
fails or goes stale within the run, or a claim no evidence supports, sends the
run back, and repeated failures stay bounded. The report's `Claimed` status is
empty, recording that the model claimed no outcome; `GoalStatus` keeps its
outcome mapping. A continuation asks only for what sent the run
back: Verify when checks are at issue, ReportOutcome only when a report is
required. Without ReportOutcome, a reply is how the model says the goal can't
be met, as the continuation tells it to: a turn that ends
right after a continuation, with no call between, ends the run as the limit
would, instead of drawing the same note again. A live run showed the need: a
test failed on a bug outside the task, and the model said so four times
before the run ended. A model that acts after the note still gets its next
continuation. A continuation for a failed check also says that a
check failing for a reason outside the task needn't pass: whether to fix it is
the model's judgement under its usual guidance. In a live run, a model that
had left a pre-existing bug alone fixed it once the continuation offered no
other way out.
The report of a run that ended that way says so
(`replied`). The run stays incomplete, since the same reply also says a goal
can't be met, but where checks without a pass are all that is open, hosts
show the ending as a caution ("Some checks haven't passed", the reply says
why) rather than as a failed run (`present.End`). A met report that `left`
checks is shown the same way, so a person sees what was left and why in the
CLI's text as well as in its JSON.
- A report in a turn the output limit cut off isn't taken, and steering that
  arrives before the run ends voids the report.

## Finalization

With completion on (the default; `WithoutCompletion()` turns it off), a model
turn that ends normally, or with a report, goes through one check:

1. Pending steering takes another model turn.
2. A `blocked`, `partial` or `not_met` report ends the run as it says;
   a `partial` or `not_met` one takes a continuation first
   while any remain, unless a soft limit is wrapping the run up.
3. The **completion check** fails when a check's latest evidence failed or is
   stale, when `WithRequiredVerification()` is set and any check lacks fresh
   passing evidence, when the final message or report claims tests, builds or lint
   pass without fresh passing evidence for every check (in a session that has
   Verify), or when there is no
   report.
4. A failing check adds a note saying why and takes a continuation turn, at
   most `continuations` times per run (3 by default, `WithCompletion`); then
   the run ends `incomplete`.

The note restates the goal and its revision.

## Reports

Every run ending carries a `ReportRecorded` before `RunFinished`, in the same
batch. The reducer recomputes it from the log and rejects a record that
differs, so a report can't claim what the log doesn't show. `Result.Report`
returns it.

| Outcome | `goal_status` |
|---|---|
| `success` | `met` (`not_met` if the goal was abandoned) |
| `incomplete`, `blocked` | `partial` if built-in tools changed files, else `not_met` |
| `unverified` | `partial`, as the model reported it |
| anything else | `unknown`, with `forced` set |

`verified` lists evidence IDs; `unverified` names each check without fresh
passing evidence and why; `changed` lists files built-in tools changed
(`done` before `report_recorded` version 2);
`unsupported_claims` quotes final-message claims no evidence supports.

The report merges the model's `ReportOutcome` (`claimed`, `summary`,
`blocked_by`, `open`, `left`) with what zelk checks itself; for a forced ending zelk
synthesizes it alone. The log records `CompletionChecked` (goal revision,
latest evidence IDs including failures, verdict and reason, and the decision
itself: whether the run continues, else its outcome and detail, and what sent it
back; a stored log replays the ending as recorded), `ContinuationUsed`,
`ShortcutFlagged` and `AttemptRecorded`. IDs derive from the causal event's
sequence and decision order. `loop.Records` previews on isolated state and
includes each decision immediately after its cause in the same atomic append.
The reducer rejects omitted, forged, reordered and duplicated decisions before
any dependent event can fold. A failed append cannot advance acknowledged
state.

## Failures

Each failed tool result ends with its labels:
`[certainty: failed|unknown; policy: none; recoverability: try-differently|reconcile first…]`.
A call zelk refused (plan mode, tool ceiling) is labelled
`certainty: done; policy: constraint; recoverability: stop`.

The same tool with the same input failing with the same output is counted per
run: a reminder to step back comes the time before `repeatLimit` (3 by
default), and reaching it stops the run as `incomplete`.
A call the policy refuses (a deny rule, plan mode, a
hook, or no one to ask) counts the same way, by tool, input and reason:
nothing in the run will let it run, and a headless model that kept retrying
one denied command reached the turn limit. The run then ends `incomplete`
with the reason.
A `ReportOutcome` rejected as invalid (a `blocked`
report with no `blocked_by`, an unknown status, a check set aside wrongly)
counts too, by its reason alone, so rewording the summary doesn't reset it:
a model that sent the same invalid report 98 times reached the turn limit.
A call that succeeds counts too, when it returns the
same result as the last time the same tool ran with the same input: a
headless model ran one python probe 58 times, each printing `None`, until its
time ran out. Polling a slow job can rightly see the same text a few times,
so the reminder comes at twice `repeatLimit` and the stop at three times it
(6 and 9 by default). A different result starts that call's count over, and
so does any edit by a file tool. A command's own changes to the workspace
aren't seen call by call, which the generous limit allows for.

Task-key attempts are separate from identical-action failures. A scheduled tool
captures the key of the sole `in_progress` todo; no key or multiple active todos
means no task attribution. Parallel TodoWrite updates do not relabel scheduled
calls. Each terminal error result counts once across different actions on that
key; unknown outcomes, transport retries, cancellations and TodoWrite itself do
not count. Counts persist across task status/text changes, compaction and
suspension, and reset at the end of the run. A successful action does not erase
previous failures. At `repeatLimit` (default 3), a reminder asks the model to
reconsider its approach; task counts alone do not terminate the run. Changing a
key creates another identity, so this is an advisory aid, not a semantic proof
that two tasks differ. Identical-action doom-loop limits still apply separately.

## Shortcut flags

Advisory and incomplete by design: no flag never means compliance. Each flag is
recorded as `ShortcutFlagged`, and a stored log replays with the flags it
recorded, whatever later versions of the heuristics below would raise (durability.md, "Recorded
decisions").

- Built-in `Edit`/`Write`: changes to test files that existed before the run
  (a test the run created is new work, not a weakened check); added skip or disable
  markers (`t.Skip`, `@pytest.mark.skip`, `it.skip`, `eslint-disable`,
  `#[allow(`, `# type: ignore`, `//nolint`, …); coverage or lint threshold
  changes in known config files.
- `Bash`: `--no-verify`, `git commit -n`, test runners with skip or filter
  flags.

Each flag adds a note asking the model to explain it and is listed in the
report. Changes made through Bash or MCP tools bypass the edit detectors.

Provisional replies are labeled as updates until finalization accepts an answer. ReportOutcome and evidence checks remain required; ordinary text is never automatically promoted to successful completion. Explicit conversation-owned workers survive response completion while keeping verification freshness unknown; see [background ownership](/internals/background/).
