Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions agents/conductors/hygiene/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ names — and they keep reporting even when the repo-array modes are `unscanned`

| Mode | Pre-scan (kind) | Delegates to |
|------|-----------------|--------------|
| `ci` | the slowest parts of CI, read off the Heart board's published `performance` block — smoke-script rows (python legs folded; the slowest leg is the cost, since the gate waits for it), the slowest unit tests, and every gate's wall-clock median (**timing**). Each item carries its evidence (seconds, share of its leg, `cache_jax` state, run URL) and, when the script is checked out under the scan root, the *levers* read from its text: `env_knob` (an `os.environ.get` sizing knob → a `profile_smoke.yaml` `set:`), `simulates`, `jax_jit`, `full_datasets`, `real_search`, `subprocess`, `plots`. Reads Pages, `HYGIENE_HEART_BOARD`, or a local Heart checkout; an unreachable board is exit 3, never a clean zero. On demand only — never the default scan | `/ci_speedup` (executes one item through `/start_dev` → `ship_*`; a *slowdown* row is `/bug`'s, a hang is the board's kill-timer prompt) |
| `perf` | dev-loop timing — prefers Heart's tracked timing legs when present (`import_time`, `unit_test_timing`, `workspace_testmode_timing`), else times `import <pkg>` per library in a **subprocess** (**timing**) | `/refactor` / `/bug` (+ Heart timing legs) |
| `tidy` | git debris — stale branches, stashes, `[gone]` refs, dirty checkouts (**debris**) | **condemn** → files candidates into `condemned.md` async (PyAutoGut archives the fragile forms); no synchronous per-item gate |
| `sweep` | reads `condemned.md`, classifies entries by their transit clock (**due** / pending / undated) | `pyauto-gut void` for past-due entries, behind the existing `repo_cleanup` safety gates |
Expand All @@ -92,6 +93,7 @@ names — and they keep reporting even when the repo-array modes are `unscanned`
pyauto-brain hygiene # pre-scan across modes → ranked worklist
pyauto-brain hygiene perf # import cost (subprocess) → /refactor + Heart legs
pyauto-brain hygiene perf --profile <script> # cProfile a normal-mode run → rank NON-likelihood hotspots → /refactor
pyauto-brain hygiene ci [--top N] [--lane scripts|tests|gates|all] # slowest parts of CI from the Heart board → /ci_speedup
pyauto-brain hygiene tidy # git debris → condemn into condemned.md (async, no per-item gate)
pyauto-brain hygiene sweep # void condemned.md entries past sweep-after → pyauto-gut void (repo_cleanup gates)
pyauto-brain hygiene noise # CLI noise → /cli_noise_clean
Expand All @@ -118,6 +120,16 @@ the slow-test / slow-script signal is read from Heart, not re-run. A *standing*
Heart `import_time` (or `cli_noise`) leg — promoting the import pre-scan to a
tracked Heart signal — is a deferred optional follow-up (a PyAutoHeart change).

**`ci` (CI cost).** The Heart measures CI and publishes it (`board.json`
`performance`: `scripts.rows`, `unit.tests`, `gates`); this mode is the
conductor's read of that surface, and `_hygiene_ci.py` is the stdlib helper
behind it. It ranks, folds the python legs of a script into one candidate,
attaches the levers it can read from the script file, and hands each item to
`/ci_speedup` as a 📋. It never re-times CI and never edits a script — "measure
in Heart, act in hygiene", the same split as `perf`. The board's own caveats
travel with the item: a `cache_jax: miss` leg paid every compile, a cold
dataset cache paid the simulator inside the script's timing.

