Expand description
On-disk risk register: the append protocol, id allocation, log loading,
and the derived index.json build/rebuild.
Writes mirror the evidence runner: every mutation takes the root lock
(crate::evidence::lock::RootLock), reads the tail for seq +
prev_sha256, validates the event, appends exactly one line with
O_APPEND semantics, and refreshes that risk’s index entry. Lines are
never rewritten or deleted. SHA-256 reuses
crate::evidence::hasher::sha256_bytes.
Structs§
- Append
Outcome - Result of
append: the event written and the new chain head sha. - Index
External - External tracker mirror as projected into the index (
{system, id, url}). - Open
Outcome - Result of
open: the allocated id plus theopenedevent written. - Register
- The register, leniently loaded: events for every member risk that
parses, plus
(risk_id, error)for every log that could not be read or failed chain validation. The single degradation rule for register consumers — a broken log never silently disappears and never takes the other risks with it. - Risk
Index risks/index.json— the derived register cache, same role asstate.json. Regenerable from the logs withrebuild.- Risk
Index Entry - One projected risk in the index — its fold flattened for fast list/dashboard reads.
Functions§
- append
- Append exactly one event to
risk_id’s log under the root lock, then refresh its index entry. - build_
index - Build the full index in memory by folding every risk log under
risks/. Pure-ish: reads the logs but writes nothing.rebuildwraps this with the lock and an atomic write. - build_
index_ lenient build_index, but a broken log degrades instead of failing: the index covers every readable risk and the broken ones come back as(risk_id, error)pairs the caller must surface. Read surfaces (risks list, the GUI, report assembly) use this so one corrupt log doesn’t take every register view down;rebuildstays strict — regenerating the canonical cache from a broken register must fail.- load_
events - Read and parse a risk’s
events.jsonlinseqorder. - load_
register - open
- Allocate the next
R-NNNNid under the root lock and write theopenedevent. The fingerprint is<control_id>:<finding_id>carried infinding_ref. - rebuild
- Regenerate
risks/index.jsonfrom all logs and write it atomically under the root lock — thestate.jsonrebuild analogue for the register. - risk_
ids - Every risk id in the register: a
risks/<R-NNNN>/directory whose name passes [parse_risk_id] and that has anevents.jsonl. Sorted. This is the register’s single membership rule — index builds and report assembly go through it so they can never disagree about what counts as a risk (stray dirs, backups, and scratch copies are ignored by both). - verify_
finding_ ref - Verify a
finding_refresolves to a real sealed manifest whose recomputed sha matchesmanifest_sha256. Used byrisks open --from <run-dir>so a risk cannot be bound to absent or fabricated evidence.