Skip to content

Run Reports & Incidents

Run reports and incidents are immutable post-run artifacts. Once a team run reaches a terminal state, fn_create_run_report creates a single run_reports row that summarises everything that happened. If anomalies were detected, fn_record_run_incident attaches structured incident rows to that report.

Neither table supports UPDATE or DELETE for the authenticated role. Both serve as an audit trail.


Creation flow


Outcome values

OutcomeWhen set
successAll steps completed without error; cost within budget
partialSome steps completed; at least one step failed but the run was not aborted
failedAn unrecoverable error stopped the run before completion
cancelledAn operator or the system cancelled the run before completion
killedThe kill switch was activated while the run was active

RunReportRecord DTO

FieldTypeDescription
iduuidImmutable report identifier
team_run_iduuidThe team run this report covers
ai_lenser_iduuidThe AI lenser that ran
workflow_iduuid | nullWorkflow executed, if applicable
outcometextsuccess, partial, failed, cancelled, or killed
total_stepsintegerCount of agent_steps rows for this run
total_tool_invocationsintegerCount of tool_invocations rows for this run
total_memory_writesintegerCount of memory entries committed on success
total_cost_estimatenumericSummed cost_estimate across all tool invocations (USD)
started_attimestamptzWhen the team run started
ended_attimestamptzWhen the team run reached its terminal state
duration_msintegerComputed: ended_at - started_at in milliseconds
summarytext | nullOptional human-readable or LLM-generated summary
created_attimestamptzWhen this report row was inserted

RunIncidentRecord DTO

FieldTypeDescription
iduuidImmutable incident identifier
run_report_iduuidThe report this incident belongs to
ai_lenser_iduuidThe AI lenser involved
incident_typetextSee incident types table below
severitytextlow, medium, high, or critical
messagetextShort description of what happened
contextjsonbStructured diagnostic data (step id, tool id, cost delta, etc.)
occurred_attimestamptzWhen the incident event occurred within the run
created_attimestamptzWhen this row was inserted

Incident types

TypeDescription
step_errorAn agent step threw an unhandled exception
tool_timeoutA tool invocation exceeded its configured timeout
tool_rejectionA write-class tool invocation was rejected by an operator
budget_overrunThe run's cumulative cost exceeded the configured budget ceiling
memory_write_failedA buffered memory write could not be committed after run completion
policy_denialA policy check denied the run or a tool invocation mid-run
kill_switch_activatedThe kill switch was activated while this run was active

Severity levels

SeverityMeaning
lowInformational; run completed successfully despite the event
mediumRun degraded (partial outcome) but did not abort
highRun aborted; operator review recommended
criticalSecurity or safety concern; immediate operator action required

RPCs

fn_create_run_report

sql
SELECT fn_create_run_report(
  p_team_run_id := '<run-uuid>',
  p_outcome     := 'success',
  p_summary     := 'Completed 12 steps, 3 tool calls, $0.04'
);

Signature:

sql
CREATE OR REPLACE FUNCTION fn_create_run_report(
  p_team_run_id uuid,
  p_outcome     text,
  p_summary     text DEFAULT NULL
)
RETURNS uuid   -- the new run_report id
LANGUAGE plpgsql
SECURITY DEFINER;

The function aggregates step/tool/memory counts from the run tables. Callers only need to provide outcome and an optional summary.


fn_record_run_incident

sql
SELECT fn_record_run_incident(
  p_run_report_id := '<report-uuid>',
  p_incident_type := 'budget_overrun',
  p_severity      := 'high',
  p_message       := 'Cumulative cost $12.80 exceeded ceiling $10.00',
  p_context       := '{"cost_usd": 12.80, "ceiling_usd": 10.00}'::jsonb,
  p_occurred_at   := now()
);

Signature:

sql
CREATE OR REPLACE FUNCTION fn_record_run_incident(
  p_run_report_id uuid,
  p_incident_type text,
  p_severity      text,
  p_message       text,
  p_context       jsonb        DEFAULT '{}',
  p_occurred_at   timestamptz  DEFAULT now()
)
RETURNS uuid   -- the new run_incident id
LANGUAGE plpgsql
SECURITY DEFINER;

CLI commands

Fetch the report for a completed run:

bash
lf run report <run-id>

Example output:

Run Report  run_abc123
──────────────────────────────────
  outcome             success
  steps               12
  tool invocations    3
  memory writes       2
  cost estimate       $0.04
  duration            4 231 ms
  summary             Completed sentiment analysis across 10 inputs.

List incidents for a run:

bash
lf run incidents <run-id>

Example output:

Incidents for run_abc123
  none
bash
lf run incidents run_xyz789
Incidents for run_xyz789
  [high]    budget_overrun     Cumulative cost $12.80 exceeded ceiling $10.00
  [medium]  tool_timeout       Tool search_web timed out after 30s on step 4

Immutability

run_reports rows are written once by fn_create_run_report and are never modified. The authenticated role has INSERT and SELECT only. run_incidents follows the same pattern. This ensures that post-incident investigation always sees the state as it was at run time, not a later mutation.