fix(gateway): a profile Stop reaches the agent its generation adopted
stop_authority_turns(in_process=True), the retire/shutdown path, still resolved the turn's agent through the route's running slot. Between adopt_agent and the slot's promotion that slot is the pending sentinel, so it latched a generation adopt_agent had already consumed and interrupted nobody: the adopted agent ran on through the profile stop. It now delivers to authority.adopted's agent when the generation matches (8a5193a651f made adopted hold the agent), and falls back to the running slot / latch otherwise, as the user Stop path does. Test: test_retire_stop_between_adoption_and_promotion_reaches_the_adopted_agent fails on the previous head and passes. Review: andrexibiza 5479692359 P1.1 / JoaoMarcos44 R4 (stop-latch-promotion, retire path)
This commit is contained in:
@@ -228,7 +228,9 @@ def stop_authority_turns(authority, *, in_process=False):
|
||||
generation = live.event_stream.execution.get('execution_generation')
|
||||
if generation is None or sid in workers:
|
||||
continue
|
||||
agent = running.get(live.route)
|
||||
adopted_generation, agent = authority.adopted.get(sid, (None, None))
|
||||
if adopted_generation != generation:
|
||||
agent = running.get(live.route)
|
||||
if agent is None or agent is _AGENT_PENDING_SENTINEL:
|
||||
authority.pending_stops[sid] = generation
|
||||
else:
|
||||
|
||||
@@ -39,3 +39,34 @@ async def test_stop_between_adoption_and_promotion_reaches_the_adopted_agent_aft
|
||||
await asyncio.wait_for(authority.sessions['s'].task, 5)
|
||||
assert ran['adopted'] is True, 'the Stop reached nobody: the adopted agent ran on'
|
||||
assert not authority.adopted, 'settlement must drop the adopted agent reference'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_retire_stop_between_adoption_and_promotion_reaches_the_adopted_agent(tmp_path, monkeypatch):
|
||||
"""The same window on the retire/shutdown path: stop_authority_turns(in_process=True) used to
|
||||
re-resolve the running slot (still the pending sentinel) and latch a generation adopt_agent had
|
||||
already consumed, so the adopted agent ran on through the profile stop."""
|
||||
from gateway import session_finite
|
||||
from gateway.run_runtime import stop_authority_turns
|
||||
|
||||
db, authority = _authority(tmp_path, monkeypatch)
|
||||
fresh = Agent()
|
||||
authority.runner._cached_agent_for = {}.get
|
||||
adopted, stopped = asyncio.Event(), asyncio.Event()
|
||||
ran = {}
|
||||
|
||||
async def execute(authority, ref, row):
|
||||
_wire_turn_agent(authority, row['generation'], fresh)
|
||||
adopted.set()
|
||||
await asyncio.wait_for(stopped.wait(), 5)
|
||||
ran[row['request_id']] = fresh.interrupted
|
||||
return 'done'
|
||||
monkeypatch.setattr(session_finite, 'execute_finite_admission', execute)
|
||||
|
||||
with db:
|
||||
await _submit(authority, 'adopted')
|
||||
await asyncio.wait_for(adopted.wait(), 5)
|
||||
stop_authority_turns(authority, in_process=True)
|
||||
stopped.set()
|
||||
await asyncio.wait_for(authority.sessions['s'].task, 5)
|
||||
assert ran['adopted'] is True, 'the profile Stop reached nobody: the adopted agent ran on'
|
||||
|
||||
Reference in New Issue
Block a user