ga.py: "Incomplete response" triggers on replies that merely quote a truncation marker
Summary
do_no_tool() declares a response incomplete if a truncation marker appears anywhere in the trailing window. When the model mentions such a marker in its own reply — debugging this check, writing docs, or writing a test — the reply is thrown away and the user sees the answer stop mid-way and restart.
Reproduction (deterministic, no network needed)
Ask the agent to explain or debug the truncation-handling logic in ga.py. Any reply whose tail contains a literal marker string (e.g. quoting the source line, or a test case) trips the check:
[ERROR] Incomplete response. Regenerate and tooluse.
The reply already streamed to the terminal is discarded. After 3 consecutive attempts _retry_or_exit aborts the task:
[任务中止] 模型连续 3 次未产出有效回复(...) 已停止本轮任务。
Impact
- Self-reinforcing: the more thoroughly the model explains the mechanism, the more certain it trips it. Diagnosing this bug in-conversation makes the bug worse.
- Any reply that quotes the source, writes a fixture, or discusses truncation handling is affected.
- Users observe "the answer stops and restarts" with no clear cause.
Current code
if '[!!! 流异常中断' in content[-100:] or '!!!Error:' in content[50:][-100:] or (content.endswith('</summary>') and len(content) < 100):
return self._retry_or_exit("[ERROR] Incomplete response. Regenerate and tooluse.")
The comment above it (in newer trees) states the [!!! prefix was chosen "to avoid false positives when the body quotes these words" — but quoting the complete marker, prefix included, still matches.
Additional gap found
llmcore emits four marker forms, but ga.py only checks one:
| marker | emitted at | checked by ga.py |
|---|---|---|
[!!! 流异常中断 ... !!!] |
llmcore.py:244, 541 | yes |
[!!! Response truncated: max_tokens !!!] |
llmcore.py:245 | no |
[!!! output truncated: {reason}] |
llmcore.py:331, 444 | no |
!!!Error: ... |
llmcore.py:541 | yes |
So genuinely truncated responses (max_tokens / output truncation) can also slip through as if complete.
Suggested fix
Anchor the match to the end of the content (llmcore always appends markers at the very end), and cover all marker kinds:
_tail = content.rstrip()
_MARK_TAIL = re.compile(r'\[!!!\s*(?:流异常中断|Response truncated|output truncated).*?!!!\]\s*$')
if (_MARK_TAIL.search(_tail)
or _tail.endswith('!!!Error:') or _tail.startswith('!!!Error:')
or (_tail.endswith('</summary>') and len(_tail) < 100)):
return self._retry_or_exit("[ERROR] Incomplete response. Regenerate and tooluse.")
Note: the marker itself may contain a bracket — e.g. [!!! 流异常中断,未收到完整响应(无 [DONE])!!!] — so a [^\]]* pattern silently fails on real truncation. .*? up to !!!] is required.
PR
#859 — includes 9 end-to-end cases covering both the false positive and the two previously-unchecked truncation kinds.