fix(search): --ai no longer hangs — parseArgs missing index increment#35
Draft
edwinhu wants to merge 1 commit into
Draft
fix(search): --ai no longer hangs — parseArgs missing index increment#35edwinhu wants to merge 1 commit into
edwinhu wants to merge 1 commit into
Conversation
`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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:Root cause
In
parseArgs, the--aiflag'sswitchcase setoptions.ai = truebut never advanced the parser indexi, while every sibling boolean flag does (--json,--focused,--include-done, …). BecauseparseArgsincrementsimanually per-flag insidewhile (i < args.length), the missing increment pinnedion the--aitoken and spun an infinite loop. The CLI never even reachedcmdSearch— it hung with no output on every--aiinvocation.Broken since v0.25.0 (
778a6de, 2026-04-07). The existingai-search.test.tsonly exercisedaskAISearch()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
i += 1to the--aicase.ibefore dispatch andthrowa clear error if it did not advance. Any future missing-increment regression now fails loudly and actionably instead of hanging silently.parseArgsand addsrc/__tests__/parse-args.test.ts: covers--ai(both--aiand--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.bun test).🤖 Generated with Claude Code