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): let a Codex Run yield once it is thinking or streaming
LeoXing05a2834d799a
diff --git a/apps/node-services/src/agent/runner-gateway/runner-operation.ts b/apps/node-services/src/agent/runner-gateway/runner-operation.tsindex e0a1b13b..26bf91d5 100644--- a/apps/node-services/src/agent/runner-gateway/runner-operation.ts+++ b/apps/node-services/src/agent/runner-gateway/runner-operation.ts@@ -610,7 +610,9 @@ export class RunnerOperationState {}get resumable(): boolean {- // Codex announces its thread before the first input is durably in its history.+ // Codex announces its thread before the first input is durably in its+ // history. Any model output, thinking included, comes after Codex+ // recorded that input.return (Boolean(this.#yieldSessionId) &&(this.start.runtime_type !== "codex" || this.#observedNativeWork)@@ -888,7 +890,10 @@ export class RunnerOperationState {if (envelope.event.type === "tool.called" ||envelope.event.type === "tool.returned" ||- envelope.event.type === "model.responded"+ envelope.event.type === "model.responded" ||+ envelope.event.type === "message.delta" ||+ (envelope.event.type === "status.changed" &&+ envelope.event.status === "thinking"))this.#observedNativeWork = true;if (envelope.event.type === "human_interaction.requested") {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.tsindex 646f1c32..4f5f9190 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@@ -203,6 +203,87 @@ describe("RunnerGateway", () => {},);+ it.each([+ ["thinking", { type: "status.changed", status: "thinking" }],+ [+ "streaming its answer",+ { type: "message.delta", message_id: "answer", delta: "Hel" },+ ],+ ] as const)(+ "lets a Codex Run yield to chat once it is %s",+ async (_, work) => {+ 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",+ });+ task.result.catch(() => undefined);+ const start = peer.sent.find(+ (command) => command.type === "operation.start",+ )!;+ const chat = gateway.startOperation({+ ...runTarget(),+ ...readyContextScope("chat"),+ runKind: "chat",+ });+ // The chat never starts here; the disconnect ends its wait.+ chat.then(+ (interactive) => interactive.result.catch(() => undefined),+ () => undefined,+ );+ await connection.receive(+ event(start, 1, {+ type: "operation.accepted",+ command_id: start.command_id,+ runner_pid: 100,+ }),+ );+ await connection.receive(+ event(start, 2, {+ type: "operation.event",+ event: {+ type: "run.started",+ turn_id: "turn-task",+ session: { threadId: "task-session", canYield: true },+ },+ }),+ );+ await connection.receive(+ event(start, 3, {+ type: "operation.event",+ event: { type: "status.changed", status: "working" },+ }),+ );+ expect(await settlesWithin(chat, 10)).toBe(false);+ expect(peer.sent.some((command) => command.type === "cancel")).toBe(+ false,+ );+ await connection.receive(+ event(start, 4, { type: "operation.event", event: work }),+ );+ await vi.waitFor(() =>+ expect(+ peer.sent.find((command) => command.type === "cancel"),+ ).toMatchObject({+ operation_id: start.operation_id,+ reason: "scheduler_yield",+ }),+ );+ } finally {+ connection.disconnect();+ }+ },+ );+it("keeps a user-stopped Task's place through the cancel timeout and a later chat", async () => {const gateway = createTestRunnerGateway({createId: sequenceIds(),diff --git a/docs/model-scheduling.md b/docs/model-scheduling.mdindex e26ec14d..0d33f2ee 100644--- a/docs/model-scheduling.md+++ b/docs/model-scheduling.md@@ -43,11 +43,12 @@ When work at chat priority or above is first in line and cannot start, it asksthe lowest-priority running Run below it on that endpoint or Computer to yield,one Run at a time and at any limit. A recording question can swap out a chat,and a chat can swap out a Task or a routine. A Run can yield once the Runtime-has a resumable native session. On Codex, the Run must also have reached its-first model response or tool event so that its original input is in its-history. A pending tool approval or human interaction is answered before-yielding. The waiting work starts after the Computer confirms cleanup. A Run-that finishes on its own while it is asked to yield completes normally.+has a resumable native session. On Codex, the Run must also have produced+model output, its thinking included, or a tool event so that its original+input is in its history. A pending tool approval or human interaction is+answered before yielding. The waiting work starts after the Computer confirms+cleanup. A Run that finishes on its own while it is asked to yield completes+normally.The yielded Run keeps its ID, running status and claim while it waits, andcontinues in the same session when admitted again. A user stop still ends it.If a yielded Run's cleanup cannot be confirmed, the Computer refuses further