Skip to content

fix(session): drop tool calls from aborted turns#7546

Closed
hclsys wants to merge 1 commit intoopenclaw:mainfrom
hclsys:fix/issue-6157-abort-toolcalls
Closed

fix(session): drop tool calls from aborted turns#7546
hclsys wants to merge 1 commit intoopenclaw:mainfrom
hclsys:fix/issue-6157-abort-toolcalls

Conversation

@hclsys
Copy link
Contributor

@hclsys hclsys commented Feb 2, 2026

Fixes #6157\n\n- strip toolCall/toolUse blocks from aborted assistant messages before persisting\n- avoid inserting synthetic tool_result for aborted tool calls\n- add regression test for aborted turns\n\n## Test plan\n- pnpm vitest src/agents/session-tool-result-guard.test.ts\n- pnpm format\n

Greptile Overview

Greptile Summary

This PR updates installSessionToolResultGuard to treat aborted assistant turns specially: tool call/tool use blocks are stripped from aborted assistant messages before persisting, and any pending tool results for those aborted calls are not synthesized. A regression test was added to ensure an aborted assistant message containing a tool call is persisted without tool-call blocks and does not leave pending tool-call IDs behind.

Overall, the change fits into the session transcript consistency layer: the guard tracks pending tool calls and synthesizes missing tool results when needed for strict providers, while also ensuring the transcript stays well-formed. The new behavior prevents “orphaned” synthetic tool results caused by persisting tool calls from turns that never actually executed.

Confidence Score: 4/5

  • This PR is largely safe to merge; it’s a small, targeted behavioral change with a focused regression test.
  • The implementation is straightforward and localized to transcript persistence logic, and the new test covers the reported aborted-turn scenario. The main concern is minor maintainability (duplicate tool-call type checks) rather than functional correctness.
  • src/agents/session-tool-result-guard.ts

Context used:

  • Context from dashboard - CLAUDE.md (source)
  • Context from dashboard - AGENTS.md (source)

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +8 to +14
function isToolCallBlock(block: unknown): boolean {
if (!block || typeof block !== "object") {
return false;
}
const rec = block as { type?: unknown };
return rec.type === "toolCall" || rec.type === "toolUse" || rec.type === "functionCall";
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Duplicate tool-call-type logic increases drift risk

isToolCallBlock duplicates the exact set of block types checked in extractAssistantToolCalls (toolCall/toolUse/functionCall). If this list ever changes, it’s easy to update one and forget the other, reintroducing the aborted-turn bug or missing a new tool-call variant. Consider defining a single helper (e.g., isToolCallBlock) and using it in both places, or centralizing the allowed type set.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/session-tool-result-guard.ts
Line: 8:14

Comment:
[P2] Duplicate tool-call-type logic increases drift risk

`isToolCallBlock` duplicates the exact set of block types checked in `extractAssistantToolCalls` (`toolCall`/`toolUse`/`functionCall`). If this list ever changes, it’s easy to update one and forget the other, reintroducing the aborted-turn bug or missing a new tool-call variant. Consider defining a single helper (e.g., `isToolCallBlock`) and using it in both places, or centralizing the allowed `type` set.

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

@sebslight
Copy link
Member

Closing as duplicate of #3223. If this is incorrect, comment and we can reopen.

@sebslight sebslight closed this Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session corruption when parallel tool calls are aborted

2 participants