Skip to content

fix(search): --ai no longer hangs — parseArgs missing index increment#35

Draft
edwinhu wants to merge 1 commit into
mainfrom
worktree-ai-search-fix
Draft

fix(search): --ai no longer hangs — parseArgs missing index increment#35
edwinhu wants to merge 1 commit into
mainfrom
worktree-ai-search-fix

Conversation

@edwinhu

@edwinhu edwinhu commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Problem

superhuman search "<query>" --ai (Superhuman's server-side AI search — the only search path that reaches archived / "done" mail) silently produced zero output and hung. Repro:

superhuman search "pebble pre-order confirmation" --account eddyhu@gmail.com --ai --json
# → no output, never returns

Root cause

In parseArgs, the --ai flag's switch case set options.ai = true but never advanced the parser index i, while every sibling boolean flag does (--json, --focused, --include-done, …). Because parseArgs increments i manually per-flag inside while (i < args.length), the missing increment pinned i on the --ai token and spun an infinite loop. The CLI never even reached cmdSearch — it hung with no output on every --ai invocation.

Broken since v0.25.0 (778a6de, 2026-04-07). The existing ai-search.test.ts only exercised askAISearch() directly, never the CLI argument parser, so the regression went unnoticed.

The backend endpoint (v3/ai.askAIProxy) was never the problem — direct probing showed it returns HTTP 200 with full results (retrievals + AI summary) in ~10–30s. The prior "AI search is deauthorized" hypothesis was a red herring.

Fix

  • Add the missing i += 1 to the --ai case.
  • Add a forward-progress backstop to the parse loop: capture i before dispatch and throw a clear error if it did not advance. Any future missing-increment regression now fails loudly and actionably instead of hanging silently.
  • Export parseArgs and add src/__tests__/parse-args.test.ts: covers --ai (both --ai and --ai=… forms, every position relative to other flags) plus a forward-progress sweep over all boolean flags — each under a 5s timeout so a reintroduced hang fails the test instead of stalling the suite.

Verification

  • search "pebble pre-order confirmation" --account eddyhu@gmail.com --ai --json → exit 0, 1212 bytes (2 retrievals + ai_summary). Non-JSON path also renders the AI narrative + thread IDs.
  • Full suite: 524 pass, 0 fail (bun test).

🤖 Generated with Claude Code

`superhuman search "<q>" --ai` (server-side AI search, the only path that
reaches archived/"done" mail) silently produced zero output and hung.

Root cause: in parseArgs the `--ai` flag's switch case set `options.ai = true`
but never advanced the parser index `i`, while every sibling boolean flag does
(`--json`, `--focused`, `--include-done`, …). Because parseArgs increments `i`
manually per-flag, the missing increment pinned `i` on `--ai` and spun
`while (i < args.length)` as an infinite loop. The CLI never reached cmdSearch
— it hung with no output on every `--ai` invocation. Broken since v0.25.0
(778a6de, 2026-04-07); the existing ai-search tests only exercised
askAISearch() directly, never the CLI argument parser, so it went unnoticed.

The backend endpoint (v3/ai.askAIProxy) was never the problem — it returns 200
with full results in ~10-30s. The "deauthorized" hypothesis was a red herring.

Fix:
- Add the missing `i += 1` to the `--ai` case.
- Add a forward-progress backstop in the parse loop: capture `i` before
  dispatch and throw a clear error if it did not advance. This converts any
  future missing-increment regression from a silent infinite-loop hang into a
  loud, actionable failure.
- Export parseArgs and add src/__tests__/parse-args.test.ts covering --ai
  (both `--ai` and `--ai=…` forms, all positions) plus a forward-progress
  sweep over every boolean flag, each under a 5s timeout so a reintroduced
  hang fails instead of stalling the suite.

Verified: `search "pebble pre-order confirmation" --account eddyhu@gmail.com
--ai --json` now exits 0 with retrievals + AI summary (JSON and non-JSON).
Full suite: 524 pass, 0 fail.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C8nWV3c7WRdZRL8jGwefDd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant