Skip to content

Commit 50ca97d

Browse files
committed
fix(steering): don't inject interruptions after final response
Remove the drain-after-final-response logic that forced the loop to continue after the LLM had already finished. This caused confusing double responses. Correct model: - Tool execution phase: interruption = steering (single merged response) - Final response phase: new message = new task (separate responses) Orphaned messages left in the checker queue after the task completes are now re-published to the inbound bus so they're processed as independent new tasks by the run() loop. Made-with: Cursor
1 parent ec5022a commit 50ca97d

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

nanobot/agent/loop.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -417,16 +417,6 @@ def _drain_interruptions() -> str | None:
417417
messages, clean, reasoning_content=response.reasoning_content,
418418
thinking_blocks=response.thinking_blocks,
419419
)
420-
421-
# Before ending, check if new messages arrived during the LLM call.
422-
# If so, inject them and continue — let the model address them.
423-
if injection := _drain_interruptions():
424-
messages.append({"role": "user", "content": injection})
425-
if on_progress:
426-
await on_progress(clean)
427-
logger.info("Steering: pending interruption after final response, continuing loop")
428-
continue
429-
430420
final_content = clean
431421
break
432422

@@ -559,7 +549,12 @@ async def on_stream_end(*, resuming: bool = False) -> None:
559549
))
560550
finally:
561551
if self.enable_steering:
562-
self._interrupt_checkers.pop(msg.session_key, None)
552+
checker = self._interrupt_checkers.pop(msg.session_key, None)
553+
# Re-publish orphaned messages so they're processed as new tasks
554+
if checker:
555+
for orphan in checker.drain_all():
556+
logger.info("Steering: re-queuing orphaned message for {}", msg.session_key)
557+
await self.bus.publish_inbound(orphan)
563558

564559
async def close_mcp(self) -> None:
565560
"""Drain pending background archives, then close MCP connections."""

0 commit comments

Comments
 (0)