Files
openworker/surfaces
Devika Verma 786ba30225 Continue the turn when a reply is cut off at the output limit with no action (OPE-171)
A reply that hit the output-token limit (finish_reason "length") with no tool
call — typically thinking consumed the whole budget and nothing else came back
— took the `if not turn.tool_calls` branch and ended the turn as "completed".
The task was silently abandoned (two of Fable 5.1's three failures and one of
Sonnet 5's on a ten-task trial were this shape).

Engine:
- On such a reply, append a user-role nudge (TRUNCATION_NUDGE: act now, do not
  repeat the reasoning), emit a CONTINUATION event, and go round the loop.
  At most MAX_TRUNCATION_CONTINUATIONS (2) consecutive nudges per turn; the
  counter resets on any non-truncated reply and at the start of each turn.
- On the cap, persist a `truncated` notice and end with TURN_END
  status "truncated" — never "completed".
- The cut-off reply stays in the transcript (finish_reason "length", its
  partial reasoning) but is replayed to providers as a short stub
  (`replay: "stub"` sidecar → TRUNCATION_STUB): its thinking block has no
  signature, which Anthropic rejects, and it carries nothing useful anywhere.
- A truncated reply that still has a parseable tool call is unchanged (the
  mangled-call path already covers broken arguments).

GUI (surfaces/gui): "continuation" event → info notice; turn_end "truncated"
→ warning; persisted `truncated` notice replays as a retriable warning; en/zh
strings.

Tests: tests/test_truncation_continuation.py (nudge then complete, stub
replay, partial text, cap → truncated + notice, tool-call case untouched,
counter resets within and between turns, normal path untouched, stub survives
persistence); GUI itemsFromMessages test for the truncated notice.
2026-09-08 18:29:44 +05:30
..