Stop retrying rejected callbacks, and cut the retry budget to one - #148
Merged
Conversation
The finish_query worker holds the whole decompressed TRAPI response in memory for every second a callback POST is in flight. With a 120s httpx timeout, a 3-attempt budget and TASK_LIMIT=10, that is up to ten full payloads resident for ~6 minutes each -- the peak that gets the pod OOM-killed (an uncatchable SIGKILL, which is why the crash leaves no traceback and no drain log behind). Two changes to the retry loop, both aimed at that residency: - Don't retry a 4xx. The receiver understood the request and rejected it, so an identical retry gets an identical answer; we were spending a full extra round trip, plus backoff, holding the payload, for a response that could not change. Observed in production as the same 400 logged three times for one message. 408 and 429 are kept retryable -- they describe a transient condition rather than a bad request. Everything else (5xx, timeouts, connect/protocol failures, and any exception we don't recognize) is retried exactly as before, so the loop is narrowed only where a retry is known to be pointless. - CALLBACK_RETRIES 3 -> 1. It now means retries *after* the first attempt, with the loop bounded by the derived CALLBACK_ATTEMPTS, so the name matches what it counts and the budget is two POSTs rather than three. The give-up log line now reports the attempts actually spent instead of the configured budget, which would misreport an early bail-out, and the span carries callback.retryable to separate "gave up" from "ran out". Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011RUcnjJx7gebTdjzG1MWFp
Codecov Report✅ All modified and coverable lines are covered by tests.
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
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.
The finish_query worker holds the whole decompressed TRAPI response in memory for every second a callback POST is in flight. With a 120s httpx timeout, a 3-attempt budget and TASK_LIMIT=10, that is up to ten full payloads resident for ~6 minutes each -- the peak that gets the pod OOM-killed (an uncatchable SIGKILL, which is why the crash leaves no traceback and no drain log behind).
Two changes to the retry loop, both aimed at that residency:
Don't retry a 4xx. The receiver understood the request and rejected it, so an identical retry gets an identical answer; we were spending a full extra round trip, plus backoff, holding the payload, for a response that could not change. Observed in production as the same 400 logged three times for one message. 408 and 429 are kept retryable -- they describe a transient condition rather than a bad request. Everything else (5xx, timeouts, connect/protocol failures, and any exception we don't recognize) is retried exactly as before, so the loop is narrowed only where a retry is known to be pointless.
CALLBACK_RETRIES 3 -> 1. It now means retries after the first attempt, with the loop bounded by the derived CALLBACK_ATTEMPTS, so the name matches what it counts and the budget is two POSTs rather than three.
The give-up log line now reports the attempts actually spent instead of the configured budget, which would misreport an early bail-out, and the span carries callback.retryable to separate "gave up" from "ran out".
Claude-Session: https://claude.ai/code/session_011RUcnjJx7gebTdjzG1MWFp