Skip to content

fix: guard chaos injection behind CHAOS_ENABLED env var in /suggest endpoint#199

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1779451425-fix-search-suggest-keyerror
Open

fix: guard chaos injection behind CHAOS_ENABLED env var in /suggest endpoint#199
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1779451425-fix-search-suggest-keyerror

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

Summary

Fixes the high 5xx error rate on search-service caused by the /suggest endpoint's chaos-injected ranking-score enrichment path.

Root cause: The /suggest endpoint had a chaos code path triggered unconditionally by the Redis flag chaos:search-service:suggest_500. This path:

  1. Calls service.suggest(prefix) which returns list[str] (plain strings)
  2. Tries to sort by s["_rankingScore"] on those strings → TypeError/KeyError
  3. Falls back to [{}] for empty results, which also raises KeyError
  4. No exception handler wraps this path, so all errors become 500s

Fix: Guard the chaos injection behind a CHAOS_ENABLED environment variable (defaulting to false). The broken ranking path can no longer fire in production. The normal suggest path — which correctly returns suggestions without ranking enrichment — is always used unless chaos mode is explicitly enabled.

Review & Testing Checklist for Human

  • Verify CHAOS_ENABLED is not set to true in any production deployment config (Helm values, env vars, k8s manifests)
  • Confirm 5xx rate on /suggest drops after deployment by checking Grafana dashboard
  • Test the /suggest endpoint manually: curl /api/v1/search/suggest?q=test should return 200 with suggestions

Notes

  • All 41 existing tests pass with this change
  • The chaos path is preserved for intentional chaos testing — set CHAOS_ENABLED=true to re-enable it
  • Alert: SearchSuggestHighErrorRate

Link to Devin session: https://partner-workshops.devinenterprise.com/sessions/249344b7740f4bc59aee1c352ed685a2

…ndpoint

The /suggest endpoint had a chaos-injected ranking-score enrichment path
that was unconditionally triggered by the Redis flag
chaos:search-service:suggest_500. This path calls service.suggest() which
returns list[str], then tries to sort by s['_rankingScore'] — causing
TypeError/KeyError and returning 500s.

Guard the chaos path behind CHAOS_ENABLED=true so it cannot fire in
production. The normal suggest path (which works correctly) is now always
used unless chaos mode is explicitly enabled.
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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.

0 participants