Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,7 @@ When an asynchronous promise chain manages its own error caching (e.g., throwing

**Action:**
To enforce clean architecture and prevent orphaned cache entries on error, centralize cache eviction logic at the point of cache insertion by appending a \`.then()\` (to check for "Error:" strings) and a \`.catch()\` (to catch rejections) block to the Promise before storing it in the cache, and remove all redundant manual \`cache.delete\` calls within the async function.

## 2026-11-05 — Fix DuckDuckGo HTML Parsing and Cache Eviction
- **Learning:** When parsing HTML search results where elements like snippet or title might contain nested wrapper tags, regex that blindly looks for a closing `</div>` can truncate the block prematurely, losing data. Additionally, scattering `cache.delete` across async code can lead to orphaned entries if an unexpected error occurs.
- **Action:** Fixed DuckDuckGo HTML parser to match blocks based on next result div or EOF. Centralized cache eviction logic by chaining `.catch()` before storing the promise in the cache, returning the validated promise to ensure cleanup on error.
5 changes: 5 additions & 0 deletions .jules/warden.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2026-11-05 — Lifecycle & Assurance Ledger
- **QA & Veto Actions:** Audited recent changes and verified test suite execution. No veto necessary. Fixed regex HTML truncation bug in DuckDuckGoSearcher and centralized cache eviction logic.
- **Entropy Pruned:** 0 lines deleted.
- **Deferred / Blocked:** None.

## 2026-11-04 — Lifecycle & Assurance Ledger
- **QA & Veto Actions:** Audited recent changes and verified test suite execution. No veto necessary.
- **Entropy Pruned:** 0 lines deleted.
Expand Down
15 changes: 10 additions & 5 deletions src/tools/DuckDuckGoSearcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class DuckDuckGoSearcher implements ISearchProvider {
// Parse result blocks to keep titles and snippets synchronized
// Pattern: <div class="result results_links">...</div>
const blockRegex =
/<div[^>]*class="[^"]*\bresult\b[^"]*"[^>]*>([\s\S]*?)<\/div>/gi;
/<div[^>]*class="[^"]*\bresult\b[^"]*"[^>]*>([\s\S]*?)(?=<div[^>]*class="[^"]*\bresult\b[^"]*"|$)/gi;
const titleRegex =
/<a[^>]+class="[^"]*result__a[^"]*"[^>]+href="([^"]+)"[^>]*>([\s\S]*?)<\/a>/i;
const snippetRegex =
Expand Down Expand Up @@ -128,8 +128,7 @@ export class DuckDuckGoSearcher implements ISearchProvider {
} catch (error) {
attempt++;
if (attempt > this.maxRetries) {
this.cache.delete(cacheKey);
return [];
throw new Error("Max retries exceeded");
}
await new Promise((resolve) => setTimeout(resolve, attempt * 1000));
}
Expand All @@ -138,7 +137,13 @@ export class DuckDuckGoSearcher implements ISearchProvider {
return [];
})();

this.cache.set(cacheKey, searchPromise);
return searchPromise;
this.cache.set(
cacheKey,
searchPromise.catch((err) => {
this.cache.delete(cacheKey);
return [];
}),
);
return this.cache.get(cacheKey) as Promise<SearchResult[]>;
}
}
11 changes: 8 additions & 3 deletions src/tools/GoogleSearcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,17 @@ export class GoogleSearcher implements ISearchProvider {
console.error(
`[GoogleSearcher] Search failed for query "${query}": ${error instanceof Error ? error.message : String(error)}`,
);
this.cache.delete(cacheKey);
throw error;
}
})();

this.cache.set(cacheKey, searchPromise);
return searchPromise;
this.cache.set(
cacheKey,
searchPromise.catch((err) => {
this.cache.delete(cacheKey);
throw err;
}),
);
return this.cache.get(cacheKey) as Promise<SearchResult[]>;
}
}
Loading