Repository navigation
feat(enrichment): log retry causes and the real end of slow deliveries - #24548
Merged
Merged
Conversation
The enrichment queue (50 dispatch slots) holds a 2.7h FIFO backlog. Prod request logs for /v2/enrichment/run over 2h (23:50Z 11-03, sampled) show where the slot time goes: 600s 504s are 3% of requests but 42% of slot time, 409 retries 17%, and successful deliveries only 39%. Neither class names itself: - A 504 is Cloud Tasks abandoning the attempt at its 600s dispatch deadline. The handler thread keeps running, and nothing records whether it finished, how, or whether it waited for an executor thread first. - Four different waits return the same callback_pending 409, and none of them logs. (The dependency-warming 409 already logs: zero events in 20 min.) Now every retry, and every delivery that runs 120s or longer, logs event=enrichment_delivery with its outcome, reason, executor wait and run time. Each callback_pending site logs a fixed cause token. Neither line includes a uid, key or token. Behaviour, responses and the outbox contract are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Luna round 1 (P2): rows still bound to /v2/sync-jobs/run call consume() directly from enrichment_response, so a slow delivery there would end without an event=enrichment_delivery line. The timing now lives in consume() itself, with an optional accepted timestamp, and both handlers pass one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
1 issue found across 3 files
Confidence score: 3/5
- In
backend/routers/enrichment.py, a delivery still queued inpostprocess_executorcan be abandoned before_timed_consumestarts, leaving noenrichment_deliveryrecord. Ensure the delivery is recorded before the request can be cancelled.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/routers/enrichment.py">
<violation number="1" location="backend/routers/enrichment.py:97">
P2: A delivery still waiting in `postprocess_executor` when Cloud Tasks abandons the request can produce no `enrichment_delivery` record at all. Cancelling the awaited queued future prevents `_timed_consume` from starting, so the new `wait_s` diagnostic is lost for exactly the long queue waits this change is intended to measure; record queue-wait completion outside the cancellable worker future or otherwise preserve the future until it starts/finishes.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| if not outbox.owns_runtime(): | ||
| return JSONResponse(status_code=200, content={'status': 'foreign_runtime'}) | ||
| result = await run_blocking(postprocess_executor, consume, *task) | ||
| result = await run_blocking(postprocess_executor, _timed_consume, *task, time.monotonic()) |
There was a problem hiding this comment.
P2: A delivery still waiting in postprocess_executor when Cloud Tasks abandons the request can produce no enrichment_delivery record at all. Cancelling the awaited queued future prevents _timed_consume from starting, so the new wait_s diagnostic is lost for exactly the long queue waits this change is intended to measure; record queue-wait completion outside the cancellable worker future or otherwise preserve the future until it starts/finishes.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/routers/enrichment.py, line 97:
<comment>A delivery still waiting in `postprocess_executor` when Cloud Tasks abandons the request can produce no `enrichment_delivery` record at all. Cancelling the awaited queued future prevents `_timed_consume` from starting, so the new `wait_s` diagnostic is lost for exactly the long queue waits this change is intended to measure; record queue-wait completion outside the cancellable worker future or otherwise preserve the future until it starts/finishes.</comment>
<file context>
@@ -69,7 +94,7 @@ async def run_enrichment_task(request: Request, _retry_count: int = Depends(veri
if not outbox.owns_runtime():
return JSONResponse(status_code=200, content={'status': 'foreign_runtime'})
- result = await run_blocking(postprocess_executor, consume, *task)
+ result = await run_blocking(postprocess_executor, _timed_consume, *task, time.monotonic())
return http_response(result)
</file context>
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.
Why
Held, untitled batch conversations (169 at 23:33Z, up from 125 at 21:56Z) are not stuck in projection. All 172 that had every linked unit committed were fully projected (
projection_state=completed, receiptready). 168 of them have an unclaimed enrichment obligation whose named task is sitting in theenrichmentqueue withdispatchCount=0, scheduled 10–180 minutes ago. The queue holds 15.7k due tasks, its oldest is 164 minutes old, and it runs at its 50-dispatch cap.Request logs for
/v2/enrichment/run(prod, backend-integration, 2h sampled to 23:50Z) show where the 50 slots go:Neither the 504s nor the 409s say what they were doing:
callback_pending, and none of them logs. The dependency-warming 409 already logs, and it had zero events in 20 minutes.The queue raise (50→100) is on hold pending David. Before anyone adds slots, the lead needs to know what the 42% and the 17% are.
What
routers/enrichment.py: every 409 retry, and every delivery that runs 120 s or longer, logsevent=enrichment_delivery outcome=… reason=… wait_s=… run_s=…. That covers executor queue wait and processing time, including the real end of a delivery Cloud Tasks already timed out.utils/enrichment/consumer.py: eachcallback_pendingreturn logsevent=enrichment_consumer outcome=retry reason=callback_pending cause=<token>. The tokens areadmitted_no_output,empty_output_unrecorded,redirect_*, or the fixed FirstSummaryCallbackPending literal.Verification
backend/test.shwithBACKEND_UNIT_TEST_FILE_LIST:tests/unit/test_enrichment_route.py: 35 passed, 3 of them new (retry cause and timing, slow-only logging, and the error path still logs its end).tests/unit/test_sync_processing_hold.py: 49 passed.Evidence: projlag report (lane-local), queue and cohort probes are read-only on ro-prod.
🤖 Generated with Claude Code