Skip to content

fix(agents): drop orphaned thinking blocks when NO_REPLY text leaves an assistant message with only thinking content (#99620) - #99772

Merged
steipete merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/no-reply-merge-thinking-99620
Jul 21, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/no-reply-merge-thinking-99620

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #99620

What Problem This Solves

Fixes an issue where a silent NO_REPLY assistant turn could retain only signed thinking after replay cleanup. When the next turn used a tool, Anthropic turn validation merged both assistant rows into one [thinking, thinking, tool_use] message and the provider rejected every subsequent request, leaving the session stuck until reset.

Why This Change Was Made

Replay normalization now records when it removes silent text and drops the assistant row only when the remaining content is exclusively thinking or redacted-thinking blocks. It reuses the existing reasoning-only classifier; visible text, tool calls, primitive blocks, and unknown blocks remain unchanged. The global transcript-hygiene reference documents the new boundary.

This is the generic boundary because NO_REPLY is an OpenClaw-wide silent-turn contract. No provider config, compatibility shim, or second replay path is added.

User Impact

Affected sessions can rebuild context after a silent yield and continue normally instead of entering a permanent Anthropic HTTP 400 loop. Ordinary replies and silent turns that carry tool or unknown content are unchanged.

Evidence

  • node scripts/run-vitest.mjs src/agents/embedded-agent-runner/replay-history.test.ts — 42 passed.
  • node scripts/run-vitest.mjs src/agents/embedded-agent-helpers.validate-turns.test.ts src/agents/embedded-agent-runner/thinking.test.ts — 33 + 47 passed.
  • Testbox changed gate — passed at tbx_01ky1rcvtmq5k0j5jkvtj78dj0: https://github.com/openclaw/openclaw/actions/runs/29809708167
  • Structured autoreview — clean, no accepted/actionable findings, confidence 0.96.
  • The linked issue includes direct Anthropic evidence: the merged replay shape returned HTTP 400 while the separated shape returned HTTP 200. A fresh exact-head live rerun was attempted, but the Testbox Actions secret was unavailable and no provider call ran.

Credit

Maintainer rewrite of the fix contributed by SunnyShu (@SunnyShu0925). The landed commit preserves Co-authored-by: SunnyShu <[email protected]>.

AI-assisted: yes; the human maintainer reviewed the full replay, validation, provider, test, and documentation surfaces.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Jul 4, 2026
@clawsweeper

clawsweeper Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 17, 2026, 2:18 AM ET / 06:18 UTC.

Summary
The PR drops an assistant replay turn when silent-reply text removal leaves only recognized thinking or redacted-thinking blocks, with regression coverage for preservation and edge cases.

PR surface: Source +32, Tests +121. Total +153 across 2 files.

Reproducibility: yes. at high confidence from source and payload construction: current behavior leaves an adjacent thinking-only assistant turn after NO_REPLY cleanup, and the linked production report demonstrates Anthropic rejecting the resulting merged shape. A fresh live Anthropic run was not performed on this head.

Review metrics: 2 noteworthy metrics.

  • Generic replay rules: 1 added. The new deletion runs in shared replay normalization and therefore affects every provider before provider-owned policy hooks.
  • Regression scenarios: 5 added. Coverage exercises the failing shape plus metadata, tool-call, and unknown-content preservation boundaries.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] Merging establishes a generic cross-provider rule that removes a persisted assistant turn from replay whenever NO_REPLY removal leaves only thinking-family content; this may intentionally change context for providers other than Anthropic.
  • [P1] Because deletion occurs during generic cleanup before provider-owned replay hooks, a provider cannot opt out if its protocol assigns replay value to a hidden-only silent turn.

Maintainer options:

  1. Confirm and land the shared invariant (recommended)
    Explicitly accept that silent-reply thinking-only turns are disposable across providers, then merge the proven current head.
  2. Limit cleanup to Anthropic-family replay
    Refactor the guard behind provider replay policy before merge if maintainers do not want generic transcript deletion.

Next step before merge

  • A replay-policy owner should accept or reject the generic deletion invariant, then merge the exact reviewed head or request provider-scoping; no automated repair is currently indicated.

Maintainer decision needed

  • Question: Should silent-reply normalization globally delete an assistant turn that becomes thinking-only for every provider, or should this cleanup be limited to Anthropic-family replay policy?
  • Rationale: The patch is technically sound, but it converts an Anthropic-observed failure into a permanent generic transcript-deletion invariant that provider hooks cannot override.
  • Likely owner: steipete — This person landed adjacent replay sanitation and is the explicit decision recipient in the PR discussion.
  • Options:
    • Accept the generic invariant (recommended): Treat thinking-only residue from a silent reply as universally non-replayable and land the tested current head.
    • Scope by provider: Move the deletion into Anthropic-compatible replay policy so other providers retain their existing generic replay behavior.

