Skip to content

Bug: Subagent announce-delivery echo messages inherit wrong provider/model metadata, causing persistent "thinking blocks cannot be modified" errors after gateway restart #87329

Closed

Description

@travellingsoldier85

Issue Title

Bug: Subagent announce-delivery echo messages inherit wrong provider/model metadata, causing persistent "thinking blocks cannot be modified" errors after gateway restart


GitHub Issue

Bug: Echo assistant messages from subagent announce-delivery bypass isTranscriptOnlyOpenClawAssistantMessage filter, causing persistent Anthropic API errors after gateway restart

Summary

When a gateway restart occurs while a session has active thinking blocks, the subagent announce-delivery mechanism writes echo assistant messages to the parent session that inherit the original API response metadata (provider="anthropic", model="claude-sonnet-4-6"). Because these messages are not tagged as internal echoes (provider="openclaw", model="delivery-mirror"), they bypass the existing isTranscriptOnlyOpenClawAssistantMessage filter and appear as real consecutive assistant turns in subsequent API requests. This causes Anthropic to reject every subsequent user message with "thinking or redacted_thinking blocks in the latest assistant message cannot be modified" — an error that repeats on every turn for up to 23 minutes until the offending thinking block naturally rotates out of the message window.


Steps to Reproduce

  1. Enable thinking in a session: /thinking medium
  2. Spawn one or more subagents that will deliver results back to the parent session.
  3. While a turn is in progress (subagent running), restart the OpenClaw gateway.
  4. After the gateway comes back, send any user message.
  5. Observe the error immediately:
LLM request rejected: messages.25.content.1: thinking or redacted_thinking blocks
in the latest assistant message cannot be modified. These blocks must remain as
they were in the original response.
  1. Send another message. The error fires again. Repeat for every message for approximately 20–23 minutes.

Expected Behavior

Subagent announce-delivery echo messages should be transparently filtered from the API message replay. The session transcript should include them as internal bookkeeping entries only, invisible to the Anthropic API, with no impact on the conversation flow. Users should be able to send messages immediately after a gateway restart without error.

Actual Behavior

Every user message after the gateway restart triggers the Anthropic "thinking or redacted_thinking blocks cannot be modified" error. The error self-resolves only once the offending thinking block rotates out of the active message context window (~23 minutes, 8 failed attempts observed in a single session).


Root Cause Analysis

The failure is a chain of three distinct issues. RC-1 is the root cause; RC-2 and RC-3 amplify the damage.

RC-1 (Root of Roots): Echo messages are tagged with the wrong provider/model

When the announce-delivery path writes an echo of the assistant response to the parent session, it copies the original API response metadata verbatim. The resulting session entries look like this (from live session 38ff0e59):

{"id": "8a80757e", "message": {"role": "assistant", "provider": "anthropic", "model": "claude-sonnet-4-6", "api": "anthropic-messages", "content": [{"type": "text", "text": "..."}]}}
{"id": "7e1f9a8e", "message": {"role": "assistant", "provider": "anthropic", "model": "claude-sonnet-4-6", "api": "anthropic-messages", "content": [{"type": "text", "text": "..."}]}}

An existing filter (isTranscriptOnlyOpenClawAssistantMessage) is specifically designed to identify internal echo messages and exclude them from API replay:

// selection-DZnXuqgh.js / normalizeAssistantReplayContent
function isTranscriptOnlyOpenClawAssistantMessage(message) {
    const provider = normalizeOptionalString(message.provider) ?? "";
    const model = normalizeOptionalString(message.model) ?? "";
    return provider === "openclaw" && (model === "delivery-mirror" || model === "gateway-injected");
}

Because the echo messages carry provider="anthropic", this predicate returns false. The echoes pass through as real assistant turns, creating consecutive assistant turns in the API payload — with the earlier turn containing a thinking block that Anthropic refuses to allow in any position other than the final assistant message.

RC-2 (Amplifier): validateAnthropicTurns does not merge consecutive assistant turns

The Gemini validation path already handles consecutive assistant turns correctly:

// pi-embedded-helpers-seljzB3q.js
function validateGeminiTurns(messages) {
    return validateTurnsWithConsecutiveMerge({
        messages,
        role: "assistant",              // merges consecutive assistant turns
        merge: mergeConsecutiveAssistantTurns,
    });
}

The Anthropic path does not:

