Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(memory-sources): a paused scheduler is not draining the embed backlog

Shanu711ae3ef501f
diff --git a/.claude/memory.md b/.claude/memory.md
index 78a0cd6eef..aeb5dca058 100644
--- a/.claude/memory.md
+++ b/.claude/memory.md
@@ -359,6 +359,6 @@ Quick reference for anyone starting with Claude on this project. Updated by the
- **`backfill_in_progress` is a process-global flag, not a query** — set when a re-embed chain is armed, cleared only when the chain ends (Done/Skipped/StaleSignature/Failed), so it stays true while the job sits starved in `ready` behind `extract_chunk` on the single LLM permit. Not per-workspace.
- **Test fixtures: a stuck backlog needs `freshness: 'idle'`** — `chunks_pending > 0` with `recent`/`active` freshness renders the neutral note, not the warning. `vi.mock` factories for `utils/tauriCommands/memoryTree` must list `memoryTreeBackfillStatus` or `MemorySourcesRegistry.refresh` throws inside its `Promise.all`.
- **`t()` does not interpolate** — the caller replaces placeholders: `t('sync.pipeline.vectorsPending').replace('{count}', n.toLocaleString())` (pattern from `SyncAuditPanel.tsx`).
-- **`SYNC_PASS_MAX_ITEMS` (200) has five consumers** — the Sources-row loop (`composio_sync_budgeted`, ≤50 passes) plus four single-pass entry points: `periodic.rs`, `memory/ops/sync.rs`, `bus_part_02.rs` (`connection_created` initial sync), `slack/rpc.rs`. One pass is one `AcceptSourceItems` call that embeds each document in turn (~1.7 s each) against the 15-min `module_call_slow!` deadline; 500 tripped it.
+- **`SYNC_PASS_MAX_ITEMS` (200) sizes one `AcceptSourceItems` call** — the module embeds each document in turn (~1.7 s each) against the 15-min `module_call_slow!` deadline; 500 tripped it. The Sources-row loop (`composio_sync_budgeted`, ≤50 passes) is unaffected; the four entry points that sync once per invocation (`periodic.rs`, `memory/ops/sync.rs`, `bus_part_02.rs` `connection_created`, `slack/rpc.rs`) go through `ops::pass_budget::run_sync_within_budget`, which repeats the pass within a 500-**record** budget. Charge that budget by `records_read`, never by `written`: a module returning already-ingested pages with `more_pending` would otherwise be asked forever.
- **`providers_ops.rs` sits at exactly 750 lines** — the `check-openhuman-rust-layout.mjs` limit; edits there must be net-zero lines or split the file.
- **`node app/scripts/build-parallel.mjs` fails with `vite: command not found`** when run directly — it shells out to bare `tsc`/`vite`; use `pnpm build` or prefix `PATH=app/node_modules/.bin:$PATH`.
diff --git a/app/src/components/intelligence/sourcePipelineStatus.test.ts b/app/src/components/intelligence/sourcePipelineStatus.test.ts
index ca026f090e..58dee24378 100644
--- a/app/src/components/intelligence/sourcePipelineStatus.test.ts
+++ b/app/src/components/intelligence/sourcePipelineStatus.test.ts
@@ -290,6 +290,27 @@ describe('deriveSourcePipelineHealth — vectors pending vs stored without vecto
expect(h.vectorsPending).toBe(true);
});
+ it.each([
+ { label: 'is_paused', pipeline: makePipeline({ is_paused: true }) },
+ { label: "status 'paused'", pipeline: makePipeline({ status: 'paused', reason: 'gate off' }) },
+ ])(
+ 'reads a paused scheduler ($label) as stuck even while a chain is armed and ingest is fresh',
+ ({ pipeline }) => {
+ // Pausing the memory-tree scheduler stops every LLM-bound job, the embed
+ // chain included, while leaving its `in_progress` flag armed and letting
+ // ingest keep writing. Nothing will drain the backlog until the user
+ // resumes, so "shortly" would be a promise nobody is keeping.
+ const h = deriveSourcePipelineHealth(
+ makeStatus({ chunks_synced: 10, chunks_pending: 4, freshness: 'active' }),
+ pipeline,
+ makeBackfill({ in_progress: true, pending_jobs: 1 })
+ );
+ expect(h.state).toBe('ingested_only');
+ expect(h.issues).toEqual(['stored_without_vectors']);
+ expect(h.vectorsPending).toBe(false);
+ }
+ );
+
it('stays retrieval_ready when a backfill runs but this source has nothing pending', () => {
const h = deriveSourcePipelineHealth(
makeStatus({ chunks_pending: 0 }),
diff --git a/app/src/components/intelligence/sourcePipelineStatus.ts b/app/src/components/intelligence/sourcePipelineStatus.ts
index ba4a998911..492a8bbf7c 100644
--- a/app/src/components/intelligence/sourcePipelineStatus.ts
+++ b/app/src/components/intelligence/sourcePipelineStatus.ts
@@ -123,6 +123,10 @@ export function deriveSourcePipelineHealth(
// - the global "semantic recall degraded" latch (no usable provider): hard;
// - an embeddings-family blocking cause: the provider cannot write vectors,
// so the backlog will not drain: hard;
+ // - a paused scheduler (`is_paused` / `status === 'paused'`): the chain may
+ // be armed and ingest may still be writing, but no worker will embed
+ // anything until the user resumes, so "shortly" would be a promise nobody
+ // is keeping. Pending chunks are hard until then;
// - otherwise pending chunks are soft while the engine reports a re-embed
// chain with rows to process, OR this source's newest chunk landed inside
// the core's own `recent` window (≤ 5 min: ingest is still writing and
@@ -137,10 +141,12 @@ export function deriveSourcePipelineHealth(
const pending = status?.chunks_pending ?? 0;
const recallLatched = degraded?.semantic_recall === true;
const embeddingsBlocked = causeCode !== null && EMBEDDINGS_BLOCKING_CAUSES.has(causeCode);
+ const paused = pipeline?.is_paused === true || pipeline?.status === 'paused';
const draining =
- backfill?.in_progress === true ||
- status?.freshness === 'active' ||
- status?.freshness === 'recent';
+ !paused &&
+ (backfill?.in_progress === true ||
+ status?.freshness === 'active' ||
+ status?.freshness === 'recent');
const storedWithoutVectors = recallLatched || (pending > 0 && (embeddingsBlocked || !draining));
if (storedWithoutVectors) {
issues.push('stored_without_vectors');