@@ -2299,7 +2299,13 @@ describe("ClaudeAdapterV2 background wake turns", () => {
22992299 });
23002300 const makeAssistantErrorFrame = (input: {
23012301 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;
23032309 readonly parentToolUseId?: string | null;
23042310 }) =>
23052311 claudeSdkFrame({
@@ -2309,7 +2315,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
23092315 id: `msg_${input.uuid}`,
23102316 type: "message",
23112317 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." }],
23132319 stop_reason: null,
23142320 stop_sequence: null,
23152321 usage: {
@@ -5295,10 +5301,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
52955301 assert.equal(terminal.status, "failed");
52965302 if (terminal.status !== "failed") return;
52975303 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");
53025305 assert.isFalse(
53035306 harness.events.some(
53045307 (event) =>
@@ -5318,6 +5321,70 @@ describe("ClaudeAdapterV2 background wake turns", () => {
53185321 ),
53195322 );
53205323
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+
53215388 const providerThreadRosterEvents = (
53225389 events: ReadonlyArray<ProviderAdapter.ProviderAdapterV2Event>,
53235390 ) =>
0 commit comments