Skip to content

fix: cancel agent runs when the HTTP client disconnects - #12

Merged
autoantohaki merged 1 commit into
mainfrom
fix/cancel-on-client-disconnect
Oct 21, 2026
Merged

autoantohaki merged 1 commit into
mainfrom
fix/cancel-on-client-disconnect

Conversation

@autoantohaki

Copy link
Copy Markdown
Member

Requested by mau

Summary

Before: when a client hung up on POST /v1/chat or POST /v1/chat/stream, the agent kept running until it finished or hit AGENT_TIMEOUT_MS, still calling the model and tools for nobody. The handlers listened for the request's aborted event, but Node doesn't emit it once the request body has been fully read, so the abort signal never fired.

After: both endpoints watch the response's close event, and the run is cancelled when the response closes before it finished.

How: a small abortOnDisconnect(response) helper in src/http.ts replaces the two request.once("aborted") listeners. A new test in tests/http.test.ts opens a chat request, destroys the socket while the agent is still running, and checks that the agent's signal is aborted. That test fails on main and passes with this change.

Verification

  • npm run verify (format, lint, types, tests with coverage, and build all pass locally)
  • Tests do not require live credentials
  • Documentation updated (not needed, since the docs already describe cancellation)
  • No secrets or machine-specific paths added

@autoantohaki
autoantohaki merged commit e914507 into main Oct 21, 2026
3 checks 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