# Debug a Run: standing rules

## Standing rules

## Standing rule: auth errors after a cross-host transition

If the failure looks like a credential or session issue (401/403, "session expired", login redirect, "please sign in"), **first reconstruct the URL timeline around the failure**.

1. Read the failed step's rollup (`steps/<NNN>-<stepId>.md`) — the "Navigation (in step window)" section lists URL transitions and marks cross-host transitions with `⚠ cross-host`.
2. Skim the prior step's navigation as well — the cross-host hop often happens between steps.
3. Compare host names case-insensitively, stripping a leading `www.`. So `staging.example.com` → `www.example.com` is a cross-host change; `www.example.com` ↔ `example.com` is not.

**If the hostname changed between two entries shortly before the auth failure, the test navigated off its authenticated origin. That is the root cause, not stale credentials.** Do not classify as `dependency_issue` (credentials problem) without ruling out cross-host.

Auth errors after a cross-host transition are almost never credential issues.


## Standing rule: workflow variables and macros

Workflow steps can use **macros** and **variable references** in their configuration:

- **Macros** (generate values at runtime): `$MACRO_NAME(args)` — e.g. `$EMAIL()`, `$UUID()`, `$RANDOM_STRING(10)`. Used in `inputValues` on action nodes; resolved fresh each run.
- **Variable references** (reference workflow inputs or values from action inputs and earlier steps): `$var.variable_name`. Macro-resolved action inputs are pre-registered before variable substitution, so one input in step N may reference another input from the same step. References to values captured from the page remain available only after that capture runs.

Common variable-related failures:
- A same-step input references `$var.X`, but X still contains another `$var.*` reference and therefore cannot be pre-registered safely.
- A step references `$var.X` where X was defined in a step that was skipped or failed earlier.
- Misspelled variable names (e.g. `$var.client_name` vs `$var.clientName`).
- An `inputValue` was set without a matching `dataRequirements` entry — only inputs with a dataRequirement become variables.

When drafting a flow fix that touches variables:
- Use `Read` on `workflow/nodes/<nodeId>.json` to see the full configJson before changing that node.
- Preserve any existing `$var.` references and `$MACRO()` calls — don't break them.
- For array fields like `inlineAssertions` or `playbookSteps`, write the **full replacement array** in the snapshot, not a partial — read the existing array first and include the merged result.


## Standing rule: assertion severity and step/run status

Assertion severity drives what a failure means — `fatal` halts the run at the failing step, `fail` marks the step (and ultimately the run) failed but execution continues, `warn` records a warning and the run still passes. Because `fail` and `warn` are non-blocking, later steps run normally after an assertion failure. Assertion records carry a `nonBlocking` flag reflecting how each was treated at run time.

When investigating:

- Open the step's rollup (`steps/<NNN>-<stepId>.md`) and look at the "Assertions" section. Each line shows `passed`/`FAILED`, severity, and a `nonBlocking` marker. Entries marked not-checked (`checked: false`) were configured on the node but never evaluated — the step broke before assertions ran; do not read them as failures.
- **Do not treat "failed assertion + completed step" on its own as evidence of `platform_error` or contradictory state.** For `warn`/`fail` severities (`nonBlocking` true), that combination is expected and carries no signal about the actual cause.
- A non-blocking failed assertion does not tell you which category applies. It only rules out one specific false-positive narrative (`platform_error` / bookkeeping). Continue investigating from network, console, thoughts, visual, and history. The actual cause may be any of `software_bug`, `dependency_issue`, `agent_confusion`, `test_underspecified`, or `platform_error`.

When `platform_error` is still a live possibility:

- A failed `fatal`-severity assertion (`nonBlocking: false`) alongside a step recorded as completed successfully. That is a genuine disagreement worth flagging.
- Infrastructure-level failures (browser session died, worker crash, Cofactor's own stack traces) independent of any assertion outcome.

Always consult the assertions section of the rollup before writing a bookkeeping-bug narrative.


## Standing rule: a passed assertion is never the divergence; check what produced the state

A **passed** assertion — and **any** non-blocking assertion (`warn`/`fail` severity) — can never be your smoking gun or "the earliest blocking divergence". It records that a check held (or was tolerated), not that anything went wrong. The divergence is always an **action or state change**, visible in the step's action timeline, that an assertion failed to catch. If your draft smokingGun quotes an assertion line, you have anchored on a symptom — go find the action that caused it.

Watch for an assertion that passed only because the page reached a **degenerate** state:

- A weak predicate ("the deleted item is gone", "no rows match the filter", "the field is empty") is **also satisfied when *everything* is gone** — an empty list, a blank canvas, a wiped form, a zeroed count, the empty/first-run chooser. So "X is absent" passing while a *later* step fails for missing content is a red flag, not confirmation: the page overshot into emptiness and the assertion was too loose to notice.
- When you see this, open the failing-or-prior step's action timeline and look for the **action sequence that produced the degenerate state**, especially:
  - a **repeated destructive action** — a delete / remove / clear / archive / reset triggered **twice** within one step (often with a stretch of re-inspection or re-snapshotting between the two), where the second pass acted on whatever survived the first;
  - an **over-broad selection** — a select-all, a multi-select that grabbed more than the named targets, or a re-selection that picked up the items that should have remained.

Name that action as the root cause (typically `agent_confusion` when the agent repeated or over-selected; `software_bug` if the app deleted more than instructed). The empty end-state and the later "content missing" failure are downstream symptoms — cite them as consequences, not as the cause.
