Repository navigation
Send a healthcheck a browser can read on the session events socket - #2811
Merged
Merged
Conversation
A browser answers the router's WebSocket pings without telling the page, so a page whose
network went away without a close cannot tell its socket is dead until TCP gives up.
- `heartbeat=true` on /v1/agents/sessions/{id}/events sends
{"type": "heartbeat", "interval_ms": 10000} every interval, written by the node holding the
socket. It carries no cursor and is never replayed on resume.
- A relayed socket now closes with 1011 when the node running its session has not answered a
refresh for 90 s (it crashed or lost Redis), instead of staying open and silent. The edge
asks for an answer (answer_refresh) and the holder says it gives one (answers_refresh), so
mixed-version nodes keep today's behavior during a rolling deploy.
- Spec and generated clients regenerated; SDK note in .claude/skills/sdk/notes/.
👋 Thanks, Oliver! I'm on it.How to work with me
CommandsComment any of these on the PR:
|
There was a problem hiding this comment.
Round 1 · 🆕 1 new · 1 should-fix to go
| Finding | Where | |
|---|---|---|
| 🟡 Should Fix | The note says Go has no resume path, but Go resumes text sessions on a 1011 close | 2026-11-30-session-heartbeat.md:17 |
➡️ Round 2 started on 3a09c52.
…Kotlin - The query parameter and frame are now `healthcheck`, as the rest of the product spells it. - Swift and Kotlin name the frame in AgentEvent.Kind: their wire tests read every frame type sessionws.go writes, and failed on the new one. - A client starts its timer only once the first healthcheck arrives. A router without this change ignores the parameter, and a timer started at the open would drop a healthy, quiet socket every 20-30 s. The spec and the SDK note say so.
Go dials text sessions with resumable=true and reconnects on any close but 1000, so it already treats the new 1011 as a drop. Its calls, and the JavaScript, Dart, Swift and Kotlin sessions, do not resume yet.
martinmitrevski
approved these changes
Dec 1, 2026
martinmitrevski
added a commit
that referenced
this pull request
Dec 1, 2026
URLSession never reads a connection that went away without a close as gone: receive() waits on, and the request timeout does not apply once the socket is open. A text session now: - asks for the router's heartbeats (#2811) and, once one has come, takes three intervals with nothing read as a lost connection. Nothing is timed before the first, so a router without heartbeats is not taken for dead; - lets its socket go when the network goes, and makes no attempt to reopen it until the network is back; - keeps its socket for one background task, then lets it go, and makes no attempt until the app is back. A session moved onto a call keeps it. The background task ends on every way out. A socket let go here ends its stream with socketClosed itself, for the opening it was decided for, so it reads as a drop and is resumed. AgentEvent.Kind names heartbeat, which WireTests needs once the router writes it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
martinmitrevski
added a commit
that referenced
this pull request
Dec 1, 2026
URLSession never reads a connection that went away without a close as gone: receive() waits on, and the request timeout does not apply once the socket is open. A text session now: - asks for the router's healthchecks (#2811) and, once one has come, takes three intervals with nothing read as a lost connection. Nothing is timed before a socket's first, so a router without them is not taken for dead; - lets its socket go when the network goes, and makes no attempt to reopen it until the network is back. Only a change counts: a first reading of no network is not believed; - keeps its socket for one background task, then lets it go, and makes no attempt until the app is back. A socket that opens in the background with no time left is let go at once, and a session moved onto a call keeps its socket. The background task ends on every way out. A socket let go here ends its stream with socketClosed itself, for the opening it was decided for, so it reads as a drop and is resumed. Reviewed by a fresh agent: a first reading of no network stopped every reconnect, the app going to the background while a socket opened was missed, and two test checks could not fail. All fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
martinmitrevski
added a commit
that referenced
this pull request
Dec 1, 2026
URLSession never reads a connection that went away without a close as gone: receive() waits on, and the request timeout does not apply once the socket is open. A text session now: - asks for the router's healthchecks (#2811) and, once one has come, takes three intervals with nothing read as a lost connection. Nothing is timed before a socket's first, so a router without them is not taken for dead; - lets its socket go when the network goes, and makes no attempt to reopen it until the network is back. Only a change counts: a first reading of no network is not believed; - keeps its socket for one background task, then lets it go, and makes no attempt until the app is back. A socket that opens in the background with no time left is let go at once, and a session moved onto a call keeps its socket. The background task ends on every way out. A socket let go here ends its stream with socketClosed itself, for the opening it was decided for, so it reads as a drop and is resumed. Reviewed by a fresh agent: a first reading of no network stopped every reconnect, the app going to the background while a socket opened was missed, and two test checks could not fail. All fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
martinmitrevski
added a commit
that referenced
this pull request
Dec 1, 2026
URLSession never reads a connection that went away without a close as gone: receive() waits on, and the request timeout does not apply once the socket is open. A text session now: - asks for the router's healthchecks (#2811) and, once one has come, takes three intervals with nothing read as a lost connection. Nothing is timed before a socket's first, so a router without them is not taken for dead; - lets its socket go when the network goes, and makes no attempt to reopen it until the network is back. Only a change counts: a first reading of no network is not believed; - keeps its socket for one background task, then lets it go, and makes no attempt until the app is back. A socket that opens in the background with no time left is let go at once, and a session moved onto a call keeps its socket. The background task ends on every way out. A socket let go here ends its stream with socketClosed itself, for the opening it was decided for, so it reads as a drop and is resumed. Reviewed by a fresh agent: a first reading of no network stopped every reconnect, the app going to the background while a socket opened was missed, and two test checks could not fail. All fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
martinmitrevski
added a commit
that referenced
this pull request
Dec 1, 2026
URLSession never reads a connection that went away without a close as gone: receive() waits on, and the request timeout does not apply once the socket is open. A text session now: - asks for the router's healthchecks (#2811) and, once one has come, takes three intervals with nothing read as a lost connection. Nothing is timed before a socket's first, so a router without them is not taken for dead; - lets its socket go when the network goes, and makes no attempt to reopen it until the network is back. Only a change counts: a first reading of no network is not believed; - keeps its socket for one background task, then lets it go, and makes no attempt until the app is back. A socket that opens in the background with no time left is let go at once, and a session moved onto a call keeps its socket. The background task ends on every way out. A socket let go here ends its stream with socketClosed itself, for the opening it was decided for, so it reads as a drop and is resumed. Reviewed by a fresh agent: a first reading of no network stopped every reconnect, the app going to the background while a socket opened was missed, and two test checks could not fail. All fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
martinmitrevski
added a commit
that referenced
this pull request
Dec 1, 2026
URLSession never reads a connection that went away without a close as gone: receive() waits on, and the request timeout does not apply once the socket is open. A text session now: - asks for the router's healthchecks (#2811) and, once one has come, takes three intervals with nothing read as a lost connection. Nothing is timed before a socket's first, so a router without them is not taken for dead; - lets its socket go when the network goes, and makes no attempt to reopen it until the network is back. Only a change counts: a first reading of no network is not believed; - keeps its socket for one background task, then lets it go, and makes no attempt until the app is back. A socket that opens in the background with no time left is let go at once, and a session moved onto a call keeps its socket. The background task ends on every way out. A socket let go here ends its stream with socketClosed itself, for the opening it was decided for, so it reads as a drop and is resumed. Reviewed by a fresh agent: a first reading of no network stopped every reconnect, the app going to the background while a socket opened was missed, and two test checks could not fail. All fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A browser answers the router's WebSocket control pings itself and never shows them to the page. A page whose network went away without a close (a laptop sleeping, a change of wifi) keeps a socket that looks open until TCP gives up, which can take minutes. The router already pings every 30 s, but only the router can see those.
What
healthcheck=trueon/v1/agents/sessions/{id}/eventssends{"type": "healthcheck", "interval_ms": 10000}every interval from when the socket opens. It is namedhealthcheckto match the rest of the product.cursor, is not kept in the 256-frame replay buffer, and is never replayed on resume.refreshedbus message. If no answer comes for 90 s, the socket is closed with 1011, so the close lands within about 2 minutes of the node going away. Before, the socket stayed open and silent forever, and a healthcheck would have made that look healthy.answer_refresh), and the session's node says on attach that it answers (answers_refresh). An older node is never timed out, and never sent an answer it would forward to its client as an empty frame.AgentEvent.Kind.healthcheck/Healthcheck). Their wire tests read every frame typesessionws.gowrites and would fail otherwise. Neither SDK asks for healthchecks yet.--checkpasses, and Go, Kotlin, .NET, PHP and Rust had no diff. The Dart image could not be pulled, but Dart's generator skipswatchSession..claude/skills/sdk/notes/2026-11-30-session-healthcheck.mdcovers what each SDK should do. The JS reconnect loop must treat both the healthcheck timeout and 1011 as a drop.Tests
SessionHealthcheckSuite, covering the local and relayed node, no healthcheck unless asked, nocursor, no replay on resume, and the 10 s default.RelayedSessionSuitetests:-race, and the fullinternal/apiintegration package passes.TestPoliciesSuitefailed once because the run crossed midnight, and passed when rerun.WireTestspass on an iOS simulator, and KotlinWireTestpasses. Both include the check that every frame the router writes is named.Not covered: the dispatch socket (
/v1/dispatch) still has no healthcheck.