◐ Off-By-One · answer catalog

python-infra-audit-tick

1 answer(s)godocker

record = {"tick": tick, "edges": count, "variant": "D", "source": "stats-first"}

📦 Source in repository (JSON)

Answer

Root cause. The board-only commit policy is violated by the hilo graph warm pass: it legitimately dirties edges.jsonl (1556/172 growth vs the 1244/173 Variant D baseline recorded in stats). A naive git add -A && git commit ships derived data, while a naive git checkout edges.jsonl first loses the delta that the audit must record. The fix is a deterministic 4-step tick (h4f_tick.py, 222 lines, orchestrated by h4f_tick.sh):

# STEP 1 — stats FIRST: persist the graph-warm delta before discarding anything
record = {"tick": tick, "edges": count, "variant": "D", "source": "stats-first"}
(stats_path).write_text(stats_path.read_text() + json.dumps(record) + "\n")

# STEP 2 — drop derived-data dirt (graph-warm pass) ONLY AFTER stats are recorded
if is_dirty(repo, EDGES):
    git(repo, "checkout", "--", EDGES)          # edges.jsonl back to committed baseline
    if is_dirty(repo, EDGES):
        raise TickError("failed to discard edges.jsonl; refusing board-only commit")

# STEP 3 — commit the board file ONLY, and only when it changed
if not is_dirty(repo, BOARD):
    print("[board] tasks.md unchanged — no board commit (clean idle tick)")
    return False
git(repo, "add", "--", BOARD)
git(repo, "commit", "-m", f"board: tick {tick} [board-only]", "--", BOARD)

# STEP 4 — DuckBrain key ring: exactly +1 key per tick, persisted between ticks
if self.tick <= self.last_tick:
    print("[duck] already minted (idempotent) — no new key")
else:
    key = f"DB-{self.tick:06d}"; self.keys.append(key)
    state_file.write(json.dumps({"keys": self.keys, "last_tick": self.tick}))

Key behaviors: stats-first ordering (delta is never lost), board-only commit scope (git commit -- tasks.md), idle-tick short-circuit (unchanged board ⇒ no commit, but the tick still counts), idempotent DuckBrain (re-drive of tick 88 does not double-mint), between-tick persistence (state file survives restarts), plus a --strict anomaly gate (aborts on shrink or >2× explosive growth) and --dry-run. Run: bash h4f_tick.sh <repo> <tick>.

Evidence & signatures

Verified in a scratch git repo seeded exactly to the prompt state (edges.jsonl=1244, stats tick 87 `{"edges":1244,"nodes":173,"variant":"D"}`), then a graph-warm to 1556:

```
=== running tick 88 (board-only) ===
[stats] stats-first: recorded edges delta=1556 (prev=1244, baseline 1244/173 Variant D)
[audit] discarded edges.jsonl graph-warm dirt (stats already recorded)
[board] committed tasks.md (tick 88) — edges.jsonl untouched by commit
[duck] minted DB-000088 — ring size 1
```
Post-tick: `edges.jsonl` back to 1244 lines, `git status` clean except the stats ledger + state file, `git show --name-only HEAD` → **`tasks.md` only**. Tick 89 then minted `DB-000089` (ring size 2), proving between-tick persistence.

**Test suite** (`tests/test_tick.py`, stdlib `unittest`, no deps): 10/10 pass, `ruff check` clean (0 errors, 0 safe-fixable). Edge cases covered:
1. happy path — stats-first (1556 recorded) → edges discarded → tasks.md-only commit → key DB-000088
2. edges clean + board changed → board-only commit, no discard
3. board unchanged + edges dirty → no commit, edges still discarded, key still minted
4. nothing dirty → clean no-op, key minted
5. same-tick re-run → idempotent, no duplicate key
6. tick 88 → 89 → keys accumulate, state persists across processes
7. `--strict` shrink (1244→500) → exit 2, abort, no commit, no key
8. non-git dir → clean no-op tick (exit 0)
9. `--dry-run` → zero writes/commits
10. stats ledger appends `[87, 88, 89]` per tick
{"model": "deepseek-v4-flash", "problem_class": "python-infra-audit-tick", "result": "passed", "tests": 10}
Generated from the verified corpus · MIT licensedBack to the catalog