Skip to content
Open
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
74 changes: 73 additions & 1 deletion apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ const makeInstructionCompactionHarness = Effect.fnUntraced(function* (
flavor: {
driver: ACP_TEST_DRIVER,
capabilities: AcpProviderCapabilitiesV2,
supportsCompaction: true,
compaction: "marker",
makeRuntime: makeMockRuntime({
childProcessSpawner,
mockAgentPath,
Expand Down Expand Up @@ -3353,6 +3353,78 @@ describe("AcpAdapterV2", () => {
}).pipe(Effect.provide(layerTest), Effect.scoped),
);

it.effect.each([
["marker", ["Context compacted"]],
["native", []],
] as const)(
"%s compaction: /compact without compaction_update projects %j",
([compaction, expectedCompactions]) =>
Effect.gen(function* () {
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
const path = yield* Path.Path;
const mockAgentPath = yield* path.fromFileUrl(
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
);
const instanceId = ProviderInstanceId.make(`acp-test-compaction-${compaction}`);
const adapter = yield* makeAcpAdapterV2({
instanceId,
flavor: {
driver: ACP_TEST_DRIVER,
capabilities: AcpProviderCapabilitiesV2,
compaction,
makeRuntime: makeMockRuntime({ childProcessSpawner, mockAgentPath }),
},
selfInvocation: yield* resolveSelfInvocation(),
});
const threadId = ThreadId.make(`thread-acp-compaction-${compaction}`);
const runtimePolicy = ProviderAdapter.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-compaction-${compaction}`),
modelSelection,
runtimePolicy,
});
const providerThread = yield* runtime.ensureThread({
threadId,
modelSelection,
runtimePolicy,
});
assert.isDefined(runtime.compactThread);
yield* runtime.compactThread!(
makeTurnInput({
threadId,
providerThread,
instanceId,
runtimePolicy,
now: yield* DateTime.now,
messageText: "/compact",
}),
);
const events = Array.from(
yield* runtime.events.pipe(
Stream.takeUntil((event) => event.type === "turn.terminal"),
Stream.runCollect,
),
);
assert.isTrue(
events.some((event) => event.type === "turn.terminal" && event.status === "completed"),
);
assert.deepEqual(
events.flatMap((event) =>
event.type === "turn_item.updated" && event.turnItem.type === "compaction"
? [event.turnItem.title]
: [],
),
[...expectedCompactions],
);
}).pipe(Effect.provide(layerTest), Effect.scoped),
);

it.effect("projects only the tail of long ACP terminal output", () =>
Effect.gen(function* () {
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
Expand Down
158 changes: 145 additions & 13 deletions apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,12 @@ describe("AcpRegistryAdapterV2", () => {
readonly storedModePick?: string;
readonly turnModels?: ReadonlyArray<string>;
readonly rejectedModel?: string;
readonly agentId?: string;
readonly turnText?: string;
readonly expectedCompaction?: { readonly status: string; readonly summary: string };
readonly expectedRunStatus?: string;
readonly interruptCompaction?: boolean;
readonly terminateCompaction?: boolean;
}) {
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
// Scope release gives the replay agent at most a second to exit, so the status
Expand Down Expand Up @@ -513,25 +519,32 @@ describe("AcpRegistryAdapterV2", () => {
);
const instanceId = ProviderInstanceId.make("acp-registry-stored-picks");
let published: AcpRegistryLiveConfiguration | undefined;
let terminateRuntime = Effect.void;
const scriptPath = yield* path.fromFileUrl(
new URL("../../../scripts/acp-replay-agent.ts", import.meta.url),
);
const adapter = yield* makeAcpRegistryAdapterV2({
selfInvocation: yield* resolveSelfInvocation(),
instanceId,
settings: yield* decodeAcpRegistryAdapterSettings({
agentId: "fixture-agent",
agentId: input.agentId ?? "fixture-agent",
authMethodId: "test",
customModels: input.customModels ?? [],
}),
environment: {},
makeRuntime: makeAcpReplayRuntime({
customModels: input.customModels,
transcript,
statusPath,
scriptPath: yield* path.fromFileUrl(
new URL("../../../scripts/acp-replay-agent.ts", import.meta.url),
),
childProcessSpawner,
fileSystem,
}),
makeRuntime: (runtimeInput) => {
terminateRuntime = runtimeInput.onTermination(
new EffectAcpErrors.AcpRequestError({ code: -32603, errorMessage: "transport exited" }),
);
return makeAcpReplayRuntime({
customModels: input.customModels,
transcript,
statusPath,
scriptPath,
childProcessSpawner,
fileSystem,
})(runtimeInput);
},
}).pipe(
Effect.provide(
Layer.mergeAll(
Expand Down Expand Up @@ -592,15 +605,48 @@ describe("AcpRegistryAdapterV2", () => {
runtimePolicy,
now,
ordinal: index + 1,
...(input.turnText === undefined ? {} : { messageText: input.turnText }),
modelSelection: target,
}),
);
let compactionObserved = false;
yield* runtime.events.pipe(
Stream.takeUntil((event) => event.type === "turn.terminal"),
Stream.runForEach((event) =>
Effect.sync(() => {
Effect.gen(function* () {
if (
event.type === "turn_item.updated" &&
event.turnItem.type === "compaction" &&
event.turnItem.status === "running"
) {
if (input.terminateCompaction) yield* terminateRuntime;
if (input.interruptCompaction)
yield* runtime.interruptTurn({
providerThread,
providerTurnId: event.turnItem.providerTurnId!,
});
}
if (
event.type === "turn_item.updated" &&
event.turnItem.type === "compaction" &&
event.turnItem.status !== "running"
) {
assert.equal(event.turnItem.status, input.expectedCompaction?.status);
assert.equal(event.turnItem.summary, input.expectedCompaction?.summary);
assert.isNotNull(event.turnItem.completedAt);
compactionObserved = true;
}
if (event.type === "turn.terminal") {
assert.equal(event.status, "completed", event.failure?.message);
assert.equal(
event.status,
input.expectedRunStatus ?? "completed",
event.failure?.message,
);
if (input.expectedCompaction)
assert.isTrue(
compactionObserved,
"native compaction must persist before turn settlement",
);
}
}),
),
Expand All @@ -626,6 +672,92 @@ describe("AcpRegistryAdapterV2", () => {
return { configurations };
});

it.effect.each([
{ ordering: "before", outcome: "completed", runStatus: "completed" },
{ ordering: "after", outcome: "completed", runStatus: "completed" },
{ ordering: "terminal-first", outcome: "completed", runStatus: "completed" },
{ ordering: "after", outcome: "failed", runStatus: "failed" },
{ ordering: "after", outcome: "cancelled", runStatus: "cancelled" },
{ ordering: "prompt-error", outcome: "failed", runStatus: "failed" },
{ ordering: "prompt-cancel", outcome: "cancelled", runStatus: "cancelled" },
{ ordering: "transport-exit", outcome: "failed", runStatus: "failed" },
{ ordering: "interrupt", outcome: "interrupted", runStatus: "interrupted" },
])(
"preserves Devin native compaction: $ordering / $outcome",
({ ordering, outcome, runStatus }) => {
const notice = (status: string) => ({
type: "emit_inbound",
frame: {
kind: "notification",
method: "_cognition.ai/compaction",
params: { sessionId: "agent-session", status, summary: "Retained native summary" },
},
});
const response =
ordering === "prompt-error"
? {
type: "emit_inbound",
frame: {
kind: "response",
method: "session/prompt",
error: { code: -32603, message: "compact failed" },
},
}
: answer("session/prompt", {
stopReason:
ordering === "prompt-error"
? "error"
: ordering === "prompt-cancel"
? "cancelled"
: "end_turn",
});
const updates =
ordering === "terminal-first"
? [notice("started"), notice(outcome), response]
: ordering === "transport-exit"
? [response, notice("started")]
: ordering === "interrupt"
? [
notice("started"),
{
type: "expect_outbound",
frame: {
kind: "notification",
method: "session/cancel",
params: { sessionId: "agent-session" },
},
},
response,
notice("completed"),
]
: ordering.startsWith("prompt-")
? [notice("started"), response]
: [
...(ordering === "before"
? [notice("started"), response]
: [response, notice("started")]),
notice(outcome),
];
return openWithStoredPicks({
setup: {},
agentId: "devin",
turnModels: ["default"],
turnText: "/compact",
expectedCompaction: { status: outcome, summary: "Retained native summary" },
expectedRunStatus: runStatus,
interruptCompaction: ordering === "interrupt",
terminateCompaction: ordering === "transport-exit",
pickFrames: [
outbound("session/prompt", {
sessionId: "agent-session",
prompt: [{ type: "text", text: "/compact" }],
}),
...updates,
],
}).pipe(Effect.provide(layerTest), Effect.scoped);
},
);

it.effect("switches an agent that only advertises modes with session/set_mode", () =>
openWithStoredPicks({
setup: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ export function makeAntigravityAcpAdapterFlavor(
extractSubagentUpdate: extractAntigravitySubagentUpdate,
supportsImagePrompts: true,
// ACP 1.3.0 treats /compact as ordinary model input.
supportsCompaction: false,
requiresSignIn: isAntigravitySignInRequiredError,
// 1.4.5 returns the root trajectory's Gemini usageMetadata delta; 1.4.1 returns none.
reportsPerTurnPromptUsage: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ export function materializeReplayTranscriptRuntimeInstructions(
Array.isArray(frame.params.prompt)
) {
const prompt: ReadonlyArray<unknown> = frame.params.prompt;
if (
prompt.some(
(part) =>
typeof part === "object" &&
part !== null &&
"type" in part &&
part.type === "text" &&
"text" in part &&
typeof part.text === "string" &&
part.text.trimStart().startsWith("/"),
)
)
return entry;
const lastPart = prompt.at(-1);
if (
typeof lastPart === "object" &&
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { OrchestratorFixtureInput } from "../shared.ts";

export const ACP_REGISTRY_COMPACTION_SUMMARY = "Retained the fixture decisions.";

/**
* A registry agent gets one normal turn, then a bare `/compact`: the message
* the Compact context action sends, or a user, MCP tool or schedule types.
*/
export function acpRegistryCompactionInput(): OrchestratorFixtureInput {
return {
steps: [
{ type: "message", text: "Respond with exactly: compaction fixture ready" },
{ type: "message", text: "/compact" },
],
};
}
Loading
Loading