Skip to content

Commit b4451af

Browse files
donjor-agent[bot]donjor
authored andcommitted
fix(server): tear down zmux sessions on thread settle and delete (#1688)
## Problem Settling or deleting a worktree thread could leave its zmux session and background commands running. ## Change Settle and delete now remove the entire managed session, including running commands and other viewers, using its exact native identity. Cleanup reads retained project ownership after project removal; the sidebar guide now distinguishes plain shells from managed sessions. ```diff - projects.getShell(thread.projectId) + projects.get(thread.projectId, { includeDeleted: true }) ``` - **Unsettle/pin:** no automatic restoration - **Terminal open:** creates a fresh session - **Root/main:** remains protected ## Scope and approval The maintainer requested permanent teardown of sessions, dev servers, and tabs, and authorized this fix and PR in T3 Code. ## Verification ### Evidence **Before settlement:** shell and dev tabs. ![Managed checkout before settlement](https://github.com/user-attachments/assets/28d01976-799d-4b7a-b30e-2efdb0d7e1e2) **After settlement and unsettle:** no managed session; retained scrollback and a plain shell. ![Unsettled thread without its old managed session](https://github.com/user-attachments/assets/eaf84b94-318b-407a-9f6f-2bdbab0bf442) **Delete, retaining checkout:** cancel worktree removal. ![Worktree removal declined during thread deletion](https://github.com/user-attachments/assets/e4ab1959-d7fb-41f5-ad3a-0ab05200f439) **Project removal:** session and HTTP process gone; main and checkout survived. ![Project-removal confirmation](https://github.com/user-attachments/assets/bf775203-fc57-43b6-96d5-83639da3d365) ![Isolated project removed](https://github.com/user-attachments/assets/cc251bc3-7dd1-414c-8ebe-40ba8469c476) ### Behavior checks - [x] **Chrome:** isolated state on VMON-1 - [x] **Settle:** session, tabs, server removed - [x] **Delete:** session gone, checkout retained - [x] **Unsettle:** no session restoration - [x] **Main:** survived both transitions - [x] **Native:** processes and bindings gone ### Project removal - [x] **Project removal:** cleanup completes - [x] **Race:** deleted during preparation ### Validation Server typecheck and bundle commands ran from `apps/server`. The latest ownership fix passed the bundle build and isolated Chrome project-removal flow; settle/unsettle media covers the earlier teardown implementation. **Rebased head:** `aad41d2`; all three feature patches unchanged. - [x] **Focused server tests:** 53 passed - [x] **`vp run typecheck`:** exit 0 - [x] **`vp run build:bundle`:** exit 0 - [x] **`vp run fork:ci`:** exit 0 - [x] **Targeted code lint:** exit 0 - [x] **Cleanup:** browser, sessions, dev stopped ### Limits - [ ] **Desktop/mobile/remote:** not exercised - **Markdown:** existing lint findings remain GPT-6.1-Sol, Codex harness in T3 Code. ## Fork trailers Squashes: - 9f74547 fix(server): tear down zmux sessions on thread settle and delete (#1688) (#1688) - 156efb2 fixup! fix(server): tear down zmux sessions on thread settle and delete (#1688) (#1688) Fork-Domain: zmux-estate Fork-Tier: bugfix Fork-Upstreamable: no Co-authored-by: donjor <[email protected]>
1 parent c40227a commit b4451af

8 files changed

Lines changed: 126 additions & 178 deletions

‎apps/server/src/project/ProjectSetupScriptRunner.settlement.fork.test.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ import { it } from "@effect/vitest";
33
import {
44
ProjectId,
55
ThreadId,
6-
type OrchestrationProjectShell,
76
type OrchestrationV2AppThread,
87
type OrchestrationV2ThreadShellSnapshot,
98
} from "@t3tools/contracts";
109
import * as Deferred from "effect/Deferred";
1110
import * as Effect from "effect/Effect";
1211
import * as Fiber from "effect/Fiber";
1312
import * as Layer from "effect/Layer";
14-
import * as Option from "effect/Option";
1513
import { expect } from "vite-plus/test";
1614

1715
import * as Orchestrator from "../orchestration-v2/Orchestrator.ts";
@@ -125,10 +123,7 @@ const harness = Effect.gen(function* () {
125123
ServerSettings.layerTest(),
126124
Layer.mock(ProjectService.ProjectService)({}),
127125
Layer.mock(ProjectStore.ProjectStoreV2)({
128-
getShell: () =>
129-
Effect.succeed(
130-
Option.some({ workspaceRoot: fixture.baseDir } as OrchestrationProjectShell),
131-
),
126+
get: () => Effect.succeedSome({ workspaceRoot: fixture.baseDir } as ProjectStore.ProjectRow),
132127
}),
133128
Layer.mock(ProjectionStore.ProjectionStoreV2)({ getThread: () => Effect.succeed(thread) }),
134129
Layer.mock(Orchestrator.OrchestratorV2)({

‎apps/server/src/terminal/SettlementAttachmentRelease.fork.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ export const makeSettlementAttachmentReleaseFork =
4747
Effect.ensuring(Effect.sync(unsubscribe)),
4848
);
4949
if (Option.isNone(result)) {
50-
yield* Effect.logWarning(
51-
"settled managed viewer did not confirm exit; session preserved",
52-
{ threadId, pid: process.pid },
53-
);
50+
yield* Effect.logWarning("settled managed viewer did not confirm exit", {
51+
threadId,
52+
pid: process.pid,
53+
});
5454
}
5555
return Option.isSome(result);
5656
}),

‎apps/server/src/zmux/SettledLaneAttachGuard.fork.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@ export class SettledLaneAttachGuard extends Context.Service<
1414
export const make = Effect.gen(function* () {
1515
const projections = yield* ProjectionStore.ProjectionStoreV2;
1616
return SettledLaneAttachGuard.of({
17-
isSettledThread: (threadId) =>
18-
projections.getThread(ThreadId.make(threadId)).pipe(
19-
Effect.map((thread) => thread.settledOverride === "settled"),
17+
isSettledThread: Effect.fn("SettledLaneAttachGuard.isSettledThread")(function (threadId) {
18+
return projections.getThread(ThreadId.make(threadId)).pipe(
19+
Effect.map((thread) => thread.settledOverride === "settled" || thread.deletedAt !== null),
2020
// An unreadable thread is not permission to create a managed session.
2121
Effect.catch((error) =>
2222
Effect.logWarning("could not verify terminal thread settlement", {
2323
threadId,
2424
detail: error.message,
2525
}).pipe(Effect.as(true)),
2626
),
27-
),
27+
);
28+
}),
2829
});
2930
});
3031

0 commit comments

Comments
 (0)