Repository navigation
Description
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.
- A stop is lost while a re-arm waits for run capacity. A
send_message(run=True)that arrives during a run'swait_for_pendingtail is parked, and the tail re-arms withrun(wait_for_capacity=True). That call checks_closingand the interrupt generation before it blocks inRunSlot.acquire, and never after. If the server is atmax_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 writesbase_state.jsonand event files into its deleted directory. /sockets/sessionsends an event twice. An event inside the replay mark whose fan-out lands aftergo_liveis sent from disk and again live./sockets/eventswithresend_modeduplicates 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.- A failed subscribe leaks a subscriber slot. If
subscribe_to_eventsfails after it registers the subscriber, the registration stays. After 50 failures every new socket gets 1013, and the conversation is never idle-evicted. PubSub.close()stops at the first failingsubscriber.close(). It stops beforeclear(), 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./sockets/sessioncan 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/sessionand/sockets/events(withresend_mode) deliver each event once, in history order. - A failed
subscribe_to_eventsleaves no registration, andPubSub.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
[-][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[/+]