Docs/Caching
#

Caching

Reference for Cofactor's test cache. How playbooks and cached actions replay, cache-only runs, every cofactor workflow cache command and commit option, the playbook file fields and limits, and the assertion and capture shapes.

Cofactor records how each step of an E2E test worked, and replays that record on later runs. A replay runs your application again with fresh data and checks the same assertions. It does not reuse an earlier result. For the plain-language version, see Self-healing. To build a cache by hand, see Author repeatable cached tests.

What a cache holds

TermMeaning
PlaybookThe ordered, readable steps for one node of a test.
Cached actionThe executable form of a step: an interaction, its inputs, captured variables and checks. For browser steps it is a self-contained Playwright snippet run against the signed-in page.
Cache rowWhat Cofactor stores per node: the playbook and its cached actions.
GapA step that cannot replay yet. It is listed with a reason.

Macros and variables stay dynamic. A cache keeps the $var and macro references, so each run uses its own values. Assertions stay part of the test, and a replay that skips one is not a working cache.

In a normal run Cofactor replays a cache that has proven itself. Otherwise an agent follows the playbook, repairs a step, or does the step fresh and records a new candidate. Editing a test or changing the application can make a cache unusable.

MCP steps cache their tool calls the same way. Cofactor records those itself, and you cannot author them.

Cache-only runs

bash
cofactor workflow run <workflow id> --cache-only [--environment <name|id>]
BehaviorDetail
WaitsThe command waits for the run. It exits with code 1 when the run fails, times out or is canceled, and with code 2 when the result is inconclusive.
No agent for cached stepsA step that has no usable cache fails the run. The failure names the first step that could not replay.
Real changesIt is a real run. It writes and deletes in the application the same way the test does.
Still agent-drivenLogin steps and steps set to always use the agent can still use an agent.
Safety checkIf the created run does not record cacheOnly, the command cancels it and exits with an error.

A green status does not prove every step replayed. Read the run's replay and assertion results.

Commands

CommandWhat it does
cofactor workflow cache status <workflow id> [--json]Shows each node's cache. In the JSON, effectivePlaybooks[].activeCache is the cache in use. nodes[] can also list a newer row that is not usable.
cofactor workflow cache commit <workflow id> --node <node id> --playbook <file>Validates a playbook file and writes it to one node.
cofactor workflow cache clear <workflow id> <mode>Marks caches unusable, or deletes them. See below.
cofactor workflow cache pin <workflow id>Pins the cache. It is read-only at run time and recached offline. unpin reverses it.
cofactor workflow run <workflow id> --cache-onlyRuns from cache only.
cofactor workflow debug cache <run id> [--misses-only]Lists cache hits and misses for a run, with the reason for each miss.
cofactor workflow debug overview <run id>Prints a run summary, including the cache hit rate.
cofactor workflow debug materialize <run id> [--out <dir>]Writes the run's evidence to a folder.
cofactor workflow guide playbookPrints the playbook authoring guide.
cofactor workflow guide assertionsPrints the assertion guide.

cache clear takes exactly one mode:

ModeEffect
--node <node id>Marks one node's cache unusable.
--below-version <n>Marks caches with an older compiler version unusable.
--mode allMarks every cache row unusable. The rows stay.
--mode hard --yesDeletes the cache rows and strips recorded playbook steps from the node configs. This is the same as Reset flow in the app.

--stale-only also exists for old rows and rarely matches anything now.

Commit options

OptionMeaning
(none)Validates and writes the playbook. The result says whether it installed your playbook, patched the row, or kept the one already there.
--dry-runRuns the validators and commit guards and writes nothing. It cannot be combined with --force or --verified.
--force --expected-cache-id <id|none> --yesReplaces the cache even when the normal rule would keep the existing one. Use the id you just read from cache status, or none when no cache exists for that node. Validation still applies.
--verified --verified-from <run id> --verified-from <run id>Imports content you attest two clean cache-only runs already proved. It needs --force, --expected-cache-id and --yes, and two different run ids. It does not run any proof.
--unverified-from-trace --yesWrites an unverified candidate from eligible trace evidence. The content must have no gaps and no agent actions. It cannot be combined with --dry-run, --force, --verified or --expected-cache-id. It was formerly --cache-only-boundary.
--jsonPrints the raw result.

