# Read lifecycle, CPU and reserved-host diagnostics

Run:

```bash
cofactor external-run debug overview <run-id>
```

The overview shows the customer-safe orchestration timeline: run state, parent
and shard job phases, attempts, timeouts, reschedules, launch completion, and
whether a later attempt recovered. It deliberately excludes job payloads,
arbitrary metadata, launch commands, environment variables, substrate handles,
and cloud resource identifiers.

`recovered_after_retry` means at least one shard attempt timed out and a later
attempt for that shard completed before the run sealed. That is a real harness
event, but not automatically the explanation for every failed assertion in the
run. Correlate timestamps and scenario attempts.

`collecting` is not by itself stuck. Check current phases/`runAt` timestamps and
poll again. A sealed run with recovered retries completed; report the transient
timeout and recovery rather than calling it permanently stuck.

## Reading copy CPU profiles

For Playwright suites on Linux Sandboxes v2 attempts, the overview shows CPU
seconds and their share by process name (for example `chromium`, `node` or `postgres`), guest busy mean
and p90 across attempt-seconds, mean cores used per passed/failed copy, and the
ten copies with the most process CPU. One core busy for one second is one CPU
second. Guest busy percentages cover all allocated cores; p90 is rounded to a
one-percent bucket. Process shares use measured process CPU, not guest CPU.
Peak RSS is the largest sampled sum for that name in one copy, not unique memory.
Use `--json` for these aggregates. Serial/dependency groups share a copy, so the
listed test keys share its CPU profile; CPU is not attributed to individual tests.
Sampling starts when the boundary reporter loads (`onBegin`); runner start-up
before then is not counted. Process names are Linux comm names (usually 15
bytes), so services sharing a name are merged. Short-lived processes that start
and exit between one-second samples are not attributed. The sampler's own CPU
cost is reported separately as `samplerCpuSeconds` and in the human output.
Passed or failed attempts without a valid profile count as missing, never zero.
Queued, running, canceled and infrastructure-failed attempts do not count as
missing. Sampling errors and reporters that did not finish are partial profiles.
Profiles retain the top 40 process names by CPU seconds plus an aggregated
"(other)" entry, along with full-duration guest totals and busy-percent histograms.
Run overviews retain the top 20 names plus one "(other)" remainder.
Checkpoints are written every five seconds and on shutdown, so a runner killed
before shutdown can still leave a partial profile. Collection rejects files
larger than 64 KB. No image change or agent installation is required.

## Reading reserved-host diagnostics

```bash
cofactor external-run debug host <run-id>
cofactor external-run debug host <run-id> --json
```

For Sandboxes v2 runs, this reads host telemetry for each reservation the run
recorded, from a minute before its first reserved attempt was created through
a minute after its last one finished (or now while one is open). A window longer
than three hours is cut to its first three hours, and the report says so. Host
telemetry exists only for a reservation that held its own hosts. A missing
reservation, a reservation without its own hosts, a host that did not answer,
or telemetry in a format the report does not recognise each produce an
explicit reason for that reservation, not zero utilization; the other
reservations are still reported.

The report shows each reservation's state and live/saved source, host CPU
mean/p50/p90/max in cores (max is the maximum of minute means), CPU classes as percentages of busy CPU, memory used
maximum and available minimum, maximum running sandboxes, and disk/network
byte totals. Host history arrives in one-minute buckets aligned to the clock;
a bucket at the edge of the window may cover less than a minute. CPU
percentiles and means weight each bucket by the time it covers, so p50 and p90
describe minute averages, not instantaneous load. JSON includes one point per
bucket: mean busy cores, the most running sandboxes and the most memory used
in that minute. Nothing finer than a minute is reported.

The top ten attempts by host CPU seconds include test keys, `hostCpuSeconds`,
`hostMeanCores`, `hostStallSeconds` and peak RSS, measured by the host from outside
the copy's sandbox. `guestBusyCpuSeconds` is the copy CPU profile's busy CPU
from inside the guest (described above), shown alongside so the two can be
compared; it is `null` when no profile was collected. Attempts join by their
retained sandbox creation receipt, so teardown does not remove the association.
Serial/dependency groups share a sandbox; the listed test keys share its
measurements, which cannot be attributed to individual tests. Mean host cores
per passing/failing attempt averages all measured attempts of that outcome,
including retries, before the top-ten limit. Infrastructure failures and other
outcomes are excluded from these two means. Sandbox histories from unrelated
runs are not returned.

Per-attempt host figures are totals over the copy's sandbox. CPU and stall
totals include successful cgroup reads only, so a sandbox whose reads all
failed shows unknown (`null`), not zero, and is not ranked or averaged; peak RSS is `null` when it was never read. `aliveSeconds` runs
from the first sample to destruction, or to the window's edge when either
falls outside it (so `hostMeanCores` can be understated for a sandbox still alive
at the window's end), and `hostMeanCores` is host CPU over `aliveSeconds`. A sandbox
missing from telemetry, or with no samples, is not ranked. Each attempt names
its reservation because the list ranks across reservations. Per-host headers
retain `droppedAtCap` and `scanTruncated`: dropped history is incomplete, and a truncated scan makes the
CPU class split undercount. Class shares need not add up to 100 percent. Hosts
with nothing to show are counted in `unavailableHosts`.

Host telemetry is kept for 14 days after the reservation ends; Cofactor neither
stores nor caches it. Missing saved telemetry may have expired, or the host may
have stopped before saving it, and the reason explains both possibilities. Read
the report within that 14-day window. This command is read-only and uses your
existing org session, like `debug overview`.
