# Pi-experiment runner

Executes the trials of the [harness experiment design](../pi-harness-experiment.md) for the `pi` harness (the design also plans for other harnesses, with agent profiles as the tested units). It launches every call through Workjig. It does not author worlds, score documents or analyse results.

Status, 2026-11-28: the runner works end to end against a stub `pi` and on one toy trial with a real model. No experiment world exists yet and no experiment data has been collected. Running the experiment still needs the operator's authorization.

## Files

- `run_experiment.py` — plans and executes trials. Run it directly; `uv` installs Workjig and PyYAML from the inline script metadata.
- `pi_stage.py` — wraps each `pi` call inside a Workjig launch. Workjig collects outputs from a launch directory, and the experiment's prompts must not mention that directory. The wrapper copies the document the agent wrote and the last assistant message into it.
- `controls/profiles.yaml` — the author profiles to test and the single reader profile. The models listed are placeholders.
- `controls/design.yaml` — seed, samples, cells per world variant, timeouts, `pi` isolation flags and author tools.
- `controls/prompts/` — prompt templates in `string.Template` syntax (`${name}`; write `$$` for a literal dollar sign).

| Template | Variables | Use |
|---|---|---|
| `task-<framing>.md` | `request`, `concept`, `document` | The operator request for one task framing |
| `priority-funded.md`, `priority-routine.md` | `practice` | The two clauses of the priority paragraph |
| `reader-probe.md`, `author-probe.md` | `concept` | The classification request for the held-out cases |
| `canary-brief.md`, `canary-task.md` | `token` (brief only) | The isolation check |

## World layout

Worlds are the experiment's materials. They are not written yet. The runner reads them from `worlds/` beside the script, or from `--worlds`.

```text
<world>/
  world.yaml                      concept, document, request, practices: {B: ..., C: ...},
                                  constituent: B | C,
                                  evidence: {main: {scope: [...], B: [...], C: [...]}, control: {...}}
  brief.md                        project brief containing ${priority} (must not name B or C outside it)
  variants/main/workspace/        files the author sees
  variants/main/cases.md          held-out candidate changes, without the truth table
  variants/control/workspace/     constituent control variant
  variants/control/cases.md
```

`request` is the world's frozen literal request, `document` is the path the author is asked to write inside the workspace, `practices` gives the names of B and C as the brief uses them, and `constituent` identifies which practice (`B` or `C`) is genuinely a constituent in the `control` variant (recorded in `trial.json`). `brief.md` must not name B or C outside `${priority}`; the baseline cells replace `${priority}` with nothing.

`evidence` names, for each variant, the workspace files that carry the evidence the author needs. The `scope` group is required: the files that fix what counts as progress on the concept. Other groups are free; the design expects one per practice, holding its dissociating case files. Each file must fit in one `read` call (under 2000 lines and 50 KB), so that a read without `offset` or `limit` returns all of it.

## Commands

```bash
./run_experiment.py plan                          # list trials; launches nothing
./run_experiment.py canary --runs ~/blending-runs/pilot
./run_experiment.py run --runs ~/blending-runs/pilot --jobs 4
./run_experiment.py status --runs ~/blending-runs/pilot
```

`--world`, `--profile`, `--samples` and `--limit` narrow a run. The runs directory must have no `AGENTS.md` or `CLAUDE.md` in it or above it, so it cannot be inside this checkout.

Model calls need network access and writable `pi` state. In a sandboxed agent session, run `canary` and `run` outside the sandbox.

## What a trial does

The first run freezes the controls, worlds, and scripts in the run directory’s `materials/` folder. All trials use those copies. Later runs and status checks use the same materials even if the original inputs move or change. A new set of materials needs a new run directory.

A trial is one world variant, task framing, priority assignment, author profile and sample. Trials run in a seeded shuffled order, so conditions interleave.

1. **Authoring.** The runner copies the workspace and starts `pi` in it with the author tools. The brief arrives through `--append-system-prompt`. The task is the only user message.
2. **Reader probe.** A `pi` call with no tools and no brief receives the frozen document and the cases as attachments.
3. **Author probe.** A fork of the authoring session receives the cases.

