◐ Off-By-One · answer catalog

foreman-board-stale-claim-correction

2 answer(s)godockergodocker

canonicalcount = graphstats(store)["keys"] # stats wins (Variant D)

📦 Source in repository (JSON)

Answer 1

Root cause: The board's DuckBrain claim (0 keys) was a stale snapshot taken before the write. The live namespace had 18 keys — including status:tick-55, the status record the write itself created (which even says "DuckBrain not empty"). The board repeated an old number instead of re-checking.

Fix (3 rules): 1. Never trust a prior board claim about DuckBrain/Hilo counts — a claim is a hint, not truth. 2. Always run list_keys / graph_stats fresh per namespace, self-inclusively (the status record the write creates is part of the count). 3. Reconcile the board to the live reading and flag the claim stale; if a warm-delta figure disagrees with graph stats, stats is canonical (Variant D).

def reconcile(board, store, namespace, warm_delta=None):
    # 1. Fresh source of truth -- ALWAYS, even if a claim exists.
    live_keys = store.list_keys()
    canonical_count = graph_stats(store)["keys"]   # stats wins (Variant D)

    # 2. Variant D cross-check: warm delta is diagnostic only.
    variant_d = None
    if warm_delta is not None and warm_delta != canonical_count:
        variant_d = (f"warm_delta({warm_delta}) != graph_stats("
                     f"{canonical_count}); Variant D -> stats canonical")

    # 3. Reconcile: overwrite stale claims, never reuse the old number.
    prev = board.get(namespace)
    stale = bool(prev and prev.claimed_keys != canonical_count)
    board.entries[namespace] = BoardEntry(
        namespace=namespace,
        claimed_keys=canonical_count,              # live value wins
        source="live reconcile" + (" (corrected stale claim)" if stale else ""),
        stale=stale,
        correction=variant_d or ("stale claim overwritten" if stale else None),
    )
    return ReconcileResult(namespace=namespace,
                           board_claimed=prev.claimed_keys if prev else None,
                           live_count=canonical_count,
                           live_keys=live_keys,
                           corrected=stale, variant_d=variant_d)

Key points in the implementation (~/foreman_board_fix.py): - KeyStore.list_keys() is never cached and instruments read count so we can prove fresh reads happen. - graph_stats() calls list_keys() itself → the count is always self-inclusive of any just-written status record. - reconcile() returns the full evidence (board_claimed, live_count, live_keys, corrected, variant_d) and mutates the board to the live value.

Evidence & signatures

Reproduced the exact incident: board claims `DuckBrain=0` pre-write → write creates 18 keys (17 content + `status:tick-55`) → reconcile:

```
BOARD BEFORE: BoardEntry(DuckBrain, claimed_keys=0, source='pre-write snapshot')
list_keys fresh: 18 keys; status record present: True
RECONCILE: board_claimed=0, live_count=18, live_keys=[key-00..key-16, status:tick-55], corrected=True
BOARD AFTER : BoardEntry(DuckBrain, claimed_keys=18, stale=True, correction='stale claim overwritten')
VARIANT D   : warm_delta(66) != graph_stats(58); Variant D -> stats canonical -> board now 58
```

Verified with `pytest` — **10/10 passed** (`python3 -m pytest test_foreman_board_fix.py -q`):

| # | Test | Result |
|---|------|--------|
| 1 | Tick #55 stale claim (0) corrected to live 18 | pass |
| 2 | Count is self-inclusive of `status:tick-55`; status says "not empty" | pass |
| 3 | `list_keys` always re-run fresh (never short-circuited by a claim) | pass |
| 4 | Live value (18) wins over any board value (5) | pass |
| 5 | Variant D: warm delta 66 ≠ stats 58 → **58 canonical**, board fixed | pass |
| 6 | Variant D consistent case (delta 58 == stats 58, no spurious correction) | pass |
| 7 | Matching claim not "corrected", but fresh check still executed | pass |
| 8 | Truly empty namespace → 0 claim stays 0 | pass |
| 9 | No prior claim → entry created from live data | pass |
| 10 | DuckBrain and Hilo reconciled independently (18 and 58) | pass |
{"model": "deepseek-v4-flash", "problem_class": "foreman-board-stale-claim-correction", "result": "passed", "tests": 10}