function validateAnthropicTurns(messages) {
    return validateTurnsWithConsecutiveMerge({
        messages: stripDanglingAnthropicToolUses(messages),
        role: "user",                   // only merges user turns — no assistant merge
        merge: mergeConsecutiveUserTurns,
    });
}

mergeConsecutiveAssistantTurns exists and is battle-tested. It is simply not wired into the Anthropic path. If it were, a leaking echo that slips past RC-1 would be silently merged rather than triggering an API error.

RC-3 (Amplifier): Recovery is per-request, not per-session

wrapAnthropicStreamWithRecovery fires when it detects a thinking-block error, strips the thinking blocks, and retries. However, recoveredAnthropicThinking is a per-request flag. The next user message creates a fresh request object with recoveredAnthropicThinking = false. The same error fires, recovery fires again, and this cycle repeats N times until the original thinking block organically scrolls past position messages[25].

This is not the proximate cause, but it is what turns a single structural bug into a 23-minute outage.


Proposed Fixes

Fix 1 — PRIMARY: Tag echo messages correctly at write time

Location: The announce-delivery message writer (wherever it appends the echo assistant message to the parent session transcript).

Change:

// Before writing the echo to the parent session, override metadata:
const echoMessage = {
    ...originalAssistantMessage,
    provider: "openclaw",       // was: inherited "anthropic"
    model: "delivery-mirror",   // was: inherited "claude-sonnet-4-6"
    api: undefined,             // clear — this is not an API response
};
// write echoMessage to session, not originalAssistantMessage

Why this is safe: The delivery-mirror model value and the isTranscriptOnlyOpenClawAssistantMessage filter are already present in production. This fix simply ensures the tag is applied at write time instead of relying on external consumers to detect echoes by other means. Risk: LOW.


Fix 2 — DEFENSE IN DEPTH: Merge consecutive assistant turns in validateAnthropicTurns

Location: src/agents/pi-embedded-helpers/turns.ts (or equivalent bundled source)

Change:

export function validateAnthropicTurns(messages: AgentMessage[]): AgentMessage[] {
    // Step 1: strip dangling tool uses (existing)
    const stripped = stripDanglingAnthropicToolUses(messages);

    // Step 2: merge consecutive assistant turns (NEW — mirrors validateGeminiTurns)
    const withMergedAssistant = validateTurnsWithConsecutiveMerge({
        messages: stripped,
        role: "assistant",
        merge: mergeConsecutiveAssistantTurns,
    });

    // Step 3: merge consecutive user turns (existing)
    return validateTurnsWithConsecutiveMerge({
        messages: withMergedAssistant,
        role: "user",
        merge: mergeConsecutiveUserTurns,
    });
}

Why this is safe: mergeConsecutiveAssistantTurns is already exercised by the Gemini path on every request. Merging [thinking, text] + [text] produces [thinking, text, text], which is valid Anthropic content. This provides a structural guarantee: even if a future bug allows a mis-tagged echo to reach the validation layer, it will be silently resolved rather than surfaced as an API error. Risk: LOW.


Fix 3 — OPTIONAL: Persist recovery state at the session level

Location: wrapAnthropicStreamWithRecovery

When recovery fires, write a custom marker entry to the session:

await session.appendCustomEntry({
    type: "anthropic-thinking-recovery",
    firedAt: Date.now(),
    strippedUpToMessageIndex: messages.length,
});

On the next turn, before building the API request, check for this marker and apply stripAllThinkingBlocks proactively to avoid the N-retry cascade.

Why this is lower priority: If Fix 1 and Fix 2 are applied, this error path should never be reached in the echo scenario. This fix targets the edge case where recovery is needed for reasons other than mis-tagged echoes (e.g., a genuine thinking block persisted across an unclean shutdown). Risk: MEDIUM (requires session state schema change).


Environment

Field Value
OpenClaw version 2026.5.26
Model anthropic/claude-sonnet-4-6
Channel webchat (TUI)
Thinking level medium
Error first observed 2026-05-27T13:49 UTC
Error duration ~23 minutes
Failed attempts before self-resolution 8
Session ID (for log correlation) 38ff0e59

Additional Context

The 2026.5.26 release improved THINKING_BLOCK_ERROR_PATTERN to catch a related error (Invalid signature in thinking block). That fix correctly targets the thinking recovery logic. This bug is distinct: it lives in the session transcript writer, not the recovery path. The two bugs are orthogonal and can both be present simultaneously — the signature error triggers recovery, and the echo-tagging bug causes recovery to fire on every subsequent turn.

