Skip to content

feat(desktop): add bounded Context Graph entity accounting - #13

Merged
branarakic-agent merged 2 commits into
OriginTrail:mainfrom
Zigoljube:feat/subgraph-entity-counts
Aug 14, 2026
Merged

feat(desktop): add bounded Context Graph entity accounting#13
branarakic-agent merged 2 commits into
OriginTrail:mainfrom
Zigoljube:feat/subgraph-entity-counts

Conversation

@Zigoljube

@Zigoljube Zigoljube commented Aug 14, 2026

Copy link
Copy Markdown

Summary

Adds entity accounting to the DKG memory panel while keeping reads bounded and the displayed units honest.

  • Counts the layer's distinct typed entities and six fixed ontology slices: decisions, evidence, people/agents, capture runs, claims, and commits.
  • Measures shared-memory entities attributed to up to 16 canonical contributors, rejecting malformed keys before SPARQL construction.
  • Runs at most four count requests concurrently and refreshes every two minutes; contributor queries avoid unused VM reads.
  • Compares typed entities with listed type assignments without assuming the ontology slices form a partition. A partial query battery renders no reconciliation line.
  • Uses measured entity totals on layer cards when available; provider *Count and bounded-list fallbacks remain explicitly graph counts.
  • Keeps loaded-view counts for the decisions lens, labels contributor event fallbacks honestly, and qualifies graph-overlay totals as "in this view".
  • Invalid, negative, fractional, or unsafe aggregate bindings degrade to unavailable rather than becoming UI totals.

Counting remains optional: any failed aggregate degrades to the prior display behavior and never gates the memory panel.

Load bound

A refresh issues seven fixed aggregate requests plus at most 16 contributor requests. The client permits four in flight at once. Fixed type requests read SWM and VM; participant requests read shared memory only. The two-minute refresh aligns with the gateway cache window.

Validation

  • Desktop unit suite: 4,764 passed
  • Entity-accounting unit tests: 5 passed
  • Focused Playwright entity-accounting flow: passed
  • TypeScript: passed
  • Biome and desktop static checks: passed
  • E2E production build: passed

Follow-up

For larger communities, the provider should eventually expose typed entity counters directly from channel_memory, replacing the bounded client-side aggregate battery.

Ziga Drev and others added 2 commits August 14, 2026 11:05
…otals

Every chip in the memory panel is conceptually a SUB-GRAPH of the
channel's Context Graph — a kind of entity, one participant's
contributions, code. This makes the numbers those chips carry mean
exactly that, and makes the sums check out (buzz-dkg-beta#13):

- subgraphCounts.ts: a battery of budget-safe semantic aggregates (exact
  type/predicate IRIs, one aggregate per query, LIMIT everywhere — the
  relay's query gate rejects GROUP BY, GRAPH clauses, and unbound
  patterns) counting each kind sub-graph (decisions, evidence events,
  people & agents, capture runs, claims, code), each contributor's
  sub-graph via prov:wasAttributedTo, and the layer's typed-entity
  total. "Entity" follows the DKG node UI's own semantics
  (packages/node-ui buildEntities): entities of every kind, not
  decisions.
- The dashboard gains a reconciliation line — e.g. "312 entities = 30
  decisions · 240 evidence · 11 people & agents · 30 capture runs" —
  and any mismatch is SHOWN ("n other" for unclassified subjects,
  "n cross-typed" for double-counted ones), never hidden. The
  invariant is verified in the UI, not assumed.
- Layer cards never present a display-bounded list length as a total
  again: an uncapped *Count from the gateway wins, a measured entity
  total is next, and a bare list renders only as a lower bound (≥n).
- The All-decisions chip carries the true decision count; each
  People & agents chip carries that agent's sub-graph entity count
  (falling back to raw event count until measured, with the unit named
  in the tooltip).
- Lens overlay legends now say "in this view" — a per-lens node tally
  can no longer impersonate a channel-wide layer total.

Counting never gates the panel: every query failure degrades to null
and the previous behavior. Covered by unit tests for the query builder,
binding parser, and reconciliation math, plus an e2e that stubs the
gateway aggregates and asserts the reconciliation line, the honest
layer card, and the per-agent chip end to end.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Ziga Drev <zigadrev@MacBook-Pro-8.local>
Signed-off-by: branarakic <branimir.rakic@origin-trail.com>
@branarakic-agent branarakic-agent changed the title feat(desktop): entity-true sub-graph counts that reconcile to layer totals feat(desktop): add bounded Context Graph entity accounting Aug 14, 2026
@branarakic-agent
branarakic-agent merged commit 6659c9b into OriginTrail:main Aug 14, 2026
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants