TypeScript
fix(server): Claude subagents keep their model after a usage-limit notice (#17097)
洁月星0ae495158e10
diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsindex 69e544a4718..af104d6309f 100644--- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts+++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts@@ -10075,7 +10075,14 @@ describe("ClaudeAdapterV2 background wake turns", () => {),);- it.effect.each(["requested", "observed-before", "observed-after", "inherit", "unknown"] as const)(+ it.effect.each([+ "requested",+ "observed-before",+ "observed-after",+ "synthetic-after",+ "inherit",+ "unknown",+ ] as const)("records the subagent model from %s without inheriting the parent override",(source) =>Effect.scoped(@@ -10084,7 +10091,10 @@ describe("ClaudeAdapterV2 background wake turns", () => {const now = yield* DateTime.now;const toolUseId = "toolu-subagent-model";const parentModel = "claude-opus-4-6";- const observedModel = "claude-haiku-4-5-20251001";+ // Claude stamps its own error frames, such as a usage-limit notice, as+ // "<synthetic>"; that is not the model the subagent runs on.+ const observedModel =+ source === "synthetic-after" ? "<synthetic>" : "claude-haiku-4-5-20251001";yield* harness.runtime.startTurn(makeClaudeTestTurnInput({threadId: harness.threadId,@@ -10153,7 +10163,9 @@ describe("ClaudeAdapterV2 background wake turns", () => {session_id: WAKE_NATIVE_SESSION,}),);- if (source === "observed-after") yield* Queue.offer(harness.sdkMessages, observed);+ if (source === "observed-after" || source === "synthetic-after") {+ yield* Queue.offer(harness.sdkMessages, observed);+ }yield* Queue.offer(harness.sdkMessages,makeResultFrame({diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.tsindex f63b0630d59..fd4d774b43f 100644--- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts+++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts@@ -7307,8 +7307,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (const parentToolUseId = message.parent_tool_use_id;const snapshotModel =typeof message.message.model === "string" ? message.message.model.trim() : "";+ // Claude's own notices (a usage limit, an API error) carry+ // "<synthetic>", which says nothing about the subagent's model.const model =- snapshotModel.length === 0+ snapshotModel.length === 0 || snapshotModel === "<synthetic>"? undefined: canonicalClaudeSubagentModel(subagentModelCatalog, snapshotModel);if (parentToolUseId !== null && model !== undefined) {