Flaky: pi_test queued_observer_events_come_before_session_shutdown loses agent_end #374
Description
queued_observer_events_come_before_session_shutdown (integrations/yoagent-rutis/tests/pi_test.rs ~2217) is flaky. It ran twice on the same commit (8337e3f, release PR #373), as a push run and as a PR run. One run passed and one failed:
assertion `left == right` failed
left: ["turn_end", "shutdown"]
right: ["turn_end", "agent_end", "shutdown"]
(job https://github.com/yologdev/yoagent/actions/runs/40028339126/job/120670122423)
What the test checks. It unloads at once after a run, while a slow turn_end observer (1.5 s) is still running and agent_end is queued behind it. It expects unloading to wait (bounded, OBSERVER_DRAIN_MS 5 s) for both, so agent_end comes before session_shutdown.
Likely cause (not verified). Sometimes agent_end is not in the adapter's queue when the drain starts. The bridge delivers agentEnd after the run's finish, so it can arrive after host.root.shutdown() has begun. At that point the adapter is closed and drops it (observe returns early on closed). The drain then sees only turn_end.
To decide:
- Is this ordering pi's semantics that we must keep (an
agent_endfor a run that ended before unload must always fire)? Then the fix is in the adapter or bridge: unloading should also wait for the bridge to deliver a finished run'sagentEnd. - Or is it a race we accept? Then the test should wait for the run's events to reach the adapter (e.g. a marker from
turn_end's start) before unloading.
Not related to #373's changes.
Activity
fix(rutis): review round 2 — AgentEnd by whether finish reached the h…