Skip to content

Commit 1d0e554

Browse files
fix(acp): a mode-only update no longer hides the drift from the mode option
An ACP v1 agent can report its own mode switch with current_mode_update alone. The mode config option kept the old value, so reapplying the selected mode was skipped as unchanged. Keep the option in step with the reported mode, and cover it with a v1 replay transcript. AI-assisted; verified with the tests and tools listed above.
1 parent 6c4c040 commit 1d0e554

2 files changed

Lines changed: 180 additions & 3 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts‎

Lines changed: 157 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import {
88
} from "@t3tools/provider-acp-registry/testing";
99
import { AcpRegistrySettings } from "@t3tools/provider-acp-registry/settings";
1010
import { AcpRegistryCatalog } from "@t3tools/provider-acp-registry/server/AcpRegistrySupport";
11-
import { decodeAcpReplayTranscript, makeAcpReplayRuntime } from "./AcpAdapterV2.testkit.ts";
11+
import {
12+
decodeAcpReplayTranscript,
13+
makeAcpReplayCompletenessAssertion,
14+
makeAcpReplayRuntime,
15+
} from "./AcpAdapterV2.testkit.ts";
1216
// @effect-diagnostics nodeBuiltinImport:off
1317
import * as NodeFS from "node:fs";
1418
import * as NodePath from "node:path";
@@ -2499,6 +2503,158 @@ describe("AcpAdapterV2", () => {
24992503
}).pipe(Effect.provide(layerTest), Effect.scoped),
25002504
);
25012505

