mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-07-10 01:39:25 +00:00
fix(agent-core): suppress close-time background notifications (#804)
This commit is contained in:
parent
aa1896ca74
commit
299b9fcad4
3 changed files with 39 additions and 3 deletions
6
.changeset/suppress-background-close-notifications.md
Normal file
6
.changeset/suppress-background-close-notifications.md
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
"@moonshot-ai/agent-core": patch
|
||||
"@moonshot-ai/kimi-code": patch
|
||||
---
|
||||
|
||||
Prevent session shutdown from resuming the agent when stopping background tasks.
|
||||
|
|
@ -346,9 +346,15 @@ export class Session {
|
|||
});
|
||||
if (keepAliveOnExit) return;
|
||||
await Promise.all(
|
||||
Array.from(this.readyAgents(), (agent) =>
|
||||
agent.background.stopAll('Session closed'),
|
||||
),
|
||||
Array.from(this.readyAgents(), async (agent) => {
|
||||
const activeTasks = agent.background.list(true);
|
||||
await Promise.all(
|
||||
activeTasks.map((task) =>
|
||||
agent.background.suppressTerminalNotification(task.taskId),
|
||||
),
|
||||
);
|
||||
await agent.background.stopAll('Session closed');
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -131,6 +131,30 @@ describe('Session lifecycle hooks', () => {
|
|||
expect(agent.background.getTask(taskId)?.status).toBe('killed');
|
||||
});
|
||||
|
||||
it('does not steer background task notifications while closing the session', async () => {
|
||||
const { sessionDir, workDir } = await hookFixture();
|
||||
const session = new Session({
|
||||
kaos: testKaos.withCwd(workDir),
|
||||
id: 'session-bg-cleanup-no-steer',
|
||||
homedir: sessionDir,
|
||||
rpc: createSessionRpc(),
|
||||
skills: { explicitDirs: [join(workDir, 'missing-skills')] },
|
||||
});
|
||||
const agent = await session.createMain();
|
||||
const steerSpy = vi.spyOn(agent.turn, 'steer');
|
||||
const { proc, killSpy } = pendingProcess();
|
||||
const taskId = agent.background.registerTask(
|
||||
new ProcessBackgroundTask(proc, 'sleep 60', 'exit cleanup without steer'),
|
||||
);
|
||||
|
||||
await session.close();
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
|
||||
expect(killSpy).toHaveBeenCalledWith('SIGTERM');
|
||||
expect(agent.background.getTask(taskId)?.status).toBe('killed');
|
||||
expect(steerSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('keeps background tasks alive on close when keepAliveOnExit is true', async () => {
|
||||
const { sessionDir, workDir } = await hookFixture();
|
||||
const session = new Session({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue