Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

wip(#6712 PR 4b lane B): round classes and summary in the pass row

garrytan8ea41e0aaf52
diff --git a/src/core/persistence/sync-pass-apply.ts b/src/core/persistence/sync-pass-apply.ts
index d2c051f000..348038d857 100644
--- a/src/core/persistence/sync-pass-apply.ts
+++ b/src/core/persistence/sync-pass-apply.ts
@@ -45,7 +45,8 @@ import { readSyncImportProvenances, recordSyncImportProvenances, syncImportParse
import { assertDrainLease } from './sync-lease.ts';
import { clearDeletesWithheld, deleteSetHash, readDeletesWithheld, readOriginDeletedMarker, retireOriginDeletedMarker, writeDeletesWithheld, type DeletesWithheld } from './sync-markers.ts';
import type { ShadowLevel, ShadowPath } from './sync-pass.ts';
-import { SETTLE_MISMATCH_STREAK, type ManagedSyncPassValue } from './sync-pass-row.ts';
+import { SETTLE_MISMATCH_STREAK, type ManagedSyncPassValue, type PassRoundSummary } from './sync-pass-row.ts';
+import { syncClassAction, type SyncClassAction } from './sync-classify.ts';
import type { SyncAdmission } from './sync-admission.ts';
/** Legacy pages the sweep screens per pass after the incarnation's first full round (design §2.7, [estimated]). */
@@ -72,11 +73,14 @@ export interface PassApplyState {
/** keep_db paths admitted in this pass: never admitted twice. */
keepDbTaken: string[];
matchedSlugs: string[];
+ /** The newest round's classes and summary (design §9), after this module settled what it finished. */
+ classes: Record<string, { count: number; action: SyncClassAction }>;
+ summary: PassRoundSummary | null;
}
export function newPassApplyState(): PassApplyState {
return { markersRetired: 0, holds: { file_gone: 0, tombstone_edited: 0, purged_differs: 0, settle_mismatch: 0 }, settleMismatch: [], adopted: 0,
- swept: { screened: 0, recorded: 0 }, sweptAll: false, withheld: null, withheldCount: 0, keepDb: { admitted: 0, pending: 0, paused: 0, refused: {} }, keepDbTaken: [], matchedSlugs: [] };
+ swept: { screened: 0, recorded: 0 }, sweptAll: false, withheld: null, withheldCount: 0, keepDb: { admitted: 0, pending: 0, paused: 0, refused: {} }, keepDbTaken: [], matchedSlugs: [], classes: {}, summary: null };
}
export interface PassApplyInput {
@@ -119,6 +123,32 @@ export async function applyPassRound(engine: BrainEngine, level: ShadowLevel, in
await sweepLegacy(engine, level, input, state);
await admitKeepDb(engine, level, input, state);
for (const entry of level.paths) if (entry.result.cls === 'matched' && entry.slug) state.matchedSlugs.push(entry.slug);
+ summarizeRound(level, state);
+}
+
+/** The round's classes (`in_flight`, `keep_db_pending`, `deletes_withheld` and `paused_*` apart) and level summary (design §9). */
+export function summarizeRound(level: ShadowLevel, state: PassApplyState): void {
+ const RANK: Record<SyncClassAction, number> = { none: 0, owner: 1, repair: 2 };
+ const classes: PassApplyState['classes'] = {};
+ const summary: PassRoundSummary = { db_ahead: { pending: 0, db_only: 0, unproven: 0, by_prefix: {} }, full_skipped_db_ahead: 0, legacy_unverified: 0, legacy_pageless: 0 };
+ for (const entry of level.paths) {
+ const r = entry.result;
+ const key = r.inFlight ? 'in_flight' : r.withheld ? 'deletes_withheld' : r.pending ? 'keep_db_pending' : r.paused ? 'paused_keep_db' : r.cls;
+ const action: SyncClassAction = key === 'deletes_withheld' ? 'repair' : key === 'keep_db_pending' || key === 'paused_keep_db' || key === 'in_flight' ? 'owner' : r.classAction ?? syncClassAction(r.cls);
+ const slot = classes[key] ?? (classes[key] = { count: 0, action });
+ slot.count++;
+ if (RANK[action] > RANK[slot.action]) slot.action = action;
+ if (r.cls === 'db_ahead' && r.sub) {
+ summary.db_ahead[r.sub]++;
+ const prefix = entry.path.includes('/') ? `${entry.path.split('/')[0]}/` : '';
+ summary.db_ahead.by_prefix[prefix] = (summary.db_ahead.by_prefix[prefix] ?? 0) + 1;
+ if (r.fullSkipped) summary.full_skipped_db_ahead++;
+ }
+ if (r.cls === 'legacy_unverified') summary.legacy_unverified++;
+ if (entry.legacyPageless) summary.legacy_pageless++;
+ }
+ state.classes = classes;
+ state.summary = summary;
}
/** Design §2.5: retire markers whose origin left both `T` and the disk, or that a live page claims again (compare-and-delete). */
diff --git a/src/core/persistence/sync-pass-row.ts b/src/core/persistence/sync-pass-row.ts
index 4a6b62c659..ee56998cd6 100644
--- a/src/core/persistence/sync-pass-row.ts
+++ b/src/core/persistence/sync-pass-row.ts
@@ -85,9 +85,20 @@ export interface ManagedSyncPassValue {
counts: Record<string, number>;
duration_ms: number | null;
timings_ms: Record<string, number>;
+ /** #6712 PR 4b (design §9): the newest round's classes (`{count, action}`) and level summary, for `sync status`'s live `convergence`. */
+ classes?: Record<string, { count: number; action: 'none' | 'owner' | 'repair' }>;
+ summary?: PassRoundSummary;
};
}
+/** What `sync status`'s live `convergence` reads of the newest round besides its classes (design §9). */
+export interface PassRoundSummary {
+ db_ahead: { pending: number; db_only: number; unproven: number; by_prefix: Record<string, number> };
+ full_skipped_db_ahead: number;
+ legacy_unverified: number;
+ legacy_pageless: number;
+}
+
export const OPEN_AT_STAMP_CAP = 256;
/** A settle mismatch at one `(path, level)` becomes a hold after this many consecutive passes (design §3.1). */
export const SETTLE_MISMATCH_STREAK = 3;
diff --git a/src/core/persistence/sync-pass-run.ts b/src/core/persistence/sync-pass-run.ts
index 12985c648b..1309c91f75 100644
--- a/src/core/persistence/sync-pass-run.ts
+++ b/src/core/persistence/sync-pass-run.ts
@@ -299,6 +299,7 @@ export async function runSyncPass(engine: BrainEngine, input: SyncPassInput): Pr
const save = async (outcome: PassOutcome, stopReason: string | null) => {
const ended = outcome !== 'open';
value.telemetry = { ...value.telemetry, outcome, stop_reason: stopReason, settled: S.size, counts: { ...counts, ...passApplyCounts(applied) },
+ classes: applied.classes, ...(applied.summary ? { summary: applied.summary } : {}),
...(ended ? { ended_at: new Date().toISOString(), duration_ms: Date.now() - started } : {}) };
if (outcome === 'blocked' || stopReason === 'not_converged') value.obligations.stuck_since ??= new Date().toISOString();
await engine.transaction(async tx => { await assertDrainLease(tx, sourceId); await writePassRow(tx, value); });