Skip to content

Commit 2f53028

Browse files
committed
refactor: drop unused message timestamp and max-age filter
1 parent 4742f43 commit 2f53028

3 files changed

Lines changed: 8 additions & 43 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
## Unreleased
99

10+
### Added
11+
12+
- Opening a workspace that's already connected in another VS Code window now shows a prompt
13+
to **Duplicate Window** (preserving tabs and panels) or **Open Without Folder**, instead of
14+
just focusing the existing window with no way to open a second view of the same workspace.
15+
1016
### Fixed
1117

1218
- The **Coder: Workspace Build** output channel is no longer created when reconnecting to an

src/workspace/duplicateWorkspaceIpc.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type { Disposable, SecretStorage } from "vscode";
77

88
import type { Logger } from "../logging/logger";
99

10-
const MESSAGE_MAX_AGE_MS = 5000;
1110
const DEFAULT_PING_TIMEOUT_MS = 1000;
1211

1312
const REQUEST_KEY = "coder.ipc.req";
@@ -17,21 +16,18 @@ const PingMessageSchema = z.object({
1716
type: z.literal("ping"),
1817
id: z.string(),
1918
authority: z.string(),
20-
ts: z.number(),
2119
});
2220

2321
const PongMessageSchema = z.object({
2422
type: z.literal("pong"),
2523
id: z.string(),
2624
sessionId: z.string(),
27-
ts: z.number(),
2825
});
2926

3027
const DuplicateMessageSchema = z.object({
3128
type: z.literal("duplicate"),
3229
id: z.string(),
3330
targetSessionId: z.string(),
34-
ts: z.number(),
3531
});
3632

3733
const RequestMessageSchema = z.discriminatedUnion("type", [
@@ -104,7 +100,7 @@ export class DuplicateWorkspaceIpc {
104100
const timer = setTimeout(() => settle(undefined), timeoutMs);
105101

106102
this.requests
107-
.send({ type: "ping", id, authority, ts: Date.now() })
103+
.send({ type: "ping", id, authority })
108104
.then(undefined, (err: unknown) => {
109105
this.logger.error("Failed to send IPC ping", err);
110106
settle(undefined);
@@ -117,7 +113,6 @@ export class DuplicateWorkspaceIpc {
117113
type: "pong",
118114
id: pingId,
119115
sessionId,
120-
ts: Date.now(),
121116
});
122117
}
123118

@@ -127,19 +122,12 @@ export class DuplicateWorkspaceIpc {
127122
type: "duplicate",
128123
id: crypto.randomUUID(),
129124
targetSessionId,
130-
ts: Date.now(),
131125
});
132126
}
133127

134-
/** Listen for incoming requests. Stale messages are dropped. */
135128
onRequest(
136129
handler: (msg: RequestMessage) => void | Promise<void>,
137130
): Disposable {
138-
return this.requests.onReceive((msg) => {
139-
if (Date.now() - msg.ts > MESSAGE_MAX_AGE_MS) {
140-
return;
141-
}
142-
return handler(msg);
143-
});
131+
return this.requests.onReceive(handler);
144132
}
145133
}

test/unit/workspace/duplicateWorkspaceIpc.test.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,35 +46,6 @@ describe("DuplicateWorkspaceIpc", () => {
4646
expect(await promise).toBeUndefined();
4747
});
4848

49-
it("delivers fresh requests but drops stale ones", async () => {
50-
const { secrets, sender, receiver } = makeIpcPair();
51-
const handler = vi.fn();
52-
receiver.onRequest(handler);
53-
54-
// Replay an old request directly through storage.
55-
await secrets.store(
56-
"coder.ipc.req",
57-
JSON.stringify({
58-
type: "ping",
59-
id: "old",
60-
authority: "ssh-remote+host",
61-
ts: Date.now() - 10_000,
62-
}),
63-
);
64-
await vi.advanceTimersByTimeAsync(10);
65-
expect(handler).not.toHaveBeenCalled();
66-
67-
// A fresh sendDuplicate should be delivered.
68-
await sender.sendDuplicate("session-fresh");
69-
await vi.advanceTimersByTimeAsync(10);
70-
expect(handler).toHaveBeenCalledWith(
71-
expect.objectContaining({
72-
type: "duplicate",
73-
targetSessionId: "session-fresh",
74-
}),
75-
);
76-
});
77-
7849
it("supports the full ping → pong → duplicate round trip", async () => {
7950
const { secrets, sender } = makeIpcPair();
8051
const duplicateReceived = vi.fn();

0 commit comments

Comments
 (0)