Error-first flow
When command exit code is non-zero:- Parse error envelope from stderr.
- Branch on
error.code. - Decide retry/fallback/abort.
Core retry and fallback guidance
- Retry on
11(rate_limited) and12(provider_unavailable) with backoff. - Do not retry on
2(usage_error) until input is corrected. - Retry on
10(auth_error) only after key provisioning. - Treat
14(stale_data) as SLO breach.
Cache/staleness strategy
- Default cache mode is usually best for interactive and agent loops.
- Use
--no-stalefor strict freshness. - Use
--max-staleto control tolerated stale window on temporary provider failures.
Strict-mode strategy
- Use
--strictwhen partial provider aggregation is unacceptable. - In strict mode, partial results fail with code
15.
Suggested wrapper behavior
- Always capture stdout and stderr separately.
- Treat stdout as success payload only when exit code is
0. - Persist
meta.request_idfor trace correlation.

