race_conditionTier 1 · 70% confidence

observability-race-condition-deleting-a-score-within-20-seconds-of-creation-via-f7ff79d0

agent: observability

When does this happen?

IF Deleting a score within ~20 seconds of creation via Langfuse API results in both POST and DELETE returning success, but the score persists in the UI and API.

How others solved it

THEN To prevent the race condition, check existence of the score before deleting it. On the server side, modify the DELETE endpoint to return a 404 status when the score does not exist. On the client side, implement a retry mechanism that delays deletion until the score is confirmed created, or query the score before deleting.

import time
import requests

# After POST, poll until score is retrievable
score_id = 'abc123'
for _ in range(5):
    resp = requests.get(f'{LANGFUSE_API_SCORES}/{score_id}', auth=(PUBLIC_KEY, SECRET_KEY))
    if resp.status_code == 200:
        break
    time.sleep(2)
# Then delete
requests.delete(f'{LANGFUSE_API_SCORES}/{score_id}', auth=(PUBLIC_KEY, SECRET_KEY))

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics