Skip to content

fix: flush tracer on WS responses final chunk#3017

Closed
thiscantbeserious wants to merge 1 commit intomaximhq:mainfrom
thiscantbeserious:fix/2999-ws-tracer-flush
Closed

fix: flush tracer on WS responses final chunk#3017
thiscantbeserious wants to merge 1 commit intomaximhq:mainfrom
thiscantbeserious:fix/2999-ws-tracer-flush

Conversation

@thiscantbeserious
Copy link
Copy Markdown

Summary

For native WebSocket streaming, the postHookRunner closure returned by RunStreamPreHooks called drainAndAttachPluginLogs on the final chunk but never called tracer.CompleteAndFlushTrace. The logging plugin accumulates completed entries in an in-memory pendingLogsToInject map keyed by trace ID. That map is only drained to the store when CompleteAndFlushTrace runs. Every native-WS response therefore left its log entry stuck in memory and no row was written to the logs table.

Root cause: a single missing CompleteAndFlushTrace call in the happy-path branch of RunStreamPreHooks. All early-exit paths in the same function and the sibling RunRealtimeTurnPreHooks already call it correctly. The HTTP streaming path also flushes correctly.

Changes

  • core/bifrost.go: add tracer.CompleteAndFlushTrace(traceID) inside the postHookRunner closure when IsFinalChunk(ctx) is true, after drainAndAttachPluginLogs. Mirrors the pattern used on every other exit path in the same function.
  • core/bifrost_test.go: add TestRunStreamPreHooks_PostHookRunner_FlushesTracerOnFinalChunk and TestRunStreamPreHooks_PostHookRunner_NoFlushOnNonFinalChunk using a recording tracer to assert the call happens exactly once on the final chunk and not on mid-stream chunks.

Type of change

  • Bug fix

Affected areas

  • Core (Go)

How to test

go build ./core/... ./transports/...
go test ./core/... -run TestRunStreamPreHooks
go vet ./core/...

Expected: both new tests pass, build and vet are clean.

End-to-end: start Bifrost, route a WebSocket Responses request through a mock upstream that sends a terminal response.completed frame, then check the logs table. Before this fix the row was never written. After this fix a row appears.

Screenshots/Recordings

N/A

Breaking changes

  • No

Related issues

Closes #2999

This bug was discovered while working on PR #2775 (OpenAI OAuth passthrough). The PR branch contains the fix that is being extracted here.

Security considerations

None. This change only adds a missing trace flush call.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

The postHookRunner closure built in RunStreamPreHooks called
drainAndAttachPluginLogs on the final chunk but never called
tracer.CompleteAndFlushTrace. The logging plugin accumulates completed
entries in pendingLogsToInject keyed by traceID; that map is only
drained to the store when CompleteAndFlushTrace runs. As a result every
native-WS response left its log entry stuck in memory and no row was
written to the logs table.

All early-exit paths in the same function and the sibling
RunRealtimeTurnPreHooks already call CompleteAndFlushTrace correctly.
This adds the missing call in the happy-path branch, mirroring the
existing pattern, and adds two regression tests.

Closes maximhq#2999
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 24, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ace8ec19-7301-4f54-be50-a2476c29008b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@thiscantbeserious
Copy link
Copy Markdown
Author

Superseded by #3018 (merged 2026-04-24), which bundles the fix for this issue and several other native WS reliability bugs. Closing this draft as redundant.

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.

[Bug]: postHookRunner on WS streams never calls CompleteAndFlushTrace, log rows never reach DB

1 participant