Stop background tasks separately from chat turns

Keep Esc and /stop scoped to the foreground turn while exposing an explicit stop-tasks operation for supported chat backends. Add the protocol, server routing, app command, and coverage for task stopping and unsupported harnesses.
This commit is contained in:
2026-11-13 16:47:41 +00:00
parent c3c2c1bbc9
commit 2a182d7f17
19 changed files with 331 additions and 2 deletions
@@ -596,6 +596,9 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
} else {
_showCommandNotice('No turn is running in this chat.', failed: true);
}
} else if (command.name == chatCommandStopTasks) {
_consumeCommandDraft();
unawaited(_stopTasksFromCommand());
} else if (command.name == chatCommandHelp) {
_consumeCommandDraft();
_showCommandNotice(chatCommandHelpText());
@@ -624,6 +627,16 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
_showCommandNotice(chatStopCommandNotice);
}
Future<void> _stopTasksFromCommand() async {
try {
if (mounted) {
_showCommandNotice(await widget.composer.stopTasks());
}
} catch (error) {
if (mounted) _showCommandNotice('$error', failed: true);
}
}
void _consumeCommandDraft() {
_text.clear();
unawaited(widget.composer.setDraft(''));
@@ -373,6 +373,17 @@ class ChatComposerController extends ChangeNotifier {
}
}
/// Stops background tasks without interrupting the current turn.
Future<String> stopTasks() async {
final reply = await _repository.stopTasks(sessionId);
final result = reply['chat_stop_tasks'];
if (result is Map) {
final message = '${result['message'] ?? ''}'.trim();
if (message.isNotEmpty) return message;
}
return 'Background tasks stop request accepted.';
}
/// Follows the server's queue report: a prompt it lists is the server's
/// (any stored device copy is dropped) and shows "Queued"; one that left
/// the queue shows what happened to it.
@@ -272,6 +272,11 @@ class ChatRepository {
'chat_query': {'session_id': sessionId},
});
Future<JsonMap> stopTasks(String sessionId) =>
gateway.call('chat_stop_tasks', {
'chat_query': {'session_id': sessionId},
});
/// Removes one prompt the server still holds in the session's queue. The
/// reply's `chat_queue` is the queue afterwards; a prompt already handed to
/// the harness is refused.
@@ -25,6 +25,7 @@ const String chatCommandNew = 'new';
const String chatCommandClose = 'close';
const String chatCommandRename = 'rename';
const String chatCommandStop = 'stop';
const String chatCommandStopTasks = 'stop_tasks';
const String chatCommandHelp = 'help';
/// The recorded command list, in the order the palette shows it.
@@ -50,6 +51,11 @@ const List<ChatCommand> chatCommands = <ChatCommand>[
summary: 'Stop the turn that is running',
usage: '/stop',
),
ChatCommand(
name: chatCommandStopTasks,
summary: 'Stop all background tasks in this chat',
usage: '/stop_tasks',
),
ChatCommand(
name: chatCommandHelp,
summary: 'List every command',