# Benchmarks

Three switches help compare runs of pic against each other:

- **Lapse compaction.** `--lapse on|off` (`PIC_LAPSE`, setting `lapseCompaction`, default on)
  compacts before a submission's first request when the conversation has been idle longer than the
  prompt cache lives and its context is above a floor, since the cache is cold anyway; tool calls
  inside a submission never count, however long they take. Idle time is the journal's clock
  less the end of the conversation's last reply. The lifetime defaults to the cache retention in
  effect: 300 s, 3600 s with `cacheRetention` long (86400 s for OpenAI's 24-hour retention), and
  never for `none`; set it with `--lapse-seconds` (`PIC_LAPSE_SECONDS`, `lapseSeconds`). The floor
  is 100000 context tokens; set it with `--lapse-floor` (`PIC_LAPSE_FLOOR`, `lapseFloorTokens`). It
  makes no summary request unless `lapseMode` is `summary`. The
  compaction is journaled with reason `lapse`, the idle seconds and the context's tokens, and its
  events are Pi's `compaction_start` and `compaction_end` with `"reason":"lapse"`. Forked
  conversations look idle, so turn it off for runs that replay them. A share of lapses is held out
  (`lapseHoldout`, `PIC_LAPSE_HOLDOUT`; default 0.1): set 0 for a benchmark that needs every lapse
  compacted. See [sessions](sessions.md) for `pic usage --lapse`.
- **Trial labels.** `--trial LABEL` (`PIC_TRIAL`; 1 to 64 printable characters) is kept on every
  request the invocation admits. `pic usage --by-trial [--json]` sums each arm's requests, input,
  output, cache read and cache write tokens, and cost, summary requests included. Pi's session
  format has no place for it on a message, so the Pi export leaves it out.
- **A verdict per request.** A trusted workspace's `.pic/verify.json`, `{"command": "make test"}`,
  names a command that says whether the work passed. pic runs it once when a request is about to
  end answered, after its Stop hooks let the reply stand: in the workspace with `/bin/sh -c`, with
  `PIC_VERIFY=1` added to pic's environment, for at most `--exec-timeout` (600 s), killed with its
  process group on Ctrl-C or when pic dies. Exit 0 is a pass, anything else a fail;
  a request that did not end answered has no verdict. The verdict is kept with the request, and a
  crash while the command runs leaves it unknown: the command is never run again for that request.
  Once any request has a verdict, `pic usage --by-trial` adds `passed` and `failed` per arm (and
  `unknown` when there is one), so a cheaper arm that fails more shows it; without a verify command
  its output is as before. `pic log` ends a judged request with a line such as `(verify: failed,
  exit 1)`, the terminal interface shows `verify: passed` under the reply, and `agent_end` carries
  `"verdict"`. pic never writes the file; an untrusted workspace's is ignored.
- **Tools.** `pic usage --by-tool [--json]` shows where a run's tool calls go: per tool, its calls and
  failures, and the requests that called it with their tokens and cost. A request that called two
  tools counts toward both, so the rows do not add up to the total.
- **A request cap.** `--max-requests N` (`PIC_MAX_REQUESTS`) stops a request cleanly before it would
  send its (N+1)th reply request. Retries of one request count once, summary requests not at all,
  and the count comes from the journal, so recovery after a crash keeps it. The request ends with
  status `stopped` and `stop_reason` `request_cap`, and `agent_end` carries
  `"status":"stopped","stopReason":"request_cap"`. `pic ask -c` continues the conversation.

pic's own speed is measured by `make bench-pic`; see [testing](../dev/testing.md).