A quick test to confirm the fix for RC-1 is working: after applying it, inspect a new session file where subagent echo messages have been written and verify the entries show "provider": "openclaw" and "model": "delivery-mirror". If isTranscriptOnlyOpenClawAssistantMessage is evaluated on those entries, it should return true.


Investigated and reported after live observation during a 23-minute error window on 2026-05-27. Root causes confirmed by direct session file inspection and source analysis of the bundled JS. All proposed fixes reference existing production code — no new infrastructure required for Fix 1 or Fix 2.

Activity

  1. clawsweeper commented on May 27, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed May 27, 2026, 11:21 AM ET / 15:21 UTC.

    Summary
    Keep open: current main filters correctly tagged delivery mirrors, but the dormant/restarted completion path still direct-runs the requester agent and Anthropic replay validation does not merge consecutive assistant turns, so the reported failure chain is still plausible and needs a narrow fix.

    Reproducibility: no. live high-confidence reproduction was performed in this read-only review. Source inspection supports the reported chain through dormant announce delivery, provider-owned assistant replay, Anthropic turn validation, and request-local thinking recovery.

    Ways to help us reproduce this

    • Add a screenshot or short recording showing the behavior.
    • Add expected vs actual behavior.

    Next step
    A narrow repair lane is reasonable because the source path is concrete, but the fix should first capture the restart/dormant completion transcript shape in a regression test.

    Review details

    Best possible solution:

    Add a focused replay-safety fix that preserves current delivery routing while ensuring announce-delivery artifacts cannot enter Anthropic replay as a separate provider-owned assistant turn after restart.

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

    No live high-confidence reproduction was performed in this read-only review. Source inspection supports the reported chain through dormant announce delivery, provider-owned assistant replay, Anthropic turn validation, and request-local thinking recovery.

    Is this the best way to solve the issue?

    Unclear that retagging all direct announce output is the best fix, because the dormant requester-agent handoff is an existing behavior. The safer repair is to add a regression test for the restart/dormant completion case and then make the replay path resilient without changing delivery semantics broadly.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • No live Anthropic gateway-restart reproduction was run in this read-only pass, so the exact persisted transcript shape still needs a regression fixture or real-environment proof before landing.
    • Dormant completion delivery appears to intentionally use requester-agent output today; retagging all such output as transcript-only could hide user-visible completions if applied too broadly.

    Codex review notes: model gpt-5.5, reasoning high; reviewed against 20eab65ff4fc.

    Label changes

    Label changes:

    • add P1: The report describes a latest-release user session that repeatedly rejects every follow-up message after gateway restart, breaking an active agent workflow.
    • add impact:session-state: The affected state is the persisted session transcript and replay window, which can keep poisoning later turns until the bad assistant entry rotates out.
    • add impact:auth-provider: The failure depends on provider/model metadata and Anthropic replay policy for thinking blocks.
    • add issue-rating: 🐚 platinum hermit: Current issue advisory state selects this label.
    • add clawsweeper:needs-live-repro: Current issue advisory state selects this label.

    Label justifications:

    • P1: The report describes a latest-release user session that repeatedly rejects every follow-up message after gateway restart, breaking an active agent workflow.
    • impact:session-state: The affected state is the persisted session transcript and replay window, which can keep poisoning later turns until the bad assistant entry rotates out.
    • impact:auth-provider: The failure depends on provider/model metadata and Anthropic replay policy for thinking blocks.
    Evidence reviewed

    Acceptance criteria:

    • node scripts/run-vitest.mjs src/agents/subagent-announce-delivery.test.ts src/agents/pi-embedded-helpers.validate-turns.test.ts src/agents/pi-embedded-runner/replay-history.test.ts src/agents/pi-embedded-runner/thinking.test.ts
    • For pre-landing proof, run the relevant changed check in Crabbox/Testbox and, if feasible, a real Anthropic replay smoke with a redacted transcript fixture.

    What I checked:

    • Repository policy read: Root AGENTS.md and the relevant src/agents scoped AGENTS.md files were read; the review applied their source-proof, current/shipped behavior, and agent hot-path guidance. (AGENTS.md:1, 20eab65ff4fc)
    • Delivery-mirror filter is narrow: The transcript-only filter only excludes assistant entries with provider=openclaw and model delivery-mirror or gateway-injected, so provider-owned Anthropic assistant entries are still replay candidates. (src/config/sessions/transcript.ts:112, 20eab65ff4fc)
    • Mirror helper tags normal mirrors correctly: The generic appendAssistantMessageToSessionTranscript helper writes provider=openclaw and model=delivery-mirror, which means the reported leak is not closed by this helper alone and likely sits on another announce path. (src/config/sessions/transcript.ts:240, 20eab65ff4fc)
    • Dormant completion path direct-runs the requester agent: Subagent completion delivery steers an active requester, but the dormant/restarted path builds directAgentParams with the parent sessionKey and trigger message, then runs the gateway agent call instead of only appending a transcript-only mirror. (src/agents/subagent-announce-delivery.ts:1072, 20eab65ff4fc)
    • Tests preserve dormant direct delivery behavior: Current tests expect dormant completion requesters to go through the gateway agent call and not the active requester queue, matching the restart-sensitive path described by the report. (src/agents/subagent-announce-delivery.test.ts:941, 20eab65ff4fc)
    • Anthropic validation lacks assistant merge: The existing assistant merge helper is wired for Gemini, while validateAnthropicTurns strips dangling tool uses and only merges consecutive user turns. (src/agents/pi-embedded-helpers/turns.ts:320, 20eab65ff4fc)

    Likely related people:

    • Vincent Koc: Local blame in the shallow checkout attributes the current central transcript, announce-delivery, and Anthropic turn-validation lines to the current grafted source snapshot. (role: recent area contributor; confidence: medium; commits: a02fe525f1c6; files: src/config/sessions/transcript.ts, src/agents/subagent-announce-delivery.ts, src/agents/pi-embedded-helpers/turns.ts)
    • Andy Ye: Recent history shows work on stale Anthropic thinking recovery and redundant delivery mirrors, both adjacent to the reported failure mode. (role: adjacent recovery and delivery-mirror contributor; confidence: medium; commits: 66965f500813, e95efa437381; files: src/agents/pi-embedded-runner/thinking.ts, src/config/sessions/transcript.ts)
    • Josh Lehman: Recent history includes provider replay runtime ownership work on the replay surface that validates and sanitizes stored session history before provider calls. (role: provider replay area contributor; confidence: low; commits: 799c6f40aa69; files: src/agents/pi-embedded-runner/replay-history.ts)
    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.
  2. WarrenJones commented on May 27, 2026

    @WarrenJones
  3. travellingsoldier85 commented on May 27, 2026

    @travellingsoldier85
    Author

    Fix Implementation — Patch Attached

    The PAT used for this account lacks the workflow scope needed to push branches containing .github/workflows/ files (which come from the upstream fork). Attaching the patch here for the maintainer to apply directly.

    Files changed (2 files, 57 insertions, 5 deletions)

    src/agents/pi-embedded-helpers/turns.ts — Add mergeConsecutiveAssistantTurns pass to validateAnthropicTurns

    src/agents/pi-embedded-helpers.validate-turns.test.ts — Update existing test (behavior changed) + add 2 new regression tests

    How to apply

    # From the openclaw repo root:
    curl -o /tmp/fix.patch <patch-url>
    git apply /tmp/fix.patch
    
    # Or copy-paste the patch below and:
    git am < fix.patch

    Patch

    From 67828cc87ac6a36aa7e121faa9cbaa19cdaee968 Mon Sep 17 00:00:00 2001
    From: T68Bot <t68bot@t68agent.ai>
    Date: Wed, 27 May 2026 15:44:11 +0000
    Subject: [PATCH] fix(agents): merge consecutive assistant turns in
     validateAnthropicTurns
    
    When announce-delivery echo messages are injected into a live session
    immediately after a real assistant turn with thinking blocks, Anthropic
    rejects the next API request with:
    
      'thinking or redacted_thinking blocks in the latest assistant message
       cannot be modified'
    
    Root cause: validateAnthropicTurns only merged consecutive user turns.
    Echo assistant messages written by the announce-delivery path can appear
    consecutively with real assistant turns in the session transcript. The
    Anthropic API treats the earlier turn (which may have thinking blocks)
    as 'the latest assistant message', then rejects the next turn because
    the thinking content appears modified.
    
    Fix: add a mergeConsecutiveAssistantTurns pass before the existing
    mergeConsecutiveUserTurns pass, mirroring what validateGeminiTurns
    already does. mergeConsecutiveAssistantTurns is already defined in
    this file and battle-tested in the Gemini path.
    
    Merging [thinking, text] + [text] produces [thinking, text, text],
    which is valid Anthropic content. The thinking block is preserved at
    the front of the merged turn.
    
    Fixes: #87329
    ---
     ...pi-embedded-helpers.validate-turns.test.ts | 44 +++++++++++++++++--
     src/agents/pi-embedded-helpers/turns.ts       | 18 +++++++-
     2 files changed, 57 insertions(+), 5 deletions(-)
    
    diff --git a/src/agents/pi-embedded-helpers.validate-turns.test.ts b/src/agents/pi-embedded-helpers.validate-turns.test.ts
    index 3847d5322d..1c041f2073 100644
    --- a/src/agents/pi-embedded-helpers.validate-turns.test.ts
    +++ b/src/agents/pi-embedded-helpers.validate-turns.test.ts
    @@ -280,7 +280,11 @@ describe("validateAnthropicTurns", () => {
         ]);
       });
     
    -  it("should not merge consecutive assistant messages", () => {
    +  it("should merge consecutive assistant messages", () => {
    +    // Consecutive assistant turns occur when announce-delivery echo messages
    +    // are injected into a live session that also has real assistant turns.
    +    // Anthropic rejects such payloads with "thinking blocks cannot be modified"
    +    // when the earlier turn has thinking content. Merging them prevents this.
         const msgs = asMessages([
           { role: "user", content: [{ type: "text", text: "Question" }] },
           {
    @@ -295,8 +299,42 @@ describe("validateAnthropicTurns", () => {
     
         const result = validateAnthropicTurns(msgs);
     
    -    // validateAnthropicTurns only merges user messages, not assistant
    -    expect(result).toHaveLength(3);
    +    // validateAnthropicTurns now merges consecutive assistant turns (mirrors validateGeminiTurns)
    +    expect(result).toHaveLength(2);
    +    expect(result[0].role).toBe("user");
    +    expect(result[1].role).toBe("assistant");
    +    const merged = result[1] as Extract<AgentMessage, { role: "assistant" }>;
    +    expect(merged.content).toHaveLength(2);
    +  });
    +
    +  it("should merge consecutive assistant turns with thinking blocks (delivery-mirror scenario)", () => {
    +    // Simulates the exact bug: a thinking-block assistant turn followed by an
    +    // echo assistant turn (no thinking). Without the merge, Anthropic rejects
    +    // the next request with "thinking blocks cannot be modified".
    +    const msgs = asMessages([
    +      { role: "user", content: [{ type: "text", text: "Question" }] },
    +      {
    +        role: "assistant",
    +        content: [
    +          { type: "thinking", thinking: "internal thoughts", thinkingSignature: "sig_abc" },
    +          { type: "text", text: "Answer with thinking" },
    +        ],
    +      },
    +      {
    +        role: "assistant",
    +        content: [{ type: "text", text: "Echo delivery" }],
    +      },
    +    ]);
    +
    +    const result = validateAnthropicTurns(msgs);
    +
    +    expect(result).toHaveLength(2);
    +    expect(result[1].role).toBe("assistant");
    +    const merged = result[1] as Extract<AgentMessage, { role: "assistant" }>;
    +    // thinking block preserved from first turn, echo text appended
    +    expect(merged.content).toHaveLength(3);
    +    expect((merged.content[0] as { type: string }).type).toBe("thinking");
    +    expect((merged.content[2] as { type: string; text?: string }).text).toBe("Echo delivery");
       });
     
       it("should handle mixed scenario with steering messages", () => {
    diff --git a/src/agents/pi-embedded-helpers/turns.ts b/src/agents/pi-embedded-helpers/turns.ts
    index 5c3871f498..f627a8a0f4 100644
    --- a/src/agents/pi-embedded-helpers/turns.ts
    +++ b/src/agents/pi-embedded-helpers/turns.ts
    @@ -378,15 +378,29 @@ function normalizeUserContentForMerge(content: unknown): UserContentBlock[] {
     /**
      * Validates and fixes conversation turn sequences for Anthropic API.
      * Anthropic requires strict alternating user→assistant pattern.
    - * Merges consecutive user messages together.
    + * Merges consecutive assistant messages together (e.g. delivery-mirror echoes
    + * followed by real assistant turns) to avoid the "thinking blocks cannot be
    + * modified" rejection from the Anthropic API.
    + * Then merges consecutive user messages together.
      * Also strips dangling tool_use blocks that lack corresponding tool_result blocks.
      */
     export function validateAnthropicTurns(messages: AgentMessage[]): AgentMessage[] {
       // First, strip dangling tool-call blocks from assistant messages.
       const stripped = stripDanglingAnthropicToolUses(messages);
     
    -  return validateTurnsWithConsecutiveMerge({
    +  // Merge consecutive assistant turns before merging user turns.
    +  // This handles the case where a delivery-mirror assistant message is
    +  // immediately followed by the actual model assistant turn, which would
    +  // otherwise cause Anthropic to reject with "thinking blocks cannot be
    +  // modified" when the delivery-mirror message contains thinking content.
    +  const withMergedAssistant = validateTurnsWithConsecutiveMerge({
         messages: stripped,
    +    role: "assistant",
    +    merge: mergeConsecutiveAssistantTurns,
    +  });
    +
    +  return validateTurnsWithConsecutiveMerge({
    +    messages: withMergedAssistant,
         role: "user",
         merge: mergeConsecutiveUserTurns,
       });
    -- 
    2.43.0
    
  4. Jefsky commented on May 27, 2026

    @Jefsky
    Contributor

    I submitted a fix for RC-2 in PR #87346.

    The function was only merging consecutive user turns but not consecutive assistant turns. The helper already existed and was used in — this fix wires it into the Anthropic path as well.

    Consecutive assistant turns (from subagent announce-delivery echo messages) are now silently merged before being sent to the Anthropic API, preventing the 'thinking blocks cannot be modified' error.

  5. bryanbaer commented on May 30, 2026

    @bryanbaer

    Update — 2026-05-30, observed against openclaw@2026.5.27 (and verified against 2026.5.28-beta.4).

    The bug is still reproducing with the symptom messages.N.content.M: thinking or redacted_thinking blocks in the latest assistant message despite RC-1 being fully fixed in the installed code (transcript.appendAssistantMessageToSessionTranscript correctly hardcodes provider="openclaw", model="delivery-mirror" and all live callers use it; no mistagged echoes are reaching the transcript).

    Investigation finding: the current source of consecutive assistant turns is not the announce-delivery mirror — it's the dormant-requester direct-agent path in src/agents/subagent-announce-delivery.ts (directAgentParams ~line 1012 in the bundled output). When a subagent completes while the requester (e.g. a cron run or a TUI in another tab) is dormant, the announce-delivery path runs the requester agent inside the parent session via runAnnounceAgentCall. This produces a real provider="anthropic" assistant turn that isTranscriptOnlyOpenClawAssistantMessage correctly does not filter, because it is not a mirror — it is a real agent run.

    The structural problem RC-2 (no assistant-turn merge in validateAnthropicTurns) is what turns this into the user-visible "thinking blocks cannot be modified" rejection. PR #87346 is exactly the right fix and is sufficient to neutralise both this Mode B (dormant-completion direct agent run) and the original Mode A.

    Notes on PR #87346 CI status: every Real behavior proof / build-artifacts / dependency-guard job has been red for two days. The patch itself is a 4-line surgical edit using helpers that are already exercised by validateGeminiTurns. CI failures look infrastructural rather than caused by the patch. Requesting maintainer help to land this — the diff is mechanically sound and matches the Gemini path's existing behaviour exactly.

    Also tangentially relevant: PR #88025 (treat stale thinking-block signature as replay_invalid) is needed to close a separate failure mode that hits long-running cron sessions when Anthropic's signature window expires. That one is not the same issue, but a session that gets RC-2 right but not RC-3 (request-local recovery flag) will still see a recovery cascade until the offending block scrolls off. The requestMeta = { id: sessionMeta.id } line in wrapAnthropicStreamWithRecovery creates a fresh recovery context per request; promoting the flag to session-level would convert the cascade into a one-shot recovery.

    Local mitigation while #87346 lands:

    function validateAnthropicTurns(messages) {
        const stripped = stripDanglingAnthropicToolUses(messages);
        const withMergedAssistant = validateTurnsWithConsecutiveMerge({
            messages: stripped,
            role: "assistant",
            merge: mergeConsecutiveAssistantTurns
        });
        return validateTurnsWithConsecutiveMerge({
            messages: withMergedAssistant,
            role: "user",
            merge: mergeConsecutiveUserTurns
        });
    }

    Both helpers are already defined and exported in the same file. Tested locally against a subagent-heavy workload and resolves the symptom.

  6. added a commit that references this issue on Jun 14, 2026
    462c076
  7. added a commit that references this issue on Jun 14, 2026
    fe3a3c9
  8. added a commit that references this issue on Jun 16, 2026
    c35f666
  9. added a commit that references this issue on Jun 17, 2026
    882c28b
  10. locked as resolved and limited conversation to collaborators on Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions