Skip to content

Commit 500d419

Browse files
committed
fix(agents): continue settled empty post-tool turns
1 parent badb5ae commit 500d419

10 files changed

Lines changed: 443 additions & 76 deletions

File tree

‎extensions/qa-lab/src/providers/mock-openai/mock-openai-contracts.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ export const QA_THINKING_VISIBILITY_OFF_PROMPT_RE = /qa thinking visibility chec
160160
export const QA_THINKING_VISIBILITY_MAX_PROMPT_RE = /qa thinking visibility check max/i;
161161
export const QA_EMPTY_RESPONSE_RECOVERY_PROMPT_RE = /empty response continuation qa check/i;
162162
export const QA_EMPTY_RESPONSE_EXHAUSTION_PROMPT_RE = /empty response exhaustion qa check/i;
163+
export const QA_EMPTY_RESPONSE_SIDE_EFFECT_RECOVERY_PROMPT_RE =
164+
/empty response after write recovery qa check/i;
163165
export const QA_STREAMING_PROMPT_RE = /(?:partial|quiet) streaming qa check/i;
164166
export const QA_FINAL_ONLY_MARKER_STREAMING_PROMPT_RE = /final-only marker streaming qa check/i;
165167
export const QA_BLOCK_STREAMING_PROMPT_RE = /block streaming qa check/i;
@@ -232,6 +234,8 @@ export const QA_REASONING_ONLY_RETRY_NEEDLE =
232234
"recorded reasoning but did not produce a user-visible answer";
233235
export const QA_EMPTY_RESPONSE_RETRY_NEEDLE =
234236
"The previous attempt did not produce a user-visible answer.";
237+
export const QA_SETTLED_TOOL_TERMINAL_CONTINUATION_NEEDLE =
238+
"The previous assistant turn completed its tool calls but did not produce a user-visible answer.";
235239
export const QA_SKILL_WORKSHOP_GIF_PROMPT_RE =
236240
/externally sourced animated GIF asset|animated GIF asset in a product UI/i;
237241
export const QA_SKILL_WORKSHOP_REVIEW_PROMPT_RE = /Review transcript for durable skill updates/i;

‎extensions/qa-lab/src/providers/mock-openai/server.test.ts‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ const QA_EMPTY_RESPONSE_RECOVERY_PROMPT =
1818
"Empty response continuation QA check: read QA_KICKOFF_TASK.md, then answer with exactly EMPTY-RECOVERED-OK.";
1919
const QA_EMPTY_RESPONSE_EXHAUSTION_PROMPT =
2020
"Empty response exhaustion QA check: read QA_KICKOFF_TASK.md, then answer with exactly EMPTY-EXHAUSTED-OK.";
21+
const QA_EMPTY_RESPONSE_SIDE_EFFECT_RECOVERY_PROMPT =
22+
"Empty response after write recovery QA check: write qa-empty-response-side-effect.txt, then answer with exactly TELEGRAM-EMPTY-WRITE-RECOVERED-OK.";
2123
const QA_REASONING_ONLY_RETRY_INSTRUCTION =
2224
"The previous assistant turn recorded reasoning but did not produce a user-visible answer. Continue from that partial turn and produce the visible answer now. Do not restate the reasoning or restart from scratch.";
2325
const QA_EMPTY_RESPONSE_RETRY_INSTRUCTION =
2426
"The previous attempt did not produce a user-visible answer. Continue from the current state and produce the visible answer now. Do not restart from scratch.";
27+
const QA_SETTLED_TOOL_TERMINAL_CONTINUATION_INSTRUCTION =
28+
"The previous assistant turn completed its tool calls but did not produce a user-visible answer. Continue from the current transcript and produce the final user-visible answer now. Do not repeat completed tool calls or restart from scratch.";
2529

