Skip to content

Commit 1653ce8

Browse files
t3dotggclaude
andcommitted
fix(home): a replaced Home's queued messages stay held
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent af7a7d4 commit 1653ce8

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

‎apps/server/src/home/HomeService.test.ts‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const makeHome = () => {
2929
const launched: Array<ThreadLaunch.ThreadLaunchInput> = [];
3030
const sent: Array<ThreadManagement.ThreadManagementSendInput> = [];
3131
const dispatched: Array<OrchestrationV2ServerCommand> = [];
32-
const interrupted: Array<ThreadId> = [];
3332
// Threads with a running turn, to model a Home that is busy when it is replaced.
3433
const running = new Set<string>();
3534
const shell = (threadId: ThreadId) =>
@@ -74,10 +73,6 @@ const makeHome = () => {
7473
sent.push(input);
7574
return Effect.succeed({} as ThreadManagement.ThreadManagementSendResult);
7675
},
77-
interruptThread: (input) => {
78-
interrupted.push(input.threadId);
79-
return Effect.succeed({} as never);
80-
},
8176
dispatch: (command) => {
8277
dispatched.push(command);
8378
return Effect.succeed({} as never);
@@ -86,7 +81,7 @@ const makeHome = () => {
8681
),
8782
),
8883
);
89-
return { layer, launched, sent, dispatched, sendFailures, interrupted, running };
84+
return { layer, launched, sent, dispatched, sendFailures, running };
9085
};
9186

9287
const event = (threadId: string, kind: HomeWatchEvent["kind"]): HomeWatchEvent => ({
@@ -194,14 +189,14 @@ it.effect("a Home thread that a fresh start replaced cannot change watches", ()
194189
}).pipe(Effect.provide(layer));
195190
});
196191

197-
it.effect("turning Home off stops the run the old Home was doing", () => {
198-
const { layer, interrupted, running } = makeHome();
192+
it.effect("turning Home off stops the old Home and holds its queued messages", () => {
193+
const { layer, dispatched, running } = makeHome();
199194
return Effect.gen(function* () {
200195
const home = yield* HomeService.HomeService;
201196
const { threadId } = yield* home.enable({ modelSelection });
202197
running.add(threadId);
203198
yield* home.disable;
204-
expect(interrupted).toEqual([threadId]);
199+
expect(dispatched).toMatchObject([{ type: "run.interrupt", threadId, holdQueue: true }]);
205200
}).pipe(Effect.provide(layer));
206201
});
207202

‎apps/server/src/home/HomeService.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,21 @@ const make = Effect.gen(function* () {
176176
const withLock = <A, E>(effect: Effect.Effect<A, E>) => lock.withPermits(1)(effect);
177177

178178
/**
179-
* Stops a former Home's active run once its grant is gone, so it does not
180-
* keep working next to the new Home. Best effort: the grant already moved.
179+
* Stops a former Home's active run once its grant is gone, and holds its
180+
* queued messages so none starts it again. Best effort: the grant already moved.
181181
*/
182182
const stopFormerHome = (threadId: ThreadId) =>
183183
Effect.gen(function* () {
184184
const shell = yield* liveShell(threadId);
185185
if (shell === null || shell.activeRunId === null) return;
186186
const id = yield* crypto.randomUUIDv4.pipe(Effect.orDie);
187-
yield* threads.interruptThread({
188-
projectId: shell.projectId,
187+
yield* threads.dispatch({
188+
type: "run.interrupt",
189189
commandId: CommandId.make(`home-stop:${id}`),
190190
threadId,
191+
runId: shell.activeRunId,
191192
reason: "Home was turned off or started fresh.",
193+
holdQueue: true,
192194
});
193195
}).pipe(Effect.ignore);
194196

0 commit comments

Comments
 (0)