Skip to content

fix(agents): retain completed answer after reasoning-only tail - #167567

Merged
obviyus merged 2 commits into
openclaw:mainfrom
goutamadwant:fix/retain-prepared-answer-after-reasoning-tail
Oct 9, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
goutamadwant:fix/retain-prepared-answer-after-reasoning-tail

Conversation

@goutamadwant

@goutamadwant goutamadwant commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #167543

What Problem This Solves

A completed answer can survive in the transcript and prepared payloads, yet be replaced by the generic generation-failure warning when a later successful assistant message contains only reasoning. The user receives the warning instead of the answer.

Changes

The incomplete-turn guard now honors the subscriber's existing keptAnswer fact. It does not select a second answer, replay tools, or disable protection for answerless turns. The terminal-resolution regression asserts the delivered payload and absence of a terminal error.

Thanks to @hannesrudolph for the report and detailed production/source evidence, and @goutamadwant for the focused fix and regression. The contributor's commit is preserved.

Evidence

Real Gateway and Telegram Test Server Proof

Built both the pinned current-main baseline ec7c8bb9454bab03e76057ecc000bfad35897ce9 and candidate d7ae52ec29e74aae83e28b6662c8d805c48ddb0d in isolated Linux containers. The candidate merges that main into the contributor's branch.

A scripted OpenAI Responses wire server emitted an asynchronous write call followed by a completed final answer, then a reasoning-only successful stop after receiving the settled tool result. The normal provider transport, agent loop, subscriber, terminal resolution, and Telegram dispatch all ran. A network-only preload redirected the native provider endpoint to the mock; no assistant messages, retained-answer state, or terminal results were injected into the runtime.

The repository's Telegram Test Server userbot recorded real DM turns under one host-owned Convex lease:

Case Observed Telegram result
Baseline Final message 72496 contained only the generation-failure warning and side-effect note. Temporary progress message 72495 was deleted. The diagnostic was stopReason=stop payloads=1 tools=1 replaySafe=no, with zero reasoning/empty/missing-assistant retries.
Candidate Final message 72499 contained RETAINED_167543: operation complete. exactly once, with no warning. Temporary progress message 72498 was deleted.
Candidate, genuinely empty output Message 72501 contained the normal generation-failure warning with “Please try again.”
Candidate, settled tools but no authored answer Message 72517 contained the existing finalizer receipt: “The tool run finished, but no final summary was produced. I did not repeat any completed actions.” A baseline built-Gateway control returned the identical receipt.

Both retained-answer runs made exactly two scripted foreground model requests. The second carried the successful write result; neither replayed the write. Separate background recap/catalog requests are excluded from that count. The write fixture was idempotent, and its recorded result reported that the existing synthetic file already had identical contents; the test proves settled potentially side-effecting tool handling, not a destructive action.

A built-Gateway CLI preflight independently reproduced the baseline mismatch: the returned payload was the warning while meta.finalAssistantVisibleText still held the completed answer and meta.error.kind was incomplete_turn.

This is a deterministic real-entry-point reproduction, not a replay of the reporter's private production session or a claim to have recovered its hidden follow-up content. Each recording completed. The runner also logged an upstream getUpdates proxy-fetch error; the recorded message and deletion events establish the outcomes above independently of that diagnostic.

Checks

  • Real pnpm tsgo native core typecheck passed on the candidate.
  • Four focused files passed: terminal resolution, incomplete-turn resolution, incomplete-turn recovery, and async subscriber tails — 66 tests, 102.71 s wall time. The existing subscriber cases cover empty/NO_REPLY tails, supersession, and input isolation.
  • Four additional direct warning-owner controls passed with the side-effect note intact: signed reasoning with a prepared reasoning payload, unsigned answerless reasoning, empty output, and incomplete tool-use output. These exercise the real resolveIncompleteTurnPayloadText without mocking its dependencies. They are boundary controls, not additional Telegram runs; the preceding settled-tool finalizer receipt is separately verified as unchanged from main.
  • Both full builds completed. Both reported the same existing Control UI startup-gzip budget excess; this runner-only diff does not reach UI assets.
  • One real gpt-5-mini agent turn on the candidate, reasoning low, output budget 4096, returned LIVE_167543_OK, with one assistant turn and no tool calls or fallback. The file-backed API credential was removed afterward.
  • The Telegram lease was explicitly released (broker HTTP 200, status=ok); leased files and the live API-key file were removed.

