Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(sync): #6712 PR 4b lane C: typecheck the drain carry and the blocked-pass receipt rows

garrytand3ae1277d6dd
diff --git a/src/commands/doctor/checks/git-holds.ts b/src/commands/doctor/checks/git-holds.ts
index 2cd8febf1a..de913967eb 100644
--- a/src/commands/doctor/checks/git-holds.ts
+++ b/src/commands/doctor/checks/git-holds.ts
@@ -111,7 +111,8 @@ function fenceAutoSentence(auto: FenceAutoRepair | undefined): string {
* `fence` marks a source whose refusal is a facts or takes fence (#6188); it is held and repaired by `gbrain repair fences`, not by frontmatter repair.
*/
export async function contentBlockedSources(engine: BrainEngine): Promise<Array<{ source_id: string; fence: boolean }>> {
- const rows = await engine.executeRaw<{ source_id: string; error_code: string | null; error_message: string | null; error_detail: unknown }>(`SELECT c.completed_keys->0->>'sourceId' AS source_id,
+ type Receipt = { source_id: string; error_code: string | null; error_message: string | null; error_detail: unknown };
+ const rows: Receipt[] = await engine.executeRaw<Receipt>(`SELECT c.completed_keys->0->>'sourceId' AS source_id,
r.error_code, r.error_message, r.error_detail FROM op_checkpoints c JOIN persistence_requests r ON r.request_id::text = c.completed_keys->0->'pending'->>'requestId'
AND r.source_id = c.completed_keys->0->>'sourceId'
WHERE c.op = 'managed-sync' AND COALESCE(c.completed_keys->0->>'done','false') <> 'true' AND r.state IN ('failed','conflict','cancelled')
@@ -121,7 +122,7 @@ export async function contentBlockedSources(engine: BrainEngine): Promise<Array<
const { readPassReadings } = await import('../../../core/persistence/sync-pass-readers.ts');
for (const { source_id, row, health } of await readPassReadings(engine, { head: false }).catch(() => [])) {
if (health.reason !== 'blocked') continue;
- rows.push(...await engine.executeRaw<{ source_id: string; error_code: string | null; error_message: string | null; error_detail: unknown }>(`SELECT source_id,
+ rows.push(...await engine.executeRaw<Receipt>(`SELECT source_id,
error_code, error_message, error_detail FROM persistence_requests WHERE source_id=$1 AND intent->>'passId'=$2 AND state IN ('failed','conflict','cancelled')`,
[source_id, row.value.telemetry.pass_id]).catch(() => []));
}
diff --git a/src/core/persistence/sync-drain.ts b/src/core/persistence/sync-drain.ts
index 41f9c70236..d1f664972c 100644
--- a/src/core/persistence/sync-drain.ts
+++ b/src/core/persistence/sync-drain.ts
@@ -535,7 +535,7 @@ export async function runDrain(input: DrainInput): Promise<SyncResult> {
attempt = 0; capacity = null;
// A cursor slice's counts are its run's so far; a pass result carries its own pass's (each resumed slice is a new pass_id).
const run = (r: SyncResult | null) => r?.runId ?? r?.pass?.pass_id;
- if (run(last) && run(result) && run(result) !== run(last)) {
+ if (last && run(last) && run(result) && run(result) !== run(last)) {
const sum: RunCounts = carried ?? { added: 0, modified: 0, deleted: 0, renamed: 0, chunksCreated: 0 };
carried = { added: sum.added + last.added, modified: sum.modified + last.modified, deleted: sum.deleted + last.deleted, renamed: sum.renamed + last.renamed, chunksCreated: sum.chunksCreated + last.chunksCreated };
}