Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,34 @@ describe("AntigravityAdapterV2 work after the prompt ends", () => {
}).pipe(Effect.provide(layerSession)),
);

it.effect("leaves no background work when the continuation run ends without starting", () =>
Effect.gen(function* () {
const { session, command, offers, send, startTurn, throughTerminal } =
yield* openSessionWithRunningCommand({ IsDaemon: true, WaitMsBeforeAsync: 500 });
yield* startTurn(1, false);
yield* throughTerminal;
yield* send({
sessionUpdate: "tool_call_update",
...command,
status: "completed",
rawOutput: { output: "Command exited with code 0.", exit_code: 0 },
});
assert.lengthOf(offers, 1, "the finished daemon must wake the thread");
yield* offers[0]!.dispatchIfCurrent!(Effect.void);
assert.isTrue(yield* session.hasPendingBackgroundWork!, "the queued continuation is owed");

assert.isDefined(
offers[0]!.onRunEndedWithoutStarting,
"a cancelled queued continuation must release its wake",
);
yield* offers[0]!.onRunEndedWithoutStarting!();
assert.isFalse(
yield* session.hasPendingBackgroundWork!,
"Stop on the queued continuation must let the thread switch providers",
);
}).pipe(Effect.provide(layerSession)),
);

// Frames as agy 1.5.11 sent them for `run_command` with `WaitMsBeforeAsync`: the prompt returns
// end_turn while the command runs, and the agent replies when the command finishes.
it.effect("keeps the run open while a command the agent waits for still runs", () =>
Expand Down
14 changes: 14 additions & 0 deletions packages/provider-acp/src/server/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5234,6 +5234,20 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
}
}),
),
// Drops the wake traffic the unstarted run would have drained, as its start does.
onRunEndedWithoutStarting: () =>
continuationPermit.withPermit(
Effect.gen(function* () {
if ((yield* Ref.get(continuationGeneration)) !== generation) return;
yield* Ref.update(continuationGeneration, (value) => value + 1);
yield* Ref.set(continuationRequested, false);
yield* Ref.set(wakeBuffer, []);
yield* Ref.update(wakeReports, ({ reports, offered }) => ({
reports: new Map([...reports].filter(([key]) => !offered.has(key))),
offered: noWakeReports.offered,
}));
}),
),
dispatchIfCurrent: (effect) =>
continuationPermit.withPermit(
Effect.gen(function* () {
Expand Down
Loading