镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

fix(logger): snapshot streams before deferred export - #919

Open
Gareth.Y (linjiaye929) wants to merge 1 commit into
braintrustdata:mainfrom
linjiaye929:codex/fix-stream-log-snapshot
Open

Gareth.Y (linjiaye929) wants to merge 1 commit into
braintrustdata:mainfrom
linjiaye929:codex/fix-stream-log-snapshot

Conversation

@linjiaye929

@linjiaye929 Gareth.Y (linjiaye929) commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Logging a BraintrustStream currently postpones copy() until background export. If the application consumes its stream first, the logged output can become None, lose a text prefix, or fail JSON assembly. This also affects a @traced function that returns a stream its caller consumes once.

Capture the logging branch at log time without reading chunks, then resolve it lazily. Keep a fresh per-attempt copy so yielded error chunks and final JSON-assembly errors remain errors on repeated resolution.

Validation

Python 3.12.14, actual SSEClient over in-memory SSE bytes, and the SDK's native memory logger:

  • Baseline regressions: 5 failed, 4 passed.
  • Fixed regressions: 9 passed.
  • Entire test_logger.py, functions/test_stream.py, and test_span_customizer.py: 248 passed, 4 skipped, 21 subtests passed. Skips require optional Pydantic or Python 3.14 t-strings.
  • Separate local validation repeated those results and passed 21 supplementary cases.
  • Ruff 0.15.21 check/format and git diff --check passed.

Tests run with cassette replay enabled, the Braintrust pytest plugin disabled, and a socket guard rejecting live connections. No live service or provider calls were used. Full nox/core/version-matrix, pylint/type-checker sessions, benchmarks, and make fixup were not run.

Compatibility and limits

  • Snapshotting buffers consumed chunks until lazy export can use them. The retry snapshot lasts until its lazy record is released; an unconsumed SSE parsing generator can retain the original stream wrapper until consumption finishes.
  • List-backed streams become one-shot at log time rather than first export. Repeating list iteration before export previously worked incidentally; the documented stream contract requires copying before repeated consumption.
  • Concurrent readers and synchronous iterators started before logging remain outside this fix. Nested streams in dictionaries retain their existing behavior.
  • Retry preservation covers yielded error chunks and final JSON assembly. Invalid JSON inside an SSE text_delta can still terminate the parser and produce None on a later retry, as before.

AI assistance

Prepared with AI assistance, including a separate local review of the reproduction, patch, tests, and compatibility boundaries.

CI status

As checked on 2026-10-13 at 11:03 UTC for head 9f6d44611c2ac07e127fda576f98f558b18c90d9, both upstream workflow runs report completed / action_required:

CI has not passed. The local validation above does not represent a successful upstream CI run.

Capture a stream branch when logging so caller consumption before export
cannot remove its output. Keep per-attempt copies for yielded error chunks
and final JSON-assembly failures.

Cover real SSE parsing with the memory logger, consumption order, traced
returns, and repeated resolution errors.
@linjiaye929
Gareth.Y (linjiaye929) marked this pull request as ready for review October 13, 2026 11:04
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T11:10:46.949927Z 9f6d446 Draft marked ready
ℹ️ About Codex in GitHub

Your 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.

This branch has not been deployed

No deployments
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