fix: sub-graph polish (issue #81 findings 1, 3, 4, 5, 7)#112
Merged
Conversation
Five targeted fixes for sub-graph implementation follow-ups identified in reviewing PR #101 against 03_PROTOCOL_CORE.md §16.2. No P0 changes — all P1/P2 polish on existing working code. 1. createSubGraph JSDoc now reflects V10.0 gossip auto-registration. The previous comment claimed "receivers store replicated data in the root data graph" which has been false since gossip auto-registration landed in gossip-publish-handler / workspace-handler / finalization- handler. 2. Deleted unused ContextGraphManager.listSubGraphs. It was a heuristic graph-URI walk with divergent semantics from DKGAgent.listSubGraphs (which is the spec-compliant _meta ASK path) and had zero callers in the codebase. Removes the divergence risk and the stale "draft/" reserved prefix. 3. assertion{Create,Write,Query,Promote,Discard} now validate that the sub-graph is registered in _meta before operating. New private helper ensureSubGraphRegistered mirrors the ASK pattern already used by publish(). Previously these ops silently orphaned triples under unregistered sub-graph URIs. Guard is opt-in: assertion ops without a subGraphName are unchanged. 4. DKGAgent.listSubGraphs literal stripping now uses the shared stripLiteral() helper instead of three per-field regex strips. The old /^"|".*$/g pattern on createdAt was greedy and ate any inner quote; the new code correctly handles datatype- and language-tagged literals. 5. publishFromSharedMemory @throws JSDoc added to document the existing constraint: subGraphName and publishContextGraphId cannot be combined (the remap flow targets /context/{id} which is incompatible with sub-graph URIs). Tests: 8 new unit tests in draft-lifecycle covering the registration check — 616/616 publisher pass, 70/70 storage pass, 15/15 agent sub-graph e2e pass. Refs: OriginTrail/dkgv10-spec#81
11 tasks
There was a problem hiding this comment.
Codex review produced 1 comment(s) but all targeted lines outside the diff and were dropped. Check the workflow logs for details.
branarakic
pushed a commit
that referenced
this pull request
Apr 10, 2026
branarakic
pushed a commit
that referenced
this pull request
Apr 10, 2026
fix: sub-graph polish (issue #81 findings 1, 3, 4, 5, 7)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Five targeted fixes from the post-PR-#101 sub-graph review (dkgv10-spec#81). All P1/P2 polish on working code — no P0 changes, no behavior breaks for callers that already follow the documented registration flow.
What's included
Stale JSDoc fixed on
DKGAgent.createSubGraph. The previous doc claimed "GossipSub broadcasts raw triples without sub-graph context; receivers store replicated data in the root data graph" — this has been false since gossip auto-registration landed ingossip-publish-handler,workspace-handler, andfinalization-handler. New doc describes the actual V10.0 replication behavior:subGraphNameis carried on the wire, receiving nodes auto-register viaensureSubGraph()+generateSubGraphRegistration(), and replicated data routes to the correct sub-graph named graph.Removed unused
ContextGraphManager.listSubGraphsfrompackages/storage/src/graph-manager.ts. This was a graph-URI walk with divergent semantics from the spec-compliantDKGAgent.listSubGraphs(which queries_metavia SPARQL). Zero callers in the codebase; its reserved-prefix list still contained stale entries post the PR feat: add SKILL.MD agent onboarding and MarkItDown document processor #104 rename. Deletion removes a footgun for future code.Assertion operations now validate sub-graph registration.
assertionCreate,assertionWrite,assertionQuery,assertionPromote, andassertionDiscardall call a new private helperensureSubGraphRegisteredthat performs the same `ASK` over `_meta` that `publish()` already does at `:710-729`. Previously these operations silently created graphs under unregistered sub-graph URIs, orphaning the triples in graph URIs no `_meta` discovery query would ever return. The guard is opt-in — calls without a `subGraphName` are unchanged. Error: `Sub-graph "{name}" has not been registered in context graph "{contextGraphId}". Call createSubGraph() first.`Behavior clarification, not a breaking change: any caller that was relying on the previous silent-orphaning behavior was already broken (the orphaned triples were unreachable via spec-compliant discovery). The new error is actionable and the fix path is one call to `createSubGraph()`. Peer-side replication is unaffected — gossip-received data goes through `store.insert` directly (`gossip-publish-handler.ts:214`), not through the assertion API, so the new guard does not block replication.
Finding 4 (assertion registration check) does not require a companion spec change: §16.2.2 already implies registration-before-write semantics. The companion spec PR covers only findings 1, 2, 6, 7 (prose), and 8 — the items the current spec omits.
Literal stripping bug fixed in `DKGAgent.listSubGraphs`. Replaced three per-field regex strips with calls to the existing in-file `stripLiteral()` helper. The previous `/^"|".*$/g` pattern on `createdAt` was greedy and ate any inner quote; the new version correctly handles `"foo"`, `"foo"^^xsd:dateTime`, and `"foo"@en`.
JSDoc `@throws` note added to `DKGPublisher.publishFromSharedMemory` documenting the existing (undocumented) constraint that `subGraphName` cannot be combined with `publishContextGraphId` — the remap flow targets `/context/{id}` URIs which are incompatible with sub-graph URIs.
Spec PR companion
Companion spec updates for the same issue (findings 2, 6, 7 prose, 8 — all spec-catchup items, plus the gossip auto-registration §16.2.6 rewrite) are in a separate dkgv10-spec PR. No spec change is required for finding 4 — §16.2.2 already implies that operations must target a registered sub-graph; this PR brings the assertion ops in line with that implicit contract.
Test plan
Reviewer guidance — Linux CI is the gating signal
Please do not be spooked by Windows-env failures. When running the full `@origintrail-official/dkg-agent` suite locally on Windows, 9 tests fail in 8 files. None of these failures are caused by this PR's changes — they are all pre-existing environmental issues that affect the agent suite generally:
None of these tests touch `packages/publisher/src/dkg-publisher.ts`, `packages/agent/src/dkg-agent.ts`, or `packages/storage/src/graph-manager.ts` (the three source files this PR modifies). The 15 sub-graph e2e tests that DO exercise the modified code all pass locally. Please rely on the GitHub Actions Linux runner for the definitive green signal — that is the merge gate, not local Windows runs.
Closes selected findings of OriginTrail/dkgv10-spec#81.
🤖 Generated with Claude Code