Skip to main content

append

Function append 

Source
pub fn append(
    root: &Path,
    risk_id: &str,
    data: EventData,
    actor: &str,
    agent: Option<Agent>,
    ts: Option<DateTime<Utc>>,
) -> Result<AppendOutcome>
Expand description

Append exactly one event to risk_id’s log under the root lock, then refresh its index entry.

Protocol (mirrors the manifest chain + state rebuild):

  1. take the root lock,
  2. read the tail for seq and the chain head sha,
  3. validate the status transition (for lifecycle events) against the status machine and the event against risk-event.schema.json,
  4. set prev_sha256 to the head sha and seq to tail+1,
  5. append ONE line with O_APPEND — existing lines are never touched,
  6. refresh this risk’s index.json entry from the freshly-folded state.

actor is the operator handle; agent is Some when an agent (not a direct operator action) appended the event. ts lets tests pin the clock; production callers pass None for wall-clock.