Skip to content

feat(agent): reconcile selected public VM from chain truth - #2184

Merged
branarakic merged 37 commits into
testnet-canaryfrom
codex/vm-metadata-provenance-repair
Aug 10, 2026
Merged

feat(agent): reconcile selected public VM from chain truth#2184
branarakic merged 37 commits into
testnet-canaryfrom
codex/vm-metadata-provenance-repair

Conversation

@branarakic

@branarakic branarakic commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Impact

Public VM inventory remains the chain. This PR does not introduce or require an RFC-64 VM catalog.

It makes two public-VM recovery paths complete and safe:

  1. A receiver that already has exact SWM bytes can materialize a finalized public KA without inventing a missing client transaction hash, but only after independent chain and content verification.
  2. An edge node that explicitly selects a public Context Graph through RFC-64 configuration now reconciles that graph's finalized VM inventory from the chain even when it is not a subscription and was only passively discovered.

The selected-only path is intentionally separate from subscription state. It does not persist a synthetic subscription, install gossip handlers, trigger RS healing, or expand automatic SWM scope. It owns a dedicated durable cursor bound to the exact DKG deployment, local CG id, name hash, and numeric on-chain CG id. Restart resumes from that cursor, while a deployment or binding change resets it fail-closed.

Startup subscription rehydration also has an independent operator gate. Disabling it leaves persisted non-system subscription rows and RDF data intact but dormant, so stale historical subscriptions do not silently fan out background work. Explicit subscriptions after startup still work normally.

/api/status.syncLifecycle.syncReconcilerEnabled exposes the effective reconciler gate using the same resolver as runtime, including environment-variable precedence, so canary certification can prove configured versus honored behavior.

Receiptless public finalization

Before

sequenceDiagram
    participant Chain
    participant Reconciler
    participant SWM
    participant VM

    Chain->>Reconciler: Finalized public KA inventory row
    Reconciler->>SWM: Verify exact assertion bytes
    SWM-->>Reconciler: Exact bytes but no transaction provenance
    Reconciler-->>VM: Defer indefinitely
Loading

After

sequenceDiagram
    participant Chain
    participant Reconciler
    participant SWM
    participant VM

    Chain->>Reconciler: Finalized public KA inventory row
    Reconciler->>Chain: Verify binding, policy, version, and root
    Reconciler->>SWM: Recompute exact assertion root and shape
    SWM-->>Reconciler: Exact chain-bound bytes
    Reconciler->>VM: Materialize finalized public assertion
    Reconciler->>VM: Persist receiptless chain-authenticated metadata
Loading

Both finalization entry points now use one applyPublicFinalizedMaterialization helper, so idempotence, metadata repair, and durable flush semantics cannot drift.

Selected public VM reconciliation

Before

sequenceDiagram
    participant Config
    participant Agent
    participant SubscriptionStore
    participant Chain

    Config->>Agent: Select a public Context Graph
    Agent->>SubscriptionStore: Create synthetic selected-only subscription
    Agent->>Chain: Reconcile through subscription path
    Note over Agent,SubscriptionStore: Selection and subscription semantics are coupled
Loading

After

sequenceDiagram
    participant Config
    participant Agent
    participant Chain
    participant CursorStore
    participant VM

    Config->>Agent: Select a public Context Graph
    Agent->>Chain: Resolve name hash to current numeric CG id
    Agent->>Chain: Enumerate finalized KA inventory
    Agent->>Chain: Revalidate binding before materialization
    Agent->>VM: Fetch, verify, and materialize exact public KA
    Agent->>CursorStore: Persist deployment-bound reconcile watermark
    Note over Agent,CursorStore: No subscription persistence or RS heal
Loading

Startup subscription rehydration

Before

sequenceDiagram
    participant Store as Persisted subscriptions
    participant Agent
    participant Network

    Store->>Agent: Load every historical non-system row
    Agent->>Network: Activate gossip and automatic sync scope
