The best way to control Claude Code, Codex and more from any computer or phone
fix(kiro): compaction is refused when Kiro does not advertise _kiro/session/compact (#35866)
Julius Marminge committed
Nov 12, 2026 at 19:29 UTC
8b23382191ba7c7db69978d6a310a4244c566741
4 files changed
+87
-35
apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts
+34
-6
@@ -18,6 +18,7 @@ import {
18
} from "@t3tools/contracts";
19
import { resolveSelfInvocation } from "@t3tools/shared/nodeRuntime";
20
import { htmlRenderFromToolItem } from "@t3tools/shared/toolOutput";
21
+import * as Cause from "effect/Cause";
22
import * as DateTime from "effect/DateTime";
23
import * as Deferred from "effect/Deferred";
24
import * as Effect from "effect/Effect";
@@ -38,8 +39,11 @@ import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSession
39
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
40
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
41
import {
42
+ ProviderAdapterTurnStartError,
43
type ProviderAdapterV2Error,
44
type ProviderAdapterV2Event,
45
+ type ProviderAdapterV2TurnInput,
46
+ ProviderCompactionUnsupportedError,
47
ProviderAdapterV2RuntimePolicy,
48
} from "@t3tools/provider-core/server/ProviderAdapter";
49
import {
@@ -316,6 +320,8 @@ const runKiroScript = Effect.fn("runKiroScript")(function* (input: {
320
model: string,
321
options?: ModelSelection["options"],
322
) => Effect.Effect<void, ProviderAdapterV2Error>;
323
+ /** Runs T3's compact action as turn `ordinal`. */
324
+ readonly compact: (ordinal: number) => Effect.Effect<void, ProviderAdapterV2Error>;
325
readonly interrupt: (
326
providerTurnId: ProviderTurnId,
327
) => Effect.Effect<void, ProviderAdapterV2Error>;
@@ -390,10 +396,15 @@ const runKiroScript = Effect.fn("runKiroScript")(function* (input: {
396
});
397
const providerThread = yield* session.ensureThread({ threadId, modelSelection, runtimePolicy });
398
const now = yield* DateTime.now;
393
- const startTurnOn = (ordinal: number, model: string, options?: ModelSelection["options"]) => {
399
+ const turnInput = (
400
+ ordinal: number,
401
+ model: string,
402
+ options?: ModelSelection["options"],
403
+ text = "Say hello",
404
+ ): ProviderAdapterV2TurnInput => {
405
const suffix = `${threadId}:${ordinal}`;
406
const turnSelection = { instanceId, model, ...(options === undefined ? {} : { options }) };
396
- return session.startTurn({
407
+ return {
408
appThread: {
409
createdBy: "user",
410
creationSource: "web",
@@ -428,17 +439,26 @@ const runKiroScript = Effect.fn("runKiroScript")(function* (input: {
439
createdBy: "user",
440
creationSource: "web",
441
messageId: MessageId.make(`message:${suffix}`),
431
- text: "Say hello",
442
+ text,
443
attachments: [],
444
},
445
modelSelection: turnSelection,
446
runtimePolicy,
436
- });
447
+ };
448
};
449
+ const startTurnOn = (ordinal: number, model: string, options?: ModelSelection["options"]) =>
450
+ session.startTurn(turnInput(ordinal, model, options));
451
+ const compact = (ordinal: number) =>
452
+ session.compactThread === undefined
453
+ ? Effect.die("Kiro adapter does not offer compactThread")
454
+ : session.compactThread(
455
+ turnInput(ordinal, modelSelection.model, input.options, "/compact"),
456
+ );
457
yield* input.drive({
458
events: session.events,
459
startTurn: startTurnOn(1, modelSelection.model, input.options),
460
startTurnOn,
461
+ compact,
462
interrupt: (providerTurnId) => session.interruptTurn({ providerThread, providerTurnId }),
463
respond: (requestId, decision) => session.respondToRuntimeRequest({ requestId, decision }),
464
});
@@ -460,7 +480,7 @@ const terminalStatus = (events: ReadonlyArray<ProviderAdapterV2Event>) => {
480
};
481
482
describe("KiroAdapterV2", () => {
463
- it.effect("opens a session on a deployment that advertises no Kiro extensions", () =>
483
+ it.effect("opens a session and refuses compaction on a deployment with no Kiro extensions", () =>
484
runKiroScript({
485
scenario: "no-extensions",
486
frames: [
@@ -476,10 +496,18 @@ describe("KiroAdapterV2", () => {
496
}),
497
answer("session/prompt", { stopReason: "end_turn" }),
498
],
479
- drive: ({ events, startTurn }) =>
499
+ drive: ({ events, startTurn, compact }) =>
500
Effect.gen(function* () {
501
yield* startTurn;
502
assert.equal(terminalStatus(yield* collectTurn(events)), "completed");
503
+ // `_kiro/session/compact` is not advertised, so T3 must not send it.
504
+ const compacted = yield* Effect.exit(compact(2));
505
+ const error = Exit.isFailure(compacted) ? Cause.squash(compacted.cause) : undefined;
506
+ assert.instanceOf(error, ProviderAdapterTurnStartError);
507
+ assert.instanceOf(
508
+ (error as ProviderAdapterTurnStartError).cause,
509
+ ProviderCompactionUnsupportedError,
510
+ );
511
}),
512
}).pipe(Effect.provide(testLayer), Effect.scoped),
513
);
packages/provider-acp/src/server/adapter.ts
+21
-9
@@ -512,11 +512,19 @@ export interface AcpAdapterV2Flavor {
512
nativeTurnId: string,
513
) => NonNullable<EffectAcpSchema.ForkSessionRequest["_meta"]>;
514
};
515
- /** Compacts with the agent's own request, for agents that answer a `/compact` prompt as chat. */
516
- readonly compactSession?: (
517
- runtime: AcpSessionRuntime.AcpSessionRuntime["Service"],
518
- sessionId: string,
519
- ) => Effect.Effect<void, EffectAcpErrors.AcpError>;
515
+ /**
516
+ * Compacts with the agent's own request, for agents that answer a `/compact` prompt as chat.
517
+ * Compaction is refused when `supported` rejects the running agent's `initialize` result.
518
+ */
519
+ readonly compactSession?: {
520
+ readonly supported: (
521
+ initializeResult: AcpSessionRuntime.AcpSessionRuntimeStartResult["initializeResult"],
522
+ ) => boolean;
523
+ readonly compact: (
524
+ runtime: AcpSessionRuntime.AcpSessionRuntime["Service"],
525
+ sessionId: string,
526
+ ) => Effect.Effect<void, EffectAcpErrors.AcpError>;
527
+ };
528
readonly runtimeHarness?: string;
529
readonly registerExtensions?: (
530
context: AcpAdapterV2ExtensionContext,
@@ -8276,11 +8284,15 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
8284
}
8285
}
8286
// Checked after activation: a loaded session advertises its own commands.
8287
+ const compactionSetup = yield* Ref.get(activeSessionSetup);
8288
if (
8280
- flavor.compactViaAdvertisedCommand === true &&
8289
isCompactionMessage(turnInput.message) &&
8282
- (yield* Ref.get(advertisedCommandNames)).get(requestedSessionId)?.has("compact") !==
8283
- true
8290
+ ((flavor.compactViaAdvertisedCommand === true &&
8291
+ (yield* Ref.get(advertisedCommandNames)).get(requestedSessionId)?.has("compact") !==
8292
+ true) ||
8293
+ (flavor.compactSession !== undefined &&
8294
+ (compactionSetup === null ||
8295
+ !flavor.compactSession.supported(compactionSetup.initializeResult))))
8296
) {
8297
return yield* new ProviderAdapter.ProviderCompactionUnsupportedError({
8298
driver,
@@ -8550,7 +8562,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
8562
runtime.prompt({ prompt: promptParts!.prompt }, promptOptions),
8563
)
8564
: Deferred.succeed(context.promptDispatched, undefined).pipe(
8553
- Effect.andThen(compactSession(runtime, requestedSessionId)),
8565
+ Effect.andThen(compactSession.compact(runtime, requestedSessionId)),
8566
Effect.as({ stopReason: "end_turn" } satisfies EffectAcpSchema.PromptResponse),
8567
)
8568
).pipe(
packages/provider-kiro/src/server/adapter.ts
+31
-19
@@ -93,25 +93,37 @@ const KiroProviderCapabilitiesV2 = {
93
const KiroCompactResult = Schema.Struct({ success: Schema.Boolean });
94
const decodeKiroCompactResult = Schema.decodeUnknownOption(KiroCompactResult);
95
96
-/** Kiro answers a `/compact` prompt as chat, so T3 compacts with Kiro's own request. */
97
-const compactKiroSession = (
98
- runtime: AcpSessionRuntime.AcpSessionRuntime["Service"],
99
- sessionId: string,
100
-) =>
101
- runtime.request(KIRO_COMPACT_METHOD, { sessionId }).pipe(
102
- Effect.flatMap((result) =>
103
- Option.exists(decodeKiroCompactResult(result), (decoded) => decoded.success)
104
- ? Effect.void
105
- : Effect.fail(
106
- new EffectAcpErrors.AcpRequestError({
107
- code: -32603,
108
- errorMessage: "Kiro could not compact the conversation.",
109
- method: KIRO_COMPACT_METHOD,
110
- data: result,
111
- }),
112
- ),
96
+const decodeKiroExtensionMethods = Schema.decodeUnknownOption(
97
+ Schema.Struct({ kiro: Schema.Struct({ extensionMethods: Schema.Array(Schema.String) }) }),
98
+);
99
+
100
+/**
101
+ * Kiro answers a `/compact` prompt as chat, so T3 compacts with Kiro's own request,
102
+ * on deployments whose `initialize` result lists it among Kiro's extension methods.
103
+ */
104
+const kiroCompactSession = {
105
+ supported: (
106
+ initializeResult: AcpSessionRuntime.AcpSessionRuntimeStartResult["initializeResult"],
107
+ ) =>
108
+ Option.exists(decodeKiroExtensionMethods(initializeResult.agentCapabilities?._meta), (meta) =>
109
+ meta.kiro.extensionMethods.includes(KIRO_COMPACT_METHOD),
110
),
114
- );
111
+ compact: (runtime: AcpSessionRuntime.AcpSessionRuntime["Service"], sessionId: string) =>
112
+ runtime.request(KIRO_COMPACT_METHOD, { sessionId }).pipe(
113
+ Effect.flatMap((result) =>
114
+ Option.exists(decodeKiroCompactResult(result), (decoded) => decoded.success)
115
+ ? Effect.void
116
+ : Effect.fail(
117
+ new EffectAcpErrors.AcpRequestError({
118
+ code: -32603,
119
+ errorMessage: "Kiro could not compact the conversation.",
120
+ method: KIRO_COMPACT_METHOD,
121
+ data: result,
122
+ }),
123
+ ),
124
+ ),
125
+ ),
126
+};
127
128
const KiroSteerResult = Schema.Struct({ queued: Schema.Literal(true), messageId: Schema.String });
129
const decodeKiroSteerResult = Schema.decodeUnknownOption(KiroSteerResult);
@@ -568,7 +580,7 @@ function makeKiroAcpAdapterFlavor(options: KiroAdapterV2Options): AcpAdapterV2Fl
580
cancelAfterPromptStarts: { isStart: isKiroPromptActivity, bound: KIRO_CANCEL_HOLD_BOUND },
581
permissionDisposition: kiroPermissionDisposition,
582
approvalOptions: kiroApprovalOptions,
571
- compactSession: compactKiroSession,
583
+ compactSession: kiroCompactSession,
584
steering: kiroSteering,
585
forkFromTurn: kiroForkFromTurn,
586
// Kiro V3 advertises `promptCapabilities.image`; the shared adapter reads it.
packages/provider-kiro/src/server/status.ts
+1
-1
@@ -90,7 +90,7 @@ const snapshot = (
90
enabled: settings.enabled,
91
checkedAt,
92
models: kiroModels(settings, listed, agents),
93
- // `/compact` runs `_kiro/session/compact`; see compactKiroSession.
93
+ // `/compact` runs `_kiro/session/compact`; see kiroCompactSession.
94
slashCommands: [COMPACT_SLASH_COMMAND],
95
probe,
96
});