fix(agent-manager): persist agent state before killing to enable resumption
This commit is contained in:
@@ -499,7 +499,7 @@ export class AgentManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Kill an agent
|
* Kill an agent
|
||||||
* Terminates the process and removes it from the manager
|
* Terminates the process but keeps it in persistence for resumption
|
||||||
*/
|
*/
|
||||||
async killAgent(agentId: string): Promise<void> {
|
async killAgent(agentId: string): Promise<void> {
|
||||||
const agent = this.agents.get(agentId);
|
const agent = this.agents.get(agentId);
|
||||||
@@ -509,15 +509,25 @@ export class AgentManager {
|
|||||||
|
|
||||||
const runtime = this.getRuntime(agent);
|
const runtime = this.getRuntime(agent);
|
||||||
|
|
||||||
|
// Persist current state before killing
|
||||||
|
if (runtime) {
|
||||||
|
await this.persistence.upsert({
|
||||||
|
id: agent.id,
|
||||||
|
title: agent.title || `Agent ${agent.id.slice(0, 8)}`,
|
||||||
|
sessionId: runtime.sessionId,
|
||||||
|
options: agent.options,
|
||||||
|
createdAt: agent.createdAt.toISOString(),
|
||||||
|
lastActivityAt: agent.lastActivityAt.toISOString(),
|
||||||
|
cwd: agent.cwd,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
agent.state = { type: "killed" };
|
agent.state = { type: "killed" };
|
||||||
|
|
||||||
// Notify subscribers BEFORE removing from manager
|
// Notify subscribers BEFORE removing from manager
|
||||||
// This ensures subscribers can still query agent info
|
// This ensures subscribers can still query agent info
|
||||||
this.notifySubscribers(agentId);
|
this.notifySubscribers(agentId);
|
||||||
|
|
||||||
// Remove from persistence
|
|
||||||
await this.persistence.remove(agentId);
|
|
||||||
|
|
||||||
// Kill the process
|
// Kill the process
|
||||||
if (runtime) {
|
if (runtime) {
|
||||||
runtime.process.kill("SIGTERM");
|
runtime.process.kill("SIGTERM");
|
||||||
|
|||||||
Reference in New Issue
Block a user