feat: block follow-up IPC after closeStdin with closingStdin flag

Prevent piping new messages to an agent that is shutting down.
Reset flag on new process start and cleanup.
This commit is contained in:
Eyejoker
2026-03-16 05:39:35 +09:00
parent ea03956d0a
commit 385f3a0349
2 changed files with 46 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ const BASE_RETRY_MS = 5000;
interface GroupState {
active: boolean;
idleWaiting: boolean;
closingStdin: boolean;
isTaskProcess: boolean;
runningTaskId: string | null;
currentRunId: string | null;
@@ -57,6 +58,7 @@ export class GroupQueue {
state = {
active: false,
idleWaiting: false,
closingStdin: false,
isTaskProcess: false,
runningTaskId: null,
currentRunId: null,
@@ -215,6 +217,7 @@ export class GroupQueue {
groupJid,
runId: state.currentRunId,
active: state.active,
closingStdin: state.closingStdin,
groupFolder: state.groupFolder,
isTaskProcess: state.isTaskProcess,
},
@@ -222,6 +225,13 @@ export class GroupQueue {
);
return false;
}
if (state.closingStdin) {
logger.info(
{ groupJid, runId: state.currentRunId, groupFolder: state.groupFolder },
'Skipping follow-up IPC because active agent is closing',
);
return false;
}
state.idleWaiting = false; // Agent is about to receive work, no longer idle
const inputDir = path.join(DATA_DIR, 'ipc', state.groupFolder, 'input');
@@ -266,6 +276,8 @@ export class GroupQueue {
): void {
const state = this.getGroup(groupJid);
if (!state.active || !state.groupFolder) return;
state.closingStdin = true;
state.idleWaiting = false;
const inputDir = path.join(DATA_DIR, 'ipc', state.groupFolder, 'input');
try {
@@ -302,6 +314,7 @@ export class GroupQueue {
const runId = this.createRunId();
state.active = true;
state.idleWaiting = false;
state.closingStdin = false;
state.isTaskProcess = false;
state.currentRunId = runId;
state.pendingMessages = false;
@@ -350,6 +363,8 @@ export class GroupQueue {
);
state.active = false;
state.startedAt = null;
state.idleWaiting = false;
state.closingStdin = false;
state.process = null;
state.processName = null;
state.groupFolder = null;
@@ -363,6 +378,7 @@ export class GroupQueue {
const state = this.getGroup(groupJid);
state.active = true;
state.idleWaiting = false;
state.closingStdin = false;
state.isTaskProcess = true;
state.runningTaskId = task.id;
state.startedAt = Date.now();
@@ -382,6 +398,8 @@ export class GroupQueue {
state.isTaskProcess = false;
state.runningTaskId = null;
state.startedAt = null;
state.idleWaiting = false;
state.closingStdin = false;
state.process = null;
state.processName = null;
state.groupFolder = null;