Maintainer intent: checked Sarah's #162948, which preserves actionable harness/auth failure copy in this owner. This fix changes only the retained-answer exception for a successful reasoning-only tail; it leaves that error copy and side-effect warning unchanged. No overlapping Pash change was found.

Merge Danger

Two-way door: reverting restores the old classification; there is no schema, configuration, or stored-data migration. The blast radius is the shared embedded runner's incomplete-turn delivery decision across channels, not Telegram formatting or transport behavior.

@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Oct 9, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Preserve an already completed answer when a later successful assistant response contains only reasoning.

Example: A completed operation is followed by a reasoning-only response

  • Before: Telegram receives the generation-failure warning instead of the completed answer.
  • After: Telegram receives “RETAINED_167543: operation complete.” exactly once without the warning.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused repair with meaningful terminal-delivery coverage and concrete before/after proof through the shipped Gateway and Telegram path.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The updated body records baseline and exact-candidate built Gateway runs through the real subscriber, terminal resolver, and Telegram Test Server delivery: the candidate delivers the retained answer once, while empty and answerless settled-tool controls retain their existing outcomes. Scripted provider wire responses make the scenario deterministic without injecting runtime retention state; the unrelated plain live-model turn is supplemental. No stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Users receive a generation-failure warning even though the agent completed an answer that remains visible in conversation history.
Reason: The existing retention contract already defines the desired behavior. A focused terminal-delivery repair addresses an observed user failure without adding settings or changing that contract.

Merge readiness

✅ Ready for maintainer review

This PR fixes a distinct answer-delivery defect still present on current main. No actionable patch defect remains, and the updated Gateway/Telegram evidence resolves the previous proof gap.

Priority: P1
Reviewed head: d7ae52ec29e74aae83e28b6662c8d805c48ddb0d

Before merge

None.

Findings

None.

Agent review details

How this fits together

The embedded agent runner turns model responses and settled tool results into replies for messaging channels. Its terminal resolver decides whether to deliver prepared answers or replace them with a failure warning.

flowchart TD
  A[Model responses and tool results] --> B[Subscriber retains completed answer]
  B --> C[Prepare reply payloads]
  C --> D[Terminal completion decision]
  D --> E[Deliver retained answer]
  D --> F[Warn when no answer exists]
  E --> G[Messaging channel]
  F --> G
Loading

Technical review

Best possible solution:

Keep answer retention subscriber-owned and make terminal delivery honor that fact while preserving answerless-turn recovery and tool replay restrictions.

Do we have a high-confidence way to reproduce the issue?

Yes: the recorded baseline Gateway/Telegram run reproduces the warning replacement, and current main retains the same responsible guard. This read-only review did not execute current-main code.

Is this the best way to solve the issue?

Yes: the narrow exception consumes the existing subscriber fact instead of selecting another answer or weakening recovery for genuinely answerless turns.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against a69dbd6385c9.

