Elffuss BraidHub

kikocis/continue public

Prevent entire indexing process from stopping on error and surface messages to Indexing menu
Changeset7cc464ab07518cbe15aa087e8574f9795085c4bb143400a12390e0f9130aeff0
AuthorTing-Wai To <tingwai.to@gmail.com> · 2025-07-01 13:33 -07:00
CommitterTing-Wai To <tingwai.to@gmail.com> · 2025-07-02 10:13 -07:00
Parents54bc82ab2ee9

Browse the files at this changeset

7 files changed

modified core/index.d.ts +1 −0
@@ -57,6 +57,7 @@
5757 | "disabled"
5858 | "cancelled";
5959 debugInfo?: string;
60+ warnings?: string[];
6061 }
6162
6263 // This is more or less a V2 of IndexingProgressUpdate for docs etc.
modified core/indexing/CodeSnippetsIndex.ts +2 −2
@@ -35,7 +35,8 @@
3535
3636 export class CodeSnippetsCodebaseIndex implements CodebaseIndex {
3737 relativeExpectedTime: number = 1;
38- artifactId = "codeSnippets";
38+ static artifactId = "codeSnippets";
39+ artifactId: string = CodeSnippetsCodebaseIndex.artifactId;
3940
4041 constructor(private readonly ide: IDE) {}
4142
@@ -220,7 +221,6 @@
220221 // Compute
221222 for (let i = 0; i < results.compute.length; i++) {
222223 const compute = results.compute[i];
223-
224224 let snippets: SnippetChunk[] = [];
225225 try {
226226 snippets = await this.getSnippetsInFile(
modified core/indexing/CodebaseIndexer.ts +140 −64
@@ -48,6 +48,16 @@
4848 private codebaseIndexingState: IndexingProgressUpdate;
4949 private readonly pauseToken: PauseToken;
5050
51+ private getUserFriendlyIndexName(artifactId: string): string {
52+ if (artifactId === FullTextSearchCodebaseIndex.artifactId)
53+ return "Full text search";
54+ if (artifactId === CodeSnippetsCodebaseIndex.artifactId)
55+ return "Code snippets";
56+ if (artifactId === ChunkCodebaseIndex.artifactId) return "Chunking";
57+ if (artifactId.startsWith("vectordb")) return "Embedding";
58+ return artifactId; // fallback to original
59+ }
60+
5161 // Note that we exclude certain Sqlite errors that we do not want to clear the indexes on,
5262 // e.g. a `SQLITE_BUSY` error.
5363 errorsRegexesToClearIndexesOn = [
@@ -314,6 +324,7 @@
314324 status: "loading",
315325 };
316326 const beginTime = Date.now();
327+ let collectedWarnings: string[] = [];
317328
318329 for (const directory of dirs) {
319330 const dirBasename = getUriPathBasename(directory);
@@ -344,45 +355,52 @@
344355 const repoName = await this.ide.getRepoName(directory);
345356 let nextLogThreshold = 0;
346357
347- try {
348- for await (const updateDesc of this.indexFiles(
349- directory,
350- directoryFiles,
351- branch,
352- repoName,
353- )) {
354- // Handle pausing in this loop because it's the only one really taking time
355- if (abortSignal.aborted) {
356- yield {
357- progress: 0,
358- desc: "Indexing cancelled",
359- status: "cancelled",
360- };
361- return;
362- }
363- if (this.pauseToken.paused) {
364- yield* this.yieldUpdateAndPause();
365- }
366- yield updateDesc;
367- if (updateDesc.progress >= nextLogThreshold) {
368- // log progress every 2.5%
369- nextLogThreshold += 0.025;
370- this.logProgress(
371- beginTime,
372- Math.floor(directoryFiles.length * updateDesc.progress),
373- updateDesc.progress,
374- );
375- }
358+ for await (const updateDesc of this.indexFiles(
359+ directory,
360+ directoryFiles,
361+ branch,
362+ repoName,
363+ )) {
364+ // Handle pausing in this loop because it's the only one really taking time
365+ if (abortSignal.aborted) {
366+ yield {
367+ progress: 0,
368+ desc: "Indexing cancelled",
369+ status: "cancelled",
370+ };
371+ return;
372+ }
373+ if (this.pauseToken.paused) {
374+ yield* this.yieldUpdateAndPause();
375+ }
376+
377+ // Collect warnings from indexFiles
378+ if (updateDesc.warnings && updateDesc.warnings.length > 0) {
379+ collectedWarnings = [...updateDesc.warnings];
380+ }
381+
382+ yield updateDesc;
383+ if (updateDesc.progress >= nextLogThreshold) {
384+ // log progress every 2.5%
385+ nextLogThreshold += 0.025;
386+ this.logProgress(
387+ beginTime,
388+ Math.floor(directoryFiles.length * updateDesc.progress),
389+ updateDesc.progress,
390+ );
376391 }
377- } catch (err) {
378- yield this.handleErrorAndGetProgressUpdate(err);
379- return;
380392 }
381393 }
394+
395+ // Final completion message with preserved warnings
382396 yield {
383397 progress: 1,
384- desc: "Indexing Complete",
398+ desc:
399+ collectedWarnings.length > 0
400+ ? `Indexing completed with ${collectedWarnings.length} warning(s)`
401+ : "Indexing Complete",
385402 status: "done",
403+ warnings: collectedWarnings.length > 0 ? collectedWarnings : undefined,
386404 };
387405 this.logProgress(beginTime, 0, 1);
388406 }
@@ -490,6 +508,8 @@
490508 const indexesToBuild = await this.getIndexesToBuild();
491509 let completedIndexCount = 0;
492510 let progress = 0;
511+ const warnings: string[] = [];
512+
493513 for (const codebaseIndex of indexesToBuild) {
494514 const tag: IndexTag = {
495515 directory,
@@ -500,45 +520,101 @@
500520 progress: progress,
501521 desc: `Planning changes for ${codebaseIndex.artifactId} index...`,
502522 status: "indexing",
523+ warnings: warnings.length > 0 ? [...warnings] : undefined,
503524 };
504- const [results, lastUpdated, markComplete] =
505- await getComputeDeleteAddRemove(
506- tag,
507- { ...stats },
508- (filepath) => this.ide.readFile(filepath),
509- repoName,
510- );
511- const totalOps = this.totalIndexOps(results);
512- let completedOps = 0;
513525
514- // Don't update if nothing to update. Some of the indices might do unnecessary setup work
515- if (totalOps > 0) {
516- for (const subResult of this.batchRefreshIndexResults(results)) {
517- for await (const { desc } of codebaseIndex.update(
526+ try {
527+ const [results, lastUpdated, markComplete] =
528+ await getComputeDeleteAddRemove(
518529 tag,
519- subResult,
520- markComplete,
530+ { ...stats },
531+ (filepath) => this.ide.readFile(filepath),
521532 repoName,
522- )) {
523- yield {
524- progress,
525- desc,
526- status: "indexing",
527- };
533+ );
534+ const totalOps = this.totalIndexOps(results);
535+ let completedOps = 0;
536+
537+ // Don't update if nothing to update. Some of the indices might do unnecessary setup work
538+ if (totalOps > 0) {
539+ for (const subResult of this.batchRefreshIndexResults(results)) {
540+ try {
541+ for await (const { desc } of codebaseIndex.update(
542+ tag,
543+ subResult,
544+ markComplete,
545+ repoName,
546+ )) {
547+ yield {
548+ progress,
549+ desc,
550+ status: "indexing",
551+ warnings: warnings.length > 0 ? [...warnings] : undefined,
552+ };
553+ }
554+ completedOps +=
555+ subResult.compute.length +
556+ subResult.del.length +
557+ subResult.addTag.length +
558+ subResult.removeTag.length;
559+ progress =
560+ (completedIndexCount + completedOps / totalOps) *
561+ (1 / indexesToBuild.length);
562+ } catch (err) {
563+ // Collect non-fatal errors as warnings and continue
564+ const warningMsg =
565+ err instanceof Error ? err.message : String(err);
566+ const friendlyName = this.getUserFriendlyIndexName(
567+ codebaseIndex.artifactId,
568+ );
569+ warnings.push(`${friendlyName}: ${warningMsg}`);
570+ console.warn(`${friendlyName}: ${warningMsg}`, err);
571+
572+ // Complete this batch and continue with next
573+ completedOps +=
574+ subResult.compute.length +
575+ subResult.del.length +
576+ subResult.addTag.length +
577+ subResult.removeTag.length;
578+ progress =
579+ (completedIndexCount + completedOps / totalOps) *
580+ (1 / indexesToBuild.length);
581+ }
528582 }
529- completedOps +=
530- subResult.compute.length +
531- subResult.del.length +
532- subResult.addTag.length +
533- subResult.removeTag.length;
534- progress =
535- (completedIndexCount + completedOps / totalOps) *
536- (1 / indexesToBuild.length);
537583 }
584+
585+ await markComplete(lastUpdated, IndexResultType.UpdateLastUpdated);
586+ completedIndexCount += 1;
587+ } catch (err) {
588+ // Handle errors during planning phase
589+ const cause = getRootCause(err as Error);
590+ if (cause instanceof LLMError) {
591+ // LLM errors are critical, re-throw them
592+ throw cause;
593+ }
594+
595+ // Collect planning errors as warnings and continue to next index
596+ const errorMsg = err instanceof Error ? err.message : String(err);
597+ const friendlyName = this.getUserFriendlyIndexName(
598+ codebaseIndex.artifactId,
599+ );
600+ warnings.push(`${friendlyName}: ${errorMsg}`);
601+ console.warn(
602+ `Warning during ${codebaseIndex.artifactId} planning:`,
603+ err,
604+ );
605+ completedIndexCount += 1;
606+ progress = completedIndexCount * (1 / indexesToBuild.length);
538607 }
608+ }
539609
540- await markComplete(lastUpdated, IndexResultType.UpdateLastUpdated);
541- completedIndexCount += 1;
610+ // Final update with any collected warnings
611+ if (warnings.length > 0) {
612+ yield {
613+ progress: 1,
614+ desc: `Indexing completed with ${warnings.length} warning(s)`,
615+ status: "done",
616+ warnings: [...warnings],
617+ };
542618 }
543619 }
544620
modified core/indexing/FullTextSearchCodebaseIndex.ts +1 −2
@@ -55,7 +55,6 @@
5555
5656 for (let i = 0; i < results.compute.length; i++) {
5757 const item = results.compute[i];
58-
5958 // Insert chunks
6059 const chunks = await db.all(
6160 "SELECT * FROM chunks WHERE path = ? AND cacheKey = ?",
@@ -68,7 +67,7 @@
6867 [item.path, chunk.content],
6968 );
7069 await db.run(
71- `INSERT INTO fts_metadata (id, path, cacheKey, chunkId)
70+ `INSERT INTO fts_metadata (id, path, cacheKey, chunkId)
7271 VALUES (?, ?, ?, ?)
7372 ON CONFLICT(id) DO UPDATE SET
7473 path = excluded.path,
modified core/indexing/README.md +3 −3
@@ -20,10 +20,10 @@
2020
2121 All indexes must be returned by `getIndexesToBuild` in [`CodebaseIndexer.ts`](./CodebaseIndexer.ts) if they are to be used.
2222
23-`CodeSnippetsCodebaseIndex`: uses tree-sitter queries to get a list of functions, classes, and other top-level code objects in each file
23+`CodeSnippetsIndex`: uses tree-sitter queries to get a list of functions, classes, and other top-level code objects in each file
2424 `FullTextSearchCodebaseIndex`: creates a full-text search index using SQLite FTS5
25-`ChunkCodebaseIndex`: chunks files recursively by code structure, for use in other embeddings providers like `LanceDbCodebaseIndex`
26-`LanceDbCodebaseIndex`: calculates embeddings for each chunk and adds them to the LanceDB vector database, with metadata going into SQLite. Note that for each branch, a unique table is created in LanceDB.
25+`ChunkCodebaseIndex`: chunks files recursively by code structure, for use in other embeddings providers like `LanceDbIndex`
26+`LanceDbIndex`: calculates embeddings for each chunk and adds them to the LanceDB vector database, with metadata going into SQLite. Note that for each branch, a unique table is created in LanceDB.
2727
2828 ## Known problems
2929
modified gui/src/pages/config/IndexingProgress/IndexingProgress.tsx +9 −7
@@ -1,17 +1,18 @@
11 import { IndexingProgressUpdate } from "core";
2+import { usePostHog } from "posthog-js/react";
23 import { useContext, useEffect, useState } from "react";
34 import { useDispatch } from "react-redux";
5+
6+import ConfirmationDialog from "../../../components/dialogs/ConfirmationDialog";
47 import { IdeMessengerContext } from "../../../context/IdeMessenger";
5-import { isJetBrains } from "../../../util";
68 import { useWebviewListener } from "../../../hooks/useWebviewListener";
9+import { setDialogMessage, setShowDialog } from "../../../redux/slices/uiSlice";
10+import { isJetBrains } from "../../../util";
711 import IndexingProgressBar from "./IndexingProgressBar";
12+import IndexingProgressErrorText from "./IndexingProgressErrorText";
813 import IndexingProgressIndicator from "./IndexingProgressIndicator";
9-import IndexingProgressTitleText from "./IndexingProgressTitleText";
1014 import IndexingProgressSubtext from "./IndexingProgressSubtext";
11-import { usePostHog } from "posthog-js/react";
12-import ConfirmationDialog from "../../../components/dialogs/ConfirmationDialog";
13-import { setShowDialog, setDialogMessage } from "../../../redux/slices/uiSlice";
14-import IndexingProgressErrorText from "./IndexingProgressErrorText";
15+import IndexingProgressTitleText from "./IndexingProgressTitleText";
1516
1617 export function getProgressPercentage(
1718 progress: IndexingProgressUpdate["progress"],
@@ -119,7 +120,8 @@
119120
120121 <IndexingProgressSubtext update={update} onClick={onClick} />
121122
122- {update.status === "failed" && (
123+ {(update.status === "failed" ||
124+ (update.warnings && update.warnings.length > 0)) && (
123125 <div className="mt-4">
124126 <IndexingProgressErrorText update={update} />
125127 </div>
modified gui/src/pages/config/IndexingProgress/IndexingProgressErrorText.tsx +81 −1
@@ -1,12 +1,27 @@
1-import { XCircleIcon } from "@heroicons/react/24/outline";
1+import {
2+ ArrowTopRightOnSquareIcon,
3+ ChevronRightIcon,
4+ ClipboardIcon,
5+ XCircleIcon,
6+} from "@heroicons/react/24/outline";
27 import { IndexingProgressUpdate } from "core";
8+import { useContext, useState } from "react";
9+import { GhostButton } from "../../../components";
10+import { IdeMessengerContext } from "../../../context/IdeMessenger";
311 import { useAppSelector } from "../../../redux/hooks";
412
513 export interface IndexingProgressErrorTextProps {
614 update: IndexingProgressUpdate;
715 }
816
17+const copyWarningsToClipboard = (warnings: string[] = []) => {
18+ const warningsText = warnings.join("\n");
19+ void navigator.clipboard.writeText(warningsText);
20+};
21+
922 function IndexingProgressErrorText({ update }: IndexingProgressErrorTextProps) {
23+ const ideMessenger = useContext(IdeMessengerContext);
24+ const [showWarnings, setShowWarnings] = useState(false);
1025 const embeddingsProvider = useAppSelector(
1126 (state) => state.config.config.selectedModelByRole.embed,
1227 );
@@ -30,6 +45,71 @@
3045 );
3146 }
3247
48+ // Show warnings if they exist (for completed indexing with warnings)
49+ if (
50+ update.warnings &&
51+ update.warnings.length > 0 &&
52+ update.status !== "failed"
53+ ) {
54+ return (
55+ <div>
56+ <div
57+ className="flex cursor-pointer items-center gap-2 italic text-yellow-600"
58+ onClick={() => setShowWarnings(!showWarnings)}
59+ >
60+ <span className="leading-relaxed">
61+ {update.warnings.length} warning
62+ {update.warnings.length > 1 ? "s" : ""} during indexing
63+ </span>
64+ <ChevronRightIcon
65+ className={`h-3 w-3 transition-transform duration-300 ${
66+ showWarnings ? "rotate-90" : ""
67+ }`}
68+ />
69+ </div>
70+
71+ <div
72+ className={`ml-3 overflow-hidden transition-all duration-300 ease-in-out ${
73+ showWarnings ? "mt-2 max-h-96 opacity-100" : "max-h-0 opacity-0"
74+ }`}
75+ >
76+ {/* Warning messages */}
77+ <div className="space-y-1">
78+ {update.warnings.map((warning, index) => (
79+ <div key={index} className="text-xs">
80+ • {warning}
81+ </div>
82+ ))}
83+ </div>
84+
85+ {/* Action Buttons */}
86+ <div className="flex flex-row items-center justify-end gap-2 pt-4">
87+ {/* Copy all warnings to clipboard */}
88+ <GhostButton
89+ onClick={() => copyWarningsToClipboard(update.warnings)}
90+ className="flex items-center !px-1.5 !py-0.5 text-xs"
91+ >
92+ <ClipboardIcon className="mr-1 h-3 w-3" />
93+ <span>Copy output</span>
94+ </GhostButton>
95+
96+ {/* Open dev tools to view logs */}
97+ <GhostButton
98+ onClick={() => {
99+ ideMessenger.post("toggleDevTools", undefined);
100+ }}
101+ className="flex items-center !px-1.5 !py-0.5 text-xs"
102+ >
103+ <ArrowTopRightOnSquareIcon className="mr-1 h-3 w-3" />
104+ <span>View Logs</span>
105+ </GhostButton>
106+ </div>
107+ </div>
108+ </div>
109+ );
110+ }
111+
112+ // Show error for failed status
33113 return (
34114 <div className="flex items-center gap-2 italic text-red-600">
35115 <XCircleIcon className="h-4 w-4" />