search-bots: fix reliability (diagnosed) - gemini 3-retry + grok xsearch auto-fallback to gemini
Mike's must-fix. Diagnosed from RAW output of failing queries (not guessed): - grok xsearch = TIMEOUT: grok-4.20-multi-agent web_search runs past budget on multi-part queries (286s/280s, rc=124, still searching - 183 thoughts, only progress-noise text); buffered json => total loss. - gemini search = INTERMITTENT empty turn (a clean re-run gave a real 2.6KB answer in 122s); the wrapper retried only once, so two empties in a row failed spuriously. Fixes: - ask-gemini.sh emit_or_fail: retry up to 3x with 3s/6s backoff (was 1). - ask-grok.sh xsearch: --output-format streaming-json (salvage partials) + AUTO-FALLBACK to ask-gemini.sh search when grok doesn't finish (rc!=0 or empty). Validated e2e: grok timed out (rc=124) -> fell back -> gemini returned a real sourced answer (UniFi Teleport invite-link API). grok's own multi-agent timeout is an xAI-side limitation; the fallback makes xsearch reliable regardless. Docs: grok SKILL.md xsearch row + CT_THOUGHTS Thought 2 Resolution. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -218,21 +218,32 @@ case "$MODE" in
|
||||
;;
|
||||
xsearch)
|
||||
[ -z "${1:-}" ] && { echo "usage: $SELF xsearch \"<query>\"" >&2; exit 2; }
|
||||
# web_search runs the grok-4.20-multi-agent model -> subagents MUST stay enabled
|
||||
# (--no-subagents made it hang with ZERO output, the long-standing xsearch bug).
|
||||
# --yolo is the documented headless tool-run posture (README/14-headless-mode.md).
|
||||
# Budget is generous: a live web_search measured ~83s end-to-end.
|
||||
GROK_SUBAGENT_FLAGS=()
|
||||
GROK_PERM_FLAGS=(--yolo)
|
||||
GROK_MODEL="" # search runs the separate grok-4.20-multi-agent model; use runtime default orchestrator
|
||||
# Lead with web_search (fast); pull in X/Twitter ONLY when the query is actually
|
||||
# about social/news/sentiment. Mandating X search on every call ran the multi-agent
|
||||
# searcher long enough to blow a 240s budget. Generous 300s budget for headroom.
|
||||
printf 'Use your web_search tool to answer this question and cite sources. Use your X/Twitter search tools ONLY if the question is specifically about social media, breaking news, or public sentiment. Then stop.\n\nQuestion: %s' "$1" > "$PF"
|
||||
run_grok 300 --max-turns 14
|
||||
txt="$(jfield text)"
|
||||
if [ -n "$txt" ]; then printf '%s\n' "$txt"; else
|
||||
echo "[$SELF] no result (stopReason=$(jfield stopReason))" >&2; _logerr "grok xsearch returned no result" --context "mode=xsearch stopReason=$(jfield stopReason)"; exit 1; fi
|
||||
# web_search uses the grok-4.20-multi-agent model (subagents ON, --yolo). It frequently TIMES
|
||||
# OUT on multi-part research queries (verified 2026-06-17: 280-286s, no answer, still searching),
|
||||
# and buffered json => total loss. So: (1) streaming-json to salvage any partial that streamed;
|
||||
# (2) a moderate budget; (3) AUTO-FALLBACK to gemini search (the reliable engine, ~120s) when grok
|
||||
# doesn't finish. Net: xsearch returns an answer even though grok alone is flaky here.
|
||||
Q="$1"
|
||||
printf 'Use your web_search tool: run a few TARGETED searches and give a CONCISE answer with source URLs, then stop.\n\nQuestion: %s' "$Q" > "$PF"
|
||||
"$TIMEOUT_CMD" 240 "$GROK" --prompt-file "$(winpath "$PF")" --output-format streaming-json \
|
||||
--yolo --no-plan --cwd "$(winpath "$RUN_CWD")" --max-turns 14 >"$OUT" 2>"$TMP/err.txt"; GRC=$?
|
||||
ans="$("$PY" -c '
|
||||
import json,sys
|
||||
t=[]
|
||||
for ln in sys.stdin:
|
||||
ln=ln.strip()
|
||||
if not ln: continue
|
||||
try: e=json.loads(ln)
|
||||
except: continue
|
||||
if e.get("type")=="text": t.append(e.get("data",""))
|
||||
print("".join(t).strip())' < "$OUT")"
|
||||
if [ "$GRC" -eq 0 ] && [ -n "$ans" ]; then printf '%s\n' "$ans"; exit 0; fi
|
||||
echo "[$SELF] grok xsearch did not finish (rc=$GRC) -> falling back to gemini search" >&2
|
||||
_logerr "grok xsearch incomplete (rc=$GRC); auto-fell back to gemini" --context "mode=xsearch"
|
||||
GEM="$REPO_ROOT/.claude/skills/agy/scripts/ask-gemini.sh"
|
||||
if [ -f "$GEM" ]; then echo "[grok xsearch timed out -> answered via gemini search]"; exec bash "$GEM" search "$Q"; fi
|
||||
[ -n "$ans" ] && { printf '%s\n' "$ans"; exit 0; } # last resort: whatever partial streamed
|
||||
echo "[$SELF] no result (grok timed out; gemini fallback unavailable)" >&2; exit 1
|
||||
;;
|
||||
review|file)
|
||||
[ -z "${1:-}" ] && { echo "usage: $SELF review <file-path> [instructions]" >&2; exit 2; }
|
||||
|
||||
Reference in New Issue
Block a user