fix: double-paren bug in dropped-tools prefix + add empty-response nudge sibling

Fix: _LENGTH_CONTINUATION_DROPPED_TOOLS_PREFIX ended with '(' but
_get_continuation_prompt still had f'({tool_list})', producing
'((write_file)' instead of '(write_file)'. Removed the '(' from
the prefix constant — the parenthesis belongs in the interpolation.

Widened: promoted the empty-response nudge (line 6993,
'You just executed tool calls but returned an empty response...')
to _EMPTY_TOOL_RESPONSE_NUDGE constant and added it to the
classifier's recognition set. Same bug class — its
_empty_recovery_synthetic metadata flag doesn't survive SessionDB
projection either.

Test: added parametrize case for the empty-response nudge (7→8 cases).
E2E: verified byte-for-byte string equivalence for all nudge constants.
This commit is contained in:
kshitij
2026-08-09 16:20:14 +05:30
parent 45cd93fb5b
commit 4f675cf2fc
3 changed files with 19 additions and 6 deletions
+2
View File
@@ -4601,6 +4601,7 @@ This compaction should PRIORITISE preserving all information related to the focu
_CODEX_ACK_CONTINUATION_NUDGE,
_CODEX_INCOMPLETE_NUDGE,
_DROPPED_TOOLCALL_NUDGE_CONTENT,
_EMPTY_TOOL_RESPONSE_NUDGE,
_LENGTH_CONTINUATION_DROPPED_TOOLS_PREFIX,
_LENGTH_CONTINUATION_NETWORK_STUB,
_LENGTH_CONTINUATION_OUTPUT_LIMIT,
@@ -4613,6 +4614,7 @@ This compaction should PRIORITISE preserving all information related to the focu
_CODEX_INCOMPLETE_NUDGE,
_CODEX_ACK_CONTINUATION_NUDGE,
_DROPPED_TOOLCALL_NUDGE_CONTENT,
_EMPTY_TOOL_RESPONSE_NUDGE,
_LENGTH_CONTINUATION_NETWORK_STUB,
_LENGTH_CONTINUATION_OUTPUT_LIMIT,
} or text.startswith(
+11 -6
View File
@@ -779,7 +779,7 @@ _LENGTH_CONTINUATION_OUTPUT_LIMIT = (
# The dropped-tools variant interpolates the tool name list right after this
# prefix, so it can't be exact-matched — this stable prefix is what
# _is_synthetic_compression_user_turn checks with str.startswith instead.
_LENGTH_CONTINUATION_DROPPED_TOOLS_PREFIX = "[System: Your previous tool call ("
_LENGTH_CONTINUATION_DROPPED_TOOLS_PREFIX = "[System: Your previous tool call "
def _get_continuation_prompt(is_partial_stub: bool, dropped_tools: Optional[List[str]] = None) -> str:
@@ -839,6 +839,15 @@ _DROPPED_TOOLCALL_NUDGE_CONTENT = (
"the actual tool call now to continue the task."
)
# Re-prompt sent when the model returns an empty response after executing tool
# calls (#9400). Named for the same reason as the nudges above — its
# _empty_recovery_synthetic metadata flag doesn't survive SessionDB projection.
_EMPTY_TOOL_RESPONSE_NUDGE = (
"You just executed tool calls but returned an "
"empty response. Please process the tool "
"results above and continue with the task."
)
# Shared recovery hint appended to every content-policy refusal message. Both
# the HTTP-200 refusal path (``finish_reason=content_filter``) and the
@@ -7070,11 +7079,7 @@ def run_conversation(
messages.append(_nudge_msg)
messages.append({
"role": "user",
"content": (
"You just executed tool calls but returned an "
"empty response. Please process the tool "
"results above and continue with the task."
),
"content": _EMPTY_TOOL_RESPONSE_NUDGE,
"_empty_recovery_synthetic": True,
})
continue
@@ -280,6 +280,12 @@ def test_real_task_wins_over_trailing_max_iterations_nudge(compressor):
"the actual tool call now to continue the task.",
id="dropped_toolcall_nudge",
),
pytest.param(
"You just executed tool calls but returned an "
"empty response. Please process the tool "
"results above and continue with the task.",
id="empty_tool_response_nudge",
),
],
)
def test_conversation_loop_retry_nudges_are_synthetic(content):