Skip to content

Commit 6fbe75f

Browse files
committed
fix(server): address ACP parser review on config options and compact flag
Refresh configOptionsRef when config_option_update arrives so validation and getConfigOptions stay live. Stop hardcoding compactsAutomatically on generic ACP token usage events; only set it when the caller knows auto-compact.
1 parent a45fb3d commit 6fbe75f

4 files changed

Lines changed: 64 additions & 16 deletions

File tree

‎apps/server/src/provider/acp/AcpCoreRuntimeEvents.test.ts‎

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,19 @@ describe("AcpCoreRuntimeEvents", () => {
137137
},
138138
});
139139

140-
expect(
141-
makeAcpTokenUsageEvent({
142-
stamp,
143-
provider: ProviderDriverKind.make("cursor"),
144-
threadId: "thread-1" as never,
145-
turnId,
146-
usedTokens: 1200,
147-
maxTokens: 256_000,
148-
rawPayload: {
149-
sessionId: "session-1",
150-
update: { sessionUpdate: "usage_update", used: 1200, size: 256_000 },
151-
},
152-
}),
153-
).toMatchObject({
140+
const usageWithoutCompact = makeAcpTokenUsageEvent({
141+
stamp,
142+
provider: ProviderDriverKind.make("cursor"),
143+
threadId: "thread-1" as never,
144+
turnId,
145+
usedTokens: 1200,
146+
maxTokens: 256_000,
147+
rawPayload: {
148+
sessionId: "session-1",
149+
update: { sessionUpdate: "usage_update", used: 1200, size: 256_000 },
150+
},
151+
});
152+
expect(usageWithoutCompact).toMatchObject({
154153
type: "thread.token-usage.updated",
155154
payload: {
156155
usage: {
@@ -160,6 +159,29 @@ describe("AcpCoreRuntimeEvents", () => {
160159
},
161160
},
162161
});
162+
// Generic ACP must not hardcode auto-compact; omit when unknown.
163+
expect(
164+
(usageWithoutCompact as { payload: { usage: Record<string, unknown> } }).payload.usage
165+
.compactsAutomatically,
166+
).toBeUndefined();
167+
168+
const usageWithCompact = makeAcpTokenUsageEvent({
169+
stamp,
170+
provider: ProviderDriverKind.make("cursor"),
171+
threadId: "thread-1" as never,
172+
turnId,
173+
usedTokens: 1200,
174+
maxTokens: 256_000,
175+
compactsAutomatically: true,
176+
rawPayload: {
177+
sessionId: "session-1",
178+
update: { sessionUpdate: "usage_update", used: 1200, size: 256_000 },
179+
},
180+
});
181+
expect(
182+
(usageWithCompact as { payload: { usage: Record<string, unknown> } }).payload.usage
183+
.compactsAutomatically,
184+
).toBe(true);
163185

164186
expect(
165187
makeAcpAssistantItemEvent({

‎apps/server/src/provider/acp/AcpCoreRuntimeEvents.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ export function makeAcpTokenUsageEvent(input: {
253253
readonly outputTokens?: number;
254254
readonly cachedInputTokens?: number;
255255
readonly reasoningOutputTokens?: number;
256+
/**
257+
* Only set when the agent/provider is known to auto-compact.
258+
* Generic ACP (e.g. Cursor) often does not; omit when unknown so UI defaults to false.
259+
*/
260+
readonly compactsAutomatically?: boolean;
256261
readonly rawPayload: unknown;
257262
readonly source?: AcpAdapterRawSource;
258263
readonly method?: string;
@@ -286,7 +291,9 @@ export function makeAcpTokenUsageEvent(input: {
286291
...(input.reasoningOutputTokens !== undefined
287292
? { lastReasoningOutputTokens: input.reasoningOutputTokens }
288293
: {}),
289-
compactsAutomatically: true,
294+
...(input.compactsAutomatically !== undefined
295+
? { compactsAutomatically: input.compactsAutomatically }
296+
: {}),
290297
},
291298
},
292299
raw: {

‎apps/server/src/provider/acp/AcpRuntimeModel.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,15 @@ describe("AcpRuntimeModel", () => {
422422
],
423423
},
424424
} satisfies EffectAcpSchema.SessionNotification);
425-
expect(config.events[0]?._tag).toBe("ConfigOptionsUpdated");
425+
expect(config.events[0]).toMatchObject({
426+
_tag: "ConfigOptionsUpdated",
427+
configOptions: [
428+
{
429+
id: "effort",
430+
currentValue: "high",
431+
},
432+
],
433+
});
426434

427435
const info = parseSessionUpdateEvent({
428436
sessionId: "session-1",

‎apps/server/src/provider/acp/AcpSessionRuntime.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ export const make = (
402402
yield* handleSessionUpdate({
403403
queue: eventQueue,
404404
modeStateRef,
405+
configOptionsRef,
405406
toolCallsRef,
406407
assistantSegmentRef,
407408
assistantItemRuntimeId,
@@ -852,13 +853,15 @@ function configOptionCurrentValueMatches(
852853
const handleSessionUpdate = ({
853854
queue,
854855
modeStateRef,
856+
configOptionsRef,
855857
toolCallsRef,
856858
assistantSegmentRef,
857859
assistantItemRuntimeId,
858860
params,
859861
}: {
860862
readonly queue: Queue.Queue<AcpSessionRuntimeEvent>;
861863
readonly modeStateRef: Ref.Ref<AcpSessionModeState | undefined>;
864+
readonly configOptionsRef: Ref.Ref<ReadonlyArray<EffectAcpSchema.SessionConfigOption>>;
862865
readonly toolCallsRef: Ref.Ref<Map<string, AcpToolCallState>>;
863866
readonly assistantSegmentRef: Ref.Ref<AcpAssistantSegmentState>;
864867
readonly assistantItemRuntimeId: string;
@@ -872,6 +875,14 @@ const handleSessionUpdate = ({
872875
);
873876
}
874877
for (const event of parsed.events) {
878+
if (event._tag === "ConfigOptionsUpdated") {
879+
// Keep authoritative session config in sync with live agent updates so
880+
// getConfigOptions / validateConfigOptionValue / setConfigOption current-value
881+
// checks do not stay pinned to the setup-time snapshot.
882+
yield* Ref.set(configOptionsRef, event.configOptions);
883+
yield* Queue.offer(queue, event);
884+
continue;
885+
}
875886
if (event._tag === "ToolCallUpdated") {
876887
yield* closeActiveAssistantSegment({
877888
queue,

0 commit comments

Comments
 (0)