fix(agent): preserve goal continuation lifecycle
This commit is contained in:
1 parent
3c022ada6a
commit
ce885fa31e
5 files changed
+75
-22
No files matched your search
@@ -1703,7 +1703,7 @@ class AgentLoop:
|
||||
pending_queue=pending,
|
||||
delivery=delivery,
|
||||
)
|
||||
continuing = turn_continuation.internal_continuation_pending(msg.metadata)
|
||||
continuing = delivery.continuation_pending
|
||||
await delivery.complete(
|
||||
response,
|
||||
publish_completion=not continuing,
|
||||
@@ -1713,6 +1713,8 @@ class AgentLoop:
|
||||
coordinator.complete(msg, response=response)
|
||||
except asyncio.CancelledError:
|
||||
logger.info("Task cancelled for session {}", session_key)
|
||||
# The queued continuation is cancelled with this session worker.
|
||||
delivery.continuation_pending = False
|
||||
try:
|
||||
await delivery.abort_stream()
|
||||
except Exception:
|
||||
@@ -1745,15 +1747,11 @@ class AgentLoop:
|
||||
logger.opt(exception=log_content).error(
|
||||
"Error processing message for session {}", session_key,
|
||||
)
|
||||
await delivery.fail(
|
||||
publish_completion=not turn_continuation.internal_continuation_pending(
|
||||
msg.metadata
|
||||
)
|
||||
)
|
||||
await delivery.fail(publish_completion=not delivery.continuation_pending)
|
||||
for coordinator in self._automation_turn_coordinators:
|
||||
coordinator.complete(msg, error=exc)
|
||||
finally:
|
||||
if not turn_continuation.internal_continuation_pending(msg.metadata):
|
||||
if not delivery.continuation_pending:
|
||||
await delivery.idle()
|
||||
except asyncio.CancelledError:
|
||||
if not completion_published and self.commands.requires_session_queue(command_text(msg)):
|
||||
@@ -2353,7 +2351,7 @@ class AgentLoop:
|
||||
ctx.delivery.record_usage(result.round_usages)
|
||||
if ctx.kind is TurnKind.USER:
|
||||
current = await self.sessions.state.read_metadata(ctx.session_key)
|
||||
await turn_continuation.maybe_continue_turn(
|
||||
ctx.delivery.continuation_pending = await turn_continuation.maybe_continue_turn(
|
||||
ctx, session_metadata=current["metadata"] if current else {},
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user