@devries-cameron20 / t3code-1 / commits / e72dd5055e
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(client): closed terminal views release the shared grid (#36647)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Wout Stiens committed Nov 14, 2026 at 14:03 UTC e72dd5055eb437c93c0b3ddf710246ecbfe1f16e
2 files changed +38
packages/client-runtime/src/state/runtime.test.ts
+36
@@ -705,6 +705,42 @@ describe("environment query lifecycle", () => {
705 }),
706 );
707
708 + // The server sizes a shared PTY to every attached viewer, so a lingering attach pins its grid.
709 + it.effect("terminal attach detaches as soon as its last viewer leaves", () =>
710 + Effect.gen(function* () {
711 + const harness = yield* makeEnvironmentQueryHarness(Effect.void);
712 + const attached = yield* Deferred.make<void>();
713 + const detached = yield* Deferred.make<void>();
714 + const client = {
715 + [WS_METHODS.terminalAttach]: () =>
716 + Stream.fromEffect(Deferred.succeed(attached, undefined)).pipe(
717 + Stream.drain,
718 + Stream.concat(Stream.never),
719 + Stream.ensuring(Deferred.succeed(detached, undefined)),
720 + ),
721 + } as unknown as RpcSession.RpcSession["client"];
722 + yield* SubscriptionRef.set(
723 + harness.supervisorSession,
724 + Option.some({ ...QUERY_RPC_SESSION, client }),
725 + );
726 + const atoms = createTerminalEnvironmentAtoms(harness.runtime);
727 + const registry = AtomRegistry.make();
728 + yield* Effect.addFinalizer(() => Effect.sync(() => registry.dispose()));
729 + const unsubscribe = registry.subscribe(
730 + atoms.attach({
731 + environmentId: QUERY_ENVIRONMENT.environmentId,
732 + input: { threadId: "thread-1", terminalId: "terminal-1", cwd: "/tmp/project" },
733 + }),
734 + () => {},
735 + { immediate: true },
736 + );
737 + yield* Deferred.await(attached);
738 +
739 + unsubscribe();
740 + yield* Deferred.await(detached);
741 + }),
742 + );
743 +
744 it.effect(
745 "hides a session replacement, reports the relay backoff, and recovers on reconnect",
746 () =>
packages/client-runtime/src/state/terminal.ts
+2
@@ -64,6 +64,8 @@ export function createTerminalEnvironmentAtoms<R, E>(
64 }),
65 attach: createEnvironmentSubscriptionAtomFamily(runtime, {
66 label: "environment-data:terminal:attach",
67 + // The server sizes the PTY to every attached viewer, so a closed view must detach now.
68 + idleTtlMs: 0,
69 subscribe: (input: EnvironmentRpcInput<typeof WS_METHODS.terminalAttach>) => {
70 // Retry an unanswered first attach unchanged so it can still open the shell.
71 let replied = false;