Skip to content

fix: resolve connection leaks, pending request tracking, and infinite combo loops#2676

Open
pandamoon21 wants to merge 2 commits into
decolua:masterfrom
pandamoon21:master
Open

fix: resolve connection leaks, pending request tracking, and infinite combo loops#2676
pandamoon21 wants to merge 2 commits into
decolua:masterfrom
pandamoon21:master

Conversation

@pandamoon21

@pandamoon21 pandamoon21 commented Jul 17, 2026

Copy link
Copy Markdown

Problem

This PR fixes three request-handling stability issues:

  • Client disconnects were not propagated to upstream fetch execution, which could leave sockets open and eventually make the HTTP port unresponsive.
  • Successful streaming responses did not immediately decrement the pending request counter, so completed requests could stay counted as pending until the fallback timeout.
  • Combo models could reference themselves directly or indirectly, causing infinite recursion, 100% CPU usage, and a hung server.

Fix

  • Pass the incoming request's AbortSignal through the chat handling flow and wire it into the stream controller disconnect/abort path.
  • Return client-aborted 499 responses immediately so they do not mark healthy accounts unavailable or trigger account fallback.
  • Add an onComplete callback so successful streams decrement the pending request counter immediately.
  • Track visited combo models during expansion and return 400 Bad Request when a circular combo reference is detected.

Regression coverage

  • Client disconnect propagation and abort listener cleanup
  • Client aborts do not mark accounts unavailable or trigger fallback
  • Pending request decrement on successful stream completion
  • Direct and indirect circular combo detection
  • Safe 400 Bad Request response for circular combo references

Verification

  • npx eslint "src/sse/handlers/chat.js" "tests/unit/chat-client-abort-fallback.test.js" — passed
  • cd tests && npx vitest run unit/chat-client-abort-fallback.test.js unit/combo-routing.test.js unit/combo-fusion.test.js unit/gemini-native-endpoint.test.js unit/headroom-chat-core.test.js — 28/28 passed
  • git diff --check — passed

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