Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

State the connection pool when sync imports start and stall (#6366, fix wave 15 P4.7)

garrytanfb3cf883de07
diff --git a/src/commands/sync/imports.ts b/src/commands/sync/imports.ts
index db251bf19c..23a3103a18 100644
--- a/src/commands/sync/imports.ts
+++ b/src/commands/sync/imports.ts
@@ -27,6 +27,7 @@ import { resolveStallAbortSeconds, composeAbortSignals } from '../../core/sync-r
import { sanitizePathForDisplay } from '../../core/sync.ts';
import { isWindowsColonTarget } from '../../core/persistence/native-file-target.ts';
import { ERROR_CATALOGUE } from '../../core/error-catalogue.ts';
+import { enginePoolStats } from '../../core/postgres-engine/pool-stats.ts';
import type { SyncOpts, SyncResult } from '../sync.ts';
import { clearLegacyHold, holdRefusedImport, noteScreenedImport, type LegacyHolds } from './holds.ts';
import { partial, markCompleted, noteTypeWarning, maybeYield } from './sync-run.ts';
@@ -93,6 +94,8 @@ export async function runImportsPhase(
if (importsToDo.length > 0) {
progress.start('sync.imports', importsToDo.length);
+ // #6366 (P4.7): the pool's state as the drain starts, so a later hang report carries it next to the stall line.
+ serr(`[sync] imports start: ${importsToDo.length} file(s), concurrency ${effectiveConcurrency}${poolLine(engine)}`);
// Core import logic shared by serial and parallel paths.
// Paths from git diff are relative to gitContextRoot; under #4342's
@@ -231,7 +234,7 @@ function startStallWatchdog(
stallTimer = setInterval(() => {
if (Date.now() - progressAt.last >= stallMs) {
serr(
- `[sync] no import progress for ${stallSeconds}s — aborting (stall watchdog). ` +
+ `[sync] no import progress for ${stallSeconds}s — aborting (stall watchdog)${poolLine(run.engine)}. ` +
`The per-source lock will release; the next 'gbrain sync' resumes from the checkpoint.`,
);
run.stallAborted = true;
@@ -245,6 +248,12 @@ function startStallWatchdog(
return { opts, stallTimer, progressAt };
}
+/** #6366: ` · pool max=<n> checked_out=<n> waiters=<n>` for an engine that reports a pool (Postgres), empty otherwise. */
+export function poolLine(engine: unknown): string {
+ const pool = enginePoolStats(engine);
+ return pool ? ` · pool max=${pool.max} checked_out=${pool.checked_out} waiters=${pool.waiters}` : '';
+}
+
/** Core import logic shared by the serial and parallel paths. */
async function importOnePath(run: SyncRun, ctx: ImportContext, eng: BrainEngine, path: string): Promise<void> {
const { failedFiles, succeededPaths, pagesAffected, deletedSlugs } = run;
diff --git a/test/sync-imports-pool-line-6366.test.ts b/test/sync-imports-pool-line-6366.test.ts
new file mode 100644
index 0000000000..d96130e68d
--- /dev/null
+++ b/test/sync-imports-pool-line-6366.test.ts
@@ -0,0 +1,16 @@
+/**
+ * #6366 (fix wave 15 P4.7): the autopilot sync hang is not reproducible on master, so the import drain now states the
+ * pool (`max` / `checked_out` / `waiters`) once when its imports start and again in the stall watchdog's stop line, so
+ * the next report carries the evidence. Golden of the line only: an engine that reports a pool gets it, one that does
+ * not (PGLite) gets nothing appended.
+ */
+import { expect, test } from 'bun:test';
+import { poolLine } from '../src/commands/sync/imports.ts';
+
+test('poolLine renders the driver pool numbers for a Postgres engine and nothing for an engine without a pool', () => {
+ const postgres = { getPoolDiagnostics: () => ({ pool: { checked_out: 3, max: 4, waiters: 2, inflight_oldest_ms: 0, completed: 10 } }) };
+ expect(poolLine(postgres)).toBe(' · pool max=4 checked_out=3 waiters=2');
+ expect(poolLine({})).toBe('');
+ expect(poolLine({ getPoolDiagnostics: () => null })).toBe('');
+ expect(poolLine({ getPoolDiagnostics: () => { throw new Error('no pool'); } })).toBe('');
+});