Provenance checked

  • src/agents/embedded-agent-runner/run/incomplete-turn-resolution.ts: thinking-only terminal override keeps the original intent (a40df57: The introducing file split preserved existing incomplete-turn behavior; the guard distinguishes reasoning payloads from user-visible answers. Earlier origin tracing was limited by unavailable historical blobs.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +1, Tests +52. Total +53 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 1 0 +1
Tests 1 52 0 +52
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 53 0 +53

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #167543
Summary: This PR is the focused candidate fix for the linked retained-answer terminal-classification defect.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The linked production report shows completed channel answers replaced by failure warnings during normal agent use.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The changed reply is visible in Telegram; the updated Test Server userbot evidence demonstrates the exact scenario.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-09T02:10:41.249Z sha 79991b8 :: needs real behavior proof before merge. :: none

Reviewed October 9, 2026, 1:23 AM ET / 05:23 UTC (Revision 2).

@obviyus

obviyus commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 9, 2026
@obviyus

obviyus commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

CI attribution for head d7ae52ec29e74aae83e28b6662c8d805c48ddb0d:

  • checks-node-changed-2 fails only subagent-registry.requester-wake.e2e.test.ts / “resumes a persisted requester cohort after database startup inspection finishes”, with AgentDatabaseAdmissionError: Startup inspection has not finished. All seven planned invocations completed; the other six passed.
  • The same case and exception failed independently on PR fix(agents): finished subagent results dropped when a grandchild's delivery stays pending #165987 at 3572962ef89c9d4e85c76f02b9037a1c9c55c703: checks-node-changed-5. Both hosted logs were inspected. The stack fails database admission in assertAgentDatabaseAdmitted → session transcript worker/readers, before terminal answer classification. This PR changes only the retained-answer warning predicate and its regression, not database startup/admission.
  • The aggregate openclaw/ci-gate is consequently red.
  • The initial PR-context failure was mine: the proof heading needed to be literally Evidence. The heading is corrected, and the latest PR context and evidence is successful on this same head. No code was re-pushed and no job was manually rerun.
  • Cancelled: 2, both superseded automation jobs (auto-response and the older PR context and evidence), 0 selected test jobs cancelled. No cancelled test-file replay is needed.
  • Architecture and lint checks passed on this head. The previously reported main Madge issue (811d442afa) and package-activation-fault lint issue (5c81678cb2) were not changed by this PR and are not failures in this run.
  • ClawSweeper is ready on this exact SHA, zero findings, no before-merge items; the Gateway/Telegram proof was accepted.

Paused for maintainer disposition of inherited CI. No merge, unrelated repair, CI rerun, or extra push was performed.

@obviyus

obviyus commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Maintainer override: the only red job is inherited and outside this diff.

ClawSweeper is ready on this exact head, and the Telegram Test Server before/after proof is in the PR.

@obviyus
obviyus merged commit 687e6e9 into openclaw:main Oct 9, 2026
136 of 142 checks passed
@obviyus

obviyus commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Landed in 687e6e9. Thanks @goutamadwant! Verified on the Telegram Test Server: a turn whose answer is followed by a reasoning-only message now delivers the answer once (message 72499) instead of the warning main sent (72496), and empty turns still get the warning.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…law#167567)

Keep a completed final answer when a later successful assistant message is reasoning-only, instead of replacing it with the generic "Agent couldn't generate a response" incomplete-turn warning. Empty and genuinely incomplete turns still get the warning and side-effect note. Reported by @hannesrudolph.

Fixes openclaw#167543.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa pushed a commit that referenced this pull request Oct 10, 2026
Keep a completed final answer when a later successful assistant message is reasoning-only, instead of replacing it with the generic "Agent couldn't generate a response" incomplete-turn warning. Empty and genuinely incomplete turns still get the warning and side-effect note. Reported by @hannesrudolph.

Fixes #167543.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 687e6e9)
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Oct 22, 2026
…law#167567)

Keep a completed final answer when a later successful assistant message is reasoning-only, instead of replacing it with the generic "Agent couldn't generate a response" incomplete-turn warning. Empty and genuinely incomplete turns still get the warning and side-effect note. Reported by @hannesrudolph.

Fixes openclaw#167543.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 687e6e9)
(cherry picked from commit 59d6ef2)
Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Retained final answer replaced by incomplete-turn warning after a reasoning-only follow-up

2 participants