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:
co-authored by
multica-agent
parent
3228b1e0d7
commit
fc905fe6bd
@@ -15,6 +15,15 @@ emitted before the task starts; (b) runtime — generations started inside that
|
||||
ContextVar bind exactly, including the manager's both-queued-then-delayed
|
||||
interleaving, a say speech sandwiched between user turns, an unattributed
|
||||
generation (fail-closed) and an interrupted turn (cancel, no receipt).
|
||||
|
||||
HEL-879 timing closure (contract-approval round): the real SDK's
|
||||
AgentSession.say is a SYNC method returning an awaitable SpeechHandle (awaiting
|
||||
it awaits the whole playout) — speak_proactive_row must publish
|
||||
proactive_start DURING the playout with end/cancel on the handle's done
|
||||
callback; and a clearly-attributed but incomplete/no-receipt stream must close
|
||||
the subtitle turn with turn_cancel ONLY (contract v2: no complete same-turn
|
||||
receipt means no assistant_final), while the complete+receipt path keeps
|
||||
final AND the ack.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -372,6 +381,95 @@ asyncio.run(interim_seam())
|
||||
ok.append("assistant_interim seam: real LLMStream deltas feed per-speech_id v2 "
|
||||
"payloads (replace semantics); unattributed streams feed nothing")
|
||||
|
||||
# 11. HEL-879 timing closure: proactive_start DURING the playout on the real
|
||||
# sync-say shape (a bare handle.__await__ would wait out the whole play).
|
||||
async def proactive_timing_case():
|
||||
events: list[dict] = []
|
||||
h = SpeechHandle.create()
|
||||
class SyncSay:
|
||||
def say(self, *args, **kwargs): # real SDK shape: sync -> handle
|
||||
asyncio.get_running_loop().call_later(.06, h._mark_done)
|
||||
return h
|
||||
task = asyncio.create_task(worker_mod.speak_proactive_row(
|
||||
SyncSay(), seam_mod.SubtitleBus(events.append),
|
||||
{"id": 7, "text": "offline sample"}))
|
||||
await asyncio.sleep(.015)
|
||||
assert h.done() is False
|
||||
assert [e["kind"] for e in events] == ["proactive_start"], events
|
||||
await task
|
||||
await asyncio.sleep(.015)
|
||||
assert [e["kind"] for e in events] == ["proactive_start", "proactive_end"]
|
||||
start = events[0]
|
||||
assert (start["v"], start["role"], start["message_id"], start["text"]) == \
|
||||
(2, "assistant", 7, "offline sample")
|
||||
assert start["speech_id"] == h.id
|
||||
|
||||
asyncio.run(proactive_timing_case())
|
||||
ok.append("speak_proactive_row publishes proactive_start while the real "
|
||||
"SpeechHandle is still playing (sync-say shape), end/cancel on the "
|
||||
"handle's done callback")
|
||||
|
||||
# 11b. an interrupted proactive row closes with cancel, never end
|
||||
async def proactive_interrupt_case():
|
||||
events: list[dict] = []
|
||||
h = SpeechHandle.create()
|
||||
class SyncSay:
|
||||
def say(self, *args, **kwargs):
|
||||
return h
|
||||
task = asyncio.create_task(worker_mod.speak_proactive_row(
|
||||
SyncSay(), seam_mod.SubtitleBus(events.append),
|
||||
{"id": 8, "text": "被打断的主动留言"}))
|
||||
await asyncio.sleep(.005) # start emitted, done callback registered
|
||||
h.interrupt()
|
||||
h._mark_done()
|
||||
await task
|
||||
await asyncio.sleep(.02)
|
||||
assert [e["kind"] for e in events] == ["proactive_start", "proactive_cancel"], events
|
||||
assert events[-1]["reason"] == "interrupted"
|
||||
|
||||
asyncio.run(proactive_interrupt_case())
|
||||
ok.append("interrupted proactive row emits proactive_cancel(reason=interrupted), "
|
||||
"never proactive_end")
|
||||
|
||||
# 12. HEL-879 timing closure: a clearly-attributed but INCOMPLETE/no-receipt
|
||||
# stream through the ACTUAL bind_voice_session callbacks must close the
|
||||
# subtitle turn with turn_cancel ONLY — no assistant_final, no ack (v2).
|
||||
async def no_receipt_incomplete_case():
|
||||
events: list[dict] = []
|
||||
session = AgentSession()
|
||||
ledger = receipt_mod.TurnLedger()
|
||||
bus = seam_mod.SubtitleBus(events.append)
|
||||
interim = seam_mod.AssistantInterimPublisher(bus)
|
||||
confirmed: list[str] = []
|
||||
async def epoch():
|
||||
return 1
|
||||
class Receipts:
|
||||
async def confirm(self, *args):
|
||||
confirmed.append(args[0])
|
||||
return True
|
||||
llm = types.SimpleNamespace(client=types.SimpleNamespace(current_epoch=epoch))
|
||||
worker_mod.bind_voice_session(session, llm=llm, ledger=ledger, interim=interim,
|
||||
bus=bus, stt=types.SimpleNamespace(),
|
||||
receipts=Receipts())
|
||||
h = SpeechHandle.create()
|
||||
session.emit("speech_created", SpeechCreatedEvent(
|
||||
user_initiated=True, source="generate_reply", speech_handle=h,
|
||||
created_at=1.0))
|
||||
stream = types.SimpleNamespace(
|
||||
speech_id=h.id, error_phi=None, text="partial without receipt",
|
||||
turn_id="incomplete", receipt=None, completed=False)
|
||||
ledger.note_stream(stream, h)
|
||||
interim.begin(h.id)
|
||||
h._mark_done()
|
||||
await asyncio.sleep(.06)
|
||||
assert [e["kind"] for e in events] == ["turn_start", "turn_cancel"], events
|
||||
assert events[-1]["reason"] == "incomplete"
|
||||
assert confirmed == []
|
||||
|
||||
asyncio.run(no_receipt_incomplete_case())
|
||||
ok.append("incomplete/no-receipt attributed stream: actual worker callbacks emit "
|
||||
"turn_start -> turn_cancel only, no assistant_final, no ack")
|
||||
|
||||
print("HEL-877/879 real-SDK check on livekit-agents", end=" ")
|
||||
import importlib.metadata as md
|
||||
print(md.version("livekit-agents") + ":", "ALL PASS")
|
||||
|
||||
Reference in New Issue
Block a user