Skip to content

[Bug]: agent-server races: a stop lost to a queued re-arm; event sockets duplicate, reorder and leak subscriptions #6576

Closed

Description

@VascoSch92

Is there an existing issue for the same bug?

  • I have searched existing issues and this is not a duplicate.

Bug Description

Six concurrency bugs in the agent-server's run admission and event sockets, on main @ e4160d1. Each one is reproduced by a test that forces the interleaving against a real EventService/ConversationService.

  1. A stop is lost while a re-arm waits for run capacity. A send_message(run=True) that arrives during a run's wait_for_pending tail is parked, and the tail re-arms with run(wait_for_capacity=True). That call checks _closing and the interrupt generation before it blocks in RunSlot.acquire, and never after. If the server is at max_concurrent_runs, a pause or delete that lands during the wait is overridden once a permit frees. A paused conversation goes back to RUNNING. A deleted conversation runs again and writes base_state.json and event files into its deleted directory.
  2. /sockets/session sends an event twice. An event inside the replay mark whose fan-out lands after go_live is sent from disk and again live.
  3. /sockets/events with resend_mode duplicates and reorders events. It subscribes and then replays with no buffering or dedup. An event published during the replay arrives ahead of older history and again from the replay. This happens without forced timing.
  4. A failed subscribe leaks a subscriber slot. If subscribe_to_events fails after it registers the subscriber, the registration stays. After 50 failures every new socket gets 1013, and the conversation is never idle-evicted.
  5. PubSub.close() stops at the first failing subscriber.close(). It stops before clear(), and a subscriber registered while it awaits is dropped without being closed. This is also an item on [Bug]: Edge-case tests expose ~70 bugs across the SDK, agent server, tools and workspaces #6348.
  6. /sockets/session can send a stale snapshot. The connect snapshot and the replay mark are read at different times, so the replay can include a status change that the older snapshot, sent after it, overwrites.

Sockets left open after a delete are a separate issue, #5635, fixed by #5757.

Expected Behavior

An explicit stop wins over a queued re-arm. Each socket delivers every event exactly once, in order, and the connect snapshot is never older than the state sent before it. A failed subscription frees its slot, and PubSub.close() closes every subscriber.

Actual Behavior

As above. The re-arm repro ends with the deleted conversation's directory back on disk. The legacy socket repro without forced timing delivers ['E1', 'E0', 'E1'].

Steps to Reproduce

tests/agent_server/test_rearm_stop_wins.py, tests/agent_server/test_event_socket_races.py, and test_event_persisted_before_mark_but_published_after_go_live in tests/agent_server/test_session_socket.py (from #6577) all fail on main.

Acceptance Criteria

  • A pause or delete that lands while a re-arm waits for capacity starts no run and returns the permit.
  • /sockets/session and /sockets/events (with resend_mode) deliver each event once, in history order.
  • A failed subscribe_to_events leaves no registration, and PubSub.close() closes every subscriber even when one fails.
  • The session socket never sends the connect snapshot after state newer than it.

Installation Method

Other

SDK Version

main @ e4160d1

Activity

  1. added
    bug
    ready-for-dev
    on Nov 7, 2026
  2. changed the title [-][Bug]: agent-server races: a stop lost to a queued re-arm, event sockets duplicate/reorder and leak subscriptions[/-] [+][Bug]: agent-server races: a stop lost to a queued re-arm; event sockets duplicate, reorder and leak subscriptions[/+] on Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugready-for-dev

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions