Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: pre-landing review fixes

garrytanf210780f52bb
diff --git a/src/core/google/people-calendar-sweep.ts b/src/core/google/people-calendar-sweep.ts
index 2951741491..7146bb2f34 100644
--- a/src/core/google/people-calendar-sweep.ts
+++ b/src/core/google/people-calendar-sweep.ts
@@ -98,7 +98,9 @@ export async function sweepContacts(
// list from page 1, once.
let pageToken = resumeToken;
if (resumeToken) deps.log('[google] contacts full re-list resuming at its checkpointed page');
- for (let pages = 0; pages < pageBudget && !listed; pages++) {
+ // A failing contact not yet held freezes the cursor before its page, so while blocked the run lists to the end, as
+ // it did before the budget: every later contact still lands in this run.
+ for (let pages = 0; (pages < pageBudget || blocked) && !listed; pages++) {
let page;
try {
page = await people.listConnectionsPage(pageToken, signal);
diff --git a/src/core/persistence/source-lifecycle.ts b/src/core/persistence/source-lifecycle.ts
index 7fc2516453..4780a51357 100644
--- a/src/core/persistence/source-lifecycle.ts
+++ b/src/core/persistence/source-lifecycle.ts
@@ -186,7 +186,8 @@ export async function runManagedSourceLifecycle(engine:BrainEngine,input:SourceL
// #7702/#8905: a remove or purge first deletes the source's pages in bounded batches, each its own transaction behind
// the final transaction's preconditions; any precondition that would refuse or replay stops batching and the final
// transaction reports it. Committed batches are durable, so a retry with the same request_id resumes. A batch that
- // hits the statement bound is retried at half the size, so heavy pages still fit.
+ // hits the statement bound is retried at half the size, so heavy pages still fit; a lock wait or a busy writer stops
+ // the run with write_pending instead, and the retry resumes at full size.
let retiredPages=0;
try{
const retireBatch=async(limit:number):Promise<number|null>=>{ try{ return await topologyTransaction(engine,async tx=>{
@@ -206,7 +207,7 @@ export async function runManagedSourceLifecycle(engine:BrainEngine,input:SourceL
retiredPages+=gone.length;
return gone.length;
}); }catch(error){
- if(error instanceof OperationError&&error.code==='write_pending'&&limit>1) return null;
+ if(error instanceof OperationError&&error.code==='write_pending'&&error.reason==='statement_timeout'&&limit>1) return null;
throw error;
} };
if(['remove','purge'].includes(input.operation)&&input.confirmDestructive&&!missingCheckout&&!admission)
diff --git a/src/core/persistence/topology-transaction.ts b/src/core/persistence/topology-transaction.ts
index 057957c947..5dedf119ec 100644
--- a/src/core/persistence/topology-transaction.ts
+++ b/src/core/persistence/topology-transaction.ts
@@ -28,8 +28,11 @@ export async function topologyTransaction<T>(engine: BrainEngine, run: (tx: Brai
return scoped(engine, tx, run);
});
} catch (error) {
- if (['55P03','57014'].includes((error as { code?: string }).code ?? '')) {
- throw new OperationError('write_pending', 'The source transaction exceeded its bounded database wait.', 'Retry the same lifecycle request_id after the current writer finishes; work it already committed, such as the pages a source removal deleted, is kept and the retry resumes from there.');
+ const code = (error as { code?: string }).code ?? '';
+ if (['55P03','57014'].includes(code)) {
+ const pending = new OperationError('write_pending', 'The source transaction exceeded its bounded database wait.', 'Retry the same lifecycle request_id after the current writer finishes; work it already committed, such as the pages a source removal deleted, is kept and the retry resumes from there.');
+ pending.reason = code === '57014' ? 'statement_timeout' : 'lock_timeout';
+ throw pending;
}
throw error;
} finally { release(); }
diff --git a/src/core/secret-scan.ts b/src/core/secret-scan.ts
index 9917b9f02e..ce9c7e05bd 100644
--- a/src/core/secret-scan.ts
+++ b/src/core/secret-scan.ts
@@ -1322,6 +1322,8 @@ function addEchoValue(into: EchoDictionary, pattern: string, value: string): voi
for (const claimedBy of into.values()) if (VENDOR_ECHO_PATTERNS.has(claimedBy) === vendor) used++;
if (used >= (vendor ? ECHO_MAX_UNIQUE_VENDOR : ECHO_MAX_UNIQUE)) return;
into.set(value, pattern);
+ const unescaped = value.replaceAll('\\/', '/');
+ if (unescaped !== value) addEchoValue(into, pattern, unescaped);
}
/**
diff --git a/test/contacts-relist-checkpoint-8906.slow.test.ts b/test/contacts-relist-checkpoint-8906.slow.test.ts
index a6e50067e1..ad891ac242 100644
--- a/test/contacts-relist-checkpoint-8906.slow.test.ts
+++ b/test/contacts-relist-checkpoint-8906.slow.test.ts
@@ -197,6 +197,23 @@ describe('contacts full re-list checkpoints (#8906)', () => {
rmSync(dir, { recursive: true, force: true });
}
}, 240_000);
+test('a contact that keeps failing transiently does not hide the contacts past the page budget: a blocked run lists to the end', async () => {
+ const { dir, cfg } = await googleSource();
+ await engine.executeRaw(`CREATE FUNCTION relist_fail_fn() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN
+ IF NEW.title = 'Person c00200 Example' THEN RAISE EXCEPTION 'injected transient contact failure'; END IF; RETURN NEW; END $$`);
+ await engine.executeRaw('CREATE TRIGGER relist_fail BEFORE INSERT ON pages FOR EACH ROW EXECUTE FUNCTION relist_fail_fn()');
+ try {
+ const api = peopleApi(12);
+ expect((await sync(cfg, api.fetchImpl)).status).toBe('partial');
+ expect(api.served).toEqual(Array.from({ length: 12 }, (_, i) => 'p' + (i + 1)));
+ expect(await personPages()).toBe(2_399);
+ expect(relistOf(dir)?.page_token).toBe('p2');
+ expect(readGoogleState(dir).contacts_sync_token).toBeNull();
+ } finally {
+ for (const sql of ['DROP TRIGGER IF EXISTS relist_fail ON pages', 'DROP FUNCTION IF EXISTS relist_fail_fn()']) await engine.executeRaw(sql);
+ rmSync(dir, { recursive: true, force: true });
+ }
+ }, 240_000);
test('--full ignores a saved re-list checkpoint and the page budget: it lists from page 1 to the end before recording last_full_at', async () => {
const { dir, cfg } = await googleSource();
try {
diff --git a/test/secret-scan-encoded-boundary-8266.test.ts b/test/secret-scan-encoded-boundary-8266.test.ts
index a1bfe2f899..ae91993cea 100644
--- a/test/secret-scan-encoded-boundary-8266.test.ts
+++ b/test/secret-scan-encoded-boundary-8266.test.ts
@@ -48,6 +48,13 @@ describe('#8266 a bearer token with an escaped slash is redacted whole', () => {
expect(redactFindings(line).text.includes(token)).toBe(false);
});
+ test('a bare echo of an escaped token, written with a plain slash, is redacted too', () => {
+ const [head, tail] = [alnum(24), alnum(24)];
+ const out = redactFindings(`{"h":"Bearer ${head}\\/${tail}"}\nlater: ${head}/${tail} end`).text;
+ expect(out).not.toContain(head);
+ expect(out).not.toContain(tail);
+ });
+
test('the token still ends at an escaped newline or quote', () => {
const tok = alnum(40);
expect(redactFindings(`{"h":"Bearer ${tok}\\nnext"}`).text).toBe('{"h":"Bearer <REDACTED:bearer>\\nnext"}');
diff --git a/test/source-retire-batched.test.ts b/test/source-retire-batched.test.ts
index de9fa6daae..328b7968c9 100644
--- a/test/source-retire-batched.test.ts
+++ b/test/source-retire-batched.test.ts
@@ -83,6 +83,24 @@ test('a dry run or a refused remove/purge deletes no page', () => fixture(async
expect(await registered()).toBe(1);
}), 60_000);
+test('a lock wait stops the remove with write_pending instead of shrinking the batch; the retry resumes at full size', () => fixture(async () => {
+ await engine.executeRaw('CREATE SEQUENCE retire_lock_seq');
+ await engine.executeRaw(`CREATE FUNCTION retire_lock_fn() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN
+ IF nextval('retire_lock_seq') = 1 THEN RAISE EXCEPTION 'canceling statement due to lock timeout' USING ERRCODE = 'lock_not_available'; END IF;
+ RETURN NULL; END $$`);
+ await engine.executeRaw('CREATE TRIGGER retire_lock AFTER DELETE ON pages FOR EACH STATEMENT EXECUTE FUNCTION retire_lock_fn()');
+ try {
+ const requestId = randomUUID();
+ const remove = () => runManagedSourceLifecycle(engine, { operation: 'remove', sourceId: source, confirmDestructive: true, requestId });
+ await expect(remove()).rejects.toMatchObject({ code: 'write_pending', reason: 'lock_timeout' });
+ expect(await pages(source)).toBe(PAGES);
+ expect(await remove()).toMatchObject({ state: 'committed', operation: 'remove', pages_deleted: PAGES });
+ expect(await pages(source)).toBe(0);
+ } finally {
+ for (const sql of ['DROP TRIGGER IF EXISTS retire_lock ON pages', 'DROP FUNCTION IF EXISTS retire_lock_fn()', 'DROP SEQUENCE IF EXISTS retire_lock_seq']) await engine.executeRaw(sql);
+ }
+}), 60_000);
+
test('an interrupted batch keeps the committed batches and the same request_id resumes to completion', () => fixture(async () => {
await engine.executeRaw('CREATE TABLE retire_fail(armed boolean NOT NULL, seen integer NOT NULL)');
await engine.executeRaw(`CREATE FUNCTION retire_fail_fn() RETURNS trigger LANGUAGE plpgsql AS $$ DECLARE n integer; BEGIN