The best way to control Claude Code, Codex and more from any computer or phone
fix(server): a full Claude context window no longer shows as a usage limit (#19848)
fixfon committed
Oct 18, 2026 at 23:13 UTC
fb9af9e57dcfcf2a8cf74ba0a52031a65eb02dc9
2 files changed
+81
-11
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+73
-6
@@ -2299,7 +2299,13 @@ describe("ClaudeAdapterV2 background wake turns", () => {
2299
});
2300
const makeAssistantErrorFrame = (input: {
2301
readonly uuid: string;
2302
- readonly error: "authentication_failed" | "rate_limit" | "server_error" | undefined;
2302
+ readonly error:
2303
+ | "authentication_failed"
2304
+ | "invalid_request"
2305
+ | "rate_limit"
2306
+ | "server_error"
2307
+ | undefined;
2308
+ readonly text?: string;
2309
readonly parentToolUseId?: string | null;
2310
}) =>
2311
claudeSdkFrame({
@@ -2309,7 +2315,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
2315
id: `msg_${input.uuid}`,
2316
type: "message",
2317
role: "assistant",
2312
- content: [{ type: "text", text: "Claude could not complete this request." }],
2318
+ content: [{ type: "text", text: input.text ?? "Claude could not complete this request." }],
2319
stop_reason: null,
2320
stop_sequence: null,
2321
usage: {
@@ -5295,10 +5301,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
5301
assert.equal(terminal.status, "failed");
5302
if (terminal.status !== "failed") return;
5303
assert.isNotEmpty(terminal.failure.message);
5298
- assert.equal(
5299
- terminal.failure.class,
5300
- terminalReason === "blocking_limit" ? "usage_limit" : "provider_error",
5301
- );
5304
+ assert.equal(terminal.failure.class, "provider_error");
5305
assert.isFalse(
5306
harness.events.some(
5307
(event) =>
@@ -5318,6 +5321,70 @@ describe("ClaudeAdapterV2 background wake turns", () => {
5321
),
5322
);
5323
5324
+ // Frames follow #19832: a full context window ends the turn with
5325
+ // blocking_limit while the plan's rate-limit window is still allowed.
5326
+ it.effect.each([
5327
+ {
5328
+ windowStatus: "allowed",
5329
+ expectedClass: "provider_error",
5330
+ expectedMessage: "Claude stopped: the prompt exceeds the model's context window.",
5331
+ },
5332
+ {
5333
+ windowStatus: "rejected",
5334
+ expectedClass: "usage_limit",
5335
+ expectedMessage: "Claude usage limit reached. Send the message again once the limit resets.",
5336
+ },
5337
+ ] as const)(
5338
+ "classifies blocking_limit by its rate-limit evidence ($windowStatus window)",
5339
+ ({ windowStatus, expectedClass, expectedMessage }) =>
5340
+ Effect.gen(function* () {
5341
+ const harness = yield* makeWakeHarness;
5342
+ yield* harness.runtime.startTurn(
5343
+ makeClaudeTestTurnInput({
5344
+ threadId: harness.threadId,
5345
+ providerThread: harness.providerThread,
5346
+ now: yield* DateTime.now,
5347
+ attemptId: RunAttemptId.make(`attempt-blocking-limit-${windowStatus}`),
5348
+ text: "Continue.",
5349
+ attachments: [],
5350
+ }),
5351
+ );
5352
+ yield* Queue.offerAll(harness.sdkMessages, [
5353
+ claudeSdkFrame({
5354
+ type: "rate_limit_event",
5355
+ rate_limit_info: { status: windowStatus, rateLimitType: "five_hour" },
5356
+ uuid: "00000000-0000-4000-8000-000000000660",
5357
+ session_id: WAKE_NATIVE_SESSION,
5358
+ }),
5359
+ makeAssistantErrorFrame({
5360
+ uuid: "00000000-0000-4000-8000-000000000661",
5361
+ error: "invalid_request",
5362
+ text: "Prompt is too long",
5363
+ }),
5364
+ makeResultFrame({
5365
+ uuid: "00000000-0000-4000-8000-000000000662",
5366
+ result: "Prompt is too long",
5367
+ isError: true,
5368
+ numTurns: 189,
5369
+ terminalReason: "blocking_limit",
5370
+ }),
5371
+ ]);
5372
+ const terminal = yield* Queue.take(harness.terminalReceipts);
5373
+ assert.equal(terminal.status, "failed");
5374
+ if (terminal.status !== "failed") return;
5375
+ assert.equal(terminal.failure.class, expectedClass);
5376
+ assert.include(terminal.failure.message, expectedMessage);
5377
+ assert.equal(terminal.failure.code, "blocking_limit");
5378
+ if (expectedClass === "provider_error") {
5379
+ assert.include(terminal.failure.message, "/compact");
5380
+ }
5381
+ }).pipe(
5382
+ Effect.provide(
5383
+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
5384
+ ),
5385
+ ),
5386
+ );
5387
+
5388
const providerThreadRosterEvents = (
5389
events: ReadonlyArray<ProviderAdapter.ProviderAdapterV2Event>,
5390
) =>
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+8
-5
@@ -2633,6 +2633,9 @@ function resultUserFacingError(result: SDKResultMessage): string | undefined {
2633
);
2634
}
2635
2636
+const CONTEXT_WINDOW_FULL_ERROR =
2637
+ "Claude stopped: the prompt exceeds the model's context window. Run /compact or start a new thread.";
2638
+
2639
function terminalResultError(
2640
reason: SDKResultMessage["terminal_reason"],
2641
failureHint?: string,
@@ -2651,11 +2654,13 @@ function terminalResultError(
2654
case "turn_setup_failed":
2655
return "Claude could not start the turn.";
2656
case "blocking_limit":
2654
- return "Claude stopped: a usage limit blocked the request.";
2657
+ // The CLI also ends a turn with blocking_limit once the context window
2658
+ // is full ("Prompt is too long"). Only rate-limit evidence sets the hint.
2659
+ return failureHint ?? CONTEXT_WINDOW_FULL_ERROR;
2660
case "rapid_refill_breaker":
2661
return "Claude stopped: the context refilled too quickly after compaction.";
2662
case "prompt_too_long":
2658
- return "Claude stopped: the prompt exceeds the model's context window.";
2663
+ return CONTEXT_WINDOW_FULL_ERROR;
2664
case "image_error":
2665
return "Claude stopped: an image in the conversation could not be processed.";
2666
case "model_error":
@@ -2822,9 +2827,7 @@ function providerFailureFromResult(
2827
}
2828
}
2829
const failureClass =
2825
- message.terminal_reason === "blocking_limit" ||
2826
- (message.subtype === "success" && message.api_error_status === 429) ||
2827
- usageLimited
2830
+ (message.subtype === "success" && message.api_error_status === 429) || usageLimited
2831
? "usage_limit"
2832
: "provider_error";
2833
const listedError = resultUserFacingError(message);