Precedent and Graph Query Semantics¶
This document focuses on the two most BEAM-sensitive query surfaces: graph traversal and precedent lookup.
Context Graph Semantics¶
The graph is an event-derived context model, not a general-purpose graph database.
Frozen expectations:
- node and edge IDs are deterministic
TraceStartedandEntityObservedcreate trace/entity structurePolicyEvaluatedcreates policy structureExceptionRequestedcreates exception structureApprovalRecordedcreates approver nodes and exception approval edges only when the subject is an exceptionPrecedentCitedcreates a trace-to-trace citation edgeActionProposedcreates action nodes plus trace and target-entity edgesActionCommittedcreates a trace-to-action commit edge
Scoped Subgraph Behavior¶
get_context_subgraph() performs breadth-first traversal from the center node.
Frozen behavior:
- traversal is scoped by
max_depth - edge rows are visited in deterministic
edge_idorder - returned nodes are sorted by
node_id - returned edges are sorted by
edge_id - truncation is explicit when
max_nodesormax_edgeslimits are hit
Edge Pagination¶
list_node_edges() is a cursor-based API over graph edges.
Frozen behavior:
- results are sorted by
log_seq ASC, edge_id ASC - cursor state is effectively
(log_seq, edge_id, direction) - pagination must be stable across repeated calls
Precedent Search Semantics¶
find_precedents() only returns finished traces.
When policy_id is provided:
- the search joins
dg_trace_summarywithdg_precedent_index - rows are deduplicated to at most one result per trace
- exception-derived rows are preferred over policy-only rows within the same trace
- ties within a trace break by
pi.log_seq DESC, pi.source_event_id ASC
Final result ordering is:
last_log_seq DESCtrace_id ASC
When policy_id is not provided:
- the search scans
dg_trace_summary - policy-less traces remain discoverable
Staleness Rule¶
Both graph and precedent queries are projection-backed reads and must reject stale projections.