**`perf --profile <script>` (function profiling).** An on-demand action: run a
**normal-mode** script under `cProfile` in a subprocess (`HYGIENE_PYTHON`), then
rank the slowest dev-loop functions by *self* time as `/refactor` candidates (a
Expand Down
405 changes: 405 additions & 0 deletions agents/conductors/hygiene/_hygiene_ci.py

Large diffs are not rendered by default.

28 changes: 25 additions & 3 deletions agents/conductors/hygiene/hygiene.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# refs -> /refactor (folder-list drift in workspace prose: dead refs + undocumented folders)
# optdeps -> /refactor (smoke-listed scripts missing an optional-dep skip guard)
# extras -> /bug (optional deps a library declares that the smoke CI leg never installs)
# ci -> /ci_speedup (the slowest smoke scripts / unit tests / gates, read off the Heart board)
# The three Heart skills are read-only observation skills — measurement lives in
# Heart; hygiene routes and prioritises. perf's import timing runs in a
# SUBPROCESS, so the conductor itself never imports the science/JAX stack.
Expand All @@ -29,6 +30,7 @@
# hygiene.sh # pre-scan across modes -> ranked worklist (default)
# hygiene.sh perf # import-cost timing (subprocess) -> /refactor + Heart legs
# hygiene.sh perf --profile <script> # cProfile a script, rank NON-likelihood hotspots -> /refactor
# hygiene.sh ci [--top N] [--lane scripts|tests|gates|all] # slowest parts of CI from the Heart board -> /ci_speedup
# hygiene.sh tidy # git debris pre-scan -> condemn into condemned.md (async, no per-item gate)
# hygiene.sh sweep # void condemned.md entries past sweep-after -> pyauto-gut void (repo_cleanup gates)
# hygiene.sh noise # CLI-noise route -> /cli_noise_clean
Expand Down Expand Up @@ -445,17 +447,20 @@ prescan() {

# --- Arg parse. ----------------------------------------------------------------

mode="default"; json=0; profile_script=""; expect_script=0
mode="default"; json=0; profile_script=""; expect_script=0; ci_args=()
for arg in "$@"; do
if [[ "$expect_script" -eq 1 ]]; then profile_script="$arg"; expect_script=0; continue; fi
# ci takes its own flags (--top N, --lane L, --board SRC) — passed through to
# the helper verbatim, so they must not fall into the unknown-argument branch.
if [[ "$mode" == "ci" && "$arg" != "--json" ]]; then ci_args+=("$arg"); continue; fi
case "$arg" in
perf|tidy|sweep|noise|deps|docs|crlf|docstrings|escapes|refs|optdeps|extras|config|artifacts|packaging) mode="$arg" ;;
perf|tidy|sweep|noise|deps|docs|crlf|docstrings|escapes|refs|optdeps|extras|config|artifacts|packaging|ci) mode="$arg" ;;
default) mode="default" ;;
--json) json=1 ;;
--profile) mode="perf"; expect_script=1 ;;
--profile=*) mode="perf"; profile_script="${arg#*=}" ;;
-h|--help|help) mode="help" ;;
*) echo "hygiene: unknown argument '$arg' (modes: ${MODE_ORDER[*]}, --json, perf --profile <script>)" >&2; exit 2 ;;
*) echo "hygiene: unknown argument '$arg' (modes: ${MODE_ORDER[*]} ci, --json, perf --profile <script>, ci --top N --lane L)" >&2; exit 2 ;;
esac
done
if [[ "$expect_script" -eq 1 ]]; then
Expand Down Expand Up @@ -504,6 +509,23 @@ if [[ -n "$profile_script" ]]; then
run_profile "$profile_script"; exit $?
fi

# ci: the slowest parts of CI, read off the Heart board's published
# `performance` block (smoke-script rows, unit-test rows, gate wall-clocks) and
# ranked by the stdlib helper — one candidate per script (python legs folded),
# each carrying its evidence and, when the script is checked out under the
# scan root, the levers read from its text. Measurement stays in Heart; this
# mode ranks and routes to /ci_speedup, which drives the fix through the dev
# flow. Network (Pages) or a local Heart checkout — never the default scan.
run_ci() {
local -a extra=("$@")
if [[ "$json" -eq 1 ]]; then extra+=(--json); fi
python3 "$HERE/_hygiene_ci.py" --scripts-root "$ROOT" "${extra[@]}"
}

if [[ "$mode" == "ci" ]]; then
run_ci "${ci_args[@]}"; exit $?
fi

# --- PyAutoGut drive seam: tidy (condemn) + sweep (void). ----------------------
# The conductor stays a planner: it enumerates candidates / reads the manifest
# and EMITS the plan (condemned.md entries + the exact pyauto-gut commands). The
Expand Down
13 changes: 11 additions & 2 deletions skills/COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,17 @@ audit-first and confirmation-gated:
*spawned* a still-open issue. The Brain board surfaces the open-issue count
and points here; the audit itself stays this door's job.

