HEL-879 timing closure: the three contract-approval findings fixed as implementation-timing only (v2 envelope fields/event kinds untouched, web/src untouched, no re-audit of passed binding/backup/budget work) - (1) open_session re-kicks the cleanup owner AFTER registration+persist: a real dispatch await yields the loop and the pre-dispatch kick's cleaner already exited with nothing to watch (manager repro: 20ms real dispatch await, TTL 25ms, 120ms of silence -> DELETE=0, expired registration still present, cleaner=None; fixed: exactly one DELETE, registration settled, no dangling coroutine - the bounded auto-expiry/shared-cap mechanism itself is unchanged), new regressions reproduce first on the old code with a genuinely-yielding dispatch stand-in (asyncio.sleep, not the instantly-returning MockTransport) plus an earlier-deadline wake negative; (2) speak_proactive_row takes the handle the real sync AgentSession.say returns (iscoroutine only unwraps await-style stand-ins - the real SpeechHandle itself defines __await__, so awaiting it would wait out the whole playout), publishes proactive_start IMMEDIATELY, registers the handle's own end/cancel, then waits out that one row (sequential rows kept); .12 real-SDK probe: start visible while handle_done=false, end only after, cancel-only on interrupt, v2 fields identical; (3) _after_playout gates assistant_final on the completed+legal-same-turn-receipt conditions BEFORE anything is sent - incomplete streams, missing/partial receipts and stale epochs close with turn_cancel only (reason incomplete/no-receipt), never final-then-unack; the complete+receipt path keeps BOTH final and ack; phi/interrupt/failure/unattributed fail-closed unchanged; real-SDK check extended to 14/14 ALL PASS on .12 (proactive timing, proactive interrupt, no-receipt no-final negatives all driving the actual worker module's registered callbacks), before/after evidence in docs/rework/hel879/timing-fix/ and sdk-check-hel879-timing.log, reusable probe generator scripts/gen_hel879_timing_probe.py; regression at this head: pytest 352/352 x3 consecutive runs, ruff(src/tests/tools) clean, verify_hel877_voice_chain 8/8, requirements checks 4/4 (origin/main and c121c42, each with/without handoff-HEL-879.json, handoff appended with this round's scope); zero real LLM/embed/ASR/TTS, zero downloads, .12 touched read-only via SSH stdin only, not deployed, nothing merged, PR#11 and hel-870-assembly untouched, real caps stay 0

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
zonggong
2026-10-27 05:31:05 +08:00
co-authored by multica-agent
parent 3228b1e0d7
commit fc905fe6bd
12 changed files with 483 additions and 74 deletions
+71
View File
@@ -432,6 +432,77 @@ async def test_cleaner_stays_alive_while_a_session_is_registered():
await service.aclose()
@pytest.mark.asyncio
async def test_open_session_with_real_dispatch_yield_re_kicks_cleanup(monkeypatch):
"""总管契约核准轮第 1 项精确复现:建房 await 真正让出事件循环(真实 HTTP
一定如此),pre-dispatch kick 的清理所有者在等待期间已空转退出;注册成功
并持久化之后必须重新唤醒/重建清理所有者——过 TTL 且不再来任何请求也能
到期转债并真实删房。旧代码:DELETE=0、过期登记仍在、cleaner=None。"""
deletes: list[str] = []
dispatch_yielded = asyncio.Event()
async def slow_create(*args, **kwargs):
await asyncio.sleep(0.02) # real HTTP always gives the loop a chance
dispatch_yielded.set()
return SimpleNamespace(dispatch_id="AD_delayed")
async def slow_delete(*args, **kwargs):
deletes.append(kwargs["room"])
monkeypatch.setattr(livekit_wire, "create_dispatch", slow_create)
monkeypatch.setattr(livekit_wire, "delete_room", slow_delete)
service = _service(StandinLiveKit(), session_ttl_seconds=0.025)
try:
session = await service.open_session(epoch=1)
assert dispatch_yielded.is_set(), "dispatch await must really yield here"
# the registration's deadline has a live owner again right after open
assert service._cleaner is not None and not service._cleaner.done()
await asyncio.sleep(0.12) # past TTL with NO further request at all
assert deletes == [session.room] # exactly one delete, no duplicates
assert session.session_id not in service._sessions
assert service.cleanup_debt(session.session_id) is None
# settled: the cleaner exits by itself, no dangling coroutine
for _ in range(100):
if service._cleaner is None or service._cleaner.done():
break
await asyncio.sleep(0.02)
assert service._cleaner is None or service._cleaner.done()
finally:
await service.aclose()
assert service._cleaner is None
@pytest.mark.asyncio
async def test_second_registration_wakes_a_sleeping_cleaner_for_earlier_deadline(
monkeypatch):
"""注册后的 kick 也唤醒仍在睡眠的清理所有者:更短 TTL 的新会话不必等
旧会话的截止时间才被观察(min(deadlines) 立即重算)。"""
deletes: list[str] = []
async def create(*args, **kwargs):
await asyncio.sleep(0.02)
return SimpleNamespace(dispatch_id="AD_2")
async def delete(*args, **kwargs):
deletes.append(kwargs["room"])
monkeypatch.setattr(livekit_wire, "create_dispatch", create)
monkeypatch.setattr(livekit_wire, "delete_room", delete)
service = _service(StandinLiveKit(), session_ttl_seconds=5.0, backoff=0.005)
try:
first = await service.open_session(epoch=1) # long TTL keeps cleaner sleeping
service.config.session_ttl_seconds = 0.025
second = await service.open_session(epoch=1) # short TTL + real dispatch await
for _ in range(100):
if deletes:
break
await asyncio.sleep(0.02)
assert deletes == [second.room]
assert first.session_id in service._sessions # the long-TTL call is untouched
finally:
await service.aclose()
@pytest.mark.asyncio
async def test_end_after_abandoned_cap_sends_no_further_deletes():
"""总管复核 A-2 精确复现:上限 2,后台到顶后再 3 次 end 不得再发删除