Security
Cleared: The two-file patch changes in-memory replay normalization and tests only, with no permissions, dependencies, secrets, network, build, or supply-chain surface added.

Review details

Best possible solution:

Have the replay-policy owner explicitly confirm that a silent assistant turn retaining only thinking-family blocks has no cross-provider replay value, then land this narrow guard and tests; if that invariant is rejected, move equivalent cleanup behind the Anthropic-family replay policy without adding configuration.

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

Yes at high confidence from source and payload construction: current behavior leaves an adjacent thinking-only assistant turn after NO_REPLY cleanup, and the linked production report demonstrates Anthropic rejecting the resulting merged shape. A fresh live Anthropic run was not performed on this head.

Is this the best way to solve the issue?

Unclear pending one ownership decision: the predicate and preservation tests are narrow, but maintainers must confirm that generic deletion is preferable to an Anthropic-family policy rule.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 03d287d11138.

Label changes

Label justifications:

  • P1: The targeted bug can permanently block subsequent turns in an affected session and suppress message delivery until the user resets it.
  • merge-risk: 🚨 compatibility: The PR changes shared replay semantics by deleting a persisted assistant turn for all providers, not only the provider where the failure was observed.
  • merge-risk: 🚨 session-state: A merged guard will intentionally remove selected historical assistant state from future context reconstruction.
  • merge-risk: 🚨 message-delivery: An overly broad deletion predicate could change later model context and therefore suppress or alter subsequent replies even though the reported fix prevents an existing delivery loop.
  • 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. Sufficient (live_output): The PR provides after-fix live output from the actual OpenClaw normalization path, exact before/after provider-payload shapes, linked production Anthropic evidence, and a successful repository proof check; sensitive values are not exposed.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR provides after-fix live output from the actual OpenClaw normalization path, exact before/after provider-payload shapes, linked production Anthropic evidence, and a successful repository proof check; sensitive values are not exposed.
Evidence reviewed

PR surface:

Source +32, Tests +121. Total +153 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 33 1 +32
Tests 1 121 0 +121
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 154 1 +153

What I checked:

