Skip to content

fix(sessions): close the connection on teardown instead of waiting for the TTL (CHOO-2497) - #322

Open
amaudruz wants to merge 1 commit into
mainfrom
bug-fix/session-delete-stale-connection
Open

fix(sessions): close the connection on teardown instead of waiting for the TTL (CHOO-2497)#322
amaudruz wants to merge 1 commit into
mainfrom
bug-fix/session-delete-stale-connection

Conversation

@amaudruz

@amaudruz amaudruz commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

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

  • New POST /agents/{agent_id}/connection/close releases a connection and its room slots immediately. Idempotent — closing one that is already gone reports closed: false rather 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.
  • Best-effort and disclosed: a failed close is logged as a warning and the heartbeat sweep remains the backstop. Teardown never blocks on the network.

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.
  • Full backend agent-bridge suite (338) and the room-connection suite (59) pass; ruff, mypy and the desktop typecheck are clean.

🤖 Generated with Claude Code

…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>
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