fix: handle FK violation in observation_history during parallel consolidation - #2620
Conversation
…lidation Wrap the INSERT into observation_history with a try/except for ForeignKeyViolationError. Under parallel/batched consolidation, one batch may delete an observation while another writes its history, causing a race condition. Instead of failing the entire consolidation task, log a warning and skip the history entry. Also adds the missing needed to catch the specific exception type. Closes vectorize-io#2597 Closes vectorize-io#2506
|
Thanks for this fix — it matches exactly what I was about to PR myself. I hit the same This race is not limited to parallel consolidation ( Looking at
The security check at L1592 ( So the Reproduced on v0.8.4 with sequential consolidation ( |
Summary
Under parallel/batched consolidation,
_append_observation_historycan fail with:One batch deletes/replaces an observation row while another writes its history — a race condition. Instead of failing the entire consolidation task, catch the
ForeignKeyViolationErrorand skip the history entry.Change
import asyncpgto consolidation moduleINSERTin_append_observation_historywithtry/except asyncpg.exceptions.ForeignKeyViolationErrorImpact
Reproduction
Triggered by parallel consolidation (
consolidation_llm_parallelism > 1). Sequential consolidation (consolidation_llm_parallelism = 1) never hits this, confirming the race condition.Closes #2597
Closes #2506