Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: a failed extract keeps the source window; cycle-abort contract names the new extract call (#8573)

garrytan2710acd84e93
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 853619a8a7..e0875a9fff 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,7 +18,7 @@ identifiers and attribution are available in the pre-removal Git revision
- `src/core/minions/handlers/autopilot-cycle.ts`: `sourceChangedSince` is passed to every per-source cycle whose phases leave out `sync` or that has no checkout, not only to connector sources.
- `src/core/cycle.ts`: the `extract` phase of a cycle with a checkout and a source window extracts the window's pages, instead of walking the checkout. (`lint` still reads every file of the checkout, as it does for every source.)
-- `src/core/cycle/source-window.ts`: with no recorded cycle the window is one first-walk chunk in slug order (`sourceFirstWalk.pageLimit`, 2,000). The chunk's cursor and the walk's start are stamped in the source config (`last_source_cycle_walk_after`, `last_source_cycle_walk_at`); the last chunk stamps the walk's start as the window, so pages changed during the walk are picked up after it, and a failed chunk is retried. The listing instant is moved back to just before the oldest transaction still open on another connection (at most 10 minutes), because `pages.updated_at` is the writer's transaction start.
+- `src/core/cycle/source-window.ts`: with no recorded cycle the window is one first-walk chunk in slug order (`sourceFirstWalk.pageLimit`, 2,000). The chunk's cursor and the walk's start are stamped in the source config (`last_source_cycle_walk_after`, `last_source_cycle_walk_at`); the last chunk stamps the walk's start as the window, so pages changed during the walk are picked up after it. A cycle whose `extract`, `extract_facts` or `recompute_emotional_weight` phase failed keeps its window, so the same pages (or the same chunk) are retried. The listing instant is moved back to just before the oldest transaction still open on another connection (at most 10 minutes), because `pages.updated_at` is the writer's transaction start.
- `test/sync-disabled-cycle-window.test.ts` (PGLite and Postgres): an idle cycle of a sync-disabled git source walks no page in `extract_facts` or `extract`, and an explicit sync's fact page is reconciled by the next cycle; a first walk runs in bounded, resumable chunks; a source with no checkout gets the window; a write committed after a cycle's listing lands in the next window.
## [0.60.569.0] - 2026-11-04
diff --git a/src/core/cycle/source-window.ts b/src/core/cycle/source-window.ts
index 522418309d..cbc70913d2 100644
--- a/src/core/cycle/source-window.ts
+++ b/src/core/cycle/source-window.ts
@@ -62,14 +62,15 @@ export async function listSourceChangedPages(engine: BrainEngine, sourceId: stri
/**
* The config stamp that starts the next window: this listing's instant, or,
- * when a phase that consumed the window failed, the same window again
+ * when a phase that consumed the window (extract, extract_facts,
+ * recompute_emotional_weight) failed, the same window again
* ('' = the first walk, resumed from its stamped cursor). A first-walk chunk
* stamps its cursor; the last one stamps the walk's first instant.
*/
export function sourceCycleWindowStamp(phases: ReadonlyArray<{ phase: string; status: string }>, since: string | null | undefined,
window: SourceCycleWindow | undefined): Record<string, string | null> {
if (!window?.at) return {};
- const failed = phases.some(r => (r.phase === 'extract_facts' || r.phase === 'recompute_emotional_weight') && r.status === 'fail');
+ const failed = phases.some(r => (r.phase === 'extract' || r.phase === 'extract_facts' || r.phase === 'recompute_emotional_weight') && r.status === 'fail');
if (failed) return { last_source_cycle_window_at: since ?? '' };
if (!window.walk) return { last_source_cycle_window_at: window.at };
return window.walk.next !== null
diff --git a/test/cycle-abort.test.ts b/test/cycle-abort.test.ts
index 621e0ca2d6..b0157e4281 100644
--- a/test/cycle-abort.test.ts
+++ b/test/cycle-abort.test.ts
@@ -177,7 +177,7 @@ describe('#1972 — complete cooperative-abort coverage', () => {
const body = src.slice(src.indexOf('export async function runCycle'));
// Each long phase receives the signal (W0: the combined cycleSignal, so
// phases also stop on lock-steal, not just external aborts).
- expect(body).toContain('runPhaseExtract(engine, brainDir, dryRun, syncPagesAffected, cycleSignal, cycleSourceId)');
+ expect(body).toContain('runPhaseExtract(engine, brainDir, dryRun, sourceWindow?.slugs ?? syncPagesAffected, cycleSignal, cycleSourceId)');
expect(body).toMatch(/runPhaseExtractFacts\([^)]*cycleSignal\)/);
expect(body).toContain('signal: cycleSignal'); // consolidate opts
expect(body).toContain("runPhaseLint(brainDir, dryRun, engine, cycleSignal, cycleSourceId, { once: opts.onceForPhase === 'lint' })"); // #5180 threads the source id after the signal; #6369 the --once bypass after it
diff --git a/test/sync-disabled-cycle-window.test.ts b/test/sync-disabled-cycle-window.test.ts
index 44f0e99d5e..b789efded1 100644
--- a/test/sync-disabled-cycle-window.test.ts
+++ b/test/sync-disabled-cycle-window.test.ts
@@ -19,7 +19,7 @@ import { join } from 'node:path';
import type { BrainEngine } from '../src/core/engine.ts';
import { makeAutopilotCycleHandler } from '../src/core/minions/handlers/autopilot-cycle.ts';
import { SOURCE_FRESHNESS_PHASES } from '../src/core/cycle/phase-scope.ts';
-import { sourceFirstWalk } from '../src/core/cycle/source-window.ts';
+import { sourceCycleWindowStamp, sourceFirstWalk } from '../src/core/cycle/source-window.ts';
import { performSync } from '../src/commands/sync.ts';
import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';
import { withEnv } from './helpers/with-env.ts';
@@ -69,6 +69,15 @@ async function liveFacts(engine: BrainEngine, sourceId: string, slug: string) {
}
describe('#8573 sync-disabled source cycle window', () => {
+ test('a failed phase that read the window keeps it, extract included; a failed first-walk chunk keeps its cursor', () => {
+ const window = { at: '2026-01-02T00:00:00Z', slugs: ['a'] };
+ for (const phase of ['extract', 'extract_facts', 'recompute_emotional_weight']) {
+ expect(sourceCycleWindowStamp([{ phase, status: 'fail' }], '2026-01-01T00:00:00Z', window)).toEqual({ last_source_cycle_window_at: '2026-01-01T00:00:00Z' });
+ expect(sourceCycleWindowStamp([{ phase, status: 'fail' }], null, { ...window, walk: { startedAt: window.at, next: 'a' } })).toEqual({ last_source_cycle_window_at: '' });
+ }
+ expect(sourceCycleWindowStamp([{ phase: 'lint', status: 'fail' }], '2026-01-01T00:00:00Z', window)).toEqual({ last_source_cycle_window_at: window.at });
+ });
+
test('a sync-disabled git source reconciles only pages changed since its last cycle; an explicit sync between cycles lands in the next window', async () => withEnv(env, async () => {
for (const engine of engines) {
const { id, dir } = await source(engine, { syncEnabled: false });