Skip to content

fix(api): drop request timeout from WebSocket upgrade routes - #1433

Open
wizzomafizzo wants to merge 1 commit into
mainfrom
fix/ws-upgrade-timeout
Open

fix(api): drop request timeout from WebSocket upgrade routes#1433
wizzomafizzo wants to merge 1 commit into
mainfrom
fix/ws-upgrade-timeout

Conversation

@wizzomafizzo

@wizzomafizzo wizzomafizzo commented Sep 5, 2026

Copy link
Copy Markdown
Member
  • The WebSocket route group wrapped the upgrade handler in chi's Timeout middleware. The handler returns only when the connection closes, so every session older than 30s ended with a 504 header written to the hijacked connection and a http: response.WriteHeader on hijacked connection warning on stderr. Since fix(readers): recover reader auto-detect and make its failures diagnosable #1424 that stderr is captured into core.stderr.log and shipped with every log bundle.
  • Nothing on the WebSocket path reads the upgrade request's context: melody ignores it and per-message deadlines come from the dispatcher's own context. The group now matches the SSE group, which already carries no request timeout. The pairing and REST-run groups keep theirs.
  • The group moves into mountWebSocketRoutes so the real wiring can be tested, and a regression test asserts the upgrade request context carries no deadline on /api, /api/v0 and /api/v0.1. It fails with the middleware in place.

Closes #1430

Summary by CodeRabbit

  • Bug Fixes

    • Improved WebSocket connection handling by preventing request timeouts from interrupting active connections.
    • Applied consistent rate limiting and cache-control behavior to WebSocket endpoints.
  • Tests

    • Added coverage verifying WebSocket routes remain available without request deadlines.

- The WebSocket route group wrapped the upgrade handler in chi's Timeout
  middleware. The handler returns only when the connection closes, so every
  session older than 30s ended with a 504 header written to the hijacked
  connection and a net/http warning on stderr, which is now captured into
  core.stderr.log and shipped with every log bundle.
- Nothing on the WebSocket path reads the upgrade request's context; melody
  ignores it and per-message deadlines come from the dispatcher. The group
  now matches the SSE group, which already carries no request timeout.
- Move the group into mountWebSocketRoutes and add a regression test that
  asserts the upgrade request context carries no deadline on /api, /api/v0
  and /api/v0.1.
@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 5dd46faf-ca48-4d1f-9408-994a27a8a702

📥 Commits

Reviewing files that changed from the base of the PR and between 5aefeb6 and d86eb77.

📒 Files selected for processing (2)
  • pkg/api/server.go
  • pkg/api/server_ws_routes_test.go

Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

WebSocket route registration now uses a dedicated helper for /api, /api/v0, and /api/v0.1. The routes retain rate limiting and no-cache middleware but no longer apply request timeouts. Tests verify route versions and absent request deadlines.

Changes

WebSocket route handling

Layer / File(s) Summary
Route mounting and timeout validation
pkg/api/server.go, pkg/api/server_ws_routes_test.go
The WebSocket routes use a shared mounting helper with rate limiting and no-cache middleware, without request timeout middleware. Tests verify all supported versions and confirm that the request context has no deadline.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to d86eb

WebSocket upgrade routes no longer inherit the request timeout that caused long-lived sessions to emit errors on hijacked connections. Existing route protections and version behavior remain in place, with coverage for all supported upgrade paths.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: removing the request timeout from WebSocket upgrade routes.
Linked Issues check ✅ Passed The changes satisfy issue #1430 by removing the request timeout from all three WebSocket upgrade routes and adding regression coverage that verifies no request deadline is present.
Out of Scope Changes check ✅ Passed The route helper and regression test directly support issue #1430. No unrelated code changes are identified.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

fix(api): WebSocket route group's Timeout middleware writes a 504 header

1 participant