Skip to content

fix(bidi): emit OpenAI usage before response stop [replica of harness-sdk#4889] - #30

Open
poshinchen wants to merge 1 commit into
base-pr-4889from
strandly-v3-pr-4889
Open

poshinchen wants to merge 1 commit into
base-pr-4889from
strandly-v3-pr-4889

Conversation

@poshinchen

@poshinchen poshinchen commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Replica of https://github.com/strands-agents/harness-sdk/pull/4889 (URL in backticks to avoid a cross-reference on the original PR) for reviewer evaluation. Branches mirror the original PR's base and head commits.

The review below was produced by the optimized Strandly reviewer (variant v3-reason, optimization run aeb3ee, agent model Opus 4.8) during validation on PRs it never saw in training. Compare with the human and Strandly reviews on the original PR.

@poshinchen poshinchen left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strandly v3-reason (optimized) review

Assessment: approve

Assessment: Approve

A focused, well-scoped bug fix that correctly reorders usage emission to precede BidiResponseStopEvent in the OpenAI bidi adapter, matching OpenAI's response.done payload semantics. Tests assert on full event-list equality (not per-field), which guards against regressions, and docs/diagram are updated consistently.

Review Categories
  • Correctness: Core reordering in _complete_response is sound; the if usage := guard correctly skips emission when no usage is present.
  • Testing: Good use of whole-object list equality; one suggested gap is a cancelled response with no usage key.
  • Behavior change: Ordering shift is observable to consumers — worth verifying downstream aggregators and noting the change for integrators.
  • Docs: Event timeline, ordering steps, and the Nova Sonic timing note are clear and accurate to the diff.

Nicely contained fix with matching tests and documentation.


if usage := response.get("usage"):
events.append(self._convert_usage_metadata(usage))
events.append(BidiResponseStopEvent(response_id=response_id))

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion

Issue: When response.get("usage") is absent (e.g., some cancelled responses), no BidiUsageEvent is emitted and only BidiResponseStopEvent follows, which is correct — but the new ordering means consumers that previously relied on usage arriving after stop will now receive it before.
Suggestion: Please verify this ordering change is reflected wherever downstream consumers aggregate usage (and consider noting the behavior change in a changelog entry if the project maintains one), so the fix doesn't surprise existing integrations.

@@ -171,9 +188,11 @@ async def test_receive_preserves_native_order_with_late_transcription(model, moc
BidiTranscriptStartEvent("user", content_id="user-1"),

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion

Issue: test_receive_preserves_native_order_with_late_transcription now emits BidiUsageEvent(0, 0, 0) for cancelled responses, which exercises the zero-token path but doesn't cover a cancelled response that carries no usage key.
Suggestion: Consider adding a case where a cancelled response.done omits usage to confirm only BidiResponseStopEvent is emitted (no usage event), locking in the if usage := guard behavior.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

Documentation Preview Failed

The documentation deployment encountered an error. Please check the deployment logs for more details.

This branch had an error being deployed

1 failed deployment
auto-approve — 0d5aa3db Deployed Oct 9, 2026 by poshinchen via Build and Deploy Preview #9
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.

2 participants