Skip to content

Commit 280994d

Browse files
fix(antigravity): close an idle-stopped session in a finalizer
The interruptible permit release between marking and stopping could still strand the session. Close it in ensuring, which always runs. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 30dd7a6 commit 280994d

1 file changed

Lines changed: 24 additions & 28 deletions

File tree

‎apps/server/src/provider/Layers/AntigravityAdapter.ts‎

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,34 +1169,30 @@ export const makeAntigravityAdapter = Effect.fn("makeAntigravityAdapter")(functi
11691169
// session/cancel only stops a prompt. The agent kills its background
11701170
// commands when its session closes, so Stop with nothing else running
11711171
// ends the session, as Claude's does. The next turn resumes it.
1172-
yield* Effect.uninterruptibleMask((restore) =>
1173-
Effect.gen(function* () {
1174-
const idleWithCommands = yield* restore(
1175-
context.promptLock
1176-
.withPermit(
1177-
Effect.gen(function* () {
1178-
// Decided under the prompt lock so a turn cannot start in between.
1179-
if (
1180-
!context.promptFiber &&
1181-
[...context.commands.values()].some((c) => c.promoted)
1182-
) {
1183-
context.stopped = true;
1184-
return true;
1185-
}
1186-
yield* cancelRequests(context);
1187-
yield* context.runtime.cancel;
1188-
return false;
1189-
}),
1190-
)
1191-
.pipe(
1192-
Effect.mapError((cause) => mapAntigravityError(threadId, "session/cancel", cause)),
1193-
),
1194-
);
1195-
// Once marked stopped the session must close, or it is left
1196-
// unreachable with its commands still running.
1197-
if (idleWithCommands) yield* withThreadLock(threadId, stopContext(context));
1198-
}),
1199-
);
1172+
let idleWithCommands = false;
1173+
yield* context.promptLock
1174+
.withPermit(
1175+
Effect.gen(function* () {
1176+
// Decided under the prompt lock so a turn cannot start in between.
1177+
if (!context.promptFiber && [...context.commands.values()].some((c) => c.promoted)) {
1178+
context.stopped = true;
1179+
idleWithCommands = true;
1180+
return;
1181+
}
1182+
yield* cancelRequests(context);
1183+
yield* context.runtime.cancel;
1184+
}),
1185+
)
1186+
.pipe(
1187+
Effect.mapError((cause) => mapAntigravityError(threadId, "session/cancel", cause)),
1188+
// Once marked stopped the session must close, even if this call is
1189+
// interrupted, or it is left unreachable with its commands running.
1190+
Effect.ensuring(
1191+
Effect.suspend(() =>
1192+
idleWithCommands ? withThreadLock(threadId, stopContext(context)) : Effect.void,
1193+
),
1194+
),
1195+
);
12001196
});
12011197

12021198
const respondToRequest: Adapter["respondToRequest"] = (threadId, requestId, decision) =>

0 commit comments

Comments
 (0)