A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
Keep the session thinking level for /btw side questions (#2234)
Sebastian Müller5255a6b88002
diff --git a/packages/coding-agent/.changes/btw-side-question-thinking.md b/packages/coding-agent/.changes/btw-side-question-thinking.mdnew file mode 100644index 0000000000..a418c747b0--- /dev/null+++ b/packages/coding-agent/.changes/btw-side-question-thinking.md@@ -0,0 +1 @@+- Fixed `/btw` side questions discarding the main conversation's prompt cache by lowering the reasoning level: side questions now keep the session's thinking level, so providers whose cache keys include thinking parameters reuse the cached conversation.diff --git a/packages/coding-agent/src/core/side-question.ts b/packages/coding-agent/src/core/side-question.tsindex 53cac1ac9f..0b7ab10353 100644--- a/packages/coding-agent/src/core/side-question.ts+++ b/packages/coding-agent/src/core/side-question.ts@@ -6,7 +6,6 @@ import {type ProviderRetryPolicy,} from "./provider-retry.js";import { unwrapSemanticEdgeStreamFn } from "./semantic-edges.js";-import { getAuxiliaryThinkingLevel } from "./thinking-levels.js";export type SideQuestionStatus = "running" | "complete" | "cancelled" | "error";@@ -97,7 +96,9 @@ export function startSideQuestion(model,systemPrompt: parent.state.systemPrompt,messages: [...structuredClone(parent.state.messages), ...previousTurnMessages],- thinkingLevel: getAuxiliaryThinkingLevel(model, parent.state.thinkingLevel),+ // Anthropic message-level caching keys on the thinking parameters, so a+ // different level here would re-read the whole cloned conversation.+ thinkingLevel: parent.state.thinkingLevel,serviceTier: parent.state.serviceTier,// Providers serialize tool declarations ahead of the cached prefix, so an// empty list would miss the main cache; execution is blocked in beforeToolCall.diff --git a/packages/coding-agent/test/suite/regressions/6010-auxiliary-reasoning.test.ts b/packages/coding-agent/test/suite/regressions/6010-auxiliary-reasoning.test.tsindex a6231804cd..9f0b3fad19 100644--- a/packages/coding-agent/test/suite/regressions/6010-auxiliary-reasoning.test.ts+++ b/packages/coding-agent/test/suite/regressions/6010-auxiliary-reasoning.test.ts@@ -70,11 +70,13 @@ describe("auxiliary reasoning settings", () => {parent.state.thinkingLevel = testCase.parentLevel;const parentMessages = structuredClone(parent.state.messages);const observed: SimpleStreamOptions[] = [];+ // Side questions keep the session level (cache identity); the first two calls clamp.+ const expectedLevels: ThinkingLevel[] = [testCase.expectedLevel, testCase.expectedLevel, testCase.parentLevel];harness.setResponses(- [JSON.stringify(proposal), JSON.stringify(review), "Side answer"].map((text) => (_context, options) => {+ [JSON.stringify(proposal), JSON.stringify(review), "Side answer"].map((text, index) => (_context, options) => {const request = options as SimpleStreamOptions;observed.push(request);- if (request.reasoning !== testCase.expectedLevel) {+ if (request.reasoning !== expectedLevels[index]) {return fauxAssistantMessage("", {stopReason: "error",errorMessage: `Unsupported auxiliary reasoning: ${request.reasoning}`,@@ -131,7 +133,7 @@ describe("auxiliary reasoning settings", () => {noRetry,).done;expect(events.at(-1)).toMatchObject({ status: "complete", answer: "Side answer" });- expect(observed.map((options) => options.reasoning)).toEqual(Array(3).fill(testCase.expectedLevel));+ expect(observed.map((options) => options.reasoning)).toEqual(expectedLevels);expect(observed[0].maxTokens).toBe(testCase.expectedLevel === "off" ? 32_000 : model.maxTokens);expect(observed[1].maxTokens).toBe(testCase.expectedLevel === "off" ? 4_096 : model.maxTokens);expect(parent.state.thinkingLevel).toBe(testCase.parentLevel);