Loading

After

sequenceDiagram
    participant Config
    participant Store as Persisted subscriptions
    participant Agent
    participant Network

    Config->>Agent: Resolve rehydration gate
    Store->>Agent: Load persisted rows for accounting
    alt Rehydration enabled
        Agent->>Network: Activate rows up to configured cap
    else Rehydration disabled
        Agent-->>Store: Preserve rows and RDF data unchanged
        Note over Agent,Network: Rows remain dormant; no startup fan-out
    end
Loading

Safety properties

  • Public receiptless materialization requires stable on-chain CG binding, active finalized public policy, stable root count and version, matching latest root, and locally recomputed exact content.
  • Private or unknown-policy graphs still require canonical receipt provenance and locally authenticated SWM controls.
  • Selected-only reconciliation resolves directly through the chain name-hash registry; it does not depend on ontology metadata.
  • NameRegistry bytes32 commitments are verified and reverse-resolved to a positive numeric ContextGraphStorage id before RDF or subscription mutation.
  • Selected cursor reads and writes are scoped to the exact chain deployment, local id, name hash, and numeric id; unfenceable pre-v33 rows are discarded.
  • Resolver ambiguity and RPC integrity failures remain visible to operators; only a genuine null result is reported as an unresolved binding.
  • Passive discovery remains passive; selection does not become a durable subscription.
  • syncReconcilerEnabled=false gates startup sweep, periodic sweep, live registration, and selected reconciliation consistently.

Validation

  • Live testnet public CG 298, automatic recovery only:
    • Before the receiptless fix: exact VM stalled at 397/400.
    • After the fix: the receiver automatically promoted all three missing assets and reached exact 400/400.
    • Exact VM bytes: 15,428,882.
    • After receiver restart: exact 400/400 again with no manual catch-up.
  • Exact integrated local head 5fe837036:
    • Focused agent VM, binding, finalization, discovery, gap-fill, and heal lane: 279/279 passed.
    • Chain name-hash resolver and cache/fence lane: 47/47 passed.
    • Node UI durable-store, messenger-store, and v32-to-v33 migration lane: 130/130 passed.
    • Hardhat-backed stranded-KC production composition lane: 15/15 passed.
    • Real-daemon rehydration environment override lane: 1/1 passed.
    • Agent build, type tests, and package-root test passed.
    • Chain build passed.
    • Node UI build passed.
    • Full CLI build passed.
  • Fresh GitHub CI for 5fe837036 is running.

Stack and scope

  • Targets testnet-canary.
  • Includes the chain name-hash binding refactor from fix(rfc64): resolve cold selected CG bindings from chain #2205 because selected VM reconciliation depends on its historical/current binding fences.
  • Adds SQLite schema v33 for deployment-scoped selected VM reconcile cursors. Existing v32 selected-only cursor rows are discarded because their deployment cannot be inferred safely.
  • Adds contextGraphSubscriptionRehydrationEnabled and DKG_CONTEXT_GRAPH_SUBSCRIPTION_REHYDRATION_ENABLED; the default remains enabled for compatibility.
  • Adds status-only observability for the existing reconciler gate; no new protocol-wire behavior.
  • Does not activate an RFC-64 VM catalog.
  • Does not relax private-CG provenance requirements.
  • Not merged by this PR author.

