Skip to content

feat: permanent CI timing history committed to PyAutoHeart (timings/ record) #204

Closed

Description

@Jammy2211

Overview

The ⏱ performance surface now has both timing slices — workflow-level gates (ci_timing) and per-script smoke timings (smoke_timings, #202 / #203) — but its only "history" is the self-carried window: the aggregate steps re-read the previously published Pages board.json, cap the gate history at 30 entries and keep exactly one previous per-script observation. A publish gap loses it and nothing is ever committed. This task builds the permanent record: the daily heart-health.yml run appends the day's observations to committed, append-only files under timings/ in this repo, the two checks read their baselines from that record (the Pages self-carry becomes a fallback cache), and the board links to it.

Phase 2 of the ci-timing-fast-tests epic (PyAutoMind/draft/feature/pyautoheart/ci_timing_fast_tests_epic.md). Design reference: Plane C ("durable baselines") of PyAutoMind/docs/pyautoheart/test_performance_board_assessment.md.

Plan

  • Add heart/timings.py: a pure append-only record with two shapes — a per-day gates line (timings/gates.jsonl) and a per-repo, per-run scripts line (timings/scripts/<repo>.jsonl) — plus readers that hand the two checks their baselines.
  • Dedupe on identity, not date: a gates line per date; a scripts line per (python leg, run_id). A quiet week must not write seven copies of one run (the script_timing "one value repeated seven times" defect, phase 0 of the board arc).
  • Make ci_timing and smoke_timings read the committed record first and the previous board.json only as fallback; keep the board.json shape unchanged so the Brain board and the dashboard tests are untouched.
  • Wire one workflow step after the checks that appends today's observations and commits timings/ on main only, in the same commit as the README badge update (one commit per day, [skip ci], stable line ordering, no rewrite of past lines).
  • Document the record in timings/README.md (schema, dedupe rule, how to read it) and reserve the place phase 4 will mark the LEGACY epoch boundary.
Detailed implementation plan

Affected Repositories

  • PyAutoHeart (primary, only)

Work Classification

Library (organ code) — no workspace follow-up.

Branch Survey

Repository Current Branch Dirty?
./PyAutoHeart main @ 7a286ea clean

Branch: claude/ci-test-timing-epic-ke2lul (designated for the epic; restarted from the merged main; cloud session, no task worktree).

The record (timings/)

timings/
  README.md               # schema + the rules below (doctrine, not a ledger entry)
  gates.jsonl             # one line per UTC date
  scripts/<repo>.jsonl    # one line per (python leg, run id) observation
  • gates.jsonl line — {"date": "2026-09-06", "ts": "...", "gates": {"<repo>/<workflow>": {"p50_s", "pr_median_s", "max_s", "queue_median_s", "runs"}}} — exactly the per-gate figures ci_timing.roll_history already stores per day, plus pr_median_s/max_s/queue_median_s. Keyed by date: re-running the same day replaces nothing — the append is skipped when the date is already present (the workflow runs once a day; a manual re-dispatch must not double-write).
  • scripts/<repo>.jsonl line — one per leg observation: {"date", "at", "python", "run_id", "run_url", "head_branch", "head_sha", "env_profile", "entries": {"<entry>": [seconds|null, "<status>", cap_s|null]}} with entries sorted by path. Keyed by (python, run_id): a day whose newest artifact is the same run as yesterday's appends nothing for that leg. This is the whole point of phase 1 stamping run_id on every row.
  • Append-only: append_* functions only ever add lines; a test asserts that existing lines are byte-identical after an append. Lines are compact single-line JSON with sorted keys so a daily diff is one or a few added lines. Files are created on first use; a missing file is an empty record.
  • Growth shape: gates ≈ 1 line/day (~3 KB); scripts ≤ 2 lines/day/repo (~2–5 KB each) — reviewable for years; note in the README when to consider yearly sharding (not now).
  • Phase 4 reservation: the README names timings/epochs.jsonl as the place a labeled epoch boundary (e.g. {"date", "label": "legacy", "note"}) will live, so drift never fires across it; do not create it here.

Implementation Steps

  1. heart/timings.py (stdlib only, pure core + thin I/O):

    • TIMINGS_DIR = HEART_HOME / "timings", GATES_FILE, scripts_file(repo).
    • read_jsonl(path) -> list[dict] (tolerates a missing file and skips unparseable lines, counting them so the caller can report them).
    • gates_line_from_rollup(rollup, today, ts) -> dict (from ci_timing.json's gates, only gates with a numeric median_s); append_gates(path, line) -> bool (False when date already present).
    • scripts_lines_from_rollup(rollup) -> dict[repo, list[line]] (from smoke_timings.json's repos + rows: one line per (repo, python, run_id) with non-empty run_id; entries include untimed rows with null seconds so coverage is recorded); append_scripts(path, lines) -> int (count appended; skip lines whose (python, run_id) is already present).
    • Readers for the checks: gates_history(path, cap) -> list[dict] in the exact shape ci_timing.history_baseline/_gate_spark consume ({"date", "gates": {key: {"p50_s", "runs"}}}, oldest first, last cap lines); previous_script_rows(scripts_dir) -> dict[(repo, python, entry) -> {seconds, run_id, run_url}] = for each repo file, the latest line per python leg, in the shape smoke_timings.prev_rows_of returns.
    • main(argv): append --ci-timing FILE --smoke-timings FILE [--today YYYY-MM-DD] [--ts ISO] [--dir DIR] (prints one summary line: timings: gates +1 line, scripts +N lines across M repos, K skipped (already recorded)), and show [--dir DIR] (a one-screen census: line counts per file, first/last date).
  2. heart/checks/ci_timing.py — aggregate(...) gains record_history: list | None = None: when given (non-empty) it is the history source; the previous board's history is used only when the record has no lines. main --aggregate gains --record-dir DIR (default HEART_HOME/timings) and loads gates_history(record/gates.jsonl, cap). roll_history still runs so board.json keeps its performance.history (the cache/fallback and the Brain board's sparkline input) — shape unchanged.

  3. heart/checks/smoke_timings.py — aggregate(...) gains record_prev_rows: dict | None = None, preferred over prev_rows_of(prev_board) when non-empty; main --aggregate gains --record-dir DIR. The board.json performance.scripts block is unchanged.

  4. Shell legs — ci_timing.sh and smoke_timings.sh pass --record-dir "$HEART_HOME/timings" in their aggregate calls (the record lives in the checkout the workflow runs from; on a dev box the same checkout).

  5. .github/workflows/heart-health.yml:

    • New step right after the checks and before the aggregate/render steps? No — the checks' aggregate passes already read the record for baselines, and today's observation must not be in the baseline it is compared against (ci_timing excludes today's date; scripts compare by run id, so ordering is safe either way). Put the step after "Run cloud-safe checks" and before "Aggregate snapshot": PYTHONPATH="$PWD" python -m heart.timings append --ci-timing "$HEART_STATE_DIR/ci_timing.json" --smoke-timings "$HEART_STATE_DIR/smoke_timings.json".
    • The README step becomes "Commit the README block + today's timing record (own repo only, main only)": git add README.md timings/ and a commit message docs(heart): daily board block + timing record [skip ci]; the git diff --quiet guard covers both paths (git status --porcelain README.md timings/). Header comment updated. Nothing else in the job order moves.
    • Consider (and reject, with a comment) committing from the dev-box tick: only the workflow appends, so the record has one writer.
  6. Dashboard — heart/dashboard.py: the CI wall-clock and Smoke scripts sections gain one detail line record: timings/ (<n> days of gates, <m> script observations) when snapshot["timings_record"] is present; heart/state.py aggregates a small timings_record census written by heart.timings append ($HEART_STATE_DIR/timings_record.json: {gates_days, scripts_observations, repos, appended_today: {...}}). Absent → no line (an older snapshot renders identically). Nothing else on the board changes.

  7. timings/README.md — schema, the two dedupe keys and why (the phase-0 lesson), append-only rule (ledger, never edited by hand; a wrong line is superseded by a later one, never rewritten), the epochs.jsonl reservation for phase 4, and how to read it (python -m heart.timings show, jq).

  8. Tests — tests/test_timings.py (fake names): gates line built from a rollup and skipped on a repeated date; scripts lines built per (repo, python, run_id), skipped on a repeated (python, run_id), appended for a new run of the same leg; existing bytes untouched after append (read the file before/after and assert prefix equality); sorted keys / single line per record; missing files = empty record; unparseable line skipped and counted; gates_history shape matches what ci_timing.history_baseline and dashboard._gate_spark read (feed it to them); previous_script_rows picks the latest line per leg and matches smoke_timings.classify_drift's expectations; main append writes both files and the census, prints the summary, and is idempotent when run twice with the same inputs. tests/test_ci_timing.py + tests/test_smoke_timings.py: record preferred over prev board, prev board used when the record is empty. tests/test_heart_health_wiring.py: the append step exists between the checks and the aggregate step, and the commit step adds timings/. Existing tests unmodified.

Key Files

  • heart/checks/ci_timing.py:398-500 (history_baseline, roll_history, prev_history_of, aggregate) and heart/checks/smoke_timings.py (prev_rows_of, classify_drift, aggregate) — the readers the record feeds.
  • .github/workflows/heart-health.yml — the README commit step (git add README.md, [skip ci]) is the commit pattern to extend.
  • heart/publish.py — the other committed-state precedent (state/devbox_board.json).
  • tests/test_heart_health_wiring.py — the wiring assertions from phase 1 to extend.

Out of scope

  • The legacy epoch marker and the first labeled snapshot (phase 4).
  • Sharding the record by year, or a Pages "history" page beyond the record link.

Original Prompt

Click to expand starting prompt
# Permanent CI timing history stored in PyAutoHeart

Type: feature
Target: PyAutoHeart
Repos:
- PyAutoHeart
Difficulty: medium
Autonomy: safe
Priority: high
Status: formalised
Consequence: judge
Review-minutes: 20
Unattended: ready
Epic: ci-timing-fast-tests
Phase: 2

Permanent CI timing history stored in PyAutoHeart (replace the 30-day self-carried window).

Today the only "history" is the performance block's rolled-forward window: the aggregate
step re-reads the previously published Pages `board.json` (`heart/checks/ci_timing.sh:64-79`)
and caps at 30 entries (`history_cap: 30`) — a publish gap loses it and nothing is ever
committed to the repo. The user's intent: run-time information on all CI tests tracked with
the nightly run and stored in PyAutoHeart as a PERMANENT record, with the dashboard showing
the most recent times but having access to all history.

Build the durable record: the daily heart-health run appends the day's observations (the
workflow-level gates from ci_timing AND the per-script rows from the phase-1 ingester) to
committed history files in the PyAutoHeart repo (e.g. under `state/` or a dedicated
`timings/` tree — append-only, compact JSON/JSONL per repo, committed by the workflow the
way `state/devbox_board.json` already is). The board keeps rendering the recent window but
links/reads from the committed record; the 30-day Pages self-carry becomes a cache, not the
source of truth. Design reference: Plane C ("durable baselines") of
`PyAutoMind/docs/pyautoheart/test_performance_board_assessment.md`.

Mind the file-growth shape: daily append across ~26 gates + a few hundred script rows must
stay reviewable (one commit/day, stable ordering, no churn of past lines).

Activity

  1. Jammy2211 commented on Sep 5, 2026

    @Jammy2211
    ContributorAuthor

    Shipped

    PyAutoHeart#205 → 7b4e109, merged 2026-09-05 (CI green on both matrix legs; suite 735 → 767).

    • heart/timings.py + timings/README.md — the permanent, append-only timing record: timings/gates.jsonl (one line per date, every tracked gate's medians) and timings/scripts/<repo>.jsonl (one line per python leg × run id, every timed script's seconds/status/cap with run provenance). Dedupe on identity (date; python leg + run id), never on the day.
    • ci_timing and smoke_timings read their baselines from the record first; the published board.json is the fallback. The performance block shape is unchanged.
    • heart-health.yml appends today's observations after the checks and commits timings/ beside the README block — one [skip ci] commit a day, single writer.
    • Board: one record: … detail line under each timing row from the census; absent census renders byte-identically.
    • timings/epochs.jsonl is reserved (not created) for phase 4's labeled LEGACY epoch boundary.

    The data files are created by the first scheduled run after this merge; check that the next daily commit carries them.

    Phase 2 of the ci-timing-fast-tests epic; phase 3 (bring the dead timing legs live) is next.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions