Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

fix(scheduler): retain a stopped task until daemon confirmation

LeoXing75067e990e45
diff --git a/apps/node-services/src/agent/runner-gateway/runner-operation.ts b/apps/node-services/src/agent/runner-gateway/runner-operation.ts
index 97559f70..ff43cf8d 100644
--- a/apps/node-services/src/agent/runner-gateway/runner-operation.ts
+++ b/apps/node-services/src/agent/runner-gateway/runner-operation.ts
@@ -1018,7 +1018,9 @@ export class RunnerOperationState {
message,
);
} catch {
- if (this.#terminal || this.#yieldRequested) return;
+ // A user stop may precede a chat waiter. Retain the Task's occupation
+ // until the Computer reports a terminal, including across reconnects.
+ if (this.#terminal || this.#delegatedTask) return;
this.#complete(() =>
this.#outcome.reject(
new RunnerOperationError("cancelled", message, false),
diff --git a/apps/node-services/tests/agent/runner-gateway/runner-operations-public.test.ts b/apps/node-services/tests/agent/runner-gateway/runner-operations-public.test.ts
index de105b15..9660f4a9 100644
--- a/apps/node-services/tests/agent/runner-gateway/runner-operations-public.test.ts
+++ b/apps/node-services/tests/agent/runner-gateway/runner-operations-public.test.ts
@@ -199,6 +199,63 @@ describe("RunnerGateway", () => {
},
);
+ it("keeps a user-stopped Task's place through the cancel timeout and a later chat", async () => {
+ const gateway = createTestRunnerGateway({
+ createId: sequenceIds(),
+ operationCancelTimeoutMs: 10,
+ });
+ const peer = new RecordingPeer();
+ const connection = await acceptReadyConnection(gateway, peer, {
+ ...hello([], 1),
+ runtime_diagnostics: runtimeDiagnostics({ link: "api" }),
+ });
+ try {
+ const task = await gateway.startOperation({
+ ...runTarget(),
+ runKind: "task",
+ });
+ const start = peer.sent.find(
+ (command) => command.type === "operation.start",
+ )!;
+ await connection.receive(
+ event(start, 1, {
+ type: "operation.accepted",
+ command_id: start.command_id,
+ runner_pid: 100,
+ }),
+ );
+ const stopped = expect(task.result).rejects.toMatchObject({
+ code: "cancelled",
+ });
+ await task.cancel("user_stop");
+ await connection.receive(
+ event(start, 2, {
+ type: "operation.event",
+ event: { type: "status.changed", status: "working" },
+ }),
+ );
+ const chat = gateway.startOperation({
+ ...runTarget(),
+ ...readyContextScope("chat"),
+ runKind: "chat",
+ });
+ expect(await settlesWithin(task.result, 15)).toBe(false);
+ expect(await settlesWithin(chat, 15)).toBe(false);
+ expect(
+ peer.sent
+ .filter((command) => command.type === "cancel")
+ .map((command) => command.reason),
+ ).toEqual(["user_stop"]);
+ await connection.receive(
+ event(start, 3, { type: "operation.cancelled", reason: "user_stop" }),
+ );
+ await stopped;
+ void (await chat).result.catch(() => undefined);
+ } finally {
+ connection.disconnect();
+ }
+ });
+
it("records the Runtime turn a Run's Operation started as soon as it starts", async () => {
const recordRunOperation = vi.fn(async () => {});
const gateway = createTestRunnerGateway({