Skip to content

fix(api-server): keep chat-completions SSE alive during long tool runs - #7901

Closed
helix4u wants to merge 1 commit into
NousResearch:mainfrom
helix4u:fix/api-server-chat-sse-keepalive
Closed

fix(api-server): keep chat-completions SSE alive during long tool runs#7901
helix4u wants to merge 1 commit into
NousResearch:mainfrom
helix4u:fix/api-server-chat-sse-keepalive

Conversation

@helix4u

@helix4u helix4u commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

This keeps the OpenAI-compatible chat completions SSE stream alive during long quiet stretches of tool work.

Right now that stream can go completely silent while Hermes is still busy in the background. Some OpenAI-compatible frontends treat that idle connection like the run stalled or died, even though the agent is still working. This change brings the chat completions SSE path closer to the existing runs events behavior by sending periodic SSE keepalive comments and disabling proxy buffering on the stream.

Related Issue

No issue linked for this one yet.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Security fix
  • Documentation update
  • Tests (adding or improving test coverage)
  • Refactor (no behavior change)
  • New skill (bundled or hub)

Changes Made

  • add periodic keepalive SSE comments to the chat completions streaming path in gateway/platforms/api_server.py
  • add X-Accel-Buffering: no on that SSE response so buffering behavior matches the stronger runs events stream path
  • add regression coverage in tests/gateway/test_api_server.py for a long quiet tool gap and assert the buffering header on the stream response

How to Test

  1. source venv/bin/activate
  2. python -m pytest tests/gateway/test_api_server.py -q
  3. python -m pytest tests/gateway/test_sse_agent_cancel.py -q
  4. python -m pytest tests/ -q
  5. Start the API server and make a streaming chat completions request that triggers a long tool run with little or no text output; the stream should now emit periodic keepalive lines instead of going fully silent

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits
  • I searched for existing PRs to make sure this is not a duplicate
  • My PR contains only changes related to this fix
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes
  • I've tested on my platform: Ubuntu 24.04.4 LTS

Full suite result on current main: 45 failed, 10471 passed, 33 skipped.

Focused results for this change:

  • python -m pytest tests/gateway/test_api_server.py -q -> 107 passed, 67 warnings
  • python -m pytest tests/gateway/test_sse_agent_cancel.py -q -> 6 passed

Documentation & Housekeeping

  • N/A for README, docs, and docstring updates
  • N/A for cli-config.yaml.example changes
  • N/A for CONTRIBUTING.md or AGENTS.md changes
  • I've considered cross-platform impact
  • N/A for tool descriptions and schemas

Screenshots / Logs

python -m pytest tests/gateway/test_api_server.py -q
107 passed, 67 warnings in 4.24s

python -m pytest tests/gateway/test_sse_agent_cancel.py -q
6 passed in 1.21s

@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #7910. Your commit was cherry-picked onto current main with your authorship preserved in git log. Thanks for the SSE keepalive fix!

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.

2 participants