Skip to content

Commit 34938f8

Browse files
committed
Fix terminal session state bugs: metadata status override, worktree attach race, remove unused panel
- Fix combineSessionState to prefer buffer terminal status (exited/closed/error) over stale metadata summary status, preventing UI from showing a terminal as running after the attach stream has recorded exit. - Add selectedThreadDetail?.worktreePath to bootstrap effect deps so the terminal re-attaches with the correct worktree path when thread detail hydrates after initial attach. - Remove unused ThreadTerminalPanel component that duplicated attach logic alongside ThreadTerminalRouteScreen.
1 parent 907f4d7 commit 34938f8

3 files changed

Lines changed: 11 additions & 177 deletions

File tree

apps/mobile/src/features/terminal/ThreadTerminalPanel.tsx

Lines changed: 0 additions & 175 deletions
This file was deleted.

apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ export function ThreadTerminalRouteScreen() {
725725
router,
726726
selectedThread?.environmentId,
727727
selectedThread?.id,
728+
selectedThreadDetail?.worktreePath,
728729
selectedThreadProject?.workspaceRoot,
729730
terminalId,
730731
]);

packages/client-runtime/src/terminalSessionState.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,24 @@ function latestTimestamp(left: string | null, right: string | null): string | nu
242242
return Date.parse(left) >= Date.parse(right) ? left : right;
243243
}
244244

245+
function isBufferTerminalStatus(buffer: TerminalBufferState): boolean {
246+
return (
247+
buffer.version > 0 &&
248+
(buffer.status === "exited" || buffer.status === "closed" || buffer.status === "error")
249+
);
250+
}
251+
245252
function combineSessionState(
246253
summary: TerminalSummary | null,
247254
buffer: TerminalBufferState,
248255
): TerminalSessionState {
256+
const bufferTerminal = isBufferTerminalStatus(buffer);
249257
return {
250258
summary,
251259
buffer: buffer.buffer,
252-
status: summary?.status ?? buffer.status,
260+
status: bufferTerminal ? buffer.status : (summary?.status ?? buffer.status),
253261
error: buffer.error,
254-
hasRunningSubprocess: summary?.hasRunningSubprocess ?? false,
262+
hasRunningSubprocess: bufferTerminal ? false : (summary?.hasRunningSubprocess ?? false),
255263
updatedAt: latestTimestamp(summary?.updatedAt ?? null, buffer.updatedAt),
256264
version: buffer.version,
257265
};

0 commit comments

Comments
 (0)