Skip to content

Commit ebe0b7f

Browse files
authored
fix: always wait for agent idle before sending input to existing task (#10)
When an existing task has status 'active', the action previously skipped waitForTaskActive and immediately called sendTaskInput. But the task can be active while the agent is still processing a previous prompt (current_state.state === 'working'). This causes 409/502 errors from the server because the agent isn't ready to accept input. Remove the status guard so waitForTaskActive always runs for existing tasks. The function already handles the active+idle case correctly by returning immediately.
1 parent a2f4758 commit ebe0b7f

3 files changed

Lines changed: 38 additions & 20 deletions

File tree

dist/index.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,43 @@ var __getProtoOf = Object.getPrototypeOf;
33
var __defProp = Object.defineProperty;
44
var __getOwnPropNames = Object.getOwnPropertyNames;
55
var __hasOwnProp = Object.prototype.hasOwnProperty;
6+
function __accessProp(key) {
7+
return this[key];
8+
}
9+
var __toESMCache_node;
10+
var __toESMCache_esm;
611
var __toESM = (mod, isNodeMode, target) => {
12+
var canCache = mod != null && typeof mod === "object";
13+
if (canCache) {
14+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
15+
var cached = cache.get(mod);
16+
if (cached)
17+
return cached;
18+
}
719
target = mod != null ? __create(__getProtoOf(mod)) : {};
820
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
921
for (let key of __getOwnPropNames(mod))
1022
if (!__hasOwnProp.call(to, key))
1123
__defProp(to, key, {
12-
get: () => mod[key],
24+
get: __accessProp.bind(mod, key),
1325
enumerable: true
1426
});
27+
if (canCache)
28+
cache.set(mod, to);
1529
return to;
1630
};
1731
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
32+
var __returnValue = (v) => v;
33+
function __exportSetter(name, newValue) {
34+
this[name] = __returnValue.bind(null, newValue);
35+
}
1836
var __export = (target, all) => {
1937
for (var name in all)
2038
__defProp(target, name, {
2139
get: all[name],
2240
enumerable: true,
2341
configurable: true,
24-
set: (newValue) => all[name] = () => newValue
42+
set: __exportSetter.bind(all, name)
2543
});
2644
};
2745

@@ -3447,7 +3465,7 @@ var require_constants2 = __commonJS((exports2, module2) => {
34473465
}
34483466
})();
34493467
var channel;
3450-
var structuredClone = globalThis.structuredClone ?? function structuredClone(value, options = undefined) {
3468+
var structuredClone = globalThis.structuredClone ?? function structuredClone2(value, options = undefined) {
34513469
if (arguments.length === 0) {
34523470
throw new TypeError("missing argument");
34533471
}
@@ -16372,7 +16390,7 @@ var require_undici = __commonJS((exports2, module2) => {
1637216390
module2.exports.getGlobalDispatcher = getGlobalDispatcher;
1637316391
if (util.nodeMajor > 16 || util.nodeMajor === 16 && util.nodeMinor >= 8) {
1637416392
let fetchImpl = null;
16375-
module2.exports.fetch = async function fetch(resource) {
16393+
module2.exports.fetch = async function fetch2(resource) {
1637616394
if (!fetchImpl) {
1637716395
fetchImpl = require_fetch().fetch;
1637816396
}
@@ -26966,10 +26984,8 @@ class CoderTaskAction {
2696626984
const existingTask = await this.coder.getTask(coderUsername, taskName);
2696726985
if (existingTask) {
2696826986
core.info(`Coder Task: already exists: ${existingTask.name} (id: ${existingTask.id} status: ${existingTask.status})`);
26969-
if (existingTask.status !== "active") {
26970-
core.info(`Coder Task: waiting for task ${existingTask.name} to become active...`);
26971-
await this.coder.waitForTaskActive(coderUsername, existingTask.id, core.debug, 1200000);
26972-
}
26987+
core.info(`Coder Task: waiting for task ${existingTask.name} to become active and idle...`);
26988+
await this.coder.waitForTaskActive(coderUsername, existingTask.id, core.debug, 1200000);
2697326989
core.info("Coder Task: Sending prompt to existing task...");
2697426990
await this.coder.sendTaskInput(coderUsername, existingTask.id, this.inputs.coderTaskPrompt);
2697526991
core.info("Coder Task: Prompt sent successfully");

src/action.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,7 @@ describe("CoderTaskAction", () => {
867867
);
868868
coderClient.mockGetTemplateVersionPresets.mockResolvedValue([]);
869869
coderClient.mockSendTaskInput.mockResolvedValue(undefined);
870+
coderClient.mockWaitForTaskActive.mockResolvedValue(undefined);
870871
octokit.rest.issues.listComments.mockResolvedValue({
871872
data: [],
872873
} as ReturnType<typeof octokit.rest.issues.listComments>);

src/action.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,19 @@ export class CoderTaskAction {
173173
`Coder Task: already exists: ${existingTask.name} (id: ${existingTask.id} status: ${existingTask.status})`,
174174
);
175175

176-
// Wait for task to become active if it's not already
177-
if (existingTask.status !== "active") {
178-
core.info(
179-
`Coder Task: waiting for task ${existingTask.name} to become active...`,
180-
);
181-
await this.coder.waitForTaskActive(
182-
coderUsername,
183-
existingTask.id,
184-
core.debug,
185-
1_200_000,
186-
);
187-
}
176+
// Wait for task to become active and idle before sending
177+
// input. The agent may be in "working" state even when the
178+
// task status is "active", and sending input in that state
179+
// causes 409/502 errors.
180+
core.info(
181+
`Coder Task: waiting for task ${existingTask.name} to become active and idle...`,
182+
);
183+
await this.coder.waitForTaskActive(
184+
coderUsername,
185+
existingTask.id,
186+
core.debug,
187+
1_200_000,
188+
);
188189

189190
core.info("Coder Task: Sending prompt to existing task...");
190191
// Send prompt to existing task using the task ID (UUID)

0 commit comments

Comments
 (0)