Skip to content

track cg subscription#304

Merged
lupuszr merged 1 commit intomainfrom
track-sync-nodes
Apr 30, 2026
Merged

track cg subscription#304
lupuszr merged 1 commit intomainfrom
track-sync-nodes

Conversation

@lupuszr
Copy link
Copy Markdown
Contributor

@lupuszr lupuszr commented Apr 28, 2026

Summary

  • Persist context graph subscription state across daemon restarts by adding durable subscription storage, rehydration on startup, and explicit tracking for shared-memory catch-up completion.
  • Add a local membership cache for context graph nodes, agents, and identities, and keep it updated from subscription, allowlist, join request, and on-chain registration flows.
  • Expose the cached membership/subscription data through the daemon and dashboard DB, and add coverage for persistence, rehydration, and membership canonicalization.

const hasContent = await agent.contextGraphHasLocalContent(paranetId).catch(() => false);
agent.markContextGraphSubscriptionState(paranetId, {
synced: true,
...(shouldSyncSharedMemory ? { sharedMemorySynced: true } : {}),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug: This flips sharedMemorySynced to true for every subscribe request that asked for shared-memory catch-up, even when the SWM leg inserted nothing or failed while durable sync still made cleanResponse true. After that, the fast path at line 1158 will skip future SWM catch-up forever. Only persist this flag once the shared-memory phase itself completed cleanly.

): ContextGraphSub {
this.subscribedContextGraphs.set(contextGraphId, next);
if (options?.persist !== false) {
this.persistContextGraphSubscription(contextGraphId);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug: setContextGraphSubscription() now persists every subscribed=true transition immediately. subscribeToContextGraph() is called before the catch-up / allowlist result is known, so a denied or mistyped context graph will still be written to disk and rehydrated as a real subscription on restart. Persist only after a successful catch-up, or clear the row when the subscribe job ends failed/denied.

throw new Error('createOnChainContextGraph not available on chain adapter');
}
const result = await this.chain.createOnChainContextGraph(params);
const contextGraphId = result.contextGraphId.toString();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug: This helper keys membership rows by the chain-generated contextGraphId, but the rest of the daemon exposes memberships by the local context-graph id. When registerContextGraph("foo") calls this, the same graph gets split between foo and <on-chain-id> (or even "0" if the create result is unsuccessful). Thread the caller's local id into these upserts and skip them unless the on-chain create actually succeeded.

contextGraphId,
principalType: 'node',
principalId: this.peerId,
role: 'subscriber',
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Issue: Every subscription-state refresh rewrites the local node as role: 'subscriber'. That overwrites the curator row inserted during createContextGraph() / invite flows, so /api/context-graph/{id}/members will drift after the first sync or rehydrate. Preserve the existing role/source when updating metadata, or let callers pass the intended role.

@lupuszr lupuszr merged commit b80a299 into main Apr 30, 2026
22 of 35 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.

2 participants