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(desktop): limit an active resume to the origin it resumes

shoudi zhenge05bc3befad5
diff --git a/apps/desktop/src/main/local-server-resume.test.ts b/apps/desktop/src/main/local-server-resume.test.ts
index 3aace3ac..e1757852 100644
--- a/apps/desktop/src/main/local-server-resume.test.ts
+++ b/apps/desktop/src/main/local-server-resume.test.ts
@@ -95,7 +95,7 @@ function setupResumeFixture(installerScript: string) {
}
describe("LocalServerModule resume coordination", () => {
- it("tracks resuming(), passes resume_ready, and emits structured stage logs", async () => {
+ it("passes resume_ready and emits structured stage logs", async () => {
const f = setupResumeFixture(`
setTimeout(() => {
process.stdout.write(JSON.stringify({ code: 0, details: { origin: "http://localhost:3000" } }) + "\\n");
@@ -103,10 +103,8 @@ describe("LocalServerModule resume coordination", () => {
`);
await f.host.start();
- expect(f.module.resuming()).toBe(true);
await vi.waitFor(() => expect(f.module.status().phase).toBe("ready"));
- expect(f.module.resuming()).toBe(false);
expect(f.showStarting).toHaveBeenCalledOnce();
expect(f.setServer).toHaveBeenCalledWith(
"http://localhost:3000",
@@ -144,7 +142,6 @@ describe("LocalServerModule resume coordination", () => {
await f.host.start();
await vi.waitFor(() => expect(f.module.status().phase).toBe("failed"));
- expect(f.module.resuming()).toBe(false);
const failed = f.logs.find(
(entry) => entry.event === "local_server.resume_failed",
@@ -160,7 +157,7 @@ describe("LocalServerModule resume coordination", () => {
await f.host.stop("quit");
});
- it("reports resumable() true while resuming, true for a valid matching record, and false for malformed or incomplete records", async () => {
+ it("reports resumable() true for the resuming origin only, true for a valid matching record, and false for malformed or incomplete records", async () => {
const f = setupResumeFixture(`
setTimeout(() => {
process.stdout.write(JSON.stringify({ code: 0, details: { origin: "http://localhost:3000" } }) + "\\n");
@@ -168,13 +165,16 @@ describe("LocalServerModule resume coordination", () => {
`);
await f.host.start();
- expect(f.module.resuming()).toBe(true);
- await expect(f.module.resumable("http://localhost:9999")).resolves.toBe(
+ // An active resume vouches only for the origin it resumes, not for a
+ // remote server the user switched to meanwhile.
+ await expect(f.module.resumable("http://localhost:3000")).resolves.toBe(
true,
);
+ await expect(f.module.resumable("http://localhost:9999")).resolves.toBe(
+ false,
+ );
await vi.waitFor(() => expect(f.module.status().phase).toBe("ready"));
- expect(f.module.resuming()).toBe(false);
await expect(
f.module.resumable("http://localhost:3000/rooms/1"),
).resolves.toBe(true);
diff --git a/apps/desktop/src/main/local-server.ts b/apps/desktop/src/main/local-server.ts
index 2009f660..bd3b1f77 100644
--- a/apps/desktop/src/main/local-server.ts
+++ b/apps/desktop/src/main/local-server.ts
@@ -584,12 +584,9 @@ export class LocalServerModule implements Module {
}
}
- resuming(): boolean {
- return this.#resuming;
- }
-
async resumable(serverUrl: string): Promise<boolean> {
- if (this.#resuming) return true;
+ if (this.#resuming && this.#origin && sameOrigin(this.#origin, serverUrl))
+ return true;
const record = await this.#readRecord();
return record !== undefined && sameOrigin(record.origin, serverUrl);
}
diff --git a/apps/desktop/src/main/navigation.test.ts b/apps/desktop/src/main/navigation.test.ts
index 626361c3..02f1277c 100644
--- a/apps/desktop/src/main/navigation.test.ts
+++ b/apps/desktop/src/main/navigation.test.ts
@@ -228,7 +228,7 @@ describe("windowLoadDecision", () => {
},
local,
moved,
- { movedFrom: local },
+ { movedFrom: local, reason: "port_moved" },
),
).toEqual({ action: "load", targetUrl: moved, reason: "port_moved" });
diff --git a/apps/desktop/src/main/navigation.ts b/apps/desktop/src/main/navigation.ts
index e36d0cca..49fc9a1a 100644
--- a/apps/desktop/src/main/navigation.ts
+++ b/apps/desktop/src/main/navigation.ts
@@ -66,20 +66,13 @@ export function windowLoadDecision(
state: WindowLoadState,
currentServerUrl: string | undefined,
nextOrigin: string,
- options?: { movedFrom?: string; reason?: WindowLoadReason },
+ options: { movedFrom?: string; reason: WindowLoadReason },
): WindowLoadDecision {
const targetOrigin = parseServerUrl(nextOrigin);
const sw = targetOrigin
- ? serverSwitch(currentServerUrl, targetOrigin, options?.movedFrom)
+ ? serverSwitch(currentServerUrl, targetOrigin, options.movedFrom)
: undefined;
- const reason: WindowLoadReason =
- options?.reason ??
- (sw?.moved &&
- currentServerUrl !== undefined &&
- options?.movedFrom !== undefined &&
- sameOrigin(currentServerUrl, options.movedFrom)
- ? "port_moved"
- : "server_changed");
+ const { reason } = options;
if (!targetOrigin) return { action: "noop", reason };
// Keep the current server when a non-explicit load targets another server,
@@ -91,7 +84,7 @@ export function windowLoadDecision(
reason !== "local_ready" &&
!(
sw?.moved &&
- options?.movedFrom !== undefined &&
+ options.movedFrom !== undefined &&
sameOrigin(currentServerUrl, options.movedFrom)
)
) {
diff --git a/apps/desktop/src/main/window-manager.ts b/apps/desktop/src/main/window-manager.ts
index a7c97550..923766f4 100644
--- a/apps/desktop/src/main/window-manager.ts
+++ b/apps/desktop/src/main/window-manager.ts
@@ -466,7 +466,7 @@ export class WindowManagerModule implements Module {
#navigateToServer(
targetOrigin: string,
- options?: { movedFrom?: string; reason?: WindowLoadReason },
+ options: { movedFrom?: string; reason: WindowLoadReason },
): void {
const contents = this.#content?.webContents;
if (!contents || contents.isDestroyed()) return;