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
6 changes: 6 additions & 0 deletions .changeset/subagent-stop-wording.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@moonshot-ai/agent-core": patch
"@moonshot-ai/kimi-code": patch
---

Clarify subagent and background task stop messages as user-initiated.
2 changes: 1 addition & 1 deletion apps/kimi-code/src/tui/controllers/tasks-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion packages/agent-core/src/agent/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
29 changes: 17 additions & 12 deletions packages/agent-core/src/tools/builtin/collaboration/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -299,12 +300,14 @@ export class AgentTool implements BuiltinTool<AgentToolInput> {
];
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}`,
Expand All @@ -315,12 +318,14 @@ export class AgentTool implements BuiltinTool<AgentToolInput> {
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();
Expand Down
2 changes: 1 addition & 1 deletion packages/agent-core/src/tools/builtin/shell/bash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ export class BashTool implements BuiltinTool<BashInput> {
}
const info = backgroundManager.getTask(taskId);
if (info && info.status === 'running') {
void backgroundManager.stop(taskId);
void backgroundManager.stop(taskId, 'Timed out');
}
})();
}, timeoutMs);
Expand Down
Loading