Repository navigation
Description
Overview
autonerves/jax_wrapper.py already writes a persistent JAX compilation cache (JAX_COMPILATION_CACHE_DIR, default ~/.cache/pyauto_jax, JAX_PERSISTENT_CACHE_MIN_COMPILE_TIME_SECS=1), certified by the closed jax-compile-time arc at 51× local / 5.9× A100. The one reusable smoke workflow every workspace / _test / HowTo gate calls — .github/workflows/smoke-tests.yml — has no actions/cache step, so the cache helps only within one job and is discarded between runs. Likewise dataset/ is gitignored in every workspace, so CI clones fresh and should_simulate re-simulates every dataset family on every run (~10–20 s per family including import).
The legacy digest (timings/legacy_round_2026-09.md, #209) shows where that lands: in both _test flagships the time sits in ~15 compile-dominated jax_likelihood scripts (autogalaxy_test 537 s / 39 scripts; autolens_test 435 s / 27). This task adds both caches to the reusable workflow, records the cache state into the timing artifact so every ingested row says whether it ran hot or cold, and lets the record measure the win honestly. Phase 7 of the ci-timing-fast-tests epic, pulled forward before the phase-5/6 rebuild waves per the epic ledger's review (the waves then target what remains once compile is cached, and their before/after is measured on one cache state).
Plan
smoke-tests.yml: restore/save the JAX compile cache (explicitJAX_COMPILATION_CACHE_DIRunder the job workspace) keyed on runner OS × Python leg × jaxlib version × a manual epoch salt; restore/saveworkspace/datasetkeyed on the hash of the simulator scripts × the dependency-chain HEAD SHAs × the salt. Every cache step non-fatal — the workflow is referenced@mainby eleven repos.- Write
test-results/cache_state.jsonafter the runner (restored key, hit/miss, sizes before/after) so it rides the existingsmoke-timings-<py>artifact. smoke_timingsingests it: legs/rows/record lines gain an additivecachefield; drift is not classified across differing known cache states (a cold run after a hot one is not a regression); the board's per-repo lines sayjax cache hit/miss.- Measure after merge from the record: hit vs miss per-script seconds and gate wall-clock, and the restore/save overhead on the small repos.
Detailed implementation plan
Affected Repositories
- PyAutoHeart (primary, only). The workspaces inherit through the reusable workflow — no per-workspace change. PyAutoNerves is named in the prompt but needs no change: its default cache location is simply overridden by the workflow env.
Work Classification
Library (organ code / CI infrastructure) — no workspace follow-up.
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoHeart | main @ ad56720 | clean |
Branch: claude/ci-test-timing-epic-ke2lul (designated for the epic; restarted from main; cloud session, no task worktree).
Facts the design rests on
- The smoke runner builds each script's env from
os.environ.copy()plus the profile (PyAutoHands/autohands/env_config.py), so a job-levelJAX_COMPILATION_CACHE_DIRreaches every script subprocess;autonerves/jax_wrapper.pyonly sets its default when the var is absent. should_simulate(PyAutoArray/autoarray/util/dataset_util.py) keeps a dataset only when itsSMALLDATstamp/shape matches the regime in force; a restored small-regime dataset is reused by small-regime scripts and deleted+re-simulated by full-regime ones — exactly today's within-job behaviour, so restoringdataset/changes nothing about correctness, only about how often the first script of each family pays the simulation.- Simulators live at
**/simulator*.py,**/simulator/**,**/simulators/**in the workspaces (e.g. autolens_workspace_test has 18 such files);dataset/**is gitignored with an!allowlist for real/external data. - The
smoke-timings-<py>upload already globsworkspace/test-results/, so a new sidecar file there ships with no change to the upload.
Implementation Steps
-
smoke-tests.yml— job-level env:PYAUTO_CACHE_EPOCH: "1"(the manual salt; bump to invalidate every cache at once — comment says so) andJAX_COMPILATION_CACHE_DIR: ${{ github.workspace }}/.pyauto_jax_cacheon the runner step's env (besideJAX_ENABLE_X64), with a comment that autonerves would otherwise default to~/.cache/pyauto_jax; an explicit workspace path is what the cache step can name. -
Step "Resolve cache keys" (after "Install",
id: keys,continue-on-error: true):jaxlib=$(python -c 'import jaxlib; print(jaxlib.__version__)' 2>/dev/null || echo nojax)→ outputjaxlib.- chain hash:
for dep in ${{ inputs.chain }}; do git -C "$dep" rev-parse HEAD; done | sha256sum | cut -c1-16→ outputchain(the inputs.chain value reaches the shell throughenv:, never interpolated intorun:; the existing clone step's pattern is the model). - simulator hash:
${{ hashFiles('workspace/**/simulator*.py', 'workspace/**/simulator/**', 'workspace/**/simulators/**') }}→ outputsims(empty when a workspace has none — the dataset cache then keys on the chain only, which is still correct).
-
Step "Restore the JAX compile cache" —
actions/cache/restore@v4,id: jax-cache,continue-on-error: true,path: ${{ github.workspace }}/.pyauto_jax_cache,key: pyauto-jax-${{ runner.os }}-py${{ matrix.python-version }}-jaxlib${{ steps.keys.outputs.jaxlib }}-e${{ env.PYAUTO_CACHE_EPOCH }}-${{ github.run_id }},restore-keys: pyauto-jax-${{ runner.os }}-py${{ matrix.python-version }}-jaxlib${{ steps.keys.outputs.jaxlib }}-e${{ env.PYAUTO_CACHE_EPOCH }}-. Comment: the run-id suffix makes every save a fresh superset (the standard accumulating-cache pattern); traced-code changes miss individual entries naturally, which is correct; the jaxlib version is in the key because a compiled executable is jaxlib-specific. -
Step "Restore simulated datasets" —
actions/cache/restore@v4,id: dataset-cache,continue-on-error: true,path: workspace/dataset,key: pyauto-datasets-${{ runner.os }}-e${{ env.PYAUTO_CACHE_EPOCH }}-sim${{ steps.keys.outputs.sims }}-chain${{ steps.keys.outputs.chain }}-${{ github.run_id }},restore-keys:the same prefix without the run id and nothing broader — a different simulator or library commit must miss (correctness over hit rate; comment says why). Not keyed on the Python leg: simulated FITS do not depend on the interpreter minor. -
Runner step unchanged apart from the env var in step 1.
-
Step "Record cache state (unit of the timing dataset)" —
if: always(),continue-on-error: true, after the runner, before the upload: writesworkspace/test-results/cache_state.json={"schema": "cache_state/1", "epoch": "<salt>", "jax": {"path", "restored_key": "<cache-matched-key or ''>", "hit": <bool: matched key non-empty>, "exact": <bool: cache-hit == 'true'>, "size_mb_before", "size_mb_after", "entries_before", "entries_after"}, "datasets": {same fields}}. Sizes viadu -sm, entry counts viafind -type f | wc -l; the "before" figures are captured by a tiny step right after the restores (id: cache-before, outputs) so the record step can compare. A Python heredoc reading the figures from env vars (never${{ }}inside the script body). -
Save steps —
actions/cache/save@v4withcontinue-on-error: true: JAX cacheif: always()(a compiled entry is complete or absent; a red script does not poison it) and datasetsif: success()only (a killed simulator can leave a truncated FITS thatshould_simulatewould then keep). Both skip the save when nothing changed (entries_after == entries_before && size_after == size_before→ the step'sif:reads the record step's outputs) so an unchanged cache is not re-uploaded on every run. -
Heart ingester (
heart/checks/smoke_timings.py) — additive:parse_cache_state(text) -> (dict|None, error)validatingschema == "cache_state/1", normalised to{"jax": {"hit": bool|None, "restored_key": str}, "datasets": {...}, "epoch": str}.read_downloaded_legalso readscache_state.jsonwhen present → legcache: {"jax": "hit"|"miss"|"unknown", "datasets": "hit"|"miss"|"unknown", "epoch": str}(unknownwhen the file is absent — a run from before this shipped).aggregate: eachrepos[]item and eachrows[]item gainscache({"jax", "datasets"}on the item;cache_jaxon the row for the field that matters to compile time).classify_driftgainsprev_cache/cacheawareness through a thin wrapper: when both the previous and current jax cache states are known and differ, no comparison (ok, no ratio) — a cold run after a hot one is not a regression and must not raise awarn. Prompts and events unchanged.- Board (
heart/dashboard.py_smoke_timings_section): the per-repo line gains[jax cache hit]/[jax cache miss]when known; nothing when unknown (older snapshots byte-identical). heart/timings.py:scripts_lines_from_rollupwritescache: {"jax", "datasets"}on each record line (absent →"unknown");previous_script_rowsreturnscache_jaxon each prev row so the drift rule can read it. README: the field and the "never compare across cache states" rule.
-
Tests —
tests/test_workflow_wiring.pyor a newtests/test_smoke_tests_wiring.py: the two restore steps exist withcontinue-on-error, the JAX key names the Python leg, jaxlib and the epoch salt, the dataset key names the simulator hash and the chain hash and has no broad restore-key, the runner env setsJAX_COMPILATION_CACHE_DIRunder the workspace, the record step isif: always(), the dataset save isif: success(), the JAX saveif: always(),PYAUTO_CACHE_EPOCHis declared.tests/test_smoke_timings.py: cache-state parse, legcachefrom a downloaded dir with/without the file, rows/items carry it, drift skipped across differing known states and classified normally when equal or unknown;tests/test_timings.py: record line carriescache,previous_script_rowsreturnscache_jax;tests/test_dashboard.py: the bracket suffix only when known. Fake names throughout; existing tests unmodified. -
Validate:
yaml.safe_loadon the workflow, full suite green (baseline 864), tenant firewall OK. After merge (judgment tier): the first PR run on a_testrepo is a miss (saves), the second a hit; compare the per-script seconds of thejax_likelihoodclass and the gate p50 across the two in the record, and thesize_mb/restore overhead for autocti_workspace_test (3 entries) — write the numbers into the issue's Shipped comment and the epic ledger.
Out of scope
- Any change to script content, datasets or pins (phases 5/6).
- Caching pip installs (setup-python already caches wheels in
lib-tests.yml; the smoke install epilogue is workspace-owned and out of this phase).
Original Prompt
Click to expand starting prompt
# CI caches in the reusable smoke workflow: JAX compile cache + dataset builds
Type: feature
Target: PyAutoHeart
Repos:
- PyAutoHeart
- PyAutoNerves
Difficulty: large
Autonomy: safe
Priority: high
Status: formalised
Consequence: judge
Review-minutes: 25
Unattended: needs-slicing
Epic: ci-timing-fast-tests
Phase: 7
CI caches in the reusable smoke workflow: persist the JAX compile cache and dataset builds across runs.
`autonerves/jax_wrapper.py:98-125` already auto-writes a persistent JAX compilation cache
to `~/.cache/pyauto_jax` (JAX_PERSISTENT_CACHE_MIN_COMPILE_TIME_SECS=1), and the closed
jax-compile-time arc certified the cache at both scales (51x local, 5.9x A100 end-to-end).
But `PyAutoHeart/.github/workflows/smoke-tests.yml` — the one reusable workflow every
workspace/_test/HowTo smoke gate calls — has NO actions/cache step: the cache helps within
one job (scripts are subprocesses) and is discarded between runs.
1) Add an `actions/cache` step for `~/.cache/pyauto_jax`, keyed on jaxlib version + python
matrix leg (+ a manual epoch salt for invalidation). Expected: removes the 12-18s+ compile
from every `ENV: jax` script on cache-hit runs — plausibly 30-50% off the jax_likelihood
wall total. Traced-code changes miss the cache naturally, which is correct. (Run
33078033016 already refuted any interaction between the cache and the Eigen-pool hang.)
2) Same mechanism for simulated dataset builds: `should_simulate` auto-simulation persists
datasets locally but CI runners start clean, so each job re-simulates each dataset family
(~10-20s incl. import per family). Cache the dataset build trees keyed on a hash of the
simulator scripts so any simulator edit invalidates.
3) Measure honestly: compare cache-hit vs cache-miss gate wall-clock on the phase-1/2
timing surface, and confirm cache restore/save overhead doesn't eat the win for the small
repos (autocti: 3 entries).
Activity
Jammy2211 commentedon Sep 6, 2026
Shipped
PyAutoHeart#211 →
bfcd302, merged 2026-09-06 (CI green on both matrix legs; suite 864 → 893).smoke-tests.yml(reusable, called by eleven repos): the JAX persistent compile cache is restored/saved per runner OS × Python leg × jaxlib ×PYAUTO_CACHE_EPOCH, run-id suffixed (accumulating), saved even on red runs; the workspace's simulateddataset/tree is restored/saved keyed on the simulator-script hash × dependency-chain SHAs × the salt with no broader fallback, saved only on green runs.JAX_COMPILATION_CACHE_DIRis an explicit workspace path in the runner env. Every new step iscontinue-on-error; the runner command is unchanged; the diff is purely additive.test-results/cache_state.jsonrides the existing smoke-timings artifact;smoke_timings, thetimings/scriptsrecord and the board carrycacheon every leg/row ([jax cache hit|miss]), and drift is never classified across two known but different cache states.Measurement (item 3 of the prompt) is pending live runs: the first PR run on each repo after this merge is a miss that saves; the second restores. Compare the
jax_likelihoodper-script seconds and gate p50 hot vs cold intimings/scripts/andtimings/gates.jsonl(the rows now say which they were), and the restore/save overhead on autocti_workspace_test. Numbers go into the epic ledger when they exist.Phase 7 of the
ci-timing-fast-testsepic; phase 5 (the autogalaxy_workspace_test physical+fast rebuild) is next.Generated by Claude Code