fix(orchestrator): dedupe Grok continuation dispatch
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
8ccb33f755
commit
d584feccda
5 files changed
+229
-10
No files matched your search
@@ -459,6 +459,7 @@ function makeTurnInput(input: {
|
||||
describe("AcpAdapterV2", () => {
|
||||
it.live("cleans detached fixtures when an assertion aborts the test scope", () =>
|
||||
Effect.gen(function* () {
|
||||
if (process.platform !== "linux") return;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
let published: ReadonlyArray<number> = [];
|
||||
const failed = yield* Effect.scoped(
|
||||
@@ -603,6 +604,7 @@ describe("AcpAdapterV2", () => {
|
||||
});
|
||||
const instanceId = ProviderInstanceId.make("acp-test-unexpected-termination");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -662,6 +664,7 @@ describe("AcpAdapterV2", () => {
|
||||
|
||||
it.live("reaps detached native work when the provider exits before explicit teardown", () =>
|
||||
Effect.gen(function* () {
|
||||
if (process.platform !== "linux") return;
|
||||
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const idAllocator = yield* IdAllocatorV2;
|
||||
@@ -678,6 +681,7 @@ describe("AcpAdapterV2", () => {
|
||||
);
|
||||
const instanceId = ProviderInstanceId.make("acp-test-provider-exit");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -743,6 +747,7 @@ describe("AcpAdapterV2", () => {
|
||||
|
||||
it.live("surfaces reduced guarantee when delegated cgroup containment is unavailable", () =>
|
||||
Effect.gen(function* () {
|
||||
if (process.platform !== "linux") return;
|
||||
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const idAllocator = yield* IdAllocatorV2;
|
||||
@@ -756,6 +761,7 @@ describe("AcpAdapterV2", () => {
|
||||
| undefined;
|
||||
const instanceId = ProviderInstanceId.make("acp-test-cgroup-unavailable");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -829,6 +835,7 @@ describe("AcpAdapterV2", () => {
|
||||
};
|
||||
const instanceId = ProviderInstanceId.make("acp-test-cgroup-join-failure");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -977,6 +984,7 @@ describe("AcpAdapterV2", () => {
|
||||
const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -1173,6 +1181,7 @@ describe("AcpAdapterV2", () => {
|
||||
const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -1415,6 +1424,7 @@ describe("AcpAdapterV2", () => {
|
||||
const releaseResponseAcknowledgement = yield* Deferred.make<void>();
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -1511,6 +1521,7 @@ describe("AcpAdapterV2", () => {
|
||||
const releaseResponseAcknowledgement = yield* Deferred.make<void>();
|
||||
const instanceId = ProviderInstanceId.make("acp-test-reordered-elicitation");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -1613,6 +1624,7 @@ describe("AcpAdapterV2", () => {
|
||||
const responseLifecycle: Array<string> = [];
|
||||
const instanceId = ProviderInstanceId.make("acp-test-normal-close-held-response");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -1720,6 +1732,7 @@ describe("AcpAdapterV2", () => {
|
||||
const responseLifecycle: Array<string> = [];
|
||||
const instanceId = ProviderInstanceId.make("acp-test-close-wins-registration");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -1830,6 +1843,7 @@ describe("AcpAdapterV2", () => {
|
||||
const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
|
||||
const instanceId = ProviderInstanceId.make("acp-test-pending-response-timeout");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -1966,6 +1980,7 @@ describe("AcpAdapterV2", () => {
|
||||
const releaseNativeHook = yield* Deferred.make<void>();
|
||||
const instanceId = ProviderInstanceId.make("acp-test-pending-response-cancel");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -2085,6 +2100,7 @@ describe("AcpAdapterV2", () => {
|
||||
const releaseResponseAcknowledgement = yield* Deferred.make<void>();
|
||||
const instanceId = ProviderInstanceId.make(`acp-test-${name}`);
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -2181,6 +2197,7 @@ describe("AcpAdapterV2", () => {
|
||||
const releaseResponseAcknowledgement = yield* Deferred.make<void>();
|
||||
const instanceId = ProviderInstanceId.make("acp-test-url-elicitation");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -2271,6 +2288,7 @@ describe("AcpAdapterV2", () => {
|
||||
const releaseNativeHook = yield* Deferred.make<void>();
|
||||
const instanceId = ProviderInstanceId.make("acp-test-missing-response-ack");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -2361,6 +2379,7 @@ describe("AcpAdapterV2", () => {
|
||||
const releaseTeardown = yield* Deferred.make<void>();
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -2570,6 +2589,7 @@ describe("AcpAdapterV2", () => {
|
||||
const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -2665,6 +2685,7 @@ describe("AcpAdapterV2", () => {
|
||||
const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -2771,6 +2792,7 @@ describe("AcpAdapterV2", () => {
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
let subagentPhase: "spawn" | "complete" = "spawn";
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -2930,6 +2952,7 @@ describe("AcpAdapterV2", () => {
|
||||
let cancelCalled = false;
|
||||
let runtimeOrdinalSeen = 0;
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -3112,6 +3135,7 @@ describe("AcpAdapterV2", () => {
|
||||
const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -3202,6 +3226,7 @@ describe("AcpAdapterV2", () => {
|
||||
let cancelCalled = false;
|
||||
let runtimeOrdinalSeen = 0;
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -3399,6 +3424,7 @@ describe("AcpAdapterV2", () => {
|
||||
| null;
|
||||
} = { current: null };
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -3535,6 +3561,7 @@ describe("AcpAdapterV2", () => {
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
let runtimeOrdinalSeen = 0;
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -3668,6 +3695,7 @@ describe("AcpAdapterV2", () => {
|
||||
type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"];
|
||||
let sessionUpdateHandler: Parameters<RuntimeService["handleSessionUpdate"]>[0] | undefined;
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -3978,6 +4006,7 @@ describe("AcpAdapterV2", () => {
|
||||
const promptWireReturned = yield* Deferred.make<void>();
|
||||
const releasePromptCompletion = yield* Deferred.make<void>();
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -4137,6 +4166,7 @@ describe("AcpAdapterV2", () => {
|
||||
const continuationRequests: Array<ProviderContinuationRequest> = [];
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -4249,6 +4279,126 @@ describe("AcpAdapterV2", () => {
|
||||
}).pipe(Effect.provide(testLayer), Effect.scoped),
|
||||
);
|
||||
|
||||
it.effect(
|
||||
"keeps a dispatched continuation offer sticky until a turn starts or the worker drops it",
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const idAllocator = yield* IdAllocatorV2;
|
||||
const path = yield* Path.Path;
|
||||
const serverConfig = yield* ServerConfig;
|
||||
const mockAgentPath = yield* path.fromFileUrl(
|
||||
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
|
||||
);
|
||||
const continuationRequests: Array<ProviderContinuationRequest> = [];
|
||||
type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"];
|
||||
let sessionUpdateHandler: Parameters<RuntimeService["handleSessionUpdate"]>[0] | undefined;
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
capabilities: AcpProviderCapabilitiesV2,
|
||||
enablePostSettleContinuation: true,
|
||||
makeRuntime: makeMockRuntime({
|
||||
childProcessSpawner,
|
||||
mockAgentPath,
|
||||
wrapRuntime: (runtime) => ({
|
||||
...runtime,
|
||||
handleSessionUpdate: (handler) =>
|
||||
Effect.sync(() => {
|
||||
sessionUpdateHandler = handler;
|
||||
}).pipe(Effect.andThen(runtime.handleSessionUpdate(handler))),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
fileSystem,
|
||||
idAllocator,
|
||||
serverConfig,
|
||||
continuationRequests: {
|
||||
offer: (request) =>
|
||||
Effect.sync(() => {
|
||||
continuationRequests.push(request);
|
||||
}),
|
||||
},
|
||||
});
|
||||
const threadId = ThreadId.make("thread-acp-sticky-continuation-dispatch");
|
||||
const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
cwd: process.cwd(),
|
||||
});
|
||||
const modelSelection = { instanceId, model: "default" } as const;
|
||||
const runtime = yield* adapter.openSession({
|
||||
threadId,
|
||||
providerSessionId: ProviderSessionId.make(
|
||||
"provider-session-acp-sticky-continuation-dispatch",
|
||||
),
|
||||
modelSelection,
|
||||
runtimePolicy,
|
||||
});
|
||||
const events = yield* Queue.unbounded<ProviderAdapterV2Event>();
|
||||
yield* runtime.events.pipe(
|
||||
Stream.runForEach((event) => Queue.offer(events, event)),
|
||||
Effect.forkScoped,
|
||||
);
|
||||
const providerThread = yield* runtime.ensureThread({
|
||||
threadId,
|
||||
modelSelection,
|
||||
runtimePolicy,
|
||||
});
|
||||
const now = yield* DateTime.now;
|
||||
yield* runtime.startTurn(
|
||||
makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now }),
|
||||
);
|
||||
const providerTurnId = idAllocator.derive.providerTurn({
|
||||
driver: ACP_TEST_DRIVER,
|
||||
nativeTurnId: "mock-session-1:turn:1",
|
||||
});
|
||||
let terminalStatus: string | null = null;
|
||||
while (terminalStatus === null) {
|
||||
const event = yield* Queue.take(events);
|
||||
if (event.type === "turn.terminal" && event.providerTurnId === providerTurnId) {
|
||||
terminalStatus = event.status;
|
||||
}
|
||||
}
|
||||
assert.equal(terminalStatus, "completed");
|
||||
assert.isDefined(sessionUpdateHandler, "session update handler must be wired");
|
||||
|
||||
const lateTool = (toolCallId: string) =>
|
||||
sessionUpdateHandler!({
|
||||
sessionId: "mock-session-1",
|
||||
update: {
|
||||
sessionUpdate: "tool_call_update",
|
||||
toolCallId,
|
||||
title: "Late tool result",
|
||||
kind: "other",
|
||||
status: "completed",
|
||||
rawOutput: { output: toolCallId },
|
||||
},
|
||||
});
|
||||
yield* lateTool("first-late-result");
|
||||
assert.lengthOf(continuationRequests, 1);
|
||||
const first = continuationRequests[0]!;
|
||||
assert.isDefined(first.dispatchIfCurrent);
|
||||
assert.isTrue(Option.isSome(yield* first.dispatchIfCurrent!(Effect.void)));
|
||||
|
||||
yield* lateTool("second-frame-before-dispatched-turn-starts");
|
||||
assert.lengthOf(
|
||||
continuationRequests,
|
||||
1,
|
||||
"late frames must not enqueue duplicate continuations during dispatch-to-start",
|
||||
);
|
||||
|
||||
assert.isDefined(first.clearIfCurrent);
|
||||
yield* first.clearIfCurrent!();
|
||||
yield* lateTool("new-result-after-worker-drop");
|
||||
assert.lengthOf(continuationRequests, 2);
|
||||
}).pipe(Effect.provide(testLayer), Effect.scoped),
|
||||
);
|
||||
|
||||
it.effect(
|
||||
"holds a settled turn until the injected monitor report streams instead of finalizing into it",
|
||||
() =>
|
||||
@@ -4266,6 +4416,7 @@ describe("AcpAdapterV2", () => {
|
||||
const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -4425,6 +4576,7 @@ describe("AcpAdapterV2", () => {
|
||||
const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -4674,6 +4826,7 @@ describe("AcpAdapterV2", () => {
|
||||
let terminatorCallCount = 0;
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -4880,6 +5033,7 @@ describe("AcpAdapterV2", () => {
|
||||
const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -4969,6 +5123,7 @@ describe("AcpAdapterV2", () => {
|
||||
let runtimeOrdinalSeen = 0;
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -5132,6 +5287,7 @@ describe("AcpAdapterV2", () => {
|
||||
},
|
||||
});
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -5475,6 +5631,7 @@ describe("AcpAdapterV2", () => {
|
||||
const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -5600,6 +5757,7 @@ describe("AcpAdapterV2", () => {
|
||||
let runtimeOrdinalSeen = 0;
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -5716,6 +5874,7 @@ describe("AcpAdapterV2", () => {
|
||||
|
||||
it.live("direct Stop skips uninterruptible ACP cancel and recovers after native teardown", () =>
|
||||
Effect.gen(function* () {
|
||||
if (process.platform !== "linux") return;
|
||||
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const idAllocator = yield* IdAllocatorV2;
|
||||
@@ -5734,6 +5893,7 @@ describe("AcpAdapterV2", () => {
|
||||
let cancelCalled = false;
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -6001,6 +6161,7 @@ describe("AcpAdapterV2", () => {
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
let subagentPhase: "spawn" | "complete" = "spawn";
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
@@ -6151,6 +6312,7 @@ describe("AcpAdapterV2", () => {
|
||||
|
||||
it.live("restart_active terminates native work and reloads a clean runtime", () =>
|
||||
Effect.gen(function* () {
|
||||
if (process.platform !== "linux") return;
|
||||
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const idAllocator = yield* IdAllocatorV2;
|
||||
@@ -6168,6 +6330,7 @@ describe("AcpAdapterV2", () => {
|
||||
);
|
||||
const instanceId = ProviderInstanceId.make("acp-test");
|
||||
const adapter = makeAcpAdapterV2({
|
||||
crypto: yield* Crypto.Crypto,
|
||||
instanceId,
|
||||
flavor: {
|
||||
driver: ACP_TEST_DRIVER,
|
||||
|
||||
@@ -2674,7 +2674,7 @@ export function makeAcpAdapterV2(options: AcpAdapterV2Options): ProviderAdapterV
|
||||
});
|
||||
});
|
||||
|
||||
const offerContinuationRun = Effect.fnUntraced(function* (sessionId: string) {
|
||||
const offerContinuationRun = Effect.fnUntraced(function* (_sessionId: string) {
|
||||
if (continuationRequests === undefined) {
|
||||
return;
|
||||
}
|
||||
@@ -2706,6 +2706,14 @@ export function makeAcpAdapterV2(options: AcpAdapterV2Options): ProviderAdapterV
|
||||
providerThreadId: route.providerThreadId,
|
||||
driver,
|
||||
detail: null,
|
||||
clearIfCurrent: () =>
|
||||
continuationPermit.withPermit(
|
||||
Effect.gen(function* () {
|
||||
if ((yield* Ref.get(continuationGeneration)) === generation) {
|
||||
yield* Ref.set(continuationRequested, false);
|
||||
}
|
||||
}),
|
||||
),
|
||||
dispatchIfCurrent: (effect) =>
|
||||
continuationPermit.withPermit(
|
||||
Effect.gen(function* () {
|
||||
@@ -2723,11 +2731,14 @@ export function makeAcpAdapterV2(options: AcpAdapterV2Options): ProviderAdapterV
|
||||
return Option.none();
|
||||
}
|
||||
if (!(yield* Ref.get(continuationRequested))) return Option.none();
|
||||
// Clear after success or failure so a dropped dispatch does not
|
||||
// stick the flag and pin hasPendingBackgroundWork forever.
|
||||
// A successful durable dispatch owns the sticky flag until its
|
||||
// continuation turn starts. Clearing here opens a dispatch-to-
|
||||
// start race where every late ACP frame can enqueue another
|
||||
// synthetic continuation. Failures clear immediately because
|
||||
// no turn will arrive to do so.
|
||||
const exit = yield* Effect.exit(effect);
|
||||
yield* clearIfOwner;
|
||||
if (Exit.isFailure(exit)) {
|
||||
yield* clearIfOwner;
|
||||
return yield* Effect.failCause(exit.cause);
|
||||
}
|
||||
return Option.some(exit.value);
|
||||
@@ -3863,7 +3874,10 @@ export function makeAcpAdapterV2(options: AcpAdapterV2Options): ProviderAdapterV
|
||||
const runtimeGeneration = yield* Ref.get(runtimeCallbackGeneration);
|
||||
runtime = yield* flavor
|
||||
.makeRuntime(makeRuntimeInput(runtimeGeneration))
|
||||
.pipe(Effect.provideService(Scope.Scope, runtimeScope));
|
||||
.pipe(
|
||||
Effect.provideService(Scope.Scope, runtimeScope),
|
||||
Effect.provideService(Crypto.Crypto, options.crypto),
|
||||
);
|
||||
});
|
||||
|
||||
const restartAcpRuntime = Effect.fnUntraced(function* () {
|
||||
@@ -4181,10 +4195,12 @@ export function makeAcpAdapterV2(options: AcpAdapterV2Options): ProviderAdapterV
|
||||
// Minimal quiet for all models (no per-model carveouts). Defer +
|
||||
// awaitingBackgroundHydration hold the turn through monitors; this
|
||||
// is only a short debounce after the last rearm so a slightly late
|
||||
// first post-hydration assistant chunk is not dropped. Multi-second
|
||||
// floors (4–20s) only prolonged Working on grok-4.5.
|
||||
// post-hydration assistant chunk stays in the same continuation.
|
||||
// Grok commonly sends its final summary just over two seconds after
|
||||
// the hydrated tool frame; two seconds split that tail into a second
|
||||
// synthetic wake. Longer floors (4–20s) only prolonged Working.
|
||||
yield* Effect.gen(function* () {
|
||||
yield* Effect.sleep("2000 millis");
|
||||
yield* Effect.sleep("3000 millis");
|
||||
if (
|
||||
context.finalized ||
|
||||
context.interrupted ||
|
||||
@@ -4976,6 +4992,9 @@ export function makeAcpAdapterV2(options: AcpAdapterV2Options): ProviderAdapterV
|
||||
Effect.timeoutOption("10 seconds"),
|
||||
);
|
||||
if (Option.isNone(stopped)) {
|
||||
if (!context.finalized) {
|
||||
yield* finalizeTurn(context, "interrupted");
|
||||
}
|
||||
return yield* new ProviderAdapterProtocolError({
|
||||
driver,
|
||||
detail: `ACP provider turn ${turnInput.providerTurnId} did not acknowledge cancellation before the interrupt timeout`,
|
||||
|
||||
@@ -13,6 +13,8 @@ export interface ProviderContinuationRequest {
|
||||
readonly dispatchIfCurrent?: <A, E, R>(
|
||||
effect: Effect.Effect<A, E, R>,
|
||||
) => Effect.Effect<Option.Option<A>, E, R>;
|
||||
/** Clears a pending offer that the continuation worker intentionally drops. */
|
||||
readonly clearIfCurrent?: () => Effect.Effect<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -190,4 +190,35 @@ describe("ProviderContinuationService", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it.effect("clears a sticky continuation offer when its thread is archived", () => {
|
||||
return Effect.gen(function* () {
|
||||
const dispatched = yield* Queue.unbounded<unknown>();
|
||||
const cleared = yield* Ref.make(false);
|
||||
yield* Effect.gen(function* () {
|
||||
const requests = yield* ProviderContinuationRequests;
|
||||
yield* requests.offer({
|
||||
...request(),
|
||||
clearIfCurrent: () => Ref.set(cleared, true),
|
||||
});
|
||||
for (let attempt = 0; attempt < 20 && !(yield* Ref.get(cleared)); attempt += 1) {
|
||||
yield* Effect.yieldNow;
|
||||
}
|
||||
assert.isTrue(yield* Ref.get(cleared));
|
||||
assert.isTrue(Option.isNone(yield* Queue.poll(dispatched)));
|
||||
}).pipe(
|
||||
Effect.provide(
|
||||
testLayer({
|
||||
dispatched,
|
||||
getThreadProjection: () =>
|
||||
Effect.succeed({
|
||||
...projection,
|
||||
thread: { ...projection.thread, archivedAt: "2026-07-20T00:00:00.000Z" },
|
||||
} as OrchestrationV2ThreadProjection),
|
||||
}),
|
||||
),
|
||||
Effect.scoped,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -32,8 +32,12 @@ export const workerLive = Layer.effectDiscard(
|
||||
threadId: request.threadId,
|
||||
providerThreadId: request.providerThreadId,
|
||||
});
|
||||
// Still run the guard so adapters can clear sticky continuationRequested.
|
||||
if (request.dispatchIfCurrent !== undefined) {
|
||||
// No continuation turn will start to clear the adapter's sticky offer.
|
||||
if (request.clearIfCurrent !== undefined) {
|
||||
yield* request.clearIfCurrent();
|
||||
} else if (request.dispatchIfCurrent !== undefined) {
|
||||
// Backward compatibility for request producers without an explicit
|
||||
// drop callback.
|
||||
yield* request.dispatchIfCurrent(Effect.void);
|
||||
}
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user