Uh oh!
There was an error while loading. Please reload this page.
Context-graph plugin: T0 activity-graph projection over ai_gateway_messages - #97
Merged
Conversation
Base automatically changed from
iceberg-export-compaction-and-smoke-fixes to
masterJune 12, 2026 19:02
What
The first implemented slice of the context-graph direction designed in the cgproto LLP corpus (LLP 0006, "Projection pipeline"): a T0 deterministic projection that turns recorded gateway traffic into a queryable node/edge activity graph. No models — T0 is pure relational projection over data the gateway already structures. The in-repo design rationale is LLP 0023, with
@refannotations linking the code to its decisions.@hypaware/context-graphpluginnode/edge— derived Iceberg tables fronted by the kernel cache, queryable viahyp query sql. Multi-partition queries go through a union source that keeps limit/offset at the engine level (never pushed into sub-scans).hyp graph project [--dry-run]— 9 hand-authored contract rules overai_gateway_messagesmaterialize 5 node types (Session,App,Model,Tool,File) and 4 edge types (via,used_model,used,touched). Ids are content-addressed (SHA-256 of type + NUL-delimited natural key, digests pinned in tests); every row carries inline provenance (source_dataset,source_keys,projector,projector_version). Re-projection is idempotent: pre-write dedup filters already-committed ids (a real query/storage failure aborts the run rather than weakening the guarantee), so a re-run writes zero rows. Duplicate-row merges are order-independent: earliestfirst_seenwins, props union with per-key earliest-seen-wins and a value tie-break.hyp graph compact [--dry-run]— merges duplicate rows that slip past pre-write dedup (concurrent projections, partial failures), including acrosssource=partitions: each duplicate group folds into one row (samemergeRowprojection uses) kept in the earliest-seen partition; affected partitions rewrite via the cache's generation swap (newtable-<seq>dir, cursor repoint,.retiredmarker for the kernel's grace-period sweep). The swap is conditional: cursors are positively read (tryReadCursorSync,source-tablelayout required) and re-checked before repointing — any concurrent append or an unreadable cursor aborts the swap, removes the staged table, and reports the partition skipped (stderr + span attributes; unreadable cursors exit nonzero). Home partitions rewrite before copy-droppers and copies are only dropped once their merged row landed, so a partial run can leave duplicates but never lose rows or props.Kernel-side enablers
AppendOptions.sortOrder— column-name sort declaration applied at table creation; icebird ≥ 0.8.9 then sorts every appended data file by the table's default sort order. Graph rewrites declare(node_type, node_id)/(edge_type, src_id, dst_id)so type scans and id lookups prune after the first compaction.compactSourceTable's generation swap previously recreated the replacement table without the source table's default sort order, silently dropping it.compactExportTabletelemetry — the format-iceberg export rewrite now runs inside asink.export.compactspan recording reason, data-file counts, commit-verification outcome, staged-file reclamation, anderror_kindon conflict/error paths.@hypaware/context-graphadded to the bundled-plugin allowlist.Deliberately not here
The declarative contract→SQL compiler, T1/T2 enrichment, entity resolution, per-snapshot triggering, and a partition-level maintenance lock (the conditional swap's failure mode is "duplicate persists", never data loss — see LLP 0023#graph-compaction) are later slices.
Testing
npm test: 871 passing, including newcontext-graph-ids(pinned digests, delimiter collision-freedom),context-graph-contract(every rule'stoRow: null-skips, file-tool gating, string/malformed-JSONtool_args,notebook_pathfallback, timestamp normalization),context-graph-project(mergeRow determinism across all merge orders,firstSeenTime),context-graph-datasets(union limit/offset isolation), and expandedcontext-graph-maintenance(corrupt-cursor refusal, concurrent-write swap abort with staged-table cleanup, CLI skip reporting + exit codes)context_graph_projects_rows(projection counts,node_typebreakdown, idempotent re-run,graph compactround-trip, plusgraph.project/graph.compactspan assertions per the log-driven-development policy) andcore_boot_noop— ok🤖 Generated with Claude Code