fix(sessions): close the connection on teardown instead of waiting for the TTL (CHOO-2497) - #322
Open
amaudruz wants to merge 1 commit into
Open
fix(sessions): close the connection on teardown instead of waiting for the TTL (CHOO-2497)#322amaudruz wants to merge 1 commit into
amaudruz wants to merge 1 commit into
Conversation
…r the TTL (CHOO-2497)
Deleting a session tore the runtime down locally and told switch-core
nothing. The server kept the session's connection, and with it the claim
on its room, until the heartbeat sweep collected it. For those seconds
the agent's all-scope watcher was dark on that room, so a message
arriving in the gap was never delivered and no replacement session was
spawned — the user saw a delay before a ping did anything.
Add POST /agents/{id}/connection/close and call it from RoomConnection's
teardown. Closing releases the room slot at once, handing coverage back
to the watcher. The call is idempotent, detached and best-effort: it is
logged rather than raised on failure, and the heartbeat sweep remains
the backstop.
Co-Authored-By: Claude Opus 5 (1M context) <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.
Problem
Deleting a session left a delay before a ping in that room could spawn a new one.
Session deletion tore the runtime down locally and told switch-core nothing. The server kept the session's connection — and with it the claim on its room — until the heartbeat sweep collected it. While that claim stood, the agent's all-scope watcher was deliberately dark on the room, so an incoming message was never delivered and no replacement session was spawned.
Jira: CHOO-2497
Fix
POST /agents/{agent_id}/connection/closereleases a connection and its room slots immediately. Idempotent — closing one that is already gone reportsclosed: falserather than failing — and scoped to the calling agent.RoomConnection.stop()calls it on teardown, so deleting or stopping a session frees the room straight away and coverage returns to the watcher.Not in scope
Two adjacent findings were raised and deliberately left alone: the liveness check is still an OR across the in-memory registry and a legacy database table, and the room binding row is never cleaned up on session end (harmless for spawning, but it skews the wording of the "agent unavailable" reply).
Testing
core/tests/switch_core/bridges/agent/api/test_connection_close.py— the room goes back to the watcher with no sweep, double close, unknown connection, and cross-agent close.room-connection.test.ts— teardown posts the close once, and a failed close warns instead of throwing.🤖 Generated with Claude Code