fix(telegram,core): no draft for seed turns

This commit is contained in:
hh
2026-08-28 18:59:00 +02:00
parent 43407016d0
commit 38986cb82e
3 changed files with 10 additions and 2 deletions
+6 -1
View File
@@ -779,6 +779,7 @@ class Conversations:
use_session: bool = True, use_session: bool = True,
tools: bool = True, tools: bool = True,
turn_id: str | None = None, turn_id: str | None = None,
item_origin: str | None = None,
) -> AsyncIterator[MessageStreamEvent]: ) -> AsyncIterator[MessageStreamEvent]:
"""Run one turn on ``conv`` under its lock; the only path to the backend. """Run one turn on ``conv`` under its lock; the only path to the backend.
@@ -799,6 +800,7 @@ class Conversations:
conversation_id=conv.external_id, conversation_id=conv.external_id,
turn_id=turn_id, turn_id=turn_id,
origin=origin, origin=origin,
item_origin=item_origin,
) )
stop = "error" stop = "error"
try: try:
@@ -825,6 +827,7 @@ class Conversations:
conversation_id=conv.external_id, conversation_id=conv.external_id,
turn_id=turn_id, turn_id=turn_id,
origin=origin, origin=origin,
item_origin=item_origin,
stop=stop, stop=stop,
usage=_usage_dict(capture), usage=_usage_dict(capture),
) )
@@ -837,6 +840,7 @@ class Conversations:
origin: str, origin: str,
tools: bool = True, tools: bool = True,
turn_id: str | None = None, turn_id: str | None = None,
item_origin: str | None = None,
) -> tuple[str, TurnCapture]: ) -> tuple[str, TurnCapture]:
capture = TurnCapture() capture = TurnCapture()
acc = StreamAccumulator() acc = StreamAccumulator()
@@ -848,6 +852,7 @@ class Conversations:
capture=capture, capture=capture,
tools=tools, tools=tools,
turn_id=turn_id, turn_id=turn_id,
item_origin=item_origin,
): ):
acc.feed(event) acc.feed(event)
message = acc.finalize(model=agent.model) message = acc.finalize(model=agent.model)
@@ -1062,7 +1067,7 @@ class Conversations:
prompt = "\n\n".join(f"{inject_header(i.origin)}\n{i.text}" for i in batch) prompt = "\n\n".join(f"{inject_header(i.origin)}\n{i.text}" for i in batch)
try: try:
text, capture = await self.run_text_turn( text, capture = await self.run_text_turn(
conv, prompt, origin=origin, turn_id=turn_id conv, prompt, origin=origin, turn_id=turn_id, item_origin=head.origin
) )
except Exception: # noqa: BLE001 except Exception: # noqa: BLE001
_log.exception("turn %s on %s failed", turn_id, conv.external_id) _log.exception("turn %s on %s failed", turn_id, conv.external_id)
@@ -648,7 +648,9 @@ class TelegramFrontend(Frontend):
return return
match kind: match kind:
case "turn.start": case "turn.start":
if event.get("origin") == "user": if event.get("origin") == "user" and not str(
event.get("item_origin") or ""
).startswith("сид"):
await self._open_draft(key, event, target) await self._open_draft(key, event, target)
case "stream": case "stream":
self._feed_draft(key, event) self._feed_draft(key, event)
+1
View File
@@ -465,6 +465,7 @@ async def test_commands_status_merge_and_new(stack: Stack) -> None:
await stack.world.settle(child, 1) await stack.world.settle(child, 1)
await asyncio.sleep(0.2) await asyncio.sleep(0.2)
assert all(m["thread"] != 902 for m in stack.bot.sent) assert all(m["thread"] != 902 for m in stack.bot.sent)
assert all(d["message_thread_id"] != 902 for d in stack.bot.drafts)
stack.bot.message("первое в новый топик", thread=902) stack.bot.message("первое в новый топик", thread=902)
reply = await stack.until(lambda: stack.sent_with("первое в новый топик"), what="r") reply = await stack.until(lambda: stack.sent_with("первое в новый топик"), what="r")
assert reply["thread"] == 902 assert reply["thread"] == 902