Skip to content

Chain the first event after a prune from the truncation anchor - #1831

Merged
seangalliher merged 3 commits into
mainfrom
fix/bf980-eventlog-anchor-restart-20261118
Nov 18, 2026
Merged

seangalliher merged 3 commits into
mainfrom
fix/bf980-eventlog-anchor-restart-20261118

Conversation

@seangalliher

Copy link
Copy Markdown
Owner

Refs #1811

What changes

After a prune empties the event table, the next event no longer restarts the hash chain at genesis, and the chain walk no longer accepts a genesis restart after a truncation anchor. EventLog._insert_chained_row (src/probos/substrate/event_log.py) started every append at GENESIS_HASH and replaced it only with the hash of a tail row. A prune whose age stage deletes every row records the last deleted row's hash in events_truncation_anchor (BF-942), but the next append, finding no tail row, linked to genesis, and verify_chain then accepted that genesis-linked first row after the anchor (BF-942's decision D4). Now:

  • The append chains from the anchor. With no tail row, the append reads the anchor inside the same BEGIN IMMEDIATE transaction as the tail read and chains from its row_hash verbatim (an empty hash included), and from genesis only when there is no anchor either. A tail row decides exactly as before. This is the rule the AD-1278 AuditLog.append already follows.
  • The walk has no genesis exception. After an anchor, the first row must link to the anchor's hash; a first row that links to genesis, or to anything else, is broken, (False, its id), with anchor_id set. Unanchored chains (unanchored, detached_at), wipe() (it deletes the anchor with the rows, so a wiped log starts at genesis), _compute_row_hash, prune, _delete_head, the schema and ChainVerdict are unchanged.
  • A store that already holds the old restart (an anchor and a genesis-linked first row) reads broken at that row until its next prune that deletes a row moves the anchor (decision D3, case A7); no row is rewritten and no migration runs. The reach is the code from BF-942's merge (2026-11-09) to this change, an age prune that left no row, and an append after it. The Captain's vessel is not in that state: a copy of its events.db, read raw before any code opened it, has no anchor table (BF-942's schema creates the table at start-up, so BF-942's code has not run on that store), 0 of 1.
  • Tests. tests/test_bf980_eventlog_anchor_restart.py adds 9 cases (a real EventLog under tmp_path; each asserts the state it needs before its effect). The one BF-942 case that pinned the restart (test_after_a_prune_empties_the_table_the_next_row_links_to_the_anchor) now pins the link to the anchor, with its reason inline; that file stays at 22 cases.
  • Trackers. DECISIONS.md (the BF-980 entry; BF-942's D4 line points to it), PROGRESS.md and the regenerated AD ledger pair. The rest of the diff is the contract (prompts/bf-980-eventlog-anchor-restart.md).

Commits

Commit Subject
ff2ea098 Add the contract for the event log chain after a prune empties the table
1129872f Chain an emptied event table from the truncation anchor and refuse a genesis restart
41bc07a5 Record the event log chain change in the trackers and the ledger

Review and the broad gate

Review. Two passes by the Diff Reviewer on gpt-6.1-sol (the model read back from the session log's usage records, including the first dispatched model), both over the frozen candidate 41bc07a5. Round 1 (the whole candidate, 16 minutes) found properties 1 to 7 and 9 holding, each executed on a real EventLog: the append's statement order is BEGIN, the tail read, the anchor read only when no tail row exists, INSERT, COMMIT (4 statements on a populated append, 5 on an empty-table append); an anchor-read failure rolls back and propagates; a prune and an append in two processes end truncated in both orders; the new file fails 6 of its 9 cases on the base code and the rewritten BF-942 case fails alone, each at its effect line; no other hunk touches prune, _delete_head, wipe, the schema, ChainVerdict or the BF-873 code. Its verdict was NOT READY on one P3 that concerns the review input and not the candidate: my brief named the replay's working copy of the vessel's events.db, which the replay's own run had opened through EventLog.start() (that creates an empty anchor table), so property 8's premise "no anchor table before start" could not be shown on that file; the behaviours property 8 asks for held on it. Round 1b (property 8 only, a fresh reviewer, 6 minutes, on the pristine copy of the vessel's events.db) held: head and base both read unanchored, (False, 415101) before and after an append, and after a prune that deleted all 1,796 rows the head's next row links to the anchor hash while the base's links to genesis (both read truncated); nothing contradicts the claims in DECISIONS.md and PROGRESS.md about the vessel's store. READY, 0 findings. Size findings: 0 in both passes. No repair followed either pass, so there is no delta to review again.

Size findings: 0 (no size finding in either review pass).

The broad gate. One run of the canonical wrapper on the frozen head 41bc07a53079809572007521f22dee59ca4875ed (tree 2937dd55b7f5c9e2afa5ea1416be328f6238ebdf), after the last review and with no change since: scripts/run_test_gate.py --label bf980 --receipt logs/gates/bf980.receipt.json, 3 workers, on a host with nothing else running. Result: 54193 passed, 184 skipped, 246 warnings, 7 subtests passed in 1:42:51, exit 0. The receipt validates (54,377 tests collected and reported on 3 workers) and binds the committed tree; the live-data manifest taken before and after the run is identical (54,107 files, none added, removed or changed). The count is the previous gate's (bf938-1680b: 54184 passed, 184 skipped) plus the 9 cases of the new test file; the rewritten BF-942 case replaces one and adds none. origin/main was 60e2c36b at the start of the run and at the push.

Evidence

  • The new tests on the base code, before the change. tests/test_bf980_eventlog_anchor_restart.py fails 6 of its 9 cases (A1, A2, A4, A7, A8 and A9, each at the effect line the contract names; A3, A5 and A6 pass because they pin what must not change), and with the base code the rewritten BF-942 case alone fails (1 failed, 21 passed).
  • On the head. The six focused event-log files (the new file 9, the BF-942 file 22, test_ad490, test_bf873, test_database_retention and test_event_log) 81 passed; the 36 test files that import the event log or use it through tests/bf934_world.py 2,204 passed and 2 skipped (a POSIX-only symlink case); tests/test_ad1184_ad_ledger.py 33 passed. scripts/gen_ad_ledger.py --check, check_architecture_principles.py --check and check_store_registry.py --check pass; the gate wrapper's preflight exits 0.
  • Mutation campaign (6 rows over the new file and the BF-942 file, on a tree with the same three blobs; the baseline is 31 cases passing): every mutant is killed. Restoring GENESIS_HASH in the append fails A1, A4, A8, A9 and the rewritten BF-942 case; restoring the genesis exception in the walk fails A2 and A7; removing the wipe clearing of the anchor fails A5 and the BF-942 wipe case; the unanchored-path row fails the two BF-942 cases that guard it. Rows 3 and 4 fail more cases than the contract names (3 and 29 more), which is recorded and is not a defect.
  • A copy of the Captain's events.db (1,796 rows, ids 415101 to 416896, no anchor table, read raw before any code opened it; the pristine copy's hash was unchanged by the probes; two scratch copies were used): with an ordinary start the head and the base read unanchored, (False, 415101) before and after one append, and the new row links to the old tail; with an age prune that deletes all 1,796 rows (anchor id 416896) the head's next row links to the anchor hash and the base's to genesis, and both read truncated. The live store was never opened (the live-data manifest before and after the broad gate is identical, see above).

What this pull request does not do

  • It does not migrate or rewrite any store: a store holding the old restart reads broken at that row until its next deleting prune (D3), and none is known.
  • It does not add a production caller of verify_chain (there is none in src, scripts or ui/src for the event log), so no running code reads the changed verdict.
  • It does not change what a writer of events.db can do undetected: forge the anchor and a matching cut, rewrite rows and every later hash, or delete the newest rows or every row after the anchor (the next append then chains from the anchor, as after a prune). That is BF-942's limits L1 and L2; this change narrows only the genesis-restart half of BF942-F5 (Follow-up: residual findings from the #1722 / #1604 / #1723 / #1724 / #1736 / #1741 wave (reserves BF-954) #1754, noted there after this merges).
  • It does not record a wipe() reset in the chain (the function has no production caller).

seangalliher and others added 3 commits November 18, 2026 07:03
The contract says how the next event row is linked after a prune leaves the
event table empty, and what the chain walk accepts after a truncation anchor.
It adds no code.

Refs #1811.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…genesis restart

After a prune that leaves no row, the next event is linked to the hash of the
last row the prune deleted (the truncation anchor), read in the same write
transaction as the tail read, and to genesis only when there is no anchor
either. The chain walk no longer accepts a first row that links to genesis
after an anchor: that row reads as broken. The earlier test case that pinned
the restart now pins the link to the anchor, and a new test file adds nine
cases.

Refs #1811.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds the progress and decisions entries for the change, marks the earlier
decision about an emptied table as replaced by it, and regenerates the AD
ledger.

Refs #1811.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant