Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Merge origin/capy/6712-pr4b-pass (lane B on lane A core) into #6712 PR 4b lane C

garrytan77560de66067
diff --cc src/core/persistence/sync-pass.ts
index 6922ac80d8,b6b2e281e2..6b25f13214
--- a/src/core/persistence/sync-pass.ts
+++ b/src/core/persistence/sync-pass.ts
@@@ -297,10 -348,11 +348,11 @@@ export async function readShadowLevel(e
// Working mode rehashes every path (the full round's unconditional rehash); committed mode probes candidates only.
t = timer();
- const probes = mode === 'working' ? (await hashWorkingLevel(root, gitRoot, [...domain], tree)).probes : new Map();
+ const hashed = mode === 'working' ? await hashWorkingLevel(root, gitRoot, [...domain], tree) : null;
+ const probes = hashed?.probes ?? new Map();
timings.Dp = t();
- const levelOf = (path: string, probe: { dp: string; rawOid: string | null } | undefined): string | null => {
+ const levelOf = (path: string, probe: { dp: string; rawOid: string | null; rawSha256: string | null } | undefined): string | null => {
const committed = tree.get(path) ?? null;
return mode === 'committed' ? committed?.oid ?? null
: !probe || probe.dp === 'deleted' ? null
diff --cc src/core/persistence/sync-run.ts
index f4e07b3e60,558eb7774c..e97872de5d
--- a/src/core/persistence/sync-run.ts
+++ b/src/core/persistence/sync-run.ts
@@@ -68,8 -68,9 +68,11 @@@ import { withSyncTail } from './sync-ta
import { assertDrainLease, currentDrainLease, leaseHeldResult, readDrainHolder, withDrainLease } from './sync-lease.ts';
import { LockStolenError, LockUnavailableError, syncLockId } from '../db-lock.ts';
import { currentSubmissionAuthority } from '../minions/submission-authority.ts';
+import { serr } from '../console-prefix.ts';
+import { noteIdentityDowngrades } from '../sync-identity-downgrades.ts';
+ import { assertPassAdmission, isPassBatchKey, passBatchStep, passRequestId, readPassBatch, setPassBatch, type PassEntry } from './sync-pass-batch.ts';
+ import type { PassStamp } from './sync-prepare.ts';
+ import { runSyncPass } from './sync-pass-run.ts';
export interface ManagedSyncWriteDiagnostic {
source_id: string;
@@@ -909,14 -921,14 +923,14 @@@ async function alreadyImportedAtOrigin(
/**
* #5522: the page now at the origin already holds exactly the content this entry would import (the preparer's own no-op verdict).
- * #6278: the preparation races the sync budget; past it the origin refusal stands, and a cancelled run propagates.
+ * #6278: the preparation races the sync budget; past it the origin refusal stands, and a cancelled run propagates. #6712 `pageOnly`: the page holds what `content` (a `both` entry's recorded disk blob) imports, a canonical writeback aside.
*/
async function sameContentAtOrigin(engine: BrainEngine, cursor: Cursor, entry: Cursor['entries'][number], key: string,
- snapshot: Awaited<ReturnType<BrainEngine['readPageSnapshot']>>, content: string, rawHash: string | null, lineEndingOnly: boolean, signal?: AbortSignal): Promise<boolean> {
- if (!snapshot || snapshot.page.deleted_at != null) return false;
- const intent: SyncIntent = { kind: 'managed_sync_import', expected_revision: snapshot.revision, sourcePath: entry.sourcePath, path: entry.path, rawHash, content, lineEndingOnly,
+ snapshot: Awaited<ReturnType<BrainEngine['readPageSnapshot']>>, content: string | null, rawHash: string | null, lineEndingOnly: boolean, signal?: AbortSignal, pageOnly = false): Promise<boolean> {
+ if (!snapshot || snapshot.page.deleted_at != null || content === null) return false;
+ const intent: SyncIntent = { kind: 'managed_sync_import', expected_revision: snapshot.revision, sourcePath: entry.sourcePath, path: entry.path, rawHash: pageOnly ? sha256(content) : rawHash, content, lineEndingOnly,
processingOptions: cursor.processingOptions, ownerEpoch: String(cursor.binding.owner_epoch), syncAuthority: cursor.authority,
- cursorKey: key, runId: cursor.runId, slugMode: cursor.slugMode, index: cursor.index, total: cursor.entries.length, from: cursor.from, target: cursor.target, working: entry.working ?? false };
+ ...cursorIntent(cursor, key), slugMode: cursor.slugMode, from: cursor.from, target: cursor.target, working: entry.working ?? false };
try {
const budgetMs = await syncPreparationBudgetMs(engine);
const prepared = await raceSyncBudget(prepareManagedSyncMutation(engine, screeningRequest({ source_id: cursor.sourceId, source_incarnation: cursor.incarnation, slug: snapshot.page.slug,
diff --cc src/core/persistence/sync-status.ts
index ee47b68ab2,32a025d970..501e0438fa
--- a/src/core/persistence/sync-status.ts
+++ b/src/core/persistence/sync-status.ts
@@@ -42,7 -42,10 +42,11 @@@ import { classifyRecordedFault, classif
import type { PublicCategory } from './public-category.ts';
import { readSyncFile, resolveManagedSyncContext } from './sync-discovery.ts';
import { sha256 } from './digest.ts';
+import { listIdentityDowngrades } from '../sync-identity-downgrades.ts';
+ import { passResumeArgs } from './sync-pass-readers.ts';
+ import { passConvergence, passStatusNext, passStatusState } from './sync-pass-status.ts';
+ import { MANAGED_SYNC_PASS_OP, SYNC_DELETES_WITHHELD_OP, type PassRow } from './sync-pass-row.ts';
+ import type { DeletesWithheld } from './sync-markers.ts';
export interface SyncStatusHold extends SyncFaultVerdict {
code: string;
@@@ -306,12 -318,14 +321,14 @@@ export async function readSyncStatus(en
const { recovery_next, ...terminal } = detail ? await terminalSummary(engine, sourceId, blockers.checkpoint_blockers)
: { status: 'unknown' as const, reason: 'not_read: run sync status with --detail', recovery_next: recovery.status === 'ok' && recovery.first ? recoveryAction(sourceId, recovery.first) : undefined };
const connectorLastError = await (await import('./connector-status.ts')).readConnectorLastError(engine, sourceId);
- const [state, stateReason] = statusState({ human: !!human, oldest, recovery, liveJob: liveJob !== null, unfinished, lastError: !!lastError, actionable: actionable.length > 0, holds: holds.length > 0 });
+ const [state, stateReason] = statusState({ human: !!human, oldest, recovery, liveJob: liveJob !== null, unfinished, lastError: !!lastError, actionable: actionable.length > 0, holds: holds.length > 0, pass: passState });
+ const admission = await (await import('./sync-admission.ts')).syncAdmissionStatus(engine, sourceId, source.incarnation);
+ const passNext = passRow && passState && passState[1] === stateReason ? passStatusNext(sourceId, passState[1], passRow, resume) : null;
return { source_id: sourceId, run_id: header?.runId ?? null,
cursor: header ? { index: Number(header.index), total: Number(header.total), pinned_target: header.target ?? null, last_advance_at: p ? new Date(p.lastAt).toISOString() : null, done: !!header.done } : null,
- committed_last_10m: Number(committed?.n ?? 0), ...estimate, live_job_id: liveJob, holds, last_error: lastError, needs_human: !!human, ...(human ? { human_reason: human.human_reason } : {}),
+ committed_last_10m: Number(committed?.n ?? 0), ...estimate, live_job_id: liveJob, holds, identity_downgrades: await listIdentityDowngrades(engine, [sourceId]), last_error: lastError, needs_human: !!human, ...(human ? { human_reason: human.human_reason } : {}),
resume_argv: resume, ...blockers, cursors: detail ? await liveCursors(engine, sourceId, source.incarnation, selected?.key ?? null, failures) : [],
- terminal_failures: terminal, connector_last_error: connectorLastError, next: next ?? recovery_next ?? (stateReason === 'request_pending' && oldest.status === 'ok' && oldest.request ? { argv: ['gbrain', 'sync', ...resume], consent: [], actor: 'agent', requires_exclusive: false, verify,
+ terminal_failures: terminal, connector_last_error: connectorLastError, next: next ?? recovery_next ?? passNext ?? (stateReason === 'request_pending' && oldest.status === 'ok' && oldest.request ? { argv: ['gbrain', 'sync', ...resume], consent: [], actor: 'agent', requires_exclusive: false, verify,
why: `Write request ${oldest.request.request_id} of this source is still ${oldest.request.state}${oldest.request.step ? ` (step ${oldest.request.step})` : ''}; a running owner finishes it on its own, and the next sync of this source drains it.` } satisfies Action
: stateReason === 'status_unknown' ? { argv: ['gbrain', 'sync', 'status', '--source', sourceId, '--json'], consent: [], actor: 'agent', requires_exclusive: false, verify,
why: `The oldest-blocker or recovery probe did not answer within ${SYNC_STATUS_PROBE_MS / 1000} s, so this status does not know the state (it is not reported synced). Rerun it after a short wait; gbrain doctor --json checks the database if it keeps timing out.` } satisfies Action : null),