Likely related people:

  • steipete: The adjacent missing-signature replay fix was landed in commit 791ad08, and the PR discussion directly requests this person's decision on whether the shared-core invariant is acceptable. (role: recent replay-sanitization merger and likely policy decision owner; confidence: high; commits: 791ad08; files: src/agents/embedded-agent-runner/replay-history.ts, src/agents/embedded-agent-runner/thinking.test.ts)
  • openperf: Merged work in commit 930d81a expanded replay normalization and session repair for persistent provider rejection loops. (role: introduced adjacent replay-hygiene behavior; confidence: high; commits: 930d81aa41d2; files: src/agents/embedded-agent-runner/replay-history.ts, src/agents/session-file-repair.ts, src/agents/stream-message-shared.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (15 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-04T13:22:44.590Z sha 0e845ea7d8cfaf6e88f30d5c6d6c77e18fbd1908 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-06T01:47:28.078Z sha 0e845ea7d8cfaf6e88f30d5c6d6c77e18fbd1908 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-06T03:02:32.173Z sha 0e845ea7d8cfaf6e88f30d5c6d6c77e18fbd1908 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-06T03:10:17.286Z sha 0e845ea7d8cfaf6e88f30d5c6d6c77e18fbd1908 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-17T03:58:04.572Z sha 56404ba4059857b75ac73f65b30bc663d6e610d2 :: needs changes before merge. :: [P3] Document the new replay cleanup rule
  • reviewed 2026-07-17T04:40:34.244Z sha 56404ba4059857b75ac73f65b30bc663d6e610d2 :: needs changes before merge. :: [P2] Preserve unknown blocks in the thinking-only predicate | [P3] Document the new replay cleanup rule
  • reviewed 2026-07-17T05:00:02.140Z sha 3444f13d3e5007ec3761ea5bb2fefed807bd359d :: needs maintainer review before merge. :: none
  • reviewed 2026-07-17T05:37:21.750Z sha 9e01c856d9b4f6c28419175fe9068a2734f9ca0a :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 4, 2026
@clawsweeper

clawsweeper Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@openclaw-barnacle

Copy link
Copy Markdown

Please don’t spam-ping multiple maintainers at once. Be patient, or join our community Discord for help: https://discord.gg/clawd

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

Thank you for the thorough review. I've updated the PR body with a detailed request-builder payload comparison showing the before-fix vs after-fix message structure using OpenClaw's own normalization pipeline.

On the live Anthropic round-trip proof: I do not have a thinking-enabled Anthropic API key to run the live verification. The script scripts/live-test-no-reply-thinking.mjs is ready for any maintainer with API access — it builds both payloads using genuine thinking blocks from @anthropic-ai/sdk and sends them to the live API. If a maintainer can run it, the output will show the before-fix rejection and after-fix acceptance.

The payload-structure evidence in the PR body demonstrates the fix at the request-builder level using the same code paths that the Anthropic provider serializer uses in production. The before-fix payload shape ([thinking, thinking, tool_use]) matches the Anthropic 400 rejection pattern reported in the issue.

@clawsweeper re-review

@SunnyShu0925
SunnyShu0925 force-pushed the fix/no-reply-merge-thinking-99620 branch from 72ef76b to 309f2a0 Compare July 4, 2026 12:45
@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

Rebased on latest upstream/main (commit 706443c79b) to pick up recent CI fixes. The only change in this PR is the single fix commit — the old branch history had 172 stale commits from the fork's divergent history.

Test results after rebase:

  • replay-history.test.ts: 32 passed (3 new + 29 existing) ✓
  • thinking.test.ts: 53 passed unchanged ✓
  • sanitize-session-history.test.ts: 76 passed unchanged ✓

Let's see if the QA Smoke CI passes now.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 4, 2026
@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

Fixed the metadata-stripped silent-text gap found by ClawSweeper review (P2). When stripInternalMetadataForDisplay reveals NO_REPLY text, hasSilentText is now set so the orphaned-thinking guard can fire. Added regression test covering this path.

Changes:

  • replay-history.ts: set hasSilentText on the metadata-stripped branch when the resulting text is silent
  • replay-history.test.ts: new test "drops orphaned thinking when metadata strip reveals NO_REPLY"

Test results: 33 passed (29 original + 3 from PR + 1 new) ✓

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. label Jul 4, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 17, 2026
@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

P3 finding fixed: transcript-hygiene rule documented at replay-history.ts:267-283. Rebased on latest main, 40 tests passing.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

P2 finding fixed: unknown/primitive content blocks now return false from the thinking-only predicate (was true), preventing the guard from dropping messages it cannot classify. Regression test added.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 17, 2026
@steipete steipete self-assigned this Jul 21, 2026
Prevent NO_REPLY cleanup from leaving signed reasoning that merges into the next assistant tool-use turn and bricks strict-provider sessions.

Related: openclaw#99620

Co-authored-by: SunnyShu <[email protected]>
@steipete
steipete force-pushed the fix/no-reply-merge-thinking-99620 branch from 9e01c85 to d66b0ad Compare July 21, 2026 07:20
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Jul 21, 2026
@clawsweeper

clawsweeper Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(agents): drop orphaned thinking blocks when NO_REPLY text leaves an assistant message with only thinking content (#99620) This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

Regenerate the docs map after documenting silent reasoning-only replay cleanup.

Co-authored-by: SunnyShu <[email protected]>
@clawsweeper

clawsweeper Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(agents): drop orphaned thinking blocks when NO_REPLY text leaves an assistant message with only thinking content (#99620) This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@steipete

Copy link
Copy Markdown
Contributor

Maintainer pre-merge verification for 68b1966f3f51b2a4aca85dfdf76fb24ea1067a4c:

Known proof gap: a fresh live Anthropic rerun was attempted, but the Testbox Actions key was unavailable and no provider call ran. The linked issue provides direct production/API evidence that the merged shape returns HTTP 400 and the separated shape returns HTTP 200.

Reviewed source head: 68b1966
Original contributor head: 9e01c85

@steipete
steipete merged commit 796b6fc into openclaw:main Jul 21, 2026
119 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 22, 2026
…an assistant message with only thinking content (openclaw#99620) (openclaw#99772)

* fix(agents): drop silent reasoning-only replay turns

Prevent NO_REPLY cleanup from leaving signed reasoning that merges into the next assistant tool-use turn and bricks strict-provider sessions.

Related: openclaw#99620

Co-authored-by: SunnyShu <[email protected]>

* docs: refresh transcript hygiene map

Regenerate the docs map after documenting silent reasoning-only replay cleanup.

Co-authored-by: SunnyShu <[email protected]>

---------

Co-authored-by: Peter Steinberger <[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 docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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

3 participants