Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(connectors): retained-publication recovery waits the configured write wait instead of a fixed 5 s (#5232)

garrytan3b2320e1fe9c
diff --git a/docs/protocol/MEMORY_VERBS_v1.md b/docs/protocol/MEMORY_VERBS_v1.md
index 76f4fb1c30..a85bc6097b 100644
--- a/docs/protocol/MEMORY_VERBS_v1.md
+++ b/docs/protocol/MEMORY_VERBS_v1.md
@@ -451,7 +451,9 @@ alone. `--accept-pending` maps pending to exit 0 for hooks and cron;
`GBRAIN_ACCEPT_PENDING=1` is its environment equivalent and
`--no-accept-pending` overrides it (flag beats environment).
-The CLI waits up to 30 s for the commit (agents keep 5 s). Precedence:
+The CLI waits up to 30 s for the commit (agents keep 5 s; a connector sync
+waiting for a retained publication to recover keeps 5 s unless one of the
+settings below is set). Precedence:
`--wait <seconds>` (0 to 600) > `GBRAIN_WRITE_WAIT_MS` > the file-plane
`persistence.write_wait_ms` (`gbrain config set persistence.write_wait_ms
45000`) > 30 s. The wait reaches a resident owner with each request, and over
diff --git a/src/core/persistence/connector-sync.ts b/src/core/persistence/connector-sync.ts
index 5a63d72056..c2c58b3e50 100644
--- a/src/core/persistence/connector-sync.ts
+++ b/src/core/persistence/connector-sync.ts
@@ -19,6 +19,7 @@ import { admitWriteInTransaction, assertReplayIntent, getWriteRequest, getWriteR
import { acquireWorktree, containsPath, getWorktreeBinding, probeWorktreeWriter, type WorktreeBinding } from './ownership.ts';
import { localHostId } from './identity.ts';
import { assertPersistenceAccepting, startPersistenceConsumer, waitForWrite, writeResponse } from './service.ts';
+import { AGENT_WRITE_WAIT_MS, configuredWriteWaitMs } from './write-wait.ts';
import { managedSyncAuthority, validateManagedSyncOptions, validateSyncAuthority, type SyncAuthority } from './sync-authority.ts';
import type { PreparedContentImport } from './prepared-import.ts';
import { persistenceFileHash, type PreparedMutation } from './coordinator.ts';
@@ -435,7 +436,8 @@ export class ManagedConnectorSync {
let [row] = await retained();
if (!row) return;
startPersistenceConsumer(this.engine, loadConfig() ?? { engine: this.engine.kind });
- const deadline = performance.now() + 5000;
+ // The retained publication may need a slow commit; honor the operator's configured write wait.
+ const deadline = performance.now() + configuredWriteWaitMs(AGENT_WRITE_WAIT_MS);
while (performance.now() < deadline) {
const remaining = deadline - performance.now();
if (remaining <= 0) break;
diff --git a/src/core/persistence/write-wait.ts b/src/core/persistence/write-wait.ts
index 7e7a417f25..7e1e7ac6bc 100644
--- a/src/core/persistence/write-wait.ts
+++ b/src/core/persistence/write-wait.ts
@@ -48,6 +48,15 @@ export function resolveCliWriteWaitMs(opts: {
?? CLI_WRITE_WAIT_MS;
}
+/** An explicitly configured wait (`--wait`, GBRAIN_WRITE_WAIT_MS, persistence.write_wait_ms), else `fallbackMs`. */
+export function configuredWriteWaitMs(fallbackMs: number): number {
+ const flagMs = getCliOptions().writeWaitMs;
+ if (flagMs !== undefined && flagMs !== null) return flagMs;
+ return parseMs(process.env[WRITE_WAIT_ENV], WRITE_WAIT_ENV)
+ ?? parseMs(loadConfig()?.persistence?.write_wait_ms, WRITE_WAIT_CONFIG_KEY)
+ ?? fallbackMs;
+}
+
/** The wait and pending opt-in this CLI invocation resolved. */
export function currentCliWriteWait(): { waitMs: number; acceptPending: boolean } {
const cli = getCliOptions();
diff --git a/test/persistence-connector-recovery.test.ts b/test/persistence-connector-recovery.test.ts
index aa643c4b1e..860db72e66 100644
--- a/test/persistence-connector-recovery.test.ts
+++ b/test/persistence-connector-recovery.test.ts
@@ -108,3 +108,26 @@ test('an already authenticated connector session drains later retained recovery
expect((await session.page('gh/acme-example/app/1'))?.compiled_truth).toContain('Updated organization after interruption');
}
}), 120_000);
+
+test('a blocked retained recovery waits the configured write wait, not a fixed five seconds', async () => withEnv({ ...env, GBRAIN_WRITE_WAIT_MS: '250' }, async () => {
+ for (const engine of engines) {
+ const f = await boundSource(engine, githubConfig);
+ const config = parseGitHubSourceConfig(githubConfig, f.dir);
+ await runGitHubSync(engine, f.id, config, options, githubFetch());
+ await disposePersistenceConsumer(engine);
+ const crash = await standaloneConnector(engine, f, githubConfig, true);
+ expect(crash.stdout).toContain('CONNECTOR_AFTER_PUBLICATION_BEFORE_COMMIT');
+ const path = join(f.dir, 'gh/acme-example/app/1.md');
+ const published = readFileSync(path, 'utf8');
+ writeFileSync(path, `${published}\nOperator edit blocks the recovery.\n`);
+ try {
+ const started = performance.now();
+ const failure = await beginConnectorSync(engine, f.id, 'github', config, options).then(() => null, (e: { code?: string }) => e);
+ expect(failure?.code).toBe('recovery_required');
+ expect(performance.now() - started).toBeLessThan(4_000);
+ } finally {
+ await disposePersistenceConsumer(engine);
+ writeFileSync(path, published);
+ }
+ }
+}), 120_000);