Skip to content

[BUG] One failed file keeps the code index in Standby and blocks codebase_search until a manual restart #57

Closed

Description

@simurg79

Type

Bug

Problem / Value

If even one file fails to index, the code index switches to Standby ("Indexing stopped. Partial index data preserved.") and stays there until someone clicks Start Indexing or reloads the window. While it is in Standby, codebase_search rejects every query with Code index is not ready for search. Current state: Standby, so agents silently lose semantic search for hours. On 2026-11-02 this happened twice and blocked 33 searches across 19 tasks.

Four problems combine to cause and hide this:

  1. No retry. A single transient network error fails a file for good. PR [code-index] Isolate parsing so parser failures stop indexing safely #34 removed the batch retries the scanner used to have. This caused the morning outage.
  2. No recovery. One failed file latches the whole index in Standby, failed files are never retried, and search refuses a partial index.
  3. Racy Start Indexing. The manual fix runs two rebuilds at once and logs an unhandled CodeIndexManager not initialized error that looks like the cause of the outage.
  4. No logging. Failures and state changes aren't recorded anywhere installed builds keep them, so the evening trigger can't be identified.

Context

Environment: Roo Code 3.53.7 fork build (bin/roo-cline-3.53.7.vsix, includes PR #34), VS Code 1.144.0, Windows 11 Enterprise build 26300, OpenAI-compatible embedder (3072-dim), Qdrant v1.16.3 in local Docker. Source reviewed: fork main @ 9c78783.

Timeline (PST), reconstructed from task ui_messages.json, docker logs qdrant, and the VS Code logs:

Time Event
06:12–09:12 7 codebase_search calls succeed
08:55:11 Extension host restart → full scan starts (Qdrant: GET collection, PUT /index)
09:18:13 [Extension Host] Failed to upsert points: TypeError: fetch failed (renderer.log), not retried (part 1)
09:40:37 Last scan write to Qdrant; scan ends partial → Standby
10:10:53–11:57:05 28 searches fail in 17 tasks: Code index is not ready for search. Current state: Standby
15:58 VSIX reinstall + window reload → scan 15:58–16:03 completes without errors
16:04–18:50 62 searches succeed
18:54:33 Last Qdrant write (file-watcher update after prettier --write); no Qdrant traffic at all until 19:02:03; trigger unknown (part 4)
19:00:11–19:01:41 5 searches fail in 2 tasks, same error
19:02:05 Start Indexing clicked → services rebuilt → scan; unhandled error logged (part 3)
19:22–19:42 14 searches succeed
  • verified: task histories contain 33 Error codebase_search: Code index is not ready for search. Current state: Standby messages, all inside the two outage windows above.
  • verified: docker logs qdrant shows 0 non-2xx responses and no warnings or errors for 08:55–10:12 and 18:45–19:03 PST.
  • verified: no embedder errors were logged. The OpenAI-compatible embedder console.errors every error it throws (openai-compatible.ts#L352), and those are persisted in renderer.log.

Part 1 — No retry on transient write failures (regression from PR #34)

  • Morning trigger, 09:18:13 (renderer.log): [Extension Host] Failed to upsert points: TypeError: fetch failed. Qdrant logged nothing for it, so the request failed client-side at the connection level and never got a response. The scan finished at 09:40:37 as partial → Standby.
  • Upstream retried each embed + upsert batch: origin/main scanner.ts#L385-L463 loops while (attempts < MAX_BATCH_RETRIES && !success) with INITIAL_RETRY_DELAY_MS * 2^(attempts - 1) backoff (3 attempts, 500 ms base).
  • verified: git log -S MAX_BATCH_RETRIES points at a21bd59 ("fix(code-index): preserve progress and fence cancelled indexing attempts", part of PR [code-index] Isolate parsing so parser failures stop indexing safely #34) as the commit that removed it. git grep finds no retry logic in fork file-completion.ts, scanner.ts, file-watcher.ts, or qdrant-client.ts.
  • Fork write path, with no retry anywhere: FileIndexWriter.replace → createEmbeddings → upsertPoints (logs at L386 and rethrows) → completion: deletePointsByFilePath + countPointsForFile verification (file-completion.ts#L79). Any throw fails the file.
  • Embedders still retry their own HTTP calls (for example 429 in openai-compatible.ts), but the Qdrant upsert, delete, and count calls don't.

Part 2 — One failure latches the index in Standby

Part 3 — Start Indexing runs two rebuilds at once

Clicking Start Indexing while the index is in Standby with live services (exactly the state part 2 leaves behind) starts two service rebuilds at the same time. Observed 2026-11-02 19:02:05 in %APPDATA%\Code\logs\<session>\window1\exthost\exthost.log. It is not in the Roo-Code output channel, because the handler never awaited the promise and its catch never saw the error:

2026-11-02 19:02:05.572 [error] Error: CodeIndexManager not initialized. Call initialize() first.
	at t.assertInitialized (%USERPROFILE%\.vscode\extensions\rooveterinaryinc.roo-cline-3.53.7\dist\extension.js:2608:35242)
	at t.startIndexing (%USERPROFILE%\.vscode\extensions\rooveterinaryinc.roo-cline-3.53.7\dist\extension.js:2608:37134)
	at process.processTicksAndRejections (node:internal/process/task_queues:104:5)

Sequence:

  1. webviewMessageHandler.ts#L2422: await manager.initialize(). Services are alive and not stopped (manager.ts#L225), so nothing is rebuilt.
  2. L2424: the state is Standby → L2426: manager.startIndexing() is called without await or .catch.
  3. manager.ts#L250-L262: state Standby → await this._recreateServices() (attempt N). Before its first await, L384-L392 bumps the attempt counter, calls stopWatcher() (which sets servicesStopped = true, L290) and clears _orchestrator.
  4. Back in the handler, L2428-L2429: !manager.isInitialized is now true → await manager.initialize() → servicesStopped is true → _recreateServices() runs again (attempt N+1).
  5. Attempt N is now stale and returns early (L427-L429 or L441) without creating an orchestrator → L271 this.assertInitialized() throws → unhandled rejection.
  6. Attempt N+1 finishes and initialize() starts indexing (L232-L237). The second startIndexing() at L2430-L2431 is skipped only because the state is now Indexing.

The same unawaited call appears at L2469 (toggleWorkspaceIndexing) and L2503 (setAutoEnableDefault). The doc comment at manager.ts#L247 ("should NEVER be awaited") encourages calls without .catch.

  • verified: the stack frames match assertInitialized ← startIndexing resumed after an await. Local uncommitted changes to webviewMessageHandler.ts don't touch these handlers.

Part 4 — Failures and state changes aren't logged

  • The Roo-Code output channel had zero indexing lines all day. Code-index services log through console.*; installed builds keep only console.error (renderer.log, as [Extension Host] …) and unhandled rejections (exthost.log).
  • The evening trigger is unknown: the last Qdrant write was at 18:54:33, there was no Qdrant traffic at all until the manual restart at 19:02:03, and the first failed search was at 19:00:11. Embedder and Qdrant errors are ruled out because both would have been logged. The remaining candidates are all silent today:
  • Where failures are swallowed today:

Reproduction

  1. Index a workspace until the state is Indexed.
  2. Make one file update fail once: docker stop qdrant, save a source file, wait for the watcher batch to finish, then docker start qdrant.
  3. Save another source file so that a fully successful batch runs. Expected: the state returns to Indexed. Actual: it stays Standby, and codebase_search keeps failing with Current state: Standby.
  4. Click Start Indexing. Expected: one clean restart. Actual: indexing restarts, but exthost.log shows the unhandled CodeIndexManager not initialized error, and the embedder is validated twice.

Unit-level:

  • Make the first client.upsert call in upsertPoints throw new TypeError("fetch failed") → the file fails with no retry.
  • Fire onDidFinishBatchProcessing once with a local_error file, then with an all-success batch → the state stays Standby.
  • With services alive and state Standby, dispatch startIndexing → two rebuilds and an unhandled rejection.

These are proposed steps; the incident above was observed live, not reproduced on purpose.

Acceptance criteria

Retry (part 1)

  • Transient failures in a file's embed, upsert, delete, or verify steps are retried with bounded exponential backoff (keep 3 attempts / 500 ms base unless there is a reason to change it).
  • "Transient" means connection-level errors (fetch failed, ECONNRESET, ECONNREFUSED, ETIMEDOUT, closed socket), HTTP 5xx, and 429. Validation/4xx errors and parser failures are not retried.
  • Retries respect the abort signal, the write gate, and generation fencing: a superseded or cancelled attempt never writes after cancellation.

Recovery (part 2)

  • One failed file does not keep the whole index in Standby once that file later succeeds, is deleted, or is retried successfully; the latch is cleared accordingly.
  • Failed files are retried automatically with bounded backoff (for example, re-queued into a later watcher batch or a background reconciliation pass), and the state returns to Indexed without a manual restart.
  • Decide and document what search does on a partial index: either allow codebase_search with a "partial index" note, or keep refusing with an actionable message (which files failed and how to retry).
  • While files remain failed, the status shows how many failed plus at least one path and reason, and offers a retry.

Start Indexing (part 3)

  • One click triggers exactly one rebuild-and-start sequence, from Standby and from Error.
  • No unhandled rejections from Start Indexing, Toggle Workspace Indexing, or the auto-enable default; failures are caught, logged, and reflected in the status.
  • The startIndexing() contract is clarified (for example: safe to await until services are started while the scan continues in the background, or every caller must attach .catch), and the doc comment is updated to match.

Logging (part 4)

  • Code-index logs go to the Roo-Code output channel (or a dedicated LogOutputChannel) with a [CodeIndex] prefix, so installed builds keep them.
  • Log every state change: old → new state, the status message, the source (scan end, watcher batch, stop, rebuild, error), and the attempt number.
  • Log every failed file: workspace-relative path, step (read / parse / embed / upsert / delete / verify), error message, and whether it will be retried. Aggregate per batch so a mass failure doesn't flood the log. Log each retry and the final failure.
  • Log a scan summary: files processed / skipped / failed, blocks found / indexed, duration, and why the scan ended partial.
  • Log Start, Stop, and rebuild requests, including superseded attempts.
  • Show the latest failure reason (failed count plus one file) in the indexing status text.
  • Never log secrets or file contents — paths and error messages only.

Tests

  • One transient upsert failure followed by success → the file completes; a persistent failure → fails after the maximum attempts; abort during backoff → stops promptly with no further writes.
  • A watcher failure followed by success recovers; a scan with one failed file recovers after retry; a persistent failure stays visible with bounded retries.
  • Start Indexing from Standby with live services, from Error, and a double click → exactly one rebuild and no unhandled rejection.
  • A failed file, a partial scan, and a state change each produce a log entry.

Constraints/Preferences

  • Keep PR [code-index] Isolate parsing so parser failures stop indexing safely #34's protections: write gate, generation and attempt fencing (currentAttempt / isCurrentAttempt), and preserved partial progress.
  • Don't stack another retry loop on top of the embedders' internal retries for the same error class.
  • Don't hide persistent failures; they must stay visible and logged.
  • Keep steady-state log noise low: no per-success lines by default (use debug or trace level for those).
  • Suggested order: logging (part 4) and retry (part 1) first, so a recurrence is both less likely and recorded; then recovery (part 2) and Start Indexing (part 3).
  • Coordinate status wording with [BUG] Make indexing stop status reflect what actually stopped #36.

Related: PR #34, #23, #35, #36. Consolidates #58, #59, and #60, which are closed as duplicates of this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions