Skip to content

Commit ed7b38b

Browse files
fix(terminal): serialize initial commands opened while the first still waits
A second open of a running terminal returned no initialCommandHandled flag while the first command still waited for shell readiness, so the client's fallback write could reach the shell before the pending first command. The live-session path now chains such commands behind the pending one server-side and reports them as handled; with nothing pending, opens keep returning to the client's immediate write. Co-Authored-By: Claude Code <[email protected]>
1 parent 8e7e60c commit ed7b38b

2 files changed

Lines changed: 241 additions & 47 deletions

File tree

‎apps/server/src/terminal/Manager.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,29 @@ it.layer(
595595
}),
596596
);
597597

598+
it.effect("runs a second initial command after a pending first one, in order", () =>
599+
Effect.gen(function* () {
600+
const ptyAdapter = new FakePtyAdapter();
601+
const written = yield* Deferred.make<ReadonlyArray<string>>();
602+
const seen: Array<string> = [];
603+
ptyAdapter.onWrite = (data) => {
604+
seen.push(data);
605+
if (data === " echo SECOND\r") Deferred.doneUnsafe(written, Effect.succeed([...seen]));
606+
};
607+
const { manager } = yield* createManager(5, { ptyAdapter });
608+
609+
const first = yield* manager.open(openInput({ initialCommand: "echo FIRST" }));
610+
const second = yield* manager.open(openInput({ initialCommand: "echo SECOND" }));
611+
expect(first.initialCommandHandled).toBe(true);
612+
expect(second.initialCommandHandled).toBe(true);
613+
expect(ptyAdapter.processes[0]?.writes).toEqual([]);
614+
615+
ptyAdapter.processes[0]?.emitData("\x1b[?2004h$ ");
616+
expect(yield* Deferred.await(written)).toEqual([" echo FIRST\r", " echo SECOND\r"]);
617+
expect(ptyAdapter.processes[0]?.writes).toEqual([" echo FIRST\r", " echo SECOND\r"]);
618+
}),
619+
);
620+
598621
it.effect("handles an initial command when open restarts a running session", () =>
599622
Effect.gen(function* () {
600623
const { manager, ptyAdapter, baseDir } = yield* createManager();

0 commit comments

Comments
 (0)