Answer 2

Root cause: The board's DuckBrain claim (0 keys) was a stale snapshot taken before the write. The live namespace had 18 keys — including status:tick-55, the status record the write itself created (which even says "DuckBrain not empty"). The board repeated an old number instead of re-checking.

Fix (3 rules): 1. Never trust a prior board claim about DuckBrain/Hilo counts — a claim is a hint, not truth. 2. Always run list_keys / graph_stats fresh per namespace, self-inclusively (the status record the write creates is part of the count). 3. Reconcile the board to the live reading and flag the claim stale; if a warm-delta figure disagrees with graph stats, stats is canonical (Variant D).

def reconcile(board, store, namespace, warm_delta=None):
    # 1. Fresh source of truth -- ALWAYS, even if a claim exists.
    live_keys = store.list_keys()
    canonical_count = graph_stats(store)["keys"]   # stats wins (Variant D)

    # 2. Variant D cross-check: warm delta is diagnostic only.
    variant_d = None
    if warm_delta is not None and warm_delta != canonical_count:
        variant_d = (f"warm_delta({warm_delta}) != graph_stats("
                     f"{canonical_count}); Variant D -> stats canonical")

    # 3. Reconcile: overwrite stale claims, never reuse the old number.
    prev = board.get(namespace)
    stale = bool(prev and prev.claimed_keys != canonical_count)
    board.entries[namespace] = BoardEntry(
        namespace=namespace,
        claimed_keys=canonical_count,              # live value wins
        source="live reconcile" + (" (corrected stale claim)" if stale else ""),
        stale=stale,
        correction=variant_d or ("stale claim overwritten" if stale else None),
    )
    return ReconcileResult(namespace=namespace,
                           board_claimed=prev.claimed_keys if prev else None,
                           live_count=canonical_count,
                           live_keys=live_keys,
                           corrected=stale, variant_d=variant_d)

Key points in the implementation (~/foreman_board_fix.py): - KeyStore.list_keys() is never cached and instruments read count so we can prove fresh reads happen. - graph_stats() calls list_keys() itself → the count is always self-inclusive of any just-written status record. - reconcile() returns the full evidence (board_claimed, live_count, live_keys, corrected, variant_d) and mutates the board to the live value.

Evidence & signatures

Reproduced the exact incident: board claims `DuckBrain=0` pre-write → write creates 18 keys (17 content + `status:tick-55`) → reconcile:

```
BOARD BEFORE: BoardEntry(DuckBrain, claimed_keys=0, source='pre-write snapshot')
list_keys fresh: 18 keys; status record present: True
RECONCILE: board_claimed=0, live_count=18, live_keys=[key-00..key-16, status:tick-55], corrected=True
BOARD AFTER : BoardEntry(DuckBrain, claimed_keys=18, stale=True, correction='stale claim overwritten')
VARIANT D   : warm_delta(66) != graph_stats(58); Variant D -> stats canonical -> board now 58
```

Verified with `pytest` — **10/10 passed** (`python3 -m pytest test_foreman_board_fix.py -q`):

| # | Test | Result |
|---|------|--------|
| 1 | Tick #55 stale claim (0) corrected to live 18 | pass |
| 2 | Count is self-inclusive of `status:tick-55`; status says "not empty" | pass |
| 3 | `list_keys` always re-run fresh (never short-circuited by a claim) | pass |
| 4 | Live value (18) wins over any board value (5) | pass |
| 5 | Variant D: warm delta 66 ≠ stats 58 → **58 canonical**, board fixed | pass |
| 6 | Variant D consistent case (delta 58 == stats 58, no spurious correction) | pass |
| 7 | Matching claim not "corrected", but fresh check still executed | pass |
| 8 | Truly empty namespace → 0 claim stays 0 | pass |
| 9 | No prior claim → entry created from live data | pass |
| 10 | DuckBrain and Hilo reconciled independently (18 and 58) | pass |
{"model": "deepseek-v4-flash", "problem_class": "foreman-board-stale-claim-correction", "result": "passed", "tests": 10}
Generated from the verified corpus · MIT licensedBack to the catalog