Skip to content

feat(streaming): propagate provider lifecycle events through agent and SSE#54

Draft
vadimcomanescu wants to merge 9 commits intodanshapiro:mainfrom
vadimcomanescu:upstream/feature/streaming-provider-lifecycle-events
Draft

feat(streaming): propagate provider lifecycle events through agent and SSE#54
vadimcomanescu wants to merge 9 commits intodanshapiro:mainfrom
vadimcomanescu:upstream/feature/streaming-provider-lifecycle-events

Conversation

@vadimcomanescu
Copy link

@vadimcomanescu vadimcomanescu commented Mar 4, 2026

Summary

This PR standardizes streaming lifecycle handling across provider events, agent session state, and SSE progress output.

Depends On

Problem

  • Streaming tool lifecycle events from providers were not fully normalized end-to-end.
  • One-shot stream error/finish behavior had edge cases that could hide precedence issues.
  • SSE progress output did not consistently reflect provider lifecycle semantics.

Why This Change

Streaming is part of the runtime contract. Event semantics must be consistent from provider adapters to agent session state and outward-facing SSE streams.

What Changed

  • Added provider event parsing and normalization for codex app-server tool lifecycle events.
  • Hardened one-shot stream handling and stream accumulator behavior for finish/response/tool-call edge cases.
  • Added API stream progress forwarding for agent session events to SSE clients.
  • Updated tests around heartbeat/failover and lifecycle event propagation.
  • Included a small test cleanup commit to keep vet/build strictness intact.

User-Visible Behavior

  • More reliable and semantically consistent stream progress events.
  • Better preservation of tool call and output lifecycle details in agent and SSE views.
  • Improved correctness for stream finish/error precedence in one-shot paths.

Risk

  • Broad touch surface in streaming code paths.
  • Mitigation: focused test coverage in agent, llm, provider translator, and engine progress/event paths.

Validation

  • gofmt and go vet ./...
  • go test ./internal/agent -run 'TestSession_ProviderToolLifecycleEvents_DoesNotDuplicateOutputDeltaWhenProviderStreamsAndAggregates|TestSession_StreamFinishWithoutResponse_PreservesToolCalls' -count=1
  • go test ./internal/llm -run 'TestParseCodexAppServerToolLifecycle|TestParseCodexAppServerToolOutputDelta|TestStreamAccumulator_' -count=1
  • go test ./internal/attractor/engine -run 'TestEmitStreamProgress_|TestCodergenRouter_RunAPI_OneShot_' -count=1

Out of Scope

(cherry picked from commit c0110c630859508ce3390cf976cd11e8a06fbb6b)
(cherry picked from commit 1a57a2ca640d65457fa663e9548d41c9be22ab53)
(cherry picked from commit 23f3ce1e2329597b204b530bc23b1f817b5266c2)
(cherry picked from commit a878921adc2555db9062b721489e2ba79df618c6)
Switch one_shot mode from Complete() to Stream() with StreamAccumulator,
add throttled progress emitter (100ms batched text deltas, immediate tool
call events), emit AssistantMessage CXDB turns from both agent_loop and
one_shot paths, and tag all progress events with backend:"api" for
CLI/API parity.

(cherry picked from commit 9cb2b2014b37e7d3d6c3c96ae09c29671c959e40)
(cherry picked from commit 2670b7d7933d2b238cdc884d8490bf2a221682ba)
(cherry picked from commit 72bafbf015fd60441787e9493dfbc149c03a3396)
(cherry picked from commit 200fd7afb75b7576e7c3df9d80ff1dcdd253f61f)
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