Skip to content

Track streaming lifecycle outcomes exactly once - #82

Merged
piotrekno1 merged 3 commits into
develfrom
fix/streaming-lifecycle
Oct 20, 2026
Merged

piotrekno1 merged 3 commits into
develfrom
fix/streaming-lifecycle

Conversation

@piotrekno1

@piotrekno1 piotrekno1 commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Streaming telemetry previously disappeared on early closure or task cancellation, and repeated iteration could emit completion more than once. The shared OpenAI, Anthropic and GGUF stream wrappers now keep one lifecycle state across direct iteration, exhaustion, explicit closure, context exits, cancellation and provider errors.

  • Explicit early closure emits an unsuccessful inference with STREAM_CLOSED; async cancellation emits STREAM_CANCELLED and is re-raised. Partial metadata is retained when supplied, without estimating missing token totals.
  • Provider iteration errors retain existing error classification and propagate unchanged. Repeated exhaustion/closure cannot emit another outcome.
  • TTFT ignores role-only, usage and lifecycle events and waits for a nonempty output delta.
  • Telemetry callback exceptions do not break application iteration. Callbacks retain the trace context captured when the wrapper was created.
  • Remote API EOF without its completion marker emits STREAM_INCOMPLETE instead of silently losing the operation.

Adds a streaming coverage/audit guide. This deliberately describes the existing instrumented iterator paths: OpenAI Chat Completions/Responses create(stream=True), Anthropic messages.create(stream=True), and GGUF completion streams. Anthropic messages.stream() bypasses its patched create method; MLX stream_generate() and Transformers user streamers/background threads also need dedicated adapters. Forwarded provider helpers that consume the underlying stream directly remain outside this iterator contract. Abandoned streams need explicit closure; there is no garbage-collection finalizer.

Validation

  • Full suite: 768 passed, 28 skipped.
  • Real OpenAI 3.35.1 and Anthropic 1.15.0 SDK compatibility tests with mocked HTTP: 24 passed, including sync/async early closure and Anthropic exhaustion.
  • Regression coverage includes repeated finalization, mid-stream failure, real asyncio task cancellation, callback failures, creation-context correlation, first-output timing and all four integration callbacks on interruption. GGUF is covered by unit tests, not a live model run.
  • Local process-compose pipeline: sent four closure cases and one cancellation via the shared wrappers and real SDK client; ingest accepted all 10 events. Queried Iceberg to confirm exactly five unsuccessful inference events and five linked spans, with four STREAM_CLOSED and one STREAM_CANCELLED preserved in both event data and analytics fields. Run ID: stream-lifecycle-local-6f01b5b57c6f. These were synthetic stream cases, not live provider/model calls.
  • Ruff lint, formatting and diff whitespace checks pass.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Coverage report

  • Total: 88% (10581/12009 lines)

Top uncovered files

  • wildedge/integrations/mlx.py: 28.7% (122 lines missed)
  • wildedge/integrations/transformers.py: 62.9% (112 lines missed)
  • wildedge/integrations/ultralytics.py: 67.7% (86 lines missed)
  • wildedge/integrations/pytorch.py: 57.5% (79 lines missed)
  • wildedge/platforms/macos.py: 56.8% (67 lines missed)

@piotrekno1
piotrekno1 force-pushed the fix/streaming-lifecycle branch from eb8e066 to 1b0192f Compare October 20, 2026 16:14
@piotrekno1
piotrekno1 merged commit 672502b into devel Oct 20, 2026
14 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 21, 2026
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