Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions context/workspace-runtime-lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ Processes on the execution host:

### Terminal sessions

- The base workspace tmux session is durable backend state, but production terminal panes are
pooled runtime sessions; the primary terminal endpoint is not a mounted SPA workflow
(`frontend/src/lib/components/terminal/PooledSessionTerminal.svelte`).
- The local base workspace terminal is durable backend state, shared by phone’s Workspace
choice and the standalone desktop Workspace workflow tab. It stays available while runtime
discovery is pending or fails; embedded detail panes and remote hosts remain session-only.
- Launched agent and shell sessions are not durable after natural exit.
- The shell drawer is a singleton per workspace; a tmux-backed shell survives server restarts
until it exits or the workspace is deleted.
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/lib/api/workspace-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ export function workspaceSessionWebSocketPath(workspaceId: string, sessionKey: s
export function workspaceTmuxWebSocketPath(workspaceId: string, hostKey?: string): string {
return `${wsBaseUrl()}${executionHostPrefix(hostKey)}/workspaces/${encodeURIComponent(workspaceId)}` + "/terminal";
}

export function workspaceBaseSessionKey(workspaceId: string): string {
return `${workspaceId}:@workspace`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import {
workspaceSessionWebSocketPath,
workspaceTmuxWebSocketPath,
workspaceBaseSessionKey,
type WorkspaceRuntimeState,
} from "../../api/workspace-runtime.js";
import { getAppRuntime } from "../../app/runtime-context.js";
Expand Down Expand Up @@ -183,10 +184,6 @@
return { workspaceId, ...(hostKey === undefined ? {} : { hostKey }) };
}

function baseSessionKey(id: string): string {
return `${id}:@workspace`;
}

function mobileTerminalSessions(
runtimeState: WorkspaceRuntimeState | null,
detail: WorkspaceDetail | null,
Expand All @@ -204,7 +201,7 @@
return [
...launched,
{
key: baseSessionKey(detail.id),
key: workspaceBaseSessionKey(detail.id),
label: "Workspace",
status: "running",
generation: detail.created_at,
Expand Down Expand Up @@ -248,6 +245,7 @@
kind: session.runtimeSession?.kind,
label: session.label,
cursorWheelInput: session.cursorWheelInput,
reconnectOnExit: session.runtimeSession === null,
});
}
for (const key of ownedHostKeys) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,14 @@
bind:this={terminalPane}
websocketPath={session.websocketPath}
fleetHostKey={session.fleetHostKey}
reconnectOnExit={false}
reconnectOnExit={session.reconnectOnExit ?? false}
disabled={session.disabled ?? false}
active={active && attached}
renderingEnabled={!retained}
autoFocus={false}
cursorWheelInput={session.cursorWheelInput ?? false}
initialStatus={stoppedShell ? undefined : session.status}
onExit={(code) => onExit(code)}
onExit={session.reconnectOnExit ? undefined : onExit}
onConnectionChange={(connected) => onConnectionChange(connected)}
/>
{/key}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
$effect(() => {
const el = node;
if (el === null) return;
setSessionSlotVisible(hostKey, el, visible);
return () => setSessionSlotVisible(hostKey, el, false);
const key = hostKey;
setSessionSlotVisible(key, el, visible);
return () => setSessionSlotVisible(key, el, false);
});
</script>

Expand Down
28 changes: 27 additions & 1 deletion frontend/src/lib/components/terminal/TerminalSplitTree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { cleanup, fireEvent, render, screen } from "@testing-library/svelte";
import { clearActiveTabbedPanelDrag, readTabbedPanelTabDrag } from "../shared/tabbed-panel-drag.js";
import { sessionPaneKey } from "../../stores/session-pane-key.js";
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
import type { ComponentProps } from "svelte";
import { tick, type ComponentProps } from "svelte";
import { SvelteMap } from "svelte/reactivity";
import AppRuntimeHarness from "../../../test/AppRuntimeHarness.svelte";
import TerminalSplitTree from "./TerminalSplitTree.svelte";
import type { PaneNode } from "./terminal-layout";
Expand Down Expand Up @@ -125,6 +126,31 @@ describe("TerminalSplitTree", () => {
}
});

it("releases the old slot when navigation removes its session", async () => {
const session = sessions[0]!;
const currentSessions = new SvelteMap([["current", sessions]]);
render(AppRuntimeHarness, {
props: {
component: TerminalSplitTree,
workspaceId: "ws-1",
node: split(),
get sessions() {
return currentSessions.get("current") ?? [];
},
displayLabels: {},
activeSessionKey: session.key,
},
});
const hostKey = sessionHostKey("ws-1", undefined, session.key, session.created_at);
expect(isSessionSlotVisible(hostKey)).toBe(true);

currentSessions.set("current", []);
await tick();

expect(screen.getAllByText("Session unavailable")).toHaveLength(2);
expect(isSessionSlotVisible(hostKey)).toBe(false);
});

