Skip to content

feat(enrichment): log retry causes and the real end of slow deliveries - #24548

Merged
Git-on-my-level merged 2 commits into
mainfrom
lane/projlag
Nov 4, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
lane/projlag

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

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, receipt ready). 168 of them have an unclaimed enrichment obligation whose named task is sitting in the enrichment queue with dispatchCount=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:

Status Requests Slot time
200 66% 39%
409 retry 29% 17%
504, every one at 600.0 s (Cloud Tasks dispatch deadline) 3.3% 42%

Neither the 504s nor the 409s say what they were doing:

  • 504s: Cloud Tasks abandons the attempt at 600 s, but the handler thread keeps running. Nothing records whether it finished, how, or whether it first waited for an executor thread.
  • 409s: four different waits answer 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, logs event=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: each callback_pending return logs event=enrichment_consumer outcome=retry reason=callback_pending cause=<token>. The tokens are admitted_no_output, empty_output_unrecorded, redirect_*, or the fixed FirstSummaryCallbackPending literal.
  • No uid, key or token is logged. Responses, outcomes and the outbox contract are unchanged.

Verification

  • backend/test.sh with BACKEND_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.
  • Deploy: integration-only (backend-integration). Afterwards, a 30-minute log read splits the 504 and 409 slot time by class.

Evidence: projlag report (lane-local), queue and cohort probes are read-only on ro-prod.

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

Git-on-my-level and others added 2 commits November 4, 2026 07:03
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]>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Confidence score: 3/5

  • In backend/routers/enrichment.py, a delivery still queued in postprocess_executor can be abandoned before _timed_consume starts, leaving no enrichment_delivery record. 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

Comment thread backend/routers/enrichment.py Outdated
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())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

@Git-on-my-level
Git-on-my-level merged commit 3ecc84a into main Nov 4, 2026
66 of 68 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/projlag branch November 4, 2026 00:54
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.

1 participant