Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
agent:
autoContinueLimit: 1000 # max silent "Continue" nudges when a turn ends on reasoning
autoContinueLimit: 1000 # max silent "Continue" nudges when a turn ends on reasoning or a tool message
bundledSkills: true # false = only 'reflection' loaded from .skills/
decision:
baseUrl: "" # empty = tool not registered
Expand Down
25 changes: 20 additions & 5 deletions openspec/specs/tui-streaming/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,23 +233,38 @@ The message list SHALL expose a method returning the ID of the last message in t
- **WHEN** the message list is empty
- **THEN** the method returns `undefined`

### Requirement: TUI SHALL auto-continue only when the last bubble ends on reasoning
### Requirement: TUI SHALL auto-continue only when the last bubble ends on reasoning or a tool message

The TUI SHALL dispatch a silent "Continue" user message only when the streaming assistant bubble is the last in the message list AND it ended with reasoning as its last event AND the auto-continue loop guard is not exhausted.
The TUI SHALL dispatch a silent "Continue" user message only when the streaming assistant bubble is the last in the message list AND its last event was reasoning or a tool message (`reasoning`, `tool`, or `on_tool_end`) AND the turn was not interrupted AND the auto-continue loop guard is not exhausted.

#### Scenario: Last bubble ends on reasoning

- **WHEN** the streaming bubble is the last in the list and its last event type is `reasoning` and the loop guard is not exhausted
- **THEN** the TUI dispatches a silent "Continue" user message

#### Scenario: Last bubble ends on a tool message

- **WHEN** the streaming bubble is the last in the list and its last event type is `tool` or `on_tool_end` and the loop guard is not exhausted
- **THEN** the TUI dispatches a silent "Continue" user message

#### Scenario: Earlier incomplete bubble does not trigger

- **WHEN** an earlier bubble is still streaming while a later bubble ends on reasoning
- **WHEN** an earlier bubble is still streaming while a later bubble ends on reasoning or a tool message
- **THEN** the TUI does not dispatch a "Continue" for the earlier bubble

#### Scenario: Reasoning followed by a tool call does not trigger
#### Scenario: Interrupted turn does not trigger

- **WHEN** the turn paused on an interrupt (e.g. `clarify`)
- **THEN** the TUI does not dispatch a "Continue"

#### Scenario: Tool start does not trigger

- **WHEN** the last event type is `on_tool_start`
- **THEN** the TUI does not dispatch a "Continue"

#### Scenario: Turn ends on a message does not trigger

- **WHEN** the last event type is a tool event rather than `reasoning`
- **WHEN** the last event type is `message`
- **THEN** the TUI does not dispatch a "Continue"

#### Scenario: Loop guard exhausted
Expand Down
4 changes: 2 additions & 2 deletions src/stream/consume.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { isSubagentNamespace } from "./namespace.js";
* collecting the orchestrator's own text and reasoning.
*
* Tracks the last non-subagent event type forwarded to the callback so the
* TUI can detect a turn that ended on reasoning (the model produced no
* message content) and nudge it with a silent "Continue".
* TUI can detect a turn that ended on reasoning or a tool message (the model
* produced no final message content) and nudge it with a silent "Continue".
*
* @param {AsyncIterable} stream - The agent stream (subgraphs mode)
* @param {Function} [streamingCallback] - Callback for streamed chunks
Expand Down
26 changes: 18 additions & 8 deletions src/tui/conversationArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,25 @@ export async function countToolMessageTokens(model, text) {
return 0;
}

/** Last-event types that mean a turn ended without a final assistant message. */
const AUTO_CONTINUE_EVENT_TYPES = new Set(["reasoning", "tool", "on_tool_end"]);