Each trial directory is named by a hash, because the author can see its working directory. It holds:

- `trial.json` — the condition and, per stage, the status, the reported and served model, the system-prompt check, the files the agent read, its access to each evidence file and any tool call outside the workspace
- `document.md` — a copy of the delivered document; `trial.json` records its SHA-256, and the Workjig delivery in `author-record/` is the authoritative copy
- `final-message.md`, `reader-answer.md`, `author-answer.md`
- `workspace/` — as the author left it
- `author-record/`, `reader-record/` — Workjig run records with each launch's raw event stream and session file

Trial outcomes:

- `complete` — all three stages delivered.
- `no-document` — the author stopped without writing the document. Its last message is kept and the probes are skipped. This is an observed outcome, not an execution failure: the design covers unattended work, so a stop without the document is a non-delivery whatever its reason. `final-message.md` is kept for inspection.
- `invalid-exposure` — a call's system prompt was not what the condition intends: the brief was missing or altered, the reader received an addendum, or an unexpected section appeared. The observation is kept and not probed further.
- `probes-incomplete` — the document was delivered and a probe failed. Workjig repeats the whole probe once on a timeout, launch error, or process error, using the same call inputs. Delivered answers, including partial classifications, stand as returned. The Workjig record retains each launch. If a probe still fails, the document and any delivered answer remain available for scoring.
- `failed` — authoring failed, so nothing was observed. `--rerun-failed` sets the trial aside and runs it fresh. The set-aside directory is kept.

`run` exits non-zero while any selected trial is `failed`, `probes-incomplete` or errored. `--limit` bounds which trials `--rerun-failed` sets aside.

Rerunning `run` skips finished trials and replays delivered calls from an interrupted trial’s Workjig record. Only a recorded authoring failure qualifies for `--rerun-failed`. On each invocation of `run`, the runner verifies the frozen materials against `manifest.json` and checks the resolved `pi` executable and the pi and Workjig versions. One controller at a time may use a runs directory. Older runs without a materials snapshot require their original runner to resume.

## Evidence access

An author that includes a practice without having seen the evidence against it was ignorant, not blending. `trial.json` records under `authoring.evidence_access` how much of each evidence file the author saw before the assistant turn that last wrote the document:

| Value | Meaning |
|---|---|
| `full` | one or more `read` calls before the final-write turn covered every line of the file |
| `partial` | at least one `read` call before the final-write turn covered fewer than all lines |
| `search` | a `grep` match or context line from the file before the final-write turn, and no `read` |
| `none` | none of these; reads in the same assistant turn as the final write (or later) count as none |

When the author never wrote the document, every call counts. The record shows access, not what the author noticed.

## Isolation checks

`pi` builds its system prompt from more than the context files: it also reads `SYSTEM.md` and `APPEND_SYSTEM.md` from its configuration directory and from `.pi/` in the working directory. The runner refuses to start when the global files exist or a world workspace contains `.pi/`.

`canary` makes one call per profile in the shape the trials use, in a workspace that contains decoy `AGENTS.md`, `CLAUDE.md`, `.pi/SYSTEM.md` and `.pi/APPEND_SYSTEM.md` files. An author call passes when its addendum is exactly the brief. The reader call passes when it has no addendum and can repeat a codeword from its attached document. Both also require that no decoy text and no unexpected section appear in the system prompt that `pi` records in its event stream.

Every authoring call and reader probe repeats the system-prompt check. `trial.json` also records a digest of the base prompt, so a changed base prompt shows as a different digest across trials.

## Known limits

- The author's file tools are not confined to the workspace. Trial records, including other trials' held-out cases and reader answers, sit in the same runs directory, and `pi` has no sandbox. The runner records every successful tool call on a path outside the workspace as `outside_workspace` in `trial.json`; a trial with such a call needs review before it is scored. The check covers the tools' `path` argument only.
- A forked session does not record its system prompt again, so the author probe has no system-prompt check. Whether the fork keeps the original system prompt is not verified.
- `trial.json` sits beside `document.md`. Give the blinded scorer copies of the documents only.


[Complete file listing](./dir-index.md) *(generated at build time)*
