The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 25, 16:00 UTC
Return existing bootstrap thread IDs in welcome and guard root navigatio
- Server welcome now includes bootstrap project/thread IDs when cwd project/thread already exist - Added regression test for reconnecting with persisted bootstrap state - Root route ignores post-dispose welcome handling and marks thread as handled after navigate
Julius Marminge committed
Feb 26, 2026 at 20:34 UTC
49472da6699256f6aafc88820e482e403d0ab693
3 files changed
+63
-2
apps/server/src/wsServer.test.ts
+56
-1
@@ -38,7 +38,7 @@ import type {
38
TerminalWriteInput,
39
} from "@t3tools/contracts";
40
import { TerminalManager, type TerminalManagerShape } from "./terminal/Services/Manager";
41
-import { SqlitePersistenceMemory } from "./persistence/Layers/Sqlite";
41
+import { makeSqlitePersistenceLive, SqlitePersistenceMemory } from "./persistence/Layers/Sqlite";
42
import { SqlClient } from "effect/unstable/sql";
43
import { ProviderService, type ProviderServiceShape } from "./provider/Services/ProviderService";
44
import { Open, type OpenShape } from "./open";
@@ -506,6 +506,61 @@ describe("WebSocket Server", () => {
506
);
507
});
508
509
+ it("includes bootstrap ids in welcome when cwd project and thread already exist", async () => {
510
+ const stateDir = makeTempDir("t3code-state-bootstrap-existing-");
511
+ const persistenceLayer = makeSqlitePersistenceLive(
512
+ path.join(stateDir, "state.sqlite"),
513
+ ) as unknown as Layer.Layer<SqlClient.SqlClient, never>;
514
+ const cwd = "/test/bootstrap-existing";
515
+
516
+ server = await createTestServer({
517
+ cwd,
518
+ stateDir,
519
+ persistenceLayer,
520
+ autoBootstrapProjectFromCwd: true,
521
+ });
522
+ let addr = server.address();
523
+ let port = typeof addr === "object" && addr !== null ? addr.port : 0;
524
+ expect(port).toBeGreaterThan(0);
525
+
526
+ const firstWs = await connectWs(port);
527
+ connections.push(firstWs);
528
+ const firstWelcome = (await waitForMessage(firstWs)) as WsPush;
529
+ const firstBootstrapProjectId = (firstWelcome.data as { bootstrapProjectId?: string })
530
+ .bootstrapProjectId;
531
+ const firstBootstrapThreadId = (firstWelcome.data as { bootstrapThreadId?: string })
532
+ .bootstrapThreadId;
533
+ expect(firstBootstrapProjectId).toBeDefined();
534
+ expect(firstBootstrapThreadId).toBeDefined();
535
+
536
+ firstWs.close();
537
+ await closeTestServer();
538
+ server = null;
539
+
540
+ server = await createTestServer({
541
+ cwd,
542
+ stateDir,
543
+ persistenceLayer,
544
+ autoBootstrapProjectFromCwd: true,
545
+ });
546
+ addr = server.address();
547
+ port = typeof addr === "object" && addr !== null ? addr.port : 0;
548
+ expect(port).toBeGreaterThan(0);
549
+
550
+ const secondWs = await connectWs(port);
551
+ connections.push(secondWs);
552
+ const secondWelcome = (await waitForMessage(secondWs)) as WsPush;
553
+ expect(secondWelcome.channel).toBe(WS_CHANNELS.serverWelcome);
554
+ expect(secondWelcome.data).toEqual(
555
+ expect.objectContaining({
556
+ cwd,
557
+ projectName: "bootstrap-existing",
558
+ bootstrapProjectId: firstBootstrapProjectId,
559
+ bootstrapThreadId: firstBootstrapThreadId,
560
+ }),
561
+ );
562
+ });
563
+
564
it("logs outbound websocket push events in dev mode", async () => {
565
const logSpy = vi.spyOn(console, "log").mockImplementation(() => {
566
// Keep test output clean while verifying websocket logs.
apps/server/src/wsServer.ts
+3
@@ -388,6 +388,9 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
388
});
389
welcomeBootstrapProjectId = bootstrapProjectId;
390
welcomeBootstrapThreadId = threadId;
391
+ } else {
392
+ welcomeBootstrapProjectId = bootstrapProjectId;
393
+ welcomeBootstrapThreadId = existingThread.id;
394
}
395
}).pipe(
396
Effect.mapError(
apps/web/src/routes/__root.tsx
+4
-1
@@ -194,6 +194,9 @@ function EventRouter() {
194
const unsubWelcome = onServerWelcome((payload) => {
195
void (async () => {
196
await syncSnapshot();
197
+ if (disposed) {
198
+ return;
199
+ }
200
201
if (!payload.bootstrapProjectId || !payload.bootstrapThreadId) {
202
return;
@@ -209,12 +212,12 @@ function EventRouter() {
212
if (handledBootstrapThreadIdRef.current === payload.bootstrapThreadId) {
213
return;
214
}
212
- handledBootstrapThreadIdRef.current = payload.bootstrapThreadId;
215
await navigate({
216
to: "/$threadId",
217
params: { threadId: payload.bootstrapThreadId },
218
replace: true,
219
});
220
+ handledBootstrapThreadIdRef.current = payload.bootstrapThreadId;
221
})().catch(() => undefined);
222
});
223
const unsubServerConfigUpdated = onServerConfigUpdated((payload) => {