From cd2957fa0bed5effd4fc8ca36caa1b6a2e5f4316 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Fri, 29 May 2026 12:52:32 +0800 Subject: [PATCH] fix: clarify subagent and background task stop messages as user-initiated --- .changeset/subagent-stop-wording.md | 6 ++++ .../src/tui/controllers/tasks-browser.ts | 2 +- .../agent-core/src/agent/background/index.ts | 5 +++- .../src/tools/builtin/collaboration/agent.ts | 29 +++++++++++-------- .../src/tools/builtin/shell/bash.ts | 2 +- 5 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 .changeset/subagent-stop-wording.md diff --git a/.changeset/subagent-stop-wording.md b/.changeset/subagent-stop-wording.md new file mode 100644 index 0000000000..4699e6e476 --- /dev/null +++ b/.changeset/subagent-stop-wording.md @@ -0,0 +1,6 @@ +--- +"@moonshot-ai/agent-core": patch +"@moonshot-ai/kimi-code": patch +--- + +Clarify subagent and background task stop messages as user-initiated. diff --git a/apps/kimi-code/src/tui/controllers/tasks-browser.ts b/apps/kimi-code/src/tui/controllers/tasks-browser.ts index 0da21d4be5..56f1cecc6a 100644 --- a/apps/kimi-code/src/tui/controllers/tasks-browser.ts +++ b/apps/kimi-code/src/tui/controllers/tasks-browser.ts @@ -309,7 +309,7 @@ export class TasksBrowserController { this.flash(`Stopping ${taskId}…`, 1500); try { - await session.stopBackgroundTask(taskId, { reason: 'stopped from /tasks' }); + await session.stopBackgroundTask(taskId, { reason: 'User initiated stop' }); await this.refresh({ silent: true }); } catch (error) { const message = error instanceof Error ? error.message : String(error); diff --git a/packages/agent-core/src/agent/background/index.ts b/packages/agent-core/src/agent/background/index.ts index 2e33bc2a64..f8753df1bb 100644 --- a/packages/agent-core/src/agent/background/index.ts +++ b/packages/agent-core/src/agent/background/index.ts @@ -135,7 +135,10 @@ export class BackgroundManager extends BackgroundProcessManager { source_id: info.taskId, title: `Background ${label} ${info.status}`, severity: info.status === 'completed' ? 'info' : 'warning', - body: `${info.description} ${info.status}.`, + body: + info.status === 'killed' && info.stopReason + ? `${info.description} was killed: ${info.stopReason}.` + : `${info.description} ${info.status}.`, tail_output: tailOutput, }; const content = [ diff --git a/packages/agent-core/src/tools/builtin/collaboration/agent.ts b/packages/agent-core/src/tools/builtin/collaboration/agent.ts index a65ed2482d..9838f86f9a 100644 --- a/packages/agent-core/src/tools/builtin/collaboration/agent.ts +++ b/packages/agent-core/src/tools/builtin/collaboration/agent.ts @@ -21,6 +21,7 @@ import { z } from 'zod'; import type { BuiltinTool } from '../../../agent/tool'; import type { Logger } from '../../../logging'; import { ToolAccesses } from '../../../loop/tool-access'; +import { isAbortError } from '../../../loop/errors'; import type { ExecutableToolContext, ExecutableToolResult, ToolExecution } from '../../../loop/types'; import type { ResolvedAgentProfile } from '../../../profile'; import type { SessionSubagentHost, SubagentHandle } from '../../../session/subagent-host'; @@ -299,12 +300,14 @@ export class AgentTool implements BuiltinTool { ]; return { output: lines.join('\n') }; } catch (error) { - const message = - foregroundDeadline?.timedOut() === true && args.timeout !== undefined - ? `Agent timed out after ${args.timeout}s.` - : error instanceof Error - ? error.message - : String(error); + let message: string; + if (foregroundDeadline?.timedOut() === true && args.timeout !== undefined) { + message = `Agent timed out after ${args.timeout}s.`; + } else if (isAbortError(error)) { + message = 'The subagent was stopped by the user.'; + } else { + message = error instanceof Error ? error.message : String(error); + } const lines = [ `agent_id: ${handle.agentId}`, `actual_subagent_type: ${handle.profileName}`, @@ -315,12 +318,14 @@ export class AgentTool implements BuiltinTool { return { output: lines.join('\n'), isError: true }; } } catch (error) { - const message = - foregroundDeadline?.timedOut() === true && args.timeout !== undefined - ? `Agent timed out after ${args.timeout}s.` - : error instanceof Error - ? error.message - : String(error); + let message: string; + if (foregroundDeadline?.timedOut() === true && args.timeout !== undefined) { + message = `Agent timed out after ${args.timeout}s.`; + } else if (isAbortError(error)) { + message = 'The subagent was stopped by the user.'; + } else { + message = error instanceof Error ? error.message : String(error); + } return { output: `subagent error: ${message}`, isError: true }; } finally { foregroundDeadline?.clear(); diff --git a/packages/agent-core/src/tools/builtin/shell/bash.ts b/packages/agent-core/src/tools/builtin/shell/bash.ts index 2320b2e41b..c1f2d19abf 100644 --- a/packages/agent-core/src/tools/builtin/shell/bash.ts +++ b/packages/agent-core/src/tools/builtin/shell/bash.ts @@ -430,7 +430,7 @@ export class BashTool implements BuiltinTool { } const info = backgroundManager.getTask(taskId); if (info && info.status === 'running') { - void backgroundManager.stop(taskId); + void backgroundManager.stop(taskId, 'Timed out'); } })(); }, timeoutMs);