Repository navigation
Description
Problem
The Braintrust sink gives each attachment a content-addressed key, so the same image bytes
get the same key in every session of an org. It skips keys it has already uploaded only
through an in-memory set. A new daemon process uploads the image again, and the API
answers 409 Conflict: Attachment key already exists.
The sink treats that as a delivery failure, so that session's delivery stops at the image.
Every later span operation stays undelivered, waiting for a configuration change. An
import exits 1 with "still has N undelivered span operations".
Impact
The whole rest of the session is lost, not just the image. Anyone whose session contains
image bytes that an earlier daemon process already uploaded to the same org hits it, for
example:
- the same screenshot or file read in two sessions;
- re-importing a session;
- re-running a repro.
The daemon exits after five idle minutes, so a later session usually runs in a new
process. We saw it on import and in live tracing (bt trace run), where the trace stopped
after the turn holding the image.
Steps to reproduce
In a directory holding any small PNG, red.png (Claude Code 2.1.325, bt 0.33.0):
# two separate sessions that read the same image
claude -p --model haiku --allowedTools Read --output-format json "Read red.png with the Read tool and reply with its main color in one word."
claude -p --model haiku --allowedTools Read --output-format json "Read red.png with the Read tool and reply with its main color in one word."
bt trace import claude <first-session-id> --destination project_logs:<project-id>
# after the daemon has exited, or with a separate one (we set BRAINTRUST_DAEMON_SOCKET
# and BRAINTRUST_DAEMON_DATA_DIR per import):
bt trace import claude <second-session-id> --destination project_logs:<project-id>-
First import: succeeds, with 7 spans.
-
Second import, today: it exits 1:
{"error":{"message":"imported session … still has 8 undelivered span operations; the daemon retains them and will retry delivery"}}The daemon's delivery head for that route is stuck at operation 1 of 8:
"reason": "API error (409): request failed (409 Conflict): {\"Code\":\"HTTPError\",\"Message\":\"Attachment key already exists …\"}", "condition": {"when": "configuration", …}Braintrust has nothing from the second session.
-
Expected: both sessions are delivered in full, and both reference the stored image.
Root cause
- The key is
uuid_v5(URL, "{api}/{org_id}/{digest}")
(sink/braintrust.rs:398-402),
so it's the same for the same bytes in every session of the org. - Uploads are skipped only when the key is in
completed, a bounded in-memory set
(:188-193,
:405-419).
Its comment says the set "may miss after eviction/restart; re-uploading remains safe".
But the API rejects a key that already exists. The409propagates out of the upload
and fails the span operation.
Possible fixes
- Treat
409 Attachment key already existsas success. The key is derived from the
content and the org, so an existing key holds the same bytes. That makes the comment's
assumption true. - Also keep
completedin the daemon's storage, so a restart doesn't re-upload. Limit:
other machines and users in the same org would still collide, so the first fix is
needed either way.
Related
- Add shared span attachment uploads and delivery-bound blob storage #293 added shared attachment uploads.
Activity