2506+
// regression: #27646 an ACP v1 agent can report a mode switch without a config option update
2507+
it.live("reapplies the selected native mode after a mode-only update from a v1 agent", () =>
2508+
Effect.gen(function* () {
2509+
const fileSystem = yield* FileSystem.FileSystem;
2510+
const path = yield* Path.Path;
2511+
const directory = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-acp-mode-only-" });
2512+
const statusPath = path.join(directory, "status.json");
2513+
const sessionId = "mode-only-session";
2514+
const modeOption = (currentValue: string) => ({
2515+
id: "mode",
2516+
name: "Mode",
2517+
category: "mode",
2518+
type: "select",
2519+
currentValue,
2520+
options: [
2521+
{ value: "ask", name: "Ask" },
2522+
{ value: "architect", name: "Architect" },
2523+
],
2524+
});
2525+
const setArchitect = [
2526+
{
2527+
type: "expect_outbound" as const,
2528+
frame: {
2529+
kind: "request",
2530+
method: "session/set_config_option",
2531+
params: { sessionId, configId: "mode", value: "architect" },
2532+
},
2533+
},
2534+
{
2535+
type: "emit_inbound" as const,
2536+
frame: {
2537+
kind: "response",
2538+
method: "session/set_config_option",
2539+
result: { configOptions: [modeOption("architect")] },
2540+
},
2541+
},
2542+
];
2543+
const prompt = (updates: ReadonlyArray<unknown>) => [
2544+
{
2545+
type: "expect_outbound" as const,
2546+
frame: { kind: "request", method: "session/prompt", params: "<any>" },
2547+
},
2548+
...updates.map((update) => ({
2549+
type: "emit_inbound" as const,
2550+
frame: { kind: "notification", method: "session/update", params: { sessionId, update } },
2551+
})),
2552+
{
2553+
type: "emit_inbound" as const,
2554+
frame: { kind: "response", method: "session/prompt", result: { stopReason: "end_turn" } },
2555+
},
2556+
];
2557+
const transcript = yield* decodeAcpReplayTranscript(
2558+
{
2559+
provider: ACP_TEST_DRIVER,
2560+
protocol: "acp.ndjson-jsonrpc",
2561+
version: "1",
2562+
scenario: "mode-only-update",
2563+
entries: [
2564+
{
2565+
type: "expect_outbound",
2566+
frame: { kind: "request", method: "initialize", params: "<any>" },
2567+
},
2568+
{
2569+
type: "emit_inbound",
2570+
frame: {
2571+
kind: "response",
2572+
method: "initialize",
2573+
result: { protocolVersion: 1, agentCapabilities: {}, authMethods: [] },
2574+
},
2575+
},
2576+
{
2577+
type: "expect_outbound",
2578+
frame: { kind: "request", method: "session/new", params: "<any>" },
2579+
},
2580+
{
2581+
type: "emit_inbound",
2582+
frame: {
2583+
kind: "response",
2584+
method: "session/new",
2585+
result: { sessionId, configOptions: [modeOption("ask")] },
2586+
},
2587+
},
2588+
...setArchitect,
2589+
...prompt([{ sessionUpdate: "current_mode_update", currentModeId: "ask" }]),
2590+
...setArchitect,
2591+
...prompt([]),
2592+
],
2593+
},
2594+
ACP_TEST_DRIVER,
2595+
);
2596+
const instanceId = ProviderInstanceId.make("acp-test-mode-only");
2597+
const threadId = ThreadId.make("thread-acp-mode-only");
2598+
const adapter = yield* makeAcpAdapterV2({
2599+
instanceId,
2600+
flavor: {
2601+
driver: ACP_TEST_DRIVER,
2602+
capabilities: AcpProviderCapabilitiesV2,
2603+
makeRuntime: makeAcpReplayRuntime({
2604+
transcript,
2605+
statusPath,
2606+
fileSystem,
2607+
scriptPath: yield* path.fromFileUrl(
2608+
new URL("../../../scripts/acp-replay-agent.ts", import.meta.url),
2609+
),
2610+
childProcessSpawner: yield* ChildProcessSpawner.ChildProcessSpawner,
2611+
}),
2612+
},
2613+
selfInvocation: yield* resolveSelfInvocation(),
2614+
});
2615+
const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
2616+
runtimeMode: "full-access",
2617+
interactionMode: "default",
2618+
cwd: directory,
2619+
});
2620+
const modelSelection = {
2621+
instanceId,
2622+
model: "default",
2623+
options: [{ id: "mode", value: "architect" }],
2624+
} as const;
2625+
const runtime = yield* adapter.openSession({
2626+
threadId,
2627+
providerSessionId: ProviderSessionId.make("provider-session-acp-mode-only"),
2628+
modelSelection,
2629+
runtimePolicy,
2630+
});
2631+
const providerThread = yield* runtime.ensureThread({
2632+
threadId,
2633+
modelSelection,
2634+
runtimePolicy,
2635+
});
2636+
const now = yield* DateTime.now;
2637+
for (const ordinal of [1, 2]) {
2638+
yield* runtime.startTurn(
2639+
makeTurnInput({
2640+
threadId,
2641+
providerThread,
2642+
instanceId,
2643+
runtimePolicy,
2644+
now,
2645+
ordinal,
2646+
modelSelection,
2647+
}),
2648+
);
2649+
yield* runtime.events.pipe(
2650+
Stream.takeUntil((event) => event.type === "turn.terminal"),
2651+
Stream.runDrain,
2652+
);
2653+
}
2654+
yield* makeAcpReplayCompletenessAssertion(fileSystem, statusPath, transcript);
2655+
}).pipe(Effect.provide(layerTest), Effect.scoped),
2656+
);
2657+
25022658
// regression: #21499 turns blocked only on T3 thread waits must show as waiting
25032659
it.effect.each(["agent_message_chunk"] as const)(
25042660
"keeps named ACP %s open while deriving thread wait execution state",

‎packages/provider-acp/src/server/AcpSessionRuntime.ts‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,9 +2811,30 @@ const handleSessionUpdate =
28112811
}
28122812
const parsed = parseSessionUpdateEvent(params);
28132813
if (parsed.modeId) {
2814-
yield* Ref.update(modeStateRef, (current) =>
2814+
const modeId = (yield* Ref.updateAndGet(modeStateRef, (current) =>
28152815
current === undefined ? current : updateModeState(current, parsed.modeId!),
2816-
);
2816+
))?.currentModeId;
2817+
// A mode-only update leaves the mode option stale, and setConfigOption
2818+
// skips a value the option already shows, so reapplying the mode would send nothing.
2819+
const configOptions = yield* SubscriptionRef.get(configOptionsRef);
2820+
if (
2821+
modeId !== undefined &&
2822+
configOptions.some(
2823+
(option) =>
2824+
option.category === "mode" &&
2825+
option.type === "select" &&
2826+
option.currentValue !== modeId,
2827+
)
2828+
) {
2829+
yield* SubscriptionRef.set(
2830+
configOptionsRef,
2831+
configOptions.map((option) =>
2832+
option.category === "mode" && option.type === "select"
2833+
? { ...option, currentValue: modeId }
2834+
: option,
2835+
),
2836+
);
2837+
}
28172838
}
28182839
for (const event of parsed.events) {
28192840
if (event._tag === "ToolCallUpdated") {

0 commit comments

Comments
 (0)