Comment thread packages/agent/src/finalization-handler.ts Outdated
Comment thread packages/agent/src/finalization-handler.ts Outdated
Comment thread packages/agent/src/finalization-handler.ts Outdated
Comment thread packages/agent/src/finalization-handler.ts Outdated
Comment thread packages/agent/src/receipt-backed-graph-scoped-evidence.ts
Comment thread packages/publisher/src/workspace-handler.ts
Comment thread packages/publisher/src/workspace-handler.ts
Comment thread packages/agent/src/finalization-handler.ts Outdated
Comment thread packages/agent/src/finalization-handler.ts Outdated
@branarakic branarakic changed the title fix(agent): repair durable VM metadata from canonical receipt fix(agent): recover exact public VM from chain inventory Aug 9, 2026
Comment thread packages/agent/src/receipt-backed-graph-scoped-evidence.ts
Comment thread packages/agent/src/receipt-backed-graph-scoped-evidence.ts Outdated
Comment thread packages/publisher/src/workspace-resolution.ts Outdated
Comment thread packages/agent/test/ka-graph-finalization-handler.test.ts Outdated
Comment thread packages/publisher/src/metadata.ts Outdated
Comment thread packages/agent/test/ka-graph-finalization-handler.test.ts
Comment thread packages/agent/src/dkg-agent-swm-host.ts Outdated
Comment thread packages/agent/src/finalization-handler.ts Outdated
Comment thread packages/agent/src/dkg-agent-swm-host.ts Outdated
@branarakic branarakic changed the title fix(agent): recover exact public VM from chain inventory feat(agent): reconcile selected public VM from chain truth Aug 9, 2026
Comment thread packages/cli/test/snapshot-page-index-store.test.ts
Comment thread packages/agent/src/dkg-agent-types.ts
Comment thread packages/chain/src/evm-context-graph-name-hash-fence.ts
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/test/context-graph-discovery.test.ts Outdated
@branarakic
branarakic added this pull request to the merge queue Aug 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to invalid changes in the merge commit Aug 10, 2026
@branarakic
branarakic added this pull request to the merge queue Aug 10, 2026
@branarakic
branarakic removed this pull request from the merge queue due to a manual request Aug 10, 2026
@branarakic
branarakic added this pull request to the merge queue Aug 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to invalid changes in the merge commit Aug 10, 2026
Comment thread packages/agent/src/dkg-agent.ts Outdated
Comment thread packages/agent/src/dkg-agent-lifecycle.ts
@branarakic
branarakic added this pull request to the merge queue Aug 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 10, 2026
Comment thread packages/agent/test/vm-reconcile-self-prime.test.ts
Comment thread packages/agent/src/dkg-agent-swm-host.ts Outdated
Comment thread packages/agent/src/dkg-agent-swm-host.ts
Comment thread packages/node-ui/src/db.ts
Comment thread packages/cli/src/daemon/lifecycle.ts
Comment thread packages/agent/src/finalization-handler.ts Outdated
@branarakic
branarakic merged commit f8f2638 into testnet-canary Aug 10, 2026
59 checks passed
}
});

it('sweeps only operator-selected accepted RFC-64 public CGs without creating a subscription', async () => {

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: This PR pushes vm-reconcile-self-prime.test.ts past 1k lines with a separate feature suite

What's wrong
The file now mixes the original self-prime regression coverage with a large selected-only RFC-64 reconciliation suite. That makes the test file harder to scan and violates the project-health threshold for files crossing 1000 lines without a strong structural reason.

Example
The new tests cover a coherent feature area: selected-only RFC-64 sweep eligibility, target resolution, cursor persistence, revalidation, disabled reconciler behavior, and lifecycle cancellation. That suite can stand on its own without living inside the existing self-prime regression file.

Suggested direction
Decompose before merging. Put the selected-only RFC-64 reconciliation scenarios in their own test module and leave this file focused on the original self-prime behavior.

Confidence note
The prompt diff shows this PR adds the selected-only block, and the current file is 1054 lines; the local git base was not aligned with the supplied PR diff, so the exact pre-PR count comes from the provided diff size plus current line count.

For Agents
Split the selected-only RFC-64 VM reconciliation tests from packages/agent/test/vm-reconcile-self-prime.test.ts into a focused file such as vm-reconcile-rfc64-selected.test.ts. Move shared setup helpers if needed and keep the existing self-prime tests scoped to self-prime behavior.

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