mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-22 04:19:40 +00:00
fix(a2a): abort a task's signal when the TTL cleanup fails it
cleanupExpired marked an expired task failed and dropped its controller without aborting it, so a running smart-routing fetch kept going until its own timeout. Covered by a failing-then-passing fake-timer test. Also clear OMNIROUTE_PORT (and restore the port env afterwards) in the exact config-status test, which expects the default port.
This commit is contained in:
@@ -362,6 +362,8 @@ export class A2ATaskManager {
|
||||
task.state !== "cancelled"
|
||||
) {
|
||||
task.state = "failed";
|
||||
// Stop the running work too, or its upstream call runs on until its own timeout.
|
||||
this.aborts.get(id)?.abort();
|
||||
this.aborts.delete(id);
|
||||
task.updatedAt = now.toISOString();
|
||||
task.events.push({ timestamp: now.toISOString(), state: "failed", message: "TTL expired" });
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* Uses a fake persistence object — no SQLite, no DATA_DIR.
|
||||
*/
|
||||
import test from "node:test";
|
||||
import test, { mock } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import { A2ATaskManager, type A2APersistence } from "../../src/lib/a2a/taskManager.ts";
|
||||
@@ -99,3 +99,20 @@ test("a task that already failed still rejects an unrelated transition", () => {
|
||||
|
||||
assert.throws(() => tm.updateTask(task.id, "working"), /Invalid transition: failed → working/);
|
||||
});
|
||||
|
||||
test("a task failed by the TTL cleanup aborts the signal its running work holds", () => {
|
||||
mock.timers.enable({ apis: ["setInterval", "Date"], now: Date.now() });
|
||||
try {
|
||||
const tm = newManager(); // 5-minute TTL; the cleanup runs every 60 s
|
||||
const task = newWorkingTask(tm);
|
||||
const signal = tm.getTaskSignal(task.id);
|
||||
assert.equal(signal?.aborted, false);
|
||||
|
||||
mock.timers.tick(6 * 60_000);
|
||||
|
||||
assert.equal(tm.getTask(task.id)?.state, "failed");
|
||||
assert.equal(signal?.aborted, true, "the expired task's upstream work is told to stop");
|
||||
} finally {
|
||||
mock.timers.reset();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -12,8 +12,16 @@ import path from "node:path";
|
||||
import os from "node:os";
|
||||
|
||||
process.env.DATA_DIR = path.join(os.tmpdir(), "omniroute-check-tool-exact-test");
|
||||
delete process.env.API_PORT;
|
||||
delete process.env.PORT;
|
||||
// The expected URLs use the default port: clear every variable that moves it, restore after.
|
||||
const PORT_ENV = ["API_PORT", "PORT", "OMNIROUTE_PORT"] as const;
|
||||
const savedPortEnv = PORT_ENV.map((name) => [name, process.env[name]] as const);
|
||||
for (const name of PORT_ENV) delete process.env[name];
|
||||
test.after(() => {
|
||||
for (const [name, value] of savedPortEnv) {
|
||||
if (value === undefined) delete process.env[name];
|
||||
else process.env[name] = value;
|
||||
}
|
||||
});
|
||||
|
||||
const { checkToolConfigStatus } = await import("../../src/lib/cliTools/checkToolConfigStatus.ts");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user