The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
fix(acp): /compact right after session/load waits for the agent's command list (#39891)
Julius Marminge committed
Nov 20, 2026 at 13:15 UTC
6d6ca6090794510dff93a203fc60d17e8b85a2a2
3 files changed
+35
-6
apps/server/scripts/acp-mock-agent.ts
+11
-1
@@ -29,6 +29,8 @@ const advertisedCommandNames = (process.env.T3_ACP_AVAILABLE_COMMANDS ?? "")
29
.map((name) => name.trim())
30
.filter((name) => name.length > 0);
31
const loadedCommandNames = process.env.T3_ACP_LOADED_COMMANDS?.split(",").filter(Boolean);
32
+// omp advertises a loaded session's commands only after it answers session/load.
33
+const loadedCommandsDelayMs = Number(process.env.T3_ACP_LOADED_COMMANDS_DELAY_MS ?? "");
34
const emitToolCalls = process.env.T3_ACP_EMIT_TOOL_CALLS === "1";
35
const emitInterleavedAssistantToolCalls =
36
process.env.T3_ACP_EMIT_INTERLEAVED_ASSISTANT_TOOL_CALLS === "1";
@@ -699,13 +701,21 @@ const program = Effect.gen(function* () {
701
const requestedSessionId = String(request.sessionId ?? sessionId);
702
sessionsLoading.add(requestedSessionId);
703
if (loadedCommandNames !== undefined) {
702
- yield* agent.client.sessionUpdate({
704
+ const publishLoadedCommands = agent.client.sessionUpdate({
705
sessionId: requestedSessionId,
706
update: {
707
sessionUpdate: "available_commands_update",
708
availableCommands: loadedCommandNames.map((name) => ({ name, description: name })),
709
},
710
});
711
+ if (Number.isFinite(loadedCommandsDelayMs)) {
712
+ yield* Effect.sleep(`${loadedCommandsDelayMs} millis`).pipe(
713
+ Effect.andThen(publishLoadedCommands),
714
+ Effect.forkDetach,
715
+ );
716
+ } else {
717
+ yield* publishLoadedCommands;
718
+ }
719
}
720
if (failLoadSession) {
721
return yield* AcpError.AcpRequestError.internalError("Mock load session failure");
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+6
-1
@@ -2808,15 +2808,20 @@ describe("AcpAdapterV2", () => {
2808
2809
it.live.each([
2810
{ active: "plan", target: "compact", allowed: true },
2811
+ // regression: #39880 omp advertises a loaded session's commands ~50 ms after session/load.
2812
+ { active: "plan", target: "compact", allowed: true, loadedCommandsDelayMs: 50 },
2813
{ active: "compact", target: "plan", allowed: false },
2814
{ active: "compact", target: undefined, allowed: false },
2815
])(
2816
"validates the target session's compact command ($active -> $target)",
2815
- ({ active, target, allowed }) =>
2817
+ ({ active, target, allowed, loadedCommandsDelayMs }) =>
2818
Effect.gen(function* () {
2819
const harness = yield* makeAdvertisedCompactionHarness({
2820
T3_ACP_AVAILABLE_COMMANDS: active,
2821
...(target === undefined ? {} : { T3_ACP_LOADED_COMMANDS: target }),
2822
+ ...(loadedCommandsDelayMs === undefined
2823
+ ? {}
2824
+ : { T3_ACP_LOADED_COMMANDS_DELAY_MS: String(loadedCommandsDelayMs) }),
2825
});
2826
const result = yield* harness.compact(true);
2827
assert.equal(Exit.isSuccess(result), allowed);
packages/provider-acp/src/server/adapter.ts
+18
-4
@@ -64,6 +64,7 @@ import * as Schema from "effect/Schema";
64
import * as Scope from "effect/Scope";
65
import * as Semaphore from "effect/Semaphore";
66
import * as Stream from "effect/Stream";
67
+import * as SubscriptionRef from "effect/SubscriptionRef";
68
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
69
import * as EffectAcpErrors from "effect-acp/errors";
70
import type * as EffectAcpProtocol from "effect-acp/protocol";
@@ -147,6 +148,8 @@ const ACP_DEFERRED_FINALIZE_DEBOUNCE: Duration.Input = "3000 millis";
148
// A model can stay silent this long before the first token of a reply the agent started itself.
149
const ACP_OPEN_REPLY_QUIET_LIMIT: Duration.Input = "2 minutes";
150
const ACP_BUSY_PROMPT_RETRY_INTERVAL: Duration.Input = "1 second";
151
+// Agents such as omp advertise a loaded session's commands shortly after answering session/load.
152
+const ACP_LOADED_COMMANDS_WAIT: Duration.Input = "2 seconds";
153
const ACP_PROMPT_INACTIVITY_SLICE_MILLIS = 60_000;
154
const ACP_HOST_SLEEP_TOLERANCE_MILLIS = 10_000;
155
@@ -2278,7 +2281,9 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
2281
new Map(current).set(sessionId, Symbol()),
2282
);
2283
});
2281
- const advertisedCommandNames = yield* Ref.make(new Map<string, ReadonlySet<string>>());
2284
+ const advertisedCommandNames = yield* SubscriptionRef.make(
2285
+ new Map<string, ReadonlySet<string>>(),
2286
+ );
2287
const compactsContext =
2288
flavor.supportsCompaction === true ||
2289
flavor.compactSession !== undefined ||
@@ -6985,7 +6990,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6990
if (notification.update.sessionUpdate === "available_commands_update") {
6991
const sessionId = rawNotification.sessionId;
6992
const advertisedCommands = notification.update.availableCommands;
6988
- yield* Ref.update(advertisedCommandNames, (current) => {
6993
+ yield* SubscriptionRef.update(advertisedCommandNames, (current) => {
6994
const updated = new Map(current);
6995
updated.set(
6996
sessionId,
@@ -9192,11 +9197,20 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
9197
}
9198
// Checked after activation: a loaded session advertises its own commands.
9199
const compactionSetup = yield* Ref.get(activeSessionSetup);
9200
+ const sessionCommandNames =
9201
+ flavor.compactViaAdvertisedCommand === true && isCompactionMessage(turnInput.message)
9202
+ ? yield* SubscriptionRef.changes(advertisedCommandNames).pipe(
9203
+ Stream.map((names) => names.get(requestedSessionId)),
9204
+ Stream.filter((names) => names !== undefined),
9205
+ Stream.runHead,
9206
+ Effect.timeoutOption(ACP_LOADED_COMMANDS_WAIT),
9207
+ Effect.map(Option.flatten),
9208
+ )
9209
+ : Option.none<ReadonlySet<string>>();
9210
if (
9211
isCompactionMessage(turnInput.message) &&
9212
((flavor.compactViaAdvertisedCommand === true &&
9198
- (yield* Ref.get(advertisedCommandNames)).get(requestedSessionId)?.has("compact") !==
9199
- true) ||
9213
+ !Option.exists(sessionCommandNames, (names) => names.has("compact"))) ||
9214
(flavor.compactSession !== undefined &&
9215
(compactionSetup === null ||
9216
!flavor.compactSession.supported(compactionSetup.initializeResult))))