Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
0b42ebc
fix(agent): safely clean finalized receiver SWM
Bojan131 Jul 30, 2026
4a6245c
fix(agent): defer finalized SWM cleanup under load
Bojan131 Jul 30, 2026
3a5ab91
fix(agent): preserve finalized SWM cleanup through recovery
Bojan131 Jul 30, 2026
ee1a533
fix(agent): drain finalized SWM after catchup
Bojan131 Jul 30, 2026
1d9fcfc
fix(agent): queue finalized SWM cleanup after catchup
Bojan131 Jul 30, 2026
f4ddb01
fix(agent): retain explicit public CG cleanup scope
Bojan131 Jul 30, 2026
ba05160
fix(agent): retry finalized SWM drain under load
Bojan131 Jul 30, 2026
1df66a3
fix(agent): reserve lifecycle lane for SWM drain
Bojan131 Jul 30, 2026
84353e2
fix(agent): prevent finalized SWM resurrection
Bojan131 Jul 30, 2026
79019ce
fix(agent): address red Bug Bot findings
Bojan131 Jul 31, 2026
ab39b89
test(chain): allow parallel code-check ordering
Bojan131 Jul 31, 2026
9958b67
test(agent): address finalized SWM review findings
Bojan131 Jul 31, 2026
e84d461
refactor(agent): defer finalized SWM cleanup to idle GC
Bojan131 Jul 31, 2026
36dd676
Merge remote-tracking branch 'origin/testnet-canary' into codex/fix-r…
Bojan131 Jul 31, 2026
4b1a2a9
refactor(agent): isolate finalized SWM cleanup ownership
Bojan131 Jul 31, 2026
b375fc4
Merge remote-tracking branch 'origin/testnet-canary' into codex/fix-r…
Bojan131 Jul 31, 2026
22f6f04
test(agent): pin the finalized-SWM GC safety boundaries
Jurij89 Aug 2, 2026
c2deec0
perf(agent): keep local GC rows off the peer-serving snapshot budget
Jurij89 Aug 2, 2026
e96ca29
perf(agent): read the finalization tombstone once per ingested KA
Jurij89 Aug 2, 2026
5df2104
perf(agent): bound and attribute late-receipt snapshot verification
Jurij89 Aug 2, 2026
88b56ef
fix(agent): resume finalized-SWM sweeps from a rotation cursor
Jurij89 Aug 2, 2026
bf79714
fix(agent): run finalized-SWM meta-graph discovery on the background …
Jurij89 Aug 2, 2026
4927266
docs(agent): scope the finalized-SWM discovery signal claim
Jurij89 Aug 2, 2026
4c9d937
fix(agent): correct the stalled-head deferral count and rotation docs
Jurij89 Aug 2, 2026
578fe95
fix(agent): dedupe late-receipt snapshot work by content, not by cand…
Jurij89 Aug 2, 2026
b091737
test(agent): pin the finalized-SWM GC rotation cursor
Jurij89 Aug 2, 2026
d203b85
docs(agent): record why the cleanup task is armed after the payload w…
Jurij89 Aug 2, 2026
c02da84
test(agent): pin the finalized-cleanup re-arm on every ingest path
Jurij89 Aug 2, 2026
0a52718
test(agent): pin the late-receipt snapshot content memo
Jurij89 Aug 2, 2026
28a1e3d
Merge branch 'fix-1996-sync' into integrate-1996
Jurij89 Aug 2, 2026
a13e8d6
Merge branch 'fix-1996-qa' into integrate-1996
Jurij89 Aug 2, 2026
ac2d120
test(agent): name two lock tests after what they verify
Jurij89 Aug 2, 2026
9fce03f
Merge branch 'fix-1996-qa' into integrate-1996
Jurij89 Aug 2, 2026
148c7a8
test(agent): prove wake coalescing instead of cancelling it
Jurij89 Aug 2, 2026
067e06f
fix(agent): keep thrown scheduler pressure on the GC retry path
Jurij89 Aug 2, 2026
8f56573
refactor(agent): name the transient-vs-terminal sweep failure policy
Jurij89 Aug 2, 2026
4b49265
test(agent): pin scheduler-rejection retry and its boundary
Jurij89 Aug 2, 2026
b60cc2f
Merge branch 'fix-1996-gc' into integrate-1996
Jurij89 Aug 2, 2026
f18fb01
Merge branch 'fix-1996-qa' into integrate-1996
Jurij89 Aug 2, 2026
70322bd
test(agent): cover each scheduler-rejection site independently
Jurij89 Aug 2, 2026
9cb77b7
Merge branch 'fix-1996-qa' into integrate-1996
Jurij89 Aug 2, 2026
6656dc2
test(agent): pin all three local-cleanup predicates against peer leak
Jurij89 Aug 2, 2026
3dba2a0
Merge branch 'fix-1996-sync' into integrate-1996
Jurij89 Aug 2, 2026
dfb8bd7
test(agent): pin each local-cleanup predicate in its own case
Jurij89 Aug 2, 2026
b8d8594
Merge branch 'fix-1996-sync' into integrate-1996
Jurij89 Aug 2, 2026
b7b4b4b
fix(agent): derive responder cleanup IRIs from the canonical constants
Jurij89 Aug 2, 2026
ccfb7bc
Merge branch 'fix-1996-sync' into integrate-1996
Jurij89 Aug 2, 2026
4579522
fix(agent): close the rotation when its sole head cannot finish
Jurij89 Aug 2, 2026
df43881
fix(agent): resume the meta-graph walk inside an oversized context graph
Jurij89 Aug 2, 2026
ec59670
fix(agent): persist the rotation cursor when a sweep faults
Jurij89 Aug 2, 2026
9e9f41c
test(agent): stop the rotation tests racing a real-time deadline
Jurij89 Aug 2, 2026
6501745
fix(agent): page task discovery with a keyset cursor
Jurij89 Aug 2, 2026
cc0fa07
docs(agent): correct the short-page wrap claim in 650174547
Jurij89 Aug 2, 2026
5cdd805
test(agent): record a cursor mutant that new call sites cannot outgrow
Jurij89 Aug 2, 2026
7bb0ac3
test(agent): separate site-proof from blanket mutants in the note
Jurij89 Aug 2, 2026
6ea5a38
fix(agent): serialize the cleanup-marker write with the per-KA SWM lock
Jurij89 Aug 2, 2026
ea2d3ee
Merge commit 'cc0fa0704' into integrate-1996
Jurij89 Aug 2, 2026
66b216a
Merge commit '6ea5a38e9' into integrate-1996
Jurij89 Aug 2, 2026
cbc8d90
test(agent): pin the stale-task retirement lifecycle
Jurij89 Aug 2, 2026
c4c568b
test(agent): pin the retirement path's in-lock head re-check
Jurij89 Aug 2, 2026
ab63da7
Merge commit 'c4c568bc7' into integrate-1996
Jurij89 Aug 2, 2026
bb2efd5
fix(agent): filter immutable-snapshot discovery before LIMIT, not after
Jurij89 Aug 2, 2026
4624335
Merge branch 'fix-1996-sync' into integrate-1996
Jurij89 Aug 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/agent/src/dkg-agent-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ import {
type SignedAgentDelegation,
} from './auth/agent-delegation.js';
import { SyncVerifyWorker } from './sync-verify-worker.js';
import type { FinalizedSwmCleanupWorker } from './finalized-swm-cleanup-worker.js';
import type { FinalizedSwmCleanupService } from './finalized-swm-cleanup-service.js';
import { bindRandomSampling, type RandomSamplingDisabledReason, type RandomSamplingHandle, type RandomSamplingStatus } from './random-sampling-bind.js';
import { connectToMultiaddr, ensurePeerConnected as ensurePeerConnectedAtom, primeCatchupConnections as primeCatchupConnectionsAtom } from './p2p/peer-connect.js';
import { Messenger, type SloProtocolStats } from './p2p/messenger.js';
Expand Down Expand Up @@ -879,6 +881,24 @@ export class DKGAgentBase {
*/
static readonly SWM_ACK_QUORUM_TICK_MS = 5_000;

/**
* Finalized-SWM GC slice budgets. The sweep yields once either is spent and
* resumes at the next context graph in its rotation, so these trade cleanup
* latency against how long one background slice may hold store capacity.
* Env-overridable for ops tuning; the service clamps candidates to 16.
*/
static readonly FINALIZED_SWM_CLEANUP_MAX_CANDIDATES =
Math.max(1, Number(process.env['DKG_FINALIZED_SWM_CLEANUP_MAX_CANDIDATES']) || 4);
static readonly FINALIZED_SWM_CLEANUP_BUDGET_MS =
Math.max(1, Number(process.env['DKG_FINALIZED_SWM_CLEANUP_BUDGET_MS']) || 10_000);
/**
* Delay before re-waking the GC after a sweep yielded on pressure or budget,
* or drained part of a known backlog. This is the cadence that actually fires
* while the node is draining, so it is the knob ops reach for first.
*/
static readonly FINALIZED_SWM_CLEANUP_RETRY_MS =
Math.max(1, Number(process.env['DKG_FINALIZED_SWM_CLEANUP_RETRY_MS']) || 5_000);

/**
* Phase B — chain-driven VM reconciliation sweep cadence. The periodic sweep
* is the safety net behind the live `KnowledgeAssetRegisteredToContextGraph`
Expand Down Expand Up @@ -964,6 +984,9 @@ export class DKGAgentBase {
protected messageHandler: MessageHandler | null = null;
protected chainPoller: ChainEventPoller | null = null;
protected swmCleanupTimer: ReturnType<typeof setInterval> | null = null;
protected finalizedSwmCleanupTimer: ReturnType<typeof setInterval> | null = null;
protected finalizedSwmCleanupWorker?: FinalizedSwmCleanupWorker;
protected finalizedSwmCleanupService?: FinalizedSwmCleanupService;
/** Phase B — periodic chain-driven VM reconciliation sweep timer. */
protected vmReconcileTimer: ReturnType<typeof setInterval> | null = null;
/** Phase B — unified per-CG coalescing and node-wide admission policy. */
Expand Down
8 changes: 8 additions & 0 deletions packages/agent/src/dkg-agent-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ export const SYNC_MIN_GRAPH_BUDGET_MS = 10_000;
export const DEBUG_SYNC_PROGRESS = process.env.DKG_DEBUG_SYNC_PROGRESS === '1';
export const DEFAULT_SWM_TTL_MS = 30 * 24 * 60 * 60 * 1000; // 30 days
export const SWM_CLEANUP_INTERVAL_MS = 15 * 60 * 1000; // run cleanup every 15 minutes
export const FINALIZED_SWM_CLEANUP_ROOT_PREDICATE =
'http://dkg.io/ontology/finalizedSwmCleanupRoot';
export const FINALIZED_SWM_CLEANUP_TASK_TYPE =
'http://dkg.io/ontology/FinalizedSwmCleanupTask';
export const FINALIZED_SWM_CLEANUP_MARKED_AT_PREDICATE =
'http://dkg.io/ontology/finalizedSwmCleanupMarkedAt';
export const FINALIZED_SWM_CLEANUP_HEAD_FINGERPRINT_PREDICATE =
'http://dkg.io/ontology/finalizedSwmCleanupHeadFingerprint';
export const SYNC_DENIED_RESPONSE = '__DKG_SYNC_DENIED__';

// ── Gossip reconnect ──────────────────────────────────────────────────
Expand Down
240 changes: 154 additions & 86 deletions packages/agent/src/dkg-agent-lifecycle.ts

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions packages/agent/src/dkg-agent-swm-substrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,11 @@ export class SwmSubstrateMethods extends DKGAgentBase {
markContextGraphMetaDirtyFromQuads: (quads) => {
this.contextGraphMetaProjection.markDirtyFromQuads(quads);
},
// The SAME map catch-up and the finalized-SWM GC take, so the cleanup
// marker write serializes against them on the per-KA key.
writeLocks: this.writeLocks,
publicSnapshotStore: this.publicSnapshotStore,
wakeFinalizedSwmCleanup: () => this.wakeFinalizedSwmCleanup(),
runtime: this.finalizationRuntime,
},
);
Expand Down
9 changes: 9 additions & 0 deletions packages/agent/src/dkg-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,15 @@ export class DKGAgent extends DKGAgentBase {
clearInterval(this.swmCleanupTimer);
this.swmCleanupTimer = null;
}
if (this.finalizedSwmCleanupTimer) {
clearInterval(this.finalizedSwmCleanupTimer);
this.finalizedSwmCleanupTimer = null;
}
if (this.finalizedSwmCleanupWorker) {
await this.finalizedSwmCleanupWorker.close();
this.finalizedSwmCleanupWorker = undefined;
}
this.finalizedSwmCleanupService = undefined;
if (this.hostModeReconcilerTimer) {
clearInterval(this.hostModeReconcilerTimer);
this.hostModeReconcilerTimer = null;
Expand Down
Loading
Loading