Plans and postconditions
A postcondition says what must be true after a step: the URL changed, a window opened, a process started, a button became enabled. A plan is a list of steps that each carry at least one postcondition. The runtime replays a plan with no model call, checks each postcondition as it goes, and hands over to the runtime’s loop only if one fails.
A task the loop worked out once can then run the same way every time. Let the loop solve it, compile the run into a plan, review the plan, commit it to the scenario, and later runs replay it.
Postconditions
Section titled “Postconditions”Each entry in a post: list sets exactly one kind. Every kind except screen is polled, every 250 ms by default, for up to timeout_s seconds (default 10). A condition that never holds fails the step, and the report records what was observed.
| Kind | Holds when | Needs a model |
|---|---|---|
url: "<substring>" |
The tab’s location.href contains the substring |
No |
dom: "<js boolean>" |
The expression is true in the page | No |
state: "<element> [not] <state>" |
The application reports the control in that state, over AT-SPI | No |
window: "<substring>" |
A window whose title or class contains it exists | No |
no_window: "<substring>" |
No such window exists | No |
process: "<substring>" |
A process whose command line contains it is running | No |
no_process: "<substring>" |
No such process is running | No |
file: "<path>" |
The path exists in the session | No |
screen: "<expectation>" |
The model judges the expectation true on a settled screenshot | Yes |
screen is judged once, takes no timeout_s, and is the weakest evidence in the list. Use it where nothing else can observe the effect. With no model configured, a screen condition is recorded as not judged and does not fail the step.
A post: list is accepted on a step under steps:, where it is optional and replaces an action followed by a separate wait; on a step under plan:, where at least one entry is required; and on a tool the scenario declares under tools:. Each evaluated condition is written to the step’s post array in report.json as {kind, arg, held, detail, ms}.
steps: - action: cdp_navigate "http://127.0.0.1:8901/login.html" post: - url: "/login.html"A scenario with a plan runs in three phases: steps: (setup, which must pass), then plan:, then goal: only if the plan did not complete.
plan: - action: cdp_fill "#username" "demo-user" post: - dom: "document.querySelector('#username').value === 'demo-user'" - action: cdp_click "button.login" post: - url: "#/dashboard"goal: "Sign in with the credentials provided and confirm the dashboard has loaded."The runtime rejects these at load: a plan without a goal:, which is the fallback; a plan step without an action and at least one post: entry; an observe step inside a plan; and a plan of more than 40 steps, counted apart from steps:.
A plan that completes has run every action and checked every postcondition. report.plan records {steps, completed, failed_step, reason} either way, so a run that fell back is distinguishable from one that never had a plan.
When a plan step fails
Section titled “When a plan step fails”A plan step fails when its action fails on the application’s side or its postcondition does not hold. The run does not end there. The runtime records the failed row, notes the step and the reason in the report, skips the remaining plan steps, and enters the runtime’s loop from wherever the plan left the screen. The loop’s first input action must look at the screen first, as after any other change. A lost browser connection or a missing display still ends the run as test-error.
What happens next depends on whether a model is configured.
| With a model endpoint | With no model endpoint | |
|---|---|---|
| The loop | Works towards the goal: from the current screen |
Is entered, marked degraded and returns at once |
| The failed step | Recorded in report.plan |
Recorded in report.plan |
| The verdict | The final checks decide, with the loop’s verdict added as in Goal steps | The final checks decide. A concern is added: “agentic loop degraded – goal not verified; deterministic probes own this verdict” |
| Exit code | 0, 1 or 2 by verdict | 0 with pass-with-concerns when the process and window checks are clean |
With no model, a failed plan step does not fail the run. The scenario exits 0, and the only signs are the pass-with-concerns verdict, the concern in reasons, and plan.completed: false with failed_step in report.json. A job that must stop on a plan fallback tests for those: treat pass-with-concerns as failure, or read plan.completed. If another deterministic check fails as well, the verdict is app-failed.
Compiling a run
Section titled “Compiling a run”kasm-session-runtime compile-plan <run output dir> [--scenario base.yaml]compile-plan reads report.json and trace.jsonl from a finished run of a goal: scenario and prints a plan: block. With --scenario, it prints the base scenario with the plan appended and checks that the result loads; the base scenario needs a goal: and no plan. It never edits a file in place: the output is YAML for a person to read and commit. It runs offline, with no session and no model.
It refuses a run whose model verdict was not goal-met and exits 1, because a plan compiled from an unfinished run would replay the unfinished part and pass on its own postconditions. --allow-incomplete overrides this.
Each tool call in the transcript becomes one plan step.
| The loop called | The plan gets |
|---|---|
cdp_click_described |
cdp_click_described "<resolved name>", using the element name from the result, never the per-page handle the loop passed |
cdp_click on a declared target |
cdp_click "<selector>", when --scenario supplies the target |
click_element |
click_element "<name>" |
press_key |
key "<chord>" |
click |
click "<target>" or click center. Nothing for a click with another button, a count or modifiers |
scroll, drag |
Nothing: a scripted step has neither |
type_text, cdp_fill |
Nothing: the transcript does not record typed values. Add these by hand with a variable reference |
click_grounded |
Nothing: a click located on screen has no deterministic postcondition |
Each step’s postcondition is inferred from what happened next, in this order: the page’s URL changed; a cdp_wait the loop ran held; a later cdp_url read a new URL; a filtered cdp_list_interactive found something; a check_expectation held (this compiles to a screen condition); failing all of those, the next action’s target is on the page. If a step has none, the output marks it TODO and compile-plan exits 1. Replace each TODO by hand.
A plan is specific to the page it was compiled from and does not generalise across parameters. When the application changes, a postcondition fails, the run falls back to the loop, and the report names the step where the page had moved.
An example across many sessions
Section titled “An example across many sessions”The 08-parallel-agentic-goals example runs one scenario against several pages, one Kasm session each. Phase 1 runs the loop on each page with a model. The script then runs compile-plan on each downloaded report, writes the compiled scenarios to out/plans/, and phase 2 replays them with no model call. Each phase 2 report says whether its plan completed or fell back, and at which step. Running at scale and in CI covers the fan-out.
Background
Section titled “Background”Agent JIT compilation (Winston et al., ICML 2026) found that most web-agent failures are a tool called in the wrong state, and that most of an agent’s wall clock is per-step inference. From it we took postconditions declared on steps and plans compiled from earlier runs. We left out its planner, which has a model write code that calls tools. The runtime keeps a closed vocabulary of actions, and its compiler is deterministic and produces YAML a person can review.