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 21, 12:15 UTC
fix(server): clearing a terminal that keeps printing no longer hangs (#31752)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
MarcoDotIO committed
Nov 14, 2026 at 22:18 UTC
828200fc040401a1c4f3132f10c7d0fc88ed18f8
2 files changed
+37
-1
apps/server/src/terminal/Manager.test.ts
+31
@@ -1197,6 +1197,37 @@ it.layer(
1197
}),
1198
);
1199
1200
+ it.effect("clears a terminal that keeps printing while its history is saved", () =>
1201
+ Effect.gen(function* () {
1202
+ const fs = yield* FileSystem.FileSystem;
1203
+ let printWhileSaving = Effect.void;
1204
+ const printing = FileSystem.FileSystem.of({
1205
+ ...fs,
1206
+ writeFileString: (filePath, data, options) =>
1207
+ printWhileSaving.pipe(Effect.andThen(fs.writeFileString(filePath, data, options))),
1208
+ });
1209
+ const { manager, ptyAdapter, getEvents } = yield* createManager().pipe(
1210
+ Effect.provideService(FileSystem.FileSystem, printing),
1211
+ );
1212
+ yield* manager.open(openInput());
1213
+ const process = ptyAdapter.processes[0]!;
1214
+ // Each save sees fresh output, so the history worker never goes idle.
1215
+ printWhileSaving = Effect.gen(function* () {
1216
+ const printed = yield* Deferred.make<void>();
1217
+ const unsubscribe = yield* manager.subscribe((event) =>
1218
+ event.type === "output" ? Deferred.succeed(printed, undefined) : Effect.void,
1219
+ );
1220
+ process.emitData("tick\n");
1221
+ yield* Deferred.await(printed);
1222
+ unsubscribe();
1223
+ });
1224
+
1225
+ yield* manager.clear({ threadId: "thread-1", terminalId: DEFAULT_TERMINAL_ID });
1226
+
1227
+ expect((yield* getEvents).map((event) => event.type)).toContain("cleared");
1228
+ }),
1229
+ );
1230
+
1231
it.effect("restores a log tail that starts inside a control sequence without its remainder", () =>
1232
Effect.gen(function* () {
1233
const fs = yield* FileSystem.FileSystem;
apps/server/src/terminal/Manager.ts
+6
-1
@@ -3657,7 +3657,12 @@ export const makeWithOptions = Effect.fn("TerminalManager.makeWithOptions")(func
3657
session.pendingProcessEventIndex = 0;
3658
session.processEventDrainRunning = false;
3659
const eventStamp = advanceEventSequence(session);
3660
- yield* persistHistory(input.threadId, terminalId, session.history);
3660
+ // A drain waits for the key to go idle, which never happens while the shell keeps
3661
+ // printing; every reader of the file flushes it first.
3662
+ yield* persistWorker.enqueue(toSessionKey(input.threadId, terminalId), {
3663
+ history: session.history,
3664
+ immediate: true,
3665
+ });
3666
yield* publishEvent({
3667
type: "cleared",
3668
threadId: input.threadId,