Skip to content

Commit 65631b9

Browse files
committed
fix(agents): avoid explicit override for inherited subagent thinking
1 parent 6bcce8d commit 65631b9

3 files changed

Lines changed: 65 additions & 8 deletions

File tree

‎src/agents/openclaw-tools.subagents.sessions-spawn-applies-thinking-default.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type ThinkingLevel = "high" | "medium" | "low" | "off";
66

77
function expectResolvedThinkingPlan(input: {
88
expected: ThinkingLevel;
9+
expectedOverride?: ThinkingLevel | null;
910
thinkingOverrideRaw?: string;
1011
callerThinkingRaw?: string;
1112
requesterAgentConfig?: unknown;
@@ -29,7 +30,8 @@ function expectResolvedThinkingPlan(input: {
2930

3031
expect(plan).toEqual({
3132
status: "ok",
32-
thinkingOverride: input.expected,
33+
thinkingOverride:
34+
input.expectedOverride === null ? undefined : (input.expectedOverride ?? input.expected),
3335
initialSessionPatch: { thinkingLevel: input.expected },
3436
});
3537
}
@@ -72,6 +74,7 @@ describe("sessions_spawn thinking defaults", () => {
7274
} as OpenClawConfig,
7375
callerThinkingRaw: "medium",
7476
expected: "medium",
77+
expectedOverride: null,
7578
});
7679
});
7780

@@ -90,6 +93,7 @@ describe("sessions_spawn thinking defaults", () => {
9093
} as OpenClawConfig,
9194
callerThinkingRaw: "off",
9295
expected: "off",
96+
expectedOverride: null,
9397
});
9498
});
9599

‎src/agents/subagent-spawn-thinking.ts‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,45 @@ export function resolveSubagentThinkingOverride(params: {
2626
readString(targetSubagents ?? {}, "thinking") ??
2727
readString(defaultSubagents ?? {}, "thinking");
2828

29-
const thinkingCandidateRaw =
30-
params.thinkingOverrideRaw || resolvedThinkingDefaultRaw || params.callerThinkingRaw;
31-
if (!thinkingCandidateRaw) {
29+
const overrideCandidateRaw = params.thinkingOverrideRaw || resolvedThinkingDefaultRaw;
30+
if (overrideCandidateRaw) {
31+
const normalizedThinking = normalizeThinkLevel(overrideCandidateRaw);
32+
if (!normalizedThinking) {
33+
return {
34+
status: "error" as const,
35+
thinkingCandidateRaw: overrideCandidateRaw,
36+
};
37+
}
38+
39+
return {
40+
status: "ok" as const,
41+
thinkingOverride: normalizedThinking,
42+
initialSessionPatch: {
43+
thinkingLevel: normalizedThinking,
44+
},
45+
};
46+
}
47+
48+
if (!params.callerThinkingRaw) {
3249
return {
3350
status: "ok" as const,
3451
thinkingOverride: undefined,
3552
initialSessionPatch: {},
3653
};
3754
}
3855

39-
const normalizedThinking = normalizeThinkLevel(thinkingCandidateRaw);
56+
const normalizedThinking = normalizeThinkLevel(params.callerThinkingRaw);
4057
if (!normalizedThinking) {
4158
return {
42-
status: "error" as const,
43-
thinkingCandidateRaw,
59+
status: "ok" as const,
60+
thinkingOverride: undefined,
61+
initialSessionPatch: {},
4462
};
4563
}
4664

4765
return {
4866
status: "ok" as const,
49-
thinkingOverride: normalizedThinking,
67+
thinkingOverride: undefined,
5068
initialSessionPatch: {
5169
thinkingLevel: normalizedThinking,
5270
},

‎src/agents/subagent-spawn.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,41 @@ describe("spawnSubagentDirect seam flow", () => {
878878
expect(params.thinking).toBe("high");
879879
});
880880

881+
it("does not forward inherited requester thinking as an explicit agent override", async () => {
882+
const calls: Array<{ method?: string; params?: unknown }> = [];
883+
hoisted.callGatewayMock.mockImplementation(
884+
async (request: { method?: string; params?: unknown }) => {
885+
calls.push(request);
886+
if (request.method === "agent") {
887+
return { runId: "run-inherited-thinking", status: "accepted", acceptedAt: 1000 };
888+
}
889+
if (request.method?.startsWith("sessions.")) {
890+
return { ok: true };
891+
}
892+
return {};
893+
},
894+
);
895+
hoisted.loadSessionStoreMock.mockReturnValue({
896+
"agent:main:main": { thinkingLevel: "xhigh" },
897+
});
898+
installSessionStoreCaptureMock(hoisted.updateSessionStoreMock);
899+
900+
const result = await spawnSubagentDirect(
901+
{
902+
task: "verify inherited thinking is session state",
903+
},
904+
{
905+
agentSessionKey: "agent:main:main",
906+
agentChannel: "discord",
907+
},
908+
);
909+
910+
expect(result.status).toBe("accepted");
911+
const agentCall = calls.find((call) => call.method === "agent");
912+
const params = requireRecord(agentCall?.params);
913+
expect(params.thinking).toBeUndefined();
914+
});
915+
881916
it("does not duplicate long subagent task text in the initial user message (#72019)", async () => {
882917
const calls: Array<{ method?: string; params?: unknown }> = [];
883918
hoisted.callGatewayMock.mockImplementation(

0 commit comments

Comments
 (0)