Skip to content

Commit 422dbcf

Browse files
committed
fix(task): satisfy startup race lint
1 parent 872a83c commit 422dbcf

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/agent/agent-task-executor.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,9 +1543,10 @@ async function spawnClaudeTaskIsolated(agent, context) {
15431543
resolveWrapperClose = resolveClose;
15441544
});
15451545
const markWrapperClosed = () => {
1546-
if (wrapperClosed) return;
1547-
wrapperClosed = true;
1548-
resolveWrapperClose();
1546+
if (!wrapperClosed) {
1547+
wrapperClosed = true;
1548+
resolveWrapperClose();
1549+
}
15491550
};
15501551
proc.once('close', markWrapperClosed);
15511552
proc.once('error', markWrapperClosed);
@@ -1629,7 +1630,7 @@ async function spawnClaudeTaskIsolated(agent, context) {
16291630
});
16301631

16311632
proc.on('error', (error) => {
1632-
if (!isolatedTaskId && agent.currentTask === pendingLaunch) {
1633+
if (!isolatedTaskId && agent.currentTask === isolatedPendingLaunch) {
16331634
agent.currentTask = null;
16341635
}
16351636
clearTimeout(spawnTimeout);
@@ -2332,15 +2333,15 @@ async function killTask(agent, termination = 'Task killed') {
23322333
const taskId = agent.currentTaskId;
23332334

23342335
if (currentTask?.pendingLaunch && typeof currentTask.kill === 'function') {
2335-
const termination = await currentTask.kill(reason, { code });
2336-
if (termination?.forced === false) return termination;
2336+
const pendingTermination = await currentTask.kill(reason, { code });
2337+
if (pendingTermination?.forced === false) return pendingTermination;
23372338
agent._stopLivenessCheck?.();
23382339
agent.currentTask = null;
23392340
agent.currentTaskId = null;
23402341
agent.processPid = null;
23412342
agent.lastOutputTime = null;
23422343
agent.taskStartedAt = null;
2343-
return termination;
2344+
return pendingTermination;
23442345
}
23452346

23462347
if (agent.isolation?.enabled && taskId) {

tests/agent-stuck-recovery.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const assert = require('assert');
22
const fs = require('fs');
33
const os = require('os');
44
const path = require('path');
5+
const { URL } = require('node:url');
56

67
const { startLivenessCheck, stopLivenessCheck } = require('../src/agent/agent-lifecycle');
78
const { killTask, spawnTaskProcess } = require('../src/agent/agent-task-executor');

0 commit comments

Comments
 (0)