2630
afterEach(async () => {
2731
while (cleanups.length > 0) {
@@ -6035,7 +6039,7 @@ describe("qa mock openai server", () => {
60356039
model: "gpt-5.6-luna",
60366040
input: [
60376041
makeUserInput(QA_EMPTY_RESPONSE_RECOVERY_PROMPT),
6038-
makeUserInput(QA_EMPTY_RESPONSE_RETRY_INSTRUCTION),
6042+
makeUserInput(QA_SETTLED_TOOL_TERMINAL_CONTINUATION_INSTRUCTION),
60396043
{
60406044
type: "function_call_output",
60416045
output: "QA mission: Understand this OpenClaw repo from source + docs before acting.",
@@ -6085,6 +6089,43 @@ describe("qa mock openai server", () => {
60856089
});
60866090
expect(secondEmpty.output?.[0]?.content?.[0]?.text).toBe("");
60876091
});
6092+
6093+
it("scripts settled continuation after an empty response from a side-effecting write", async () => {
6094+
const server = await startMockServer();
6095+
6096+
const toolPlan = await expectResponsesText(server, {
6097+
stream: true,
6098+
model: "gpt-5.6-luna",
6099+
input: [makeUserInput(QA_EMPTY_RESPONSE_SIDE_EFFECT_RECOVERY_PROMPT)],
6100+
});
6101+
expect(toolPlan).toContain('"name":"write"');
6102+
6103+
const toolOutput = {
6104+
type: "function_call_output" as const,
6105+
output: "Successfully wrote 27 bytes to qa-empty-response-side-effect.txt",
6106+
};
6107+
const emptyPayload = await expectResponsesJson<{
6108+
output?: Array<{ content?: Array<{ text?: string }> }>;
6109+
}>(server, {
6110+
stream: false,
6111+
model: "gpt-5.6-luna",
6112+
input: [makeUserInput(QA_EMPTY_RESPONSE_SIDE_EFFECT_RECOVERY_PROMPT), toolOutput],
6113+
});
6114+
expect(emptyPayload.output?.[0]?.content?.[0]?.text).toBe("");
6115+
6116+
const recoveredPayload = await expectResponsesJson<{
6117+
output?: Array<{ content?: Array<{ text?: string }> }>;
6118+
}>(server, {
6119+
stream: false,
6120+
model: "gpt-5.6-luna",
6121+
input: [
6122+
makeUserInput(QA_EMPTY_RESPONSE_SIDE_EFFECT_RECOVERY_PROMPT),
6123+
makeUserInput(QA_SETTLED_TOOL_TERMINAL_CONTINUATION_INSTRUCTION),
6124+
toolOutput,
6125+
],
6126+
});
6127+
expect(outputText(recoveredPayload)).toBe("TELEGRAM-EMPTY-WRITE-RECOVERED-OK");
6128+
});
60886129
});
60896130

60906131
describe("qa mock openai server provider variant tagging", () => {

‎extensions/qa-lab/src/providers/mock-openai/server.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
QA_THINKING_VISIBILITY_MAX_PROMPT_RE,
2222
QA_EMPTY_RESPONSE_RECOVERY_PROMPT_RE,
2323
QA_EMPTY_RESPONSE_EXHAUSTION_PROMPT_RE,
24+
QA_EMPTY_RESPONSE_SIDE_EFFECT_RECOVERY_PROMPT_RE,
2425
QA_STREAMING_PROMPT_RE,
2526
QA_FINAL_ONLY_MARKER_STREAMING_PROMPT_RE,
2627
QA_BLOCK_STREAMING_PROMPT_RE,
@@ -49,6 +50,7 @@ import {
4950
QA_IMAGE_GENERATION_PROMPT_RE,
5051
QA_REASONING_ONLY_RETRY_NEEDLE,
5152
QA_EMPTY_RESPONSE_RETRY_NEEDLE,
53+
QA_SETTLED_TOOL_TERMINAL_CONTINUATION_NEEDLE,
5254
QA_SKILL_WORKSHOP_GIF_PROMPT_RE,
5355
QA_SKILL_WORKSHOP_REVIEW_PROMPT_RE,
5456
QA_RELEASE_AUDIT_PROMPT_RE,
@@ -187,7 +189,9 @@ async function buildResponsesPayload(
187189
const isGroupChat = allInputText.includes('"is_group_chat": true');
188190
const isBaselineUnmentionedChannelChatter = /\bno bot ping here\b/i.test(prompt);
189191
const hasReasoningOnlyRetryInstruction = allInputText.includes(QA_REASONING_ONLY_RETRY_NEEDLE);
190-
const hasEmptyResponseRetryInstruction = allInputText.includes(QA_EMPTY_RESPONSE_RETRY_NEEDLE);
192+
const hasEmptyResponseRetryInstruction =
193+
allInputText.includes(QA_EMPTY_RESPONSE_RETRY_NEEDLE) ||
194+
allInputText.includes(QA_SETTLED_TOOL_TERMINAL_CONTINUATION_NEEDLE);
191195
const canCallMockSubagentTool =
192196
QA_SUBAGENT_DIRECT_FALLBACK_PROMPT_RE.test(allInputText) ||
193197
/subagent fanout synthesis check/i.test(allInputText) ||
@@ -430,6 +434,18 @@ async function buildResponsesPayload(
430434
}
431435
return buildAssistantEvents("");
432436
}
437+
if (QA_EMPTY_RESPONSE_SIDE_EFFECT_RECOVERY_PROMPT_RE.test(allInputText)) {
438+
if (allInputText.includes(QA_SETTLED_TOOL_TERMINAL_CONTINUATION_NEEDLE)) {
439+
return buildAssistantEvents("TELEGRAM-EMPTY-WRITE-RECOVERED-OK");
440+
}
441+
if (!toolOutput) {
442+
return buildToolCallEventsWithArgs("write", {
443+
path: "qa-empty-response-side-effect.txt",
444+
content: "side effect completed once\n",
445+
});
446+
}
447+
return buildAssistantEvents("");
448+
}
433449
if (QA_TELEGRAM_LONG_FINAL_THREE_CHUNK_PROMPT_RE.test(allInputText)) {
434450
const text = buildQaLongFinalText({
435451
endMarker: "TELEGRAM-LONG-FINAL-3CHUNK-END",
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
title: Telegram empty-response recovery after a side-effecting write
2+
3+
scenario:
4+
id: telegram-empty-response-after-write-recovery
5+
surface: channel-framework
6+
category: channel-framework.channel-actions-commands-and-approvals
7+
coverage:
8+
primary: [runtime.empty-response-recovery]
9+
secondary: [runtime.retry-policy]
10+
regressionRefs:
11+
- openclaw/openclaw#108738
12+
objective: Verify a settled side-effecting tool followed by an empty stop gets one fresh continuation and one visible Telegram final reply.
13+
successCriteria:
14+
- The model plans the side-effecting write exactly once.
15+
- The runtime continues from settled tool results without replaying the write.
16+
- Telegram receives the exact recovery marker.
17+
codeRefs:
18+
- src/agents/embedded-agent-runner/run/incomplete-turn.ts
19+
- src/agents/embedded-agent-runner/run/terminal-resolution.ts
20+
- extensions/qa-lab/src/providers/mock-openai/server.ts
21+
execution:
22+
kind: flow
23+
channel: telegram
24+
summary: Prove post-tool empty-stop recovery through real Telegram transport.
25+
config:
26+
requiredProviderMode: mock-openai
27+
promptSnippet: Empty response after write recovery QA check
28+
retryNeedle: The previous assistant turn completed its tool calls but did not produce a user-visible answer.
29+
expectedMarker: TELEGRAM-EMPTY-WRITE-RECOVERED-OK
30+
31+
flow:
32+
steps:
33+
- name: continues once after the settled write and delivers the final marker
34+
actions:
35+
- assert:
36+
expr: "env.providerMode === 'mock-openai'"
37+
message: this Telegram regression scenario is mock-openai only
38+
- resetTransport: true
39+
- set: requestCursorBefore
40+
value:
41+
expr: "env.mock ? (await fetchJson(`${env.mock.baseUrl}/debug/request-cursor`)).cursor : 0"
42+
- set: startIndex
43+
value:
44+
expr: "state.getSnapshot().messages.filter((message) => message.direction === 'outbound').length"
45+
- sendInbound:
46+
conversation: { id: telegram-command-room, kind: channel }
47+
senderId: qa-command-operator
48+
senderName: QA Command Operator
49+
text: "@openclaw Empty response after write recovery QA check: write qa-empty-response-side-effect.txt with the text side effect completed once, then answer exactly TELEGRAM-EMPTY-WRITE-RECOVERED-OK."
50+
- waitForOutbound:
51+
conversation: { id: telegram-command-room, kind: channel }
52+
sinceIndex: { ref: startIndex }
53+
textIncludes: { ref: config.expectedMarker }
54+
timeoutMs: 60000
55+
saveAs: reply
56+
- set: scenarioRequests
57+
value:
58+
expr: "env.mock ? (await fetchJson(`${env.mock.baseUrl}/debug/requests?after=${requestCursorBefore}`)).filter((request) => String(request.allInputText ?? '').includes(config.promptSnippet)) : []"
59+
- set: writeRequests
60+
value:
61+
expr: "scenarioRequests.filter((request) => request.plannedToolName === 'write')"
62+
- set: continuationRequests
63+
value:
64+
expr: "scenarioRequests.filter((request) => String(request.allInputText ?? '').includes(config.retryNeedle))"
65+
- assert:
66+
expr: "writeRequests.length === 1"
67+
message:
68+
expr: "`expected one write plan, saw ${String(writeRequests.length)}`"
69+
- assert:
70+
expr: "continuationRequests.length === 1"
71+
message:
72+
expr: "`expected one settled-tool continuation, saw ${String(continuationRequests.length)}`"
73+
- assert:
74+
expr: "continuationRequests.every((request) => !Array.isArray(request.body?.tools) || request.body.tools.length === 0)"
75+
message: settled-tool continuation exposed a model tool surface
76+
- assert:
77+
expr: "reply.text.trim() === config.expectedMarker"
78+
message:
79+
expr: "`Telegram reply did not exactly match the recovery marker: ${reply.text}`"
80+
detailsExpr: "`${reply.text}\nrequests=${String(scenarioRequests.length)} writes=${String(writeRequests.length)} continuations=${String(continuationRequests.length)}`"

‎qa/scenarios/runtime/empty-response-recovery-replay-safe-read.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ scenario:
2727
promptSnippet: Empty response continuation QA check
2828
prompt: "Empty response continuation QA check: read QA_KICKOFF_TASK.md, then answer with exactly EMPTY-RECOVERED-OK."
2929
expectedReply: EMPTY-RECOVERED-OK
30-
retryNeedle: The previous attempt did not produce a user-visible answer.
30+
retryNeedle: The previous assistant turn completed its tool calls but did not produce a user-visible answer.
3131

3232
flow:
3333
steps:

0 commit comments

Comments
 (0)