These two are complements, not overlaps: `/repo_cleanup` never touches issues,
`/issue_cleanup` never touches git. Neither handles **external** users' issues —
- **`/ci_speedup`** — the **CI clock**: the slowest smoke scripts, unit tests
and workflow gates, read off the Heart board's published timings by the
Hygiene Agent's `ci` mode (`pyauto-brain hygiene ci`), then fixed one item
at a time through `/start_dev` → `ship_*` — a smoke-profile override, an
in-script reduction, a cache or workflow change — with the number re-timed
under the smoke profile before it ships. Never demotes or skips a script to
get the number down (a coverage decision, a human's), never touches the
likelihood compute (`/profiling`'s), and a *slowdown* row is `/bug`'s.

These are complements, not overlaps: `/repo_cleanup` never touches issues,
`/issue_cleanup` never touches git, `/ci_speedup` touches neither. Neither handles **external** users' issues —
that is `/community`, whose drafts stay human-approved.

Codex skills also expose the remaining public CLI agents directly: the `clone`
Expand Down
13 changes: 13 additions & 0 deletions skills/ci_speedup/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: ci-speedup
description: Pick the slowest parts of CI off the PyAutoHeart board — smoke scripts, unit tests, workflow gates — name why each is slow, and drive the speed-up through the dev flow (a smoke-profile override, an in-script reduction, a cache or CI change), re-timing under the smoke profile before it ships. Use for "why is CI slow", "speed up the smoke tests", or the periodic CI-cost sweep; never for modelling speed (that is /profiling).
---

# CI speed-up

Follow [`ci_speedup.md`](ci_speedup.md) exactly. The Hygiene Agent's `ci`
mode ranks CI cost from the Heart's published measurements and hands out one
📋 per item; this skill is the executor that takes an item, reads the script or
test, names the cost, and drives the fix through `/start_dev` →
`ship_workspace` / `ship_library`. Measurement stays in Heart, the ranking
stays in the Brain, and no fix ships un-timed.
127 changes: 127 additions & 0 deletions skills/ci_speedup/ci_speedup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# /ci_speedup — find the slowest parts of CI and make them faster

A **maintenance door** (see `PyAutoBrain/skills/COMMANDS.md` §5): the Hygiene
Agent reasons about CI cost and *ranks*; this skill *executes*, one item at a
time, through the ordinary dev flow. It is the CI-time counterpart of
`/repo_cleanup` (git debris) and `/issue_cleanup` (tracker debris).

Shared routing context: `PyAutoBrain/skills/COMMANDS.md`.

**Where the numbers come from.** PyAutoHeart measures CI and publishes the
⏱ surface as the `performance` block of its board (`board.json`, schema v3):
per-script smoke timings per python leg, the slowest unit tests, and every
workflow's wall-clock distribution. Nothing here re-times CI and nothing here
scrapes a job log — a number that is not on the board is not a finding.

**Boundary.** This is the *developer loop's* cost — how long a gate keeps a
contributor waiting. The modelling/likelihood speed of the product is
`/profiling`; a hotspot inside `log_likelihood_function` / the JAX compile of a
fit is that agent's, and a speed-up that would change what a script *asserts*
is not a speed-up — it is a coverage cut, and it needs a human.

## Do

### 1. Rank

```bash
bin/pyauto-brain hygiene ci # top 3 per lane, all three lanes
bin/pyauto-brain hygiene ci --top 5 --lane scripts
bin/pyauto-brain hygiene ci --json # the HygieneDecision, machine-readable
```

Reads the published board (Pages), or `HYGIENE_HEART_BOARD=<path|url>`, or a
local Heart checkout's `board/board.json`. One candidate per script — the
python legs are folded and the **slowest leg is the cost**, because the legs
run in parallel and the gate waits for the slower. Each item carries its
evidence (seconds, share of that leg's total, `cache_jax` state, run URL) and,
when the script is checked out under `PYAUTO_ROOT`, the **levers** read from
its text (`env_knob`, `simulates`, `jax_jit`, `full_datasets`, `real_search`,
`subprocess`, `plots`). Pick the item you were handed, or the top one.

Read the board's caveats before believing a number: a `cache_jax: miss` leg
paid every compile in full, a cold dataset cache paid the simulator inside
the script's own timing, and `verdict: stale` means the Heart has not looked
recently. The `slowed` rows and hang `events` are separate signals — a
*slowdown* routes to `/bug` (something changed), a hang to the kill-timer
prompt the board already carries. This skill is for the standing cost.

### 2. Name the cost (measure locally, under the smoke profile)

Reproduce the CI number before touching anything — a fix to a cost you have
not seen is a guess. Run the script exactly as CI does: the repo's
`config/build/profile_smoke.yaml` defaults plus the script's own `__Env__`
declaration (`ENV: jax full_datasets` releases `PYAUTO_DISABLE_JAX` and
`PYAUTO_SMALL_DATASETS`; `real_search` releases `PYAUTO_TEST_MODE`), the
libraries on `PYTHONPATH` from source, a **cold** `JAX_COMPILATION_CACHE_DIR`
for the first run and a warm one for the second. Then:

- `python -m cProfile -o run.prof <script>` and rank by cumulative time —
`pyauto-brain hygiene perf --profile <script>` does this and applies the
likelihood-exclusion filter for you.
- Vary the levers the ranker named (`DELAUNAY_NN_CAP_RANDOM_SAMPLES=10`, a
pre-simulated dataset, a warm cache) and time each. The delta *is* the cost.

Write the split down: **compile / simulate / search / repeated construction /
plots / assertions**. A fix that does not name which of these it removes is
not ready.

### 3. Choose the lever (smallest change that keeps the assertion)

| Cost | Lever | Where the change lives |
|------|-------|------------------------|
| A sizing knob the script already reads (`os.environ.get`) | `set:` it lower in `profile_smoke.yaml` under a `pattern:` for that script | workspace `config/build/profile_smoke.yaml` (validator keys: `pattern`, `set`, `unset`) |
| Simulation inside the timing (`should_simulate` + subprocess) | keep the dataset cache warm (`pyauto-datasets-*` key), or make the simulator cheap under `PYAUTO_TEST_MODE` | Heart `smoke-tests.yml` cache keys; the simulator script |
| Compile paid in full (`cache_jax: miss`) | fix the cache key/restore, or cut *distinct* compiles (same shapes → one trace; one `jit` per shape, not per call) | Heart `smoke-tests.yml`; the script |
| Same expensive object built N times (datasets, image meshes, factor graphs) | build once, reuse — `functools.lru_cache` on the builder, or hoist out of the loop | the script |
| The search really runs (`real_search`) | cap iterations / live points for smoke via the profile, or declare `real_search` only where the assertion needs it | the script's `__Env__` / profile |
| A whole leg is slow, no single script stands out | look at `setup_s` (fixed overhead) and the per-leg `total_s` on the board; the fix is the workflow, not a script | Heart `smoke-tests.yml` |
| A unit test (`--lane tests`) | smaller fixture, fewer iterations, `pytest.mark.slow` **only** if the suite already has the marker gate — never skip | the library's tests |

**Never**: skip, disable, quarantine or demote a smoke script or test to get
the number down (the `no_run.yaml` / `smoke_tests.txt` route is a coverage
decision a human makes, with the reason written where the entry is); change
what an assertion checks; raise a cap so a slow thing hides; "fix" a
`mode=smoke`-only failure in the script when release passes (that is
`/hygiene extras`, a CI install problem).

### 4. Ship it through the dev flow

The change is ordinary development. Route it:

```bash
# a workspace script or its profile_smoke.yaml
/start_dev → /start_workspace → edit → re-time (step 2, cold + warm) → /ship_workspace
# a library test
/start_dev → /start_library → edit → pytest the file → /ship_library
# a Heart workflow / cache key
/start_dev → PyAutoHeart branch → /ship_library
```

In a remote session with no worktree, file the item instead: `/intake` the
📋 line with the measured split and the chosen lever as a
`draft/refactor/<target>/` prompt — the ranking plus the measurement is the
deliverable; the fix is the next session's `/start_dev`.

Before pushing: the script still passes under the smoke profile **and** the
release profile where it applies (`ENV:` tokens are honoured by both), the
assertion text is unchanged, and the new local timing is in the commit
message (before → after, cold and warm).

### 5. Report

One line per item: `repo/entry before → after (cold/warm) lever PR/prompt`.
Then stop. The next Heart tick re-measures; the board is the record, and the
`slowed`/`ok` state on the next render is the verification — do not arm a
watcher for it.

## Boundaries

- **vs hygiene** — hygiene ranks and routes (`hygiene ci`); this door executes.
Hygiene never edits source; this skill does, through `start_dev`/`ship_*`.
- **vs profiling** — profiling owns the science-grid likelihood, GPU tiers and
baselines. If the cost is inside the likelihood compute, hand it over.
- **vs health** — Heart observes and verdicts; a red gate is `/health`'s. This
door only touches gates that are *green and slow*.
- **vs bug** — a *slowdown* (the board's `slowed` rows: this run ≥ 1.5× the
previous, ≥ the min delta) is a regression, so it is `/bug`'s; this door owns
the standing cost that was always there.
6 changes: 4 additions & 2 deletions skills/hygiene/hygiene.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ Shared routing context: `PyAutoBrain/skills/COMMANDS.md`.

## Do

1. Run `bin/pyauto-brain hygiene [perf | tidy | noise | deps | docs | crlf |
1. Run `bin/pyauto-brain hygiene [perf | ci | tidy | noise | deps | docs | crlf |
docstrings | escapes | refs | optdeps | extras | config | artifacts | packaging]` (no arg = pre-scan across modes → a ranked worklist;
perf's import timing is deferred there). This is a **dry run** — each mode
perf's import timing and `ci` are deferred there — `ci` reads the Heart
board's published CI timings and ranks the slowest smoke scripts, unit
tests and gates, one 📋 each for `/ci_speedup`). This is a **dry run** — each mode
does a cheap read-only pre-scan and emits a `HygieneDecision` naming the
skill to run for the full audit. Nothing is executed or mutated. (`crlf` =
executable scripts w/ CRLF that break on HPC — library `.py` CRLF reported as
Expand Down
Loading
Loading