Skip to content

Commit a7b7108

Browse files
test: reproduce #31441, 200K-window Claude threads never compact
Claude Code with CLAUDE_CODE_DISABLE_1M_CONTEXT=1 runs in a 200K window and auto-compacts near 167K, so a thread never reaches the fixed 200K minimum that gates idle compaction and the Compact suggestion. These tests show a 160K-of-200K thread gets neither. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0643560 commit a7b7108

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎apps/server/src/orchestration-v2/IdleCompaction.test.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ const providerThreadId = ProviderThreadId.make("provider-thread");
3838
const modelSelection = { instanceId, model: "claude-opus-5-5" };
3939

4040
function records(
41-
usage: { readonly usedTokens?: number; readonly cacheExpiresInMs?: number } = {},
41+
usage: {
42+
readonly usedTokens?: number;
43+
readonly maxTokens?: number;
44+
readonly cacheExpiresInMs?: number;
45+
} = {},
4246
): { -readonly [Key in keyof IdleCompactionRecords]: IdleCompactionRecords[Key] } {
4347
const messageId = MessageId.make("message-1");
4448
const nodeId = NodeId.make("root-node");
@@ -134,6 +138,7 @@ function records(
134138
completedAt: at(),
135139
tokenUsage: {
136140
usedTokens: usage.usedTokens ?? 250_000,
141+
...(usage.maxTokens === undefined ? {} : { maxTokens: usage.maxTokens }),
137142
...(usage.cacheExpiresInMs === undefined
138143
? {}
139144
: { promptCacheExpiresAt: DateTime.formatIso(at(usage.cacheExpiresInMs)) }),
@@ -190,6 +195,14 @@ describe("idleCompactionWindow", () => {
190195
};
191196
expect(idleCompactionWindow(sideChat, NOW_MS)).toBeNull();
192197
});
198+
199+
it("compacts a thread at 160K of a 200K window, which Claude never lets reach 200K", () => {
200+
const window = idleCompactionWindow(
201+
records({ usedTokens: 160_000, maxTokens: 200_000, cacheExpiresInMs: 60 * MINUTE_MS }),
202+
NOW_MS,
203+
);
204+
expect(window?.runId).toBe(runId);
205+
});
193206
});
194207

195208
describe("IdleCompactionService", () => {

‎packages/client-runtime/src/state/contextWindow.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const returnedAt = "2026-10-30T23:03:21.000Z";
2828
function sendInput(
2929
overrides: {
3030
readonly usedTokens?: number;
31+
readonly maxTokens?: number;
3132
readonly promptCacheTtlMs?: number;
3233
readonly now?: string;
3334
readonly settings?: Partial<ServerSettings>;
@@ -102,6 +103,7 @@ function sendInput(
102103
),
103104
tokenUsage: {
104105
usedTokens: overrides.usedTokens ?? 293_611,
106+
...(overrides.maxTokens === undefined ? {} : { maxTokens: overrides.maxTokens }),
105107
updatedAt: lastTurnAt,
106108
...(overrides.promptCacheTtlMs === undefined
107109
? {}
@@ -202,6 +204,12 @@ describe("shouldCompactBeforeSend", () => {
202204
},
203205
{ name: "within the fallback TTL", now: "2026-10-30T15:23:02.000Z", expected: false },
204206
{ name: "under 200K", usedTokens: 150_000, expected: false },
207+
{
208+
name: "a stale Claude thread at 160K of a 200K window",
209+
usedTokens: 160_000,
210+
maxTokens: 200_000,
211+
expected: true,
212+
},
205213
{ name: "with idle compaction off", settings: { idleCompaction: "off" }, expected: false },
206214
{
207215
name: "with the Claude instance overriding idle compaction to off",

0 commit comments

Comments
 (0)