/**
* Decide whether to dispatch a silent "Continue" after a turn ends.
*
* The reasoning-only auto-continue fires only when the streaming bubble is the
* last in the message list AND it ended on reasoning AND the loop guard is not
* exhausted. Earlier incomplete bubbles must never trigger it.
* The auto-continue fires only when the streaming bubble is the last in the
* message list AND the turn ended on reasoning or a tool message (the model
* never produced a final response) AND the turn was not paused by an interrupt
* AND the loop guard is not exhausted. Earlier incomplete bubbles must never
* trigger it.
*
* @param {Object} params - Decision inputs
* @param {string | undefined} params.lastEventType - The last non-subagent event type
* @param {string | undefined} params.streamingMsgId - The streaming bubble's message ID
* @param {string | undefined} params.lastMessageId - The last message ID in the list
* @param {number} params.autoContinueCount - Current auto-continue count
* @param {number} params.autoContinueLimit - Max auto-continue count
* @param {boolean} [params.interrupted] - True when the turn paused on an interrupt
* @returns {boolean} True when a silent "Continue" should be dispatched
*/
export function shouldAutoContinue({
Expand All @@ -61,9 +67,11 @@ export function shouldAutoContinue({
lastMessageId,
autoContinueCount,
autoContinueLimit,
interrupted = false,
}) {
return (
lastEventType === "reasoning" &&
!interrupted &&
AUTO_CONTINUE_EVENT_TYPES.has(lastEventType) &&
streamingMsgId === lastMessageId &&
autoContinueCount < autoContinueLimit
);
Expand Down Expand Up @@ -493,10 +501,11 @@ const ConversationArea = forwardRef(function ConversationArea(
completedToolCalls,
);

// Reasoning-only auto-continue: when the last bubble ends on reasoning
// (the model produced no message content), nudge it with a silent
// "Continue" so it produces an actual response. Scoped to the LAST
// bubble only — earlier incomplete bubbles must not trigger it. Bounded
// Auto-continue: when the last bubble ends on reasoning or a tool
// message (the model produced no final message content), nudge it with
// a silent "Continue" so it produces an actual response. Skipped for
// interrupted turns. Scoped to the LAST bubble only — earlier
// incomplete bubbles must not trigger it. Bounded
// by config.agent.autoContinueLimit to prevent an infinite loop.
const autoContinueLimit = config?.agent?.autoContinueLimit ?? 1000;
if (
Expand All @@ -506,6 +515,7 @@ const ConversationArea = forwardRef(function ConversationArea(
lastMessageId: messageListRef.current?.getLastMessageId(),
autoContinueCount: autoContinueCountRef.current,
autoContinueLimit,
interrupted: response?.interrupted,
})
) {
autoContinueCountRef.current += 1;
Expand Down
45 changes: 45 additions & 0 deletions tests/unit/tui/conversationArea.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,51 @@ describe("shouldAutoContinue", () => {
);
});

it("returns true when the turn ends on a tool message", async () => {
const mod = await import("../../../src/tui/conversationArea.js");
for (const lastEventType of ["tool", "on_tool_end"]) {
assert.strictEqual(
mod.shouldAutoContinue({
lastEventType,
streamingMsgId: "3",
lastMessageId: "3",
autoContinueCount: 0,
autoContinueLimit: 1000,
}),
true,
);
}
});

it("returns false when the turn ends on a tool start", async () => {
const mod = await import("../../../src/tui/conversationArea.js");
assert.strictEqual(
mod.shouldAutoContinue({
lastEventType: "on_tool_start",
streamingMsgId: "3",
lastMessageId: "3",
autoContinueCount: 0,
autoContinueLimit: 1000,
}),
false,
);
});

it("returns false when the turn was interrupted", async () => {
const mod = await import("../../../src/tui/conversationArea.js");
assert.strictEqual(
mod.shouldAutoContinue({
lastEventType: "tool",
interrupted: true,
streamingMsgId: "3",
lastMessageId: "3",
autoContinueCount: 0,
autoContinueLimit: 1000,
}),
false,
);
});

it("returns false when lastEventType is undefined", async () => {
const mod = await import("../../../src/tui/conversationArea.js");
assert.strictEqual(
Expand Down
Loading