Repository navigation
fix(openai): align Decisions spans with Python SDK - #2723
Conversation
Log OpenAI Decisions calls the way the Python SDK and the Braintrust
gateway do, so the same call produces the same decision span:
- use the decision span type instead of the legacy question type
- give unnamed or repeated questions question_{index} IDs, and pair
answers with questions by name before position
- prefix boolean choice keys with boolean: only when they collide with
a string choice, instead of quoting every key
- log score criteria as {label, description} objects
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ca9dafb786
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
| const answers = value.answers.map((answer, index) => { | ||
| const { name, ...rest } = answer; | ||
| const id = name ?? args[0].questions[index]?.name ?? String(index); | ||
| const pairs = decisionAnswers(value.answers, args[0].questions); |
There was a problem hiding this comment.
Snapshot questions before awaiting the decision
If a caller reuses or clears params.questions after decisions.create() returns but before the response resolves, this rereads the live request and can drop or misassociate every output answer, even though the input IDs were already captured from the original questions. Previously, named answers did not depend on the later request state; retain the computed IDs and corresponding question data at span creation and use that snapshot during result extraction.
Useful? React with 👍 / 👎.
Summary
The JS and Python SDKs log OpenAI Decisions calls differently. We agreed to standardize on Python's behavior, which the Braintrust gateway also follows (braintrustdata/braintrust#24288). This PR switches JS to it.
questiondecisionString(index)question_{index}, with_appended until it's uniqueboolean:prefix; string keys stay as they are"label: description"strings{label, description}objectsThis brings JS in line with the decision span spec (braintrustdata/braintrust-spec#82), which says new instrumentation must emit the
decisionspan type.Testing
pnpm exec vitest run src/instrumentation/plugins/openai-decisions.test.tspasses (21 tests). One test is new: repeated and unnamed questions, with answers in a different order. Against the old instrumentation, 5 of the tests fail.openai-instrumentatione2e assertions and regenerated its snapshots withtest:e2e:update; no new recordings were needed. The only snapshot changes are the span type and the score-criteria shape. I then ran the normal e2e tests twice; both passed (729 tests).pnpm run check:typingsandeslintpass on the changed files.🤖 Generated with Claude Code
Co-authored by StarfolkAI (@starfolkai)[bot]