Skip to content

Fix get_org_id on SaaS + release 0.4.1 - #21

Merged
Doug Guthrie (dpguthrie) merged 2 commits into
mainfrom
fix/org-id-via-project
Jun 8, 2026
Merged

Fix get_org_id on SaaS + release 0.4.1#21
Doug Guthrie (dpguthrie) merged 2 commits into
mainfrom
fix/org-id-via-project

Conversation

@dpguthrie

@dpguthrie Doug Guthrie (dpguthrie) commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Problem

A user on 0.4.0 hit this migrating logs into SaaS:

Failed to migrate logs: BraintrustAPIError: Unable to determine org_id for
attachment operations. Tried /ping and /v1/ping; last error: 404 Not Found
for url 'https://api.braintrust.dev/v1/ping'

get_org_id() only tried GET /ping and /v1/ping, which 404 on the SaaS REST API (api.braintrust.dev). The 0.4.0 oversize-field attachment spilling calls get_org_id() for every row over the ~20 MB per-span limit, so any real migration with a large span fails. (The SDK resolves org_id via POST {app_url}/api/apikey/login on the app URL, which this tool doesn't use — it only has the API URL.)

Fix

Resolve org_id from a project instead. org_id is a documented top-level field on every Project object (confirmed on both the list and get-by-id responses), and every project visible to an org-scoped API key is in that org:

  • Capture opportunistically whenever the client lists or creates a project (_maybe_capture_org_id). The orchestrator discovers/creates the destination project before streaming logs, so in the normal flow org_id is already known by the time spilling happens — no extra request.
  • Fallback: get_org_id queries GET /v1/project?limit=1 when nothing has been captured yet.
  • Dropped the /ping probes entirely — they only 404 on SaaS and add nothing now.

Also repairs the latent copy_attachments path, which had the same get_org_id dependency.

Why it holds for the live case: by the time logs are migrated (and spilling), the destination project already exists (created earlier in the run), so its org_id has already been captured.

Tests

  • test_get_org_id_captured_from_list_projects / _from_create_project — captured with zero extra requests.
  • test_get_org_id_queries_project_when_not_cached — fallback query.
  • test_get_org_id_raises_when_no_project — clear error.
  • Updated the attachment-copier and oversize-spill mocks to serve /v1/project.
  • Full unit suite: 292 passing.

Release

Targets a 0.4.1 patch — blocking a live migration. Self-contained off main (one commit, client.py + tests); independent of the refactor PR #20.

🤖 Generated with Claude Code

get_org_id only tried GET /ping and /v1/ping, which 404 on the SaaS REST API
(api.braintrust.dev). The 0.4.0 oversize-field attachment spilling calls
get_org_id() for every row over the per-span limit, so a real migration into
SaaS fails:

  BraintrustAPIError: Unable to determine org_id for attachment operations.
  Tried /ping and /v1/ping; last error: 404 Not Found for /v1/ping

Resolve org_id from a project instead — org_id is a documented top-level field
on every Project object (confirmed on both the list and get-by-id responses),
and every project visible to an org-scoped API key is in that org:

- Capture org_id opportunistically whenever the client lists or creates a
  project (_maybe_capture_org_id). The orchestrator discovers/creates the dest
  project before streaming logs, so in the normal flow org_id is already known
  by the time spilling happens -- no extra request.
- get_org_id falls back to GET /v1/project?limit=1 when nothing has been
  captured yet. Dropped the /ping probes entirely (they only 404 on SaaS).

This also fixes the latent copy_attachments path, which had the same
get_org_id dependency. Adds get_org_id tests (capture from list/create,
query fallback, no-project error) and updates the attachment/spill test mocks
to serve /v1/project. Suite: 292.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Bump version to 0.4.1 (pyproject, __version__, uv.lock), add the CHANGELOG
entry for the get_org_id SaaS fix, and update the pinned install command in
the README to v0.4.1.
@dpguthrie Doug Guthrie (dpguthrie) changed the title Fix get_org_id on SaaS (0.4.0 attachment regression) Fix get_org_id on SaaS + release 0.4.1 Jun 8, 2026
@dpguthrie

Copy link
Copy Markdown
Collaborator Author

Added the 0.4.1 release prep to this PR: CHANGELOG entry, version bump (pyproject.toml, __version__, uv.lock), and README pin → v0.4.1. Merging this leaves main immediately taggable as v0.4.1.

Verified the fix end-to-end against live SaaS (seeded a 1.5 MB span, lowered the spill threshold to 1 MB, migrated): the field spilled to a braintrust_attachment, the dest span carried the reference, and the downloaded attachment matched the original bytes (content_matches_original=True). The POST /attachment (attachment_metadata_dest) call that previously 404'd now succeeds.

@dpguthrie
Doug Guthrie (dpguthrie) merged commit f66ea3b into main Jun 8, 2026
1 check passed
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