Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(embed): count a thrown page snapshot read in the --all pool (#6100)

time-attack6d5d7b330099
diff --git a/TODOS.md b/TODOS.md
index f2faee36b5..9fbe75350a 100644
--- a/TODOS.md
+++ b/TODOS.md
@@ -503,8 +503,6 @@ Evidence for each item is in `docs/test-audit/2026-09-29/`.
**What:** `skills/archive-crawler/SKILL.md` says the fence is enforced by `src/core/storage-config.ts`; the enforcing module `src/core/archive-crawler-config.ts` is unwired. **Fix:** wire the check or correct the skill text. Held in the permitted set.
- [ ] **P2 — Progressive-batch rewire or retire.**
**What:** the progressive-batch orchestrator, retrofit-wrap and stage-report modules lost their callers in #1519 while an open item (see the progressive-batch entry below) still plans to rewire them. **Fix:** decide rewire vs abandon; held in the permitted set until then.
-- [ ] **P2 — `gbrain embed --all` exits 0 with pages unembedded when the page snapshot read throws.**
- **What:** in the `--all` pool path the worker pool swallows a thrown snapshot read, so the run reports `failures: 0`. Same class as #3037. **Fix:** count the error as a failure and exit non-zero; add a test that throws from the snapshot read.
- [ ] **P2 — `gbrain auth rescope-client … --dry-run` and `auth local-writer register … --dry-run` fail with "unknown flag".**
**What:** the handlers read `--dry-run`, but the generated flag registry drops it for `auth` (the generator deletes `--dry-run` unless it finds a quoted use in the command's own module). Two guides document these commands and are allowlisted in the docs-CLI truth check. **Fix:** teach the generator about delegated handlers, regenerate, and remove the allowlist entries.
- [ ] **P3 — `jobs watch` budget-owners panel reads columns only the deleted minions budget tracker wrote.**
diff --git a/src/commands/embed.ts b/src/commands/embed.ts
index 6b1b1cb47b..7139e1690e 100644
--- a/src/commands/embed.ts
+++ b/src/commands/embed.ts
@@ -1365,20 +1365,21 @@ async function embedAll(
}
}
- // v0.41.15.0: sliding worker pool extracted into src/core/worker-pool.ts.
- // Throughput characteristics unchanged from the prior inline pool — N
- // workers atomically claim the next page; the helper is the canonical
- // primitive. embedOnePage handles its own per-page errors via try/catch
- // and stderr log (no rethrow), so we don't need failures[] here and
- // omitting onError means the default 'continue' policy applies cleanly
- // even though no errors should reach the pool's catch.
- await runSlidingPool({
+ // Sliding worker pool (src/core/worker-pool.ts). #3037: a throw that escapes
+ // embedOnePage (its snapshot read runs before the try) lands in failures[]
+ // under the default 'continue' policy; count it so the run can't exit 0.
+ const pool = await runSlidingPool({
items: pages,
workers: CONCURRENCY,
...(signal && { signal }), // #1737: pool stops claiming pages once aborted
onItem: (page) => embedOnePage(page),
failureLabel: (page) => page.slug,
});
+ for (const { label, error } of pool.failures) {
+ if (isAborted(signal)) break; // shutdown, not a failure
+ recordFailure(result, 1, label, error);
+ serr(`\n Error embedding ${label}: ${error instanceof Error ? error.message : error}`);
+ }
// Stdout summary preserved for scripts/tests that grep for counts.
if (!staleOpts?.quiet) {
diff --git a/test/embed-partial-failure-3037.serial.test.ts b/test/embed-partial-failure-3037.serial.test.ts
index 3c1ad1e273..43e6f45cb7 100644
--- a/test/embed-partial-failure-3037.serial.test.ts
+++ b/test/embed-partial-failure-3037.serial.test.ts
@@ -17,6 +17,8 @@ import { mockEmbedProjectionEngine as mockEngine, embeddingUpdates } from './hel
* 2. Cost bounding: a 429 (rate limit) does NOT fan out into N
* single-chunk calls, and neither does an AITransientError (outage) —
* isolation only fires for permanent request-shaped failures.
+ * 3. --all: a page whose snapshot read throws is counted on
+ * result.failures instead of vanishing into the worker pool.
*
* Serial: uses mock.module (leaks across files sharing a bun process).
* The CLI exit-code half of #3037 is pinned by
@@ -132,6 +134,48 @@ describe('#3037 — one bad chunk no longer darkens its page', () => {
expect(stamps).toHaveLength(0);
});
+ test('--all: a page whose snapshot read throws is counted; the other pages still embed', async () => {
+ // The guarded snapshot read runs before embedOnePage's try, so its throw
+ // (here a lock wait cancelled by statement_timeout) reaches the worker
+ // pool, which swallowed it: failures 0, exit 0, page left unembedded.
+ const engine = mockEngine({
+ listPages: async () => [
+ { slug: 'locked-page', source_id: 'default' },
+ { slug: 'healthy-page', source_id: 'default' },
+ ],
+ getPage: async (slug: string) => {
+ if (slug === 'locked-page') throw new Error('canceling statement due to statement timeout');
+ return { slug, compiled_truth: 'Fixture body', timeline: '' };
+ },
+ getChunks: async () => THREE_CHUNKS,
+ upsertChunks: async () => { throw new Error("Embedding must not replace canonical chunks"); },
+ });
+
+ const result = await runEmbedCore(engine, { all: true });
+
+ expect(embeddingUpdates(engine).map((call: any) => call.args[1][5])).toEqual(['good-a', 'BAD', 'good-b']);
+ expect(result.embedded).toBe(3);
+ expect(result.failures).toBe(1);
+ expect(result.failure_samples).toEqual(['locked-page: canceling statement due to statement timeout']);
+ });
+
+ test('--all: a snapshot read that throws because the run was aborted is shutdown, not a failure', async () => {
+ const controller = new AbortController();
+ const engine = mockEngine({
+ listPages: async () => [{ slug: 'aborted-page', source_id: 'default' }],
+ getPage: async () => {
+ controller.abort();
+ throw new Error('canceling statement due to user request');
+ },
+ getChunks: async () => THREE_CHUNKS,
+ });
+
+ const result = await runEmbedCore(engine, { all: true, signal: controller.signal });
+
+ expect(result.failures).toBe(0);
+ expect(result.failure_samples ?? []).toEqual([]);
+ });
+
test('--stale x #3507: fan-out retries the WRAPPED texts and a partially-failed page is not restamped', async () => {
// Composition pin for the #3037 + #3538 merge: the per-chunk isolation
// retry must re-send the contextually WRAPPED text (raw chunk_text here