it("uses the launch target harness icon in an agent pane header", () => {
const agentSessions = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { describe, expect, it, vi, beforeEach, afterEach } from "vite-plus/test"
import { DEFAULT_TERMINAL_SETTINGS } from "../../api/types.js";
import { makeAppRuntime, type OwnedAppRuntime } from "../../app/runtime.js";
import { createDiffStore } from "../../stores/diff.svelte.js";
import { createSettingsStore } from "../../stores/settings.svelte.js";

import { STORES_KEY } from "../../context.js";
import { createMockApiFetch, jsonResponse, type MockRouteOverride } from "../../../test/mockApiFetch.js";
Expand Down Expand Up @@ -111,6 +112,7 @@ function waitForReparent(): Promise<void> {
}

const settingsStore = {
...createSettingsStore(),
getTerminalFontSize: () => DEFAULT_TERMINAL_SETTINGS.font_size,
getQuickActions: () => [],
getTerminalSettings: () => DEFAULT_TERMINAL_SETTINGS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ describe("WorkspaceTerminalView hostVisible", () => {
// reads settingsStore.getTerminalSettings() at initialization, so the
// main subtree cannot mount without a settings store on STORES_KEY.
const settingsStore = {
...createSettingsStore(),
getTerminalFontSize: () => DEFAULT_TERMINAL_SETTINGS.font_size,
getQuickActions: () => [],
getTerminalSettings: () => DEFAULT_TERMINAL_SETTINGS,
Expand Down Expand Up @@ -626,6 +627,7 @@ describe("WorkspaceTerminalView hostVisible", () => {
globalThis.EventSource = NoopEventSource as unknown as typeof EventSource;

const settingsStore = {
...createSettingsStore(),
getTerminalFontSize: () => DEFAULT_TERMINAL_SETTINGS.font_size,
getQuickActions: () => [],
getTerminalSettings: () => DEFAULT_TERMINAL_SETTINGS,
Expand Down Expand Up @@ -724,6 +726,7 @@ describe("WorkspaceTerminalView hostVisible", () => {
globalThis.EventSource = NoopEventSource as unknown as typeof EventSource;

const settingsStore = {
...createSettingsStore(),
getTerminalFontSize: () => DEFAULT_TERMINAL_SETTINGS.font_size,
getQuickActions: () => [],
getTerminalSettings: () => DEFAULT_TERMINAL_SETTINGS,
Expand Down Expand Up @@ -795,6 +798,7 @@ describe("WorkspaceTerminalView hostVisible", () => {
// (inside the options popover) with livePreview, which writes settings
// back through the store — so the stub needs a setter too.
const settingsStore = {
...createSettingsStore(),
getTerminalFontSize: () => DEFAULT_TERMINAL_SETTINGS.font_size,
getQuickActions: () => [],
getTerminalSettings: () => DEFAULT_TERMINAL_SETTINGS,
Expand Down Expand Up @@ -888,6 +892,7 @@ describe("WorkspaceTerminalView hostVisible", () => {
globalThis.EventSource = NoopEventSource as unknown as typeof EventSource;

const settingsStore = {
...createSettingsStore(),
getTerminalFontSize: () => terminalSettings.font_size,
getQuickActions: () => [],
getTerminalSettings: () => terminalSettings,
Expand Down Expand Up @@ -956,6 +961,7 @@ describe("WorkspaceTerminalView hostVisible", () => {
globalThis.EventSource = NoopEventSource as unknown as typeof EventSource;

const settingsStore = {
...createSettingsStore(),
getTerminalFontSize: () => terminalSettings.font_size,
getQuickActions: () => [],
getTerminalSettings: () => terminalSettings,
Expand Down Expand Up @@ -1009,6 +1015,7 @@ describe("WorkspaceTerminalView hostVisible", () => {
globalThis.EventSource = NoopEventSource as unknown as typeof EventSource;

const settingsStore = {
...createSettingsStore(),
getTerminalFontSize: () => DEFAULT_TERMINAL_SETTINGS.font_size,
getQuickActions: () => [],
getTerminalSettings: () => DEFAULT_TERMINAL_SETTINGS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { describe, expect, it, vi } from "vite-plus/test";
import { Effect } from "effect";
import { DEFAULT_TERMINAL_SETTINGS } from "../../api/types.js";
import { makeAppRuntime } from "../../app/runtime.js";
import { createSettingsStore } from "../../stores/settings.svelte.js";

import { STORES_KEY } from "../../context.js";
import { createMockApiFetch, jsonResponse, type MockRouteOverride } from "../../../test/mockApiFetch.js";
Expand Down Expand Up @@ -90,10 +91,10 @@ describe("WorkspaceTerminalView layout flip", () => {
globalThis.fetch = api.fetch;
globalThis.EventSource = NoopEventSource as unknown as typeof EventSource;

// TerminalOptionsMenu (always present in the ready-workspace toolbar)
// reads settingsStore.getTerminalSettings() at initialization, so the
// main subtree cannot mount without a settings store on STORES_KEY.
// Include the terminal settings read by the shared base terminal as well
// as the toolbar's fixture-specific actions.
const settingsStore = {
...createSettingsStore(),
getTerminalFontSize: () => DEFAULT_TERMINAL_SETTINGS.font_size,
getQuickActions: () => [{ label: "Review", agent: "codex", prompt: "Review this change" }],
getTerminalSettings: () => DEFAULT_TERMINAL_SETTINGS,
Expand All @@ -107,14 +108,19 @@ describe("WorkspaceTerminalView layout flip", () => {
});

try {
const workspaceTab = screen.getByRole("tab", { name: "Workspace", exact: true });
await expect.element(workspaceTab).toBeVisible();
const launcher = page.getByRole("dialog", { name: "Launch a session", exact: true });
await expect.element(launcher).toBeVisible();
await launcher.getByRole("button", { name: "Close", exact: true }).click();
const info = screen.getByRole("button", { name: "Workspace info", exact: true });
const launch = screen.getByRole("button", { name: "Launch", exact: true });
const quickActions = screen.getByRole("button", { name: "Quick actions", exact: true });
const presets = screen.getByRole("button", { name: "Workflow presets", exact: true });
await expect.element(info).toBeVisible();
for (const [control, anchor] of [
[launch, info],
[quickActions, info],
[launch, workspaceTab],
[quickActions, workspaceTab],
[presets, screen.getByRole("button", { name: "Delete", exact: true })],
]) {
const titleRow = anchor!.element().getBoundingClientRect();
Expand Down
Loading
Loading