You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: code explorer search prompts — concept dedup and circuit breaker (#539)
* fix: improve code explorer search prompts to prevent wasted retries
- Expand no-results guidance: distinguish subfolder vs workspace-root
searches, suggest widening scope before giving up
- Add fuzzy concept dedup: normalizes queries (strips quotes, "func"
prefix, dots, case) to detect that "func ctxGetData", "ctxGetData",
"ctx.GetData" are all the same failed concept
- Add circuit breaker: after 4 consecutive no-result searches, block
further searches and force strategy change (extract, listFiles, or
answer with what was found)
- Add explicit anti-pattern examples showing the worst retry loop
(quote/syntax variations of non-existent functions) with concrete
fix options
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: remove func/type prefix stripping from concept normalizer
The Rust search engine already handles "func" and "type" as stopwords,
so stripping them in JS normalization is redundant and causes false
positives: "type Config" and "Config" are genuinely different search
intents but would collide after stripping.
Keep only syntax-level normalization (quotes, dots, underscores, case)
which catches the actual problem pattern without risk.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test: add concept normalizer tests for cross-language false positive safety
33 tests validating the fuzzy search dedup normalizer:
- Syntax variations correctly collapse (quotes, dots, snake/camel/kebab)
- Language keywords preserved (func, type, impl, class, def, trait)
- Structural chars preserved (::, (), <>, /)
- Known acceptable collisions documented (http.Server vs httpServer)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test: add concept dedup counter integration tests
7 tests proving the exact counting flow:
- 2 real failures → 3rd blocked (no search executed)
- No double-counting between block path and track path
- Counts increment correctly (3→4→5) on blocked attempts
- Different concepts and paths tracked independently
- Successful search resets circuit breaker counter
- Concept dedup fires before circuit breaker when both apply
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
' FIX: After "func ctxGetData" returns no results in gateway/:',
328
+
' Option A: Widen scope — search from the workspace root (omit path) in case the',
329
+
' function is defined in a different package (e.g., apidef/, user/, config/).',
330
+
' Option B: Discover real names — extract a file you KNOW uses context (e.g., a',
331
+
' middleware file) and READ what functions it actually calls.',
332
+
' Option C: Browse — use listFiles to see what files exist and extract the relevant ones.',
333
+
' NEVER: retry the same concept with different quoting in the same directory.',
334
+
'',
305
335
'Keyword tips:',
306
336
'- Common programming keywords are filtered as stopwords when unquoted: function, class, return, new, struct, impl, var, let, const, etc.',
307
337
'- Avoid searching for these alone — combine with a specific term (e.g., "middleware function" is fine, "function" alone is too generic).',
@@ -340,7 +370,7 @@ function buildSearchDelegateTask({ searchQuery, searchPath, exact, language, all
340
370
' - Type references and imports → include type definitions.',
341
371
' - Registered handlers/middleware → include all registered items.',
342
372
'6. If a search returns results, use extract to verify relevance. Run multiple extracts in parallel too.',
343
-
'7. If a search returns NO results, the term does not exist. Do NOT retry with variations. Move on.',
373
+
'7. If a search returns NO results: widen the path scope if you searched a subfolder, or move on. Do NOT retry with quote/syntax variations — they search the same index.',
344
374
'8. Once you have enough targets (typically 5-15), output your final JSON answer immediately.',
? `\n- Try searching from the workspace root (omit the path parameter) — the term may exist in a different directory`
546
+
: `\n- The term does not exist in this codebase at any path`;
547
+
return`CONCEPT ALREADY FAILED (${conceptCount} variations tried). You already searched for "${normalizeQueryConcept(searchQuery)}" with different quoting/syntax in this path and got NO results each time. Changing quotes, adding "func" prefix, or switching to method syntax will NOT change the results.\n\nChange your strategy:${scopeHint}\n- Use extract on a file you ALREADY found to read actual code and discover real function/type names\n- Use listFiles to browse directories and find what functions actually exist\n- Search for a BROADER concept (e.g., instead of "ctxGetData", try "context" or "middleware data access")\n- If you have enough information from prior searches, provide your final answer NOW`;
548
+
}
549
+
550
+
// Circuit breaker: too many consecutive no-result searches means the model
551
+
// is stuck in a loop guessing names that don't exist
? `\n- You have been searching in "${path}" — try searching from the workspace root or a different directory`
559
+
: '';
560
+
return`CIRCUIT BREAKER: Your last ${consecutiveNoResults} searches ALL returned no results. You appear to be guessing function/type names that don't match what's actually in the code.\n\nChange your approach:${cbScopeHint}\n1. Use extract on files you already found — read the actual code to discover real function names\n2. Use listFiles to browse directories and see what files/functions actually exist\n3. If you found some results earlier, those are likely sufficient — provide your final answer\n\nRetrying search query variations will not help. Discover real names from real code instead.`;
561
+
}
481
562
}else{
482
563
// Cap pagination to prevent runaway page-through of broad queries
returnresult+'\n\n⚠️ Your query looks like a ticket/issue ID (e.g., JIRA-1234). Ticket IDs are rarely present in source code. Search for the technical concepts described in the ticket instead (e.g., function names, error messages, variable names).';
499
587
}
588
+
// Add a hint when approaching the circuit breaker threshold
? ` You are searching in "${path}" — consider searching from the workspace root or a different directory.`
593
+
: '';
594
+
returnresult+`\n\n⚠️ WARNING: ${consecutiveNoResults} consecutive searches returned no results.${warnScopeHint} Before your next action: use extract on a file you already found to read actual code, or use listFiles to discover what functions really exist. One more failed search will trigger the circuit breaker.`;
0 commit comments