openclaw - 💡(How to fix) Fix OpenAI Responses incremental context can replay orphan toolResult without matching toolCall [2 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#72897Fetched 2026-04-28 06:30:39
View on GitHub
Comments
2
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
commented ×2closed ×1

E2E test issue from IYENsystem/OpenClaw integration: OpenAI Responses incremental turns can fail when a stale/orphan toolResult is replayed without the matching assistant toolCall in the same incremental input window.

Error Message

In long-running OpenClaw sessions with tool use + compaction/runtime context reuse, the next OpenAI Responses turn can receive a toolResult whose call_id belongs to an older assistant toolCall that is no longer present in the incremental slice. When that happens, the provider rejects the turn / context continuation, which looks like the assistant “context exploding” or failing after tool use.

Root Cause

E2E test issue from IYENsystem/OpenClaw integration: OpenAI Responses incremental turns can fail when a stale/orphan toolResult is replayed without the matching assistant toolCall in the same incremental input window.

Fix Action

Fix / Workaround

Local hotfix already tested

A local hotfix was applied to planTurnInput() in the installed OpenClaw dist build:

RAW_BUFFERClick to expand / collapse

Summary

E2E test issue from IYENsystem/OpenClaw integration: OpenAI Responses incremental turns can fail when a stale/orphan toolResult is replayed without the matching assistant toolCall in the same incremental input window.

Observed behavior

In long-running OpenClaw sessions with tool use + compaction/runtime context reuse, the next OpenAI Responses turn can receive a toolResult whose call_id belongs to an older assistant toolCall that is no longer present in the incremental slice. When that happens, the provider rejects the turn / context continuation, which looks like the assistant “context exploding” or failing after tool use.

Expected behavior

When using previous_response_id incremental sending, OpenClaw should only send tool results whose matching assistant tool call is present in the incremental input. If the incremental slice contains orphan/stale/mixed tool results, the runtime should fall back to a full-context restart instead of sending an invalid incremental turn.

Local hotfix already tested

A local hotfix was applied to planTurnInput() in the installed OpenClaw dist build:

  • Track assistant toolCall.call_id values after lastContextLength.
  • Only include incremental toolResult entries when their call_id matches a tool call in the same incremental window.
  • If orphan/stale/mixed tool results are detected, switch to full_context_restart.

Local verification:

  • node --check passed.
  • A small reproduction script confirmed:
    • valid paired toolCall/toolResult keeps incremental mode
    • orphan toolResult forces full restart
    • mixed valid+orphan toolResults forces full restart

Why this issue exists

This issue is also being used as an E2E routing test for issue-created/context-gathering automation. It is intentionally filed as a real bug report with the known reproduction shape so the downstream automation has concrete context to inspect.

extent analysis

TL;DR

The issue can be fixed by modifying the planTurnInput() function to filter out orphaned toolResult entries and switch to full_context_restart when necessary.

Guidance

  • Verify that the call_id of each toolResult matches a toolCall in the same incremental input window to prevent sending invalid incremental turns.
  • Implement a check in planTurnInput() to track toolCall.call_id values and only include toolResult entries with matching call_id values.
  • If orphaned or mixed toolResult entries are detected, switch to full_context_restart to prevent context explosion.
  • Test the fix using a reproduction script to ensure valid paired toolCall/toolResult keeps incremental mode and orphan toolResult forces full restart.

Example

No code snippet is provided as the issue does not contain enough information to generate a specific code example.

Notes

The provided local hotfix has already been tested and verified to work, but it may not be the final solution. Further testing and verification may be necessary to ensure the fix works in all scenarios.

Recommendation

Apply the workaround by modifying the planTurnInput() function to filter out orphaned toolResult entries and switch to full_context_restart when necessary, as this has already been tested and verified to work.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

When using previous_response_id incremental sending, OpenClaw should only send tool results whose matching assistant tool call is present in the incremental input. If the incremental slice contains orphan/stale/mixed tool results, the runtime should fall back to a full-context restart instead of sending an invalid incremental turn.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING