python-idle-audit-never-done
The "NEVER-DONE" audit had no scripted, idempotent mechanism behind it. The fix is audit_board.py — a DuckDB-backed board updater that finally performs the due-cycle audit for tick #179 and encodes the three contract points from the ticket:
1. COUNT guard on tick_number before INSERT — exactly one row per tick:
def record_tick(con, env, gates, result, notes) -> bool:
"""Idempotent write: COUNT guard on tick_number BEFORE INSERT."""
n = con.execute(
"SELECT COUNT(*) FROM audit_ticks WHERE tick_number = ?",
[env.tick],
).fetchone()[0]
if n > 0:
return False # already recorded -> no-op
con.execute(
"INSERT INTO audit_ticks (tick_number, window_start, window_end, "
"total_points, passed, skipped, failed, result, gates, notes, recorded_by) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, CAST(? AS JSON), ?, ?)",
[env.tick, env.window[0], env.window[1], len(gates),
counts["pass"], counts["skip"], counts["fail"], result,
[{"name": g.name, "status": g.status, "detail": g.detail} for g in gates],
notes, f"h3-shim-tick-{env.tick}"],
)
return True
Belt-and-braces: the schema also declares tick_number INTEGER PRIMARY KEY, so a stray second INSERT is rejected by ConstraintException.
2. now() not bare now — this is a real, reproducible DuckDB bug: bare now binds as a column reference and dies at bind time, while the function works:
CREATE TABLE IF NOT EXISTS audit_ticks (
...
recorded_at TIMESTAMP NOT NULL DEFAULT now() -- function, never bare now
);
3. The 14-point checklist — every gate status is honest (pass / fail / skip); nothing is fabricated:
def run_audit(env) -> tuple[list[Gate], str]:
gates = build_gates() # exactly 14 Gate objects
for gate in gates:
try:
gate.status, gate.detail = gate.check(env)
except Exception as e:
gate.status, gate.detail = "fail", f"{type(e).__name__}: {e}"
return gates, ("failed" if [g for g in gates if g.status == "fail"] else "passed")
Usage (idempotent — rerunning is a no-op, exit 0):
python3 audit_board.py --db audit.duckdb --tick 179 --window 174-179
**Environment honesty check first:** I searched the filesystem — the referenced project (`sync_protocol.py`, CLI, pytest suite, Hilo, docs/CI artifacts) **does not exist in this environment** (only `/tmp/pi` and the empty home). So the quoted gate numbers (242/242, 146e/27f, 12/12, 5/5) could **not** be re-verified here; `audit_board.py` records those gates as `skip` with explicit "artifact absent in this environment" reasons rather than asserting a pass. The mechanism itself — the idempotent board write — is fully verified.
**Verified (17/17 pytest, `test_audit_board.py`):**
| Contract point | Tests | Result |
|---|---|---|
| Idempotency | first insert → 1 row; re-run same tick → no-op; different tick allowed | ✅ |
| COUNT guard | guard precedes INSERT; row-scoped (tick 174 guarded doesn't block 175); PK backstop raises `ConstraintException` on dup | ✅ |
| `now()` vs bare `now` | `SELECT now` and `DEFAULT now` both raise `BinderException` (the bug); `DEFAULT now()` yields a fresh timestamp (<60 s old, local wall clock — DuckDB returns naive local time, which the assertion accounts for) | ✅ |
| 14-point checklist | exactly 14 unique gates; statuses ∈ {pass, skip, fail}; JSON payload has 14 records with keys {name, status, detail}; pass+skip+failed = 14 | ✅ |
| Window | tick 179 ∈ [174..179] passes; tick 180 fails; fresh board → contiguity gate skips (first-run only), after 174–178 recorded → passes | ✅ |
| Honesty | repo gates (pytest/gitreins/hilo/ruff/spec-sync/CLI/docs) → `skip`, "absent", never pass | ✅ |
| E2E | `main()` exit 0 on both runs; second run prints `inserted=False`; board row count stays 1; distinct ticks 178+179 → 2 rows | ✅ |
**Live run on the actual board** (`audit.duckdb`), first run `inserted=True`, second run `inserted=False` — board contains exactly one row for tick 179:
```
(179, 174, 179, 14, 4, 10, 0, 'passed', 2026-08-02 19:26:37.865732, 'h3-shim-tick-179')
gates recorded: 14 | statuses: ['pass', 'skip']
```
**Lint:** `ruff check audit_board.py test_audit_board.py` → "All checks passed!" (4 auto-fixed unused imports, then clean).
**Edge cases tested:** duplicate tick re-write, racing writer via guard probe, distinct-tick isolation, bare-now in both `SELECT` and `DEFAULT` contexts, first-run contiguity (skip vs fail), timestamp freshness under the container's local timezone, JSON column binding via `CAST(? AS JSON)`.{"model": "deepseek-v4-flash", "problem_class": "python-idle-audit-never-done", "result": "passed", "tests": 17}