fix(core): a turn cut by shutdown keeps running_turn for recover

This commit is contained in:
hh
2026-08-28 19:33:26 +02:00
parent e469e7e174
commit 609af9fe67
2 changed files with 28 additions and 3 deletions
+12 -3
View File
@@ -825,6 +825,7 @@ class Conversations:
item_origin=item_origin,
)
stop = "error"
cut = False
try:
events = backend.complete(
agent=self._claude_agent(conv.agent_name),
@@ -841,9 +842,12 @@ class Conversations:
async for event in events:
yield event
stop = "interrupted" if capture.interrupted else "end_turn"
except asyncio.CancelledError:
cut = True
raise
finally:
runner.turn_id = None
await self._mark_done(conv, capture)
await self._mark_done(conv, capture, cut=cut)
self._bus.publish(
"turn.end",
conversation_id=conv.external_id,
@@ -1173,9 +1177,14 @@ class Conversations:
await self._update(conv, apply)
async def _mark_done(self, conv: Conversation, capture: TurnCapture) -> None:
async def _mark_done(
self, conv: Conversation, capture: TurnCapture, *, cut: bool = False
) -> None:
"""Close the turn; a cancelled one keeps ``running_turn`` for ``recover``."""
async def apply(row: Conversation) -> None:
row.running_turn = None
if not cut:
row.running_turn = None
row.last_activity_at = datetime.now(UTC)
if capture.session_id is not None:
row.session_id = capture.session_id