--playbook was formerly --recipe, which still works. workflow promote --force is a different option. It adds a test to suite runs and does not replace a cache.

A successful commit or dry run is not proof that the playbook replays. A cache-only run is.

Playbook file

A JSON object for one node. The server recomputes the node hash and ignores any hash you send.

FieldShape
sourceRunIdUUID of a run of this same test that supplies the evidence. For a normal commit, the node must have succeeded in that run.
playbookSteps1 to 200 readable steps, order numbered from 1. Each has an action and a target. A verify step carries the configured assertionId.
plannedActionsUp to 200 executable actions. Each has stepOrder, toolName, actionType and an args object.
plannedActions[].codeFor run_code, a self-contained Playwright snippet of at most 16,000 characters.
plannedActions[].selectorsOptional selector strategy for non-code actions. A run_code action puts its locators in code.
plannedActions[].elementDescriptionOptional text, at most 2,000 characters.
plannedActions[].assertionFor an assert action, the assertion object below.
gapsUp to 200 entries of { "stepOrder": number, "reason": string } for steps that cannot replay yet. Use [] for a fully cached node. The reason is 1 to 2,000 characters.
carriedActionsOptional, up to 200 entries of { "stepOrder": number, "action": object }, copied from an existing proven cache.
variableValuesOptional map of variable names to recorded string values.

Example action for a Save click:

json
{
  "stepOrder": 1,
  "toolName": "browser_run_code",
  "actionType": "run_code",
  "args": {},
  "code": "await page.getByRole('button', { name: 'Save', exact: true }).click();"
}

Locator rules for cached code:

  • Use semantic locators, such as a role and an accessible name.
  • Cofactor refuses positional picks such as .first(), .last() and .nth() that choose an element to act on. Identify each target by its role, label or text.
  • It always refuses ephemeral element references, fixed table indexes and selectors built from volatile values.

Assertion object

A cached assertion is an action with actionType: "assert", args: {} and an assertion object.

FieldMeaning
typeOne of text_present, text_absent, element_visible, element_hidden, evaluate, playwright, toast_present, download_present, download_content.
conditionRequired, not empty. The text, selector or code for the type.
expectedOptional value to compare with.
severityOptional.
inlineAssertionIdThe id of the configured assertion this one fulfills.
labelOptional.

For playwright and evaluate, the condition returns a boolean. A condition that ends in a bare textContent(), innerText(), inputValue() or count() call with no expected is rejected, because the result alone does not say pass or fail. Add expected to compare the value, or return a comparison.

json
{
  "type": "playwright",
  "condition": "return await page.getByRole('status').innerText() === 'Saved';",
  "inlineAssertionId": "<configured assertion id>",
  "severity": "fail"
}

Capture a value

A step can save a value for later steps.

  • Declare the output name in the node's declaredOutputs.
  • Give the readable step "action": "capture" and "params": { "saveAs": "<name>" }.
  • Give its run_code action "args": { "saveAs": "<name>" }, and return a string. Use JSON.stringify to return several values.
  • Captured strings are limited to 2,048 characters.
  • Later snippets and assertions read the value as vars.<name>.

What the server checks on commit

CheckCovers
ShapeField types, supported actions, code length, assertion objects and option combinations.
Test fidelityRequired macros and variable references stay present. Assertion ids are known and not claimed twice.
Replay admissionActions must be executable under the cache contract. Strict checks cover positional locators and unstable anchors.
Write guardsThe source run belongs to the test and your organization. A forced write names the cache it replaces. A verified import names two proof runs.

Validators check the file. They do not check that a locator finds anything on the live page. Only a run does.