◐ Off-By-One · answer catalog

board-duckdb-parquet-idle-audit-append

1 answer(s)godocker

total = curtotal + 1 if "tickstotal" not in sets else int(sets["tickstotal"])

📦 Source in repository (JSON)

Answer

Root cause fixed: append_board_event_parquet.py previously applied --set overrides but then unconditionally auto-incremented both counters, so --set ticks_total=158 persisted 159 and the parquet audit row recorded pre-resolution (stale) counters — board.db and events.parquet disagreed. The fix resolves final values first (explicit --set wins verbatim; otherwise +1), writes the single audit row with the final values, and only then persists the single-row board_state — so both artifacts always agree. A second latent bug was also fixed: board_state was keyed on tick, so appends created multiple rows and reads returned stale state; it is now a guaranteed single row (id=1 CHECK (id=1)).

Key fix (resolution order in append_board_event_parquet.py):

INT_KEYS = {"ticks_total", "ticks_idle", "tick"}
AUTO_KEYS = {"ticks_total", "ticks_idle"}   # auto-incremented UNLESS --set

def resolve_values(state, sets, force):
    cur_total, cur_idle, cur_tick = state["ticks_total"], state["ticks_idle"], state["tick"]
    # explicit --set wins verbatim; otherwise auto-increment (+1)
    total = cur_total + 1 if "ticks_total" not in sets else int(sets["ticks_total"])
    idle  = cur_idle  + 1 if "ticks_idle"  not in sets else int(sets["ticks_idle"])
    tick  = cur_tick  + 1 if "tick"       not in sets else int(sets["tick"])
    last_commit = sets.get("last_commit", state.get("last_commit") or "")
    if not force and (total < cur_total or idle < cur_idle):
        raise SystemExit("non-monotonic counters ... (use --force)")
    return {"tick": tick, "ticks_total": total, "ticks_idle": idle, "last_commit": last_commit}

The single event row is then built from the resolved values (not the old ones), written atomically to parquet (temp file + os.replace), and board_state is updated to the same numbers:

row = {"seq": seq, "tick": final["tick"], "event_type": ...,
       "ticks_total": final["ticks_total"], "ticks_idle": final["ticks_idle"],
       "last_commit": final["last_commit"], ...}
write_events_atomic(events_path, pa.concat_tables([tbl, appended]))  # seq = last+1, exactly 1 row
con.execute("UPDATE board_state SET tick=?, ticks_total=?, ticks_idle=?, "
            "last_commit=?, last_event_seq=?, updated_at=now() WHERE id=1", [...])

Commit/push path (both tracked binaries, co-author trailer, origin master):

git("add", board, events); body = message
if coauthor: body += f"\n\nCo-Authored-By: {coauthor}"
git("commit", "-m", body); git("push", remote, branch)  # origin, master

check_scheduler_project.py — pin check (pin, no PUT): asserts .helios/scheduler.json has pinned=true with an approved pin_rev, method=="GET", and zero pending PUT ops; exits 0 only if every check passes (5 sub-checks).

check("pinned", state.get("pinned") is True, f"pin_rev={state.get('pin_rev')}")
check("method is GET (no PUT)", state.get("method") == "GET")
check("no pending PUT ops", len([o for o in ops if str(o.get("method","")).upper()=="PUT"]) == 0)

Evidence & signatures

The host Go repo (72/72 pkgs, gitreins guard, gh workflows) is not mounted in this sandbox, so I reconstructed the board project from the spec (seed → append → commit/push → checker) and verified the full local battery end-to-end. Host-side gates (go test, gitreins, gh scan, dep check) remain the standard pre-push gate on the real machine.

**Append semantics (10/10 cases passed):**
```
seed: board_state tick=157 ticks_total=157 ticks_idle=3, events.parquet empty
TICK 158 audit, explicit --set → RESOLVED tick=158 ticks_total=158 ticks_idle=4 last_commit=<head sha>   # pinned, NOT incremented ✓
TICK 159 no --set           → RESOLVED tick=159 ticks_total=159 ticks_idle=5                              # both +1 ✓
board_state: 1 row (159,159,5,seq=2); parquet rows: (1,158,'idle-audit',…,158,4,…), (2,159,'tick',…,159,5,…)  # row==state ✓
```
**Edge cases:** dry-run writes nothing (files untouched); non-monotonic explicit `ticks_total=1` rejected exit 1; unknown `--set bogus=1` rejected exit 1; seq monotonic → exactly one row per invocation.

**Scheduler check:** PASS case → 5/5 sub-checks PASS, exit 0. Mutation matrix → unpinned FAIL, bad pin prefix FAIL, method=PUT FAIL, pending PUT op FAIL (each exit 1).

**Git flow:** commit `7ee72c0` contains `board.db` (Bin 0→1060864) + `events.parquet` (Bin 0→2716) — both tracked binary deltas (`numstat: - -`), commit body carries `Co-Authored-By: Helios Bot <<email>>`, pushed to `origin/master`; remote head == local head `7ee72c0`. Consistency assertion: `board_state == (158,158,4)` and exactly 1 parquet row with seq 1 — PASS.
{"model": "deepseek-v4-flash", "problem_class": "board-duckdb-parquet-idle-audit-append", "result": "passed", "tests": 10}
Generated from the verified corpus · MIT licensedBack to the catalog