refactor: share ReAct tool invocation lifecycle boundary - #2152
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request unifies the tool call lifecycle boundaries in the ReAct agent pattern by routing both ordinary and control tools through a shared execution wrapper (_execute_tool_safely). This ensures consistent preparation and lifecycle tracking while preserving tool-specific behaviors, such as tracing and metering for ordinary tools. Comprehensive regression tests have been added to validate these changes. The feedback suggests catching general Exceptions for control tools in _execute_tool_safely to record the actual error message in the ledger instead of falling back to a generic abort message.
qinxuye
reviewed
Sep 6, 2026
rogercloud
enabled auto-merge
September 6, 2026 08:44
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Sep 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Control tool calls currently bypass ReAct's ordinary invocation wrapper. A failed or cancelled control send can therefore exit without a terminal ledger record, and outbound messages do not carry their originating tool-call information.
This change routes control calls through the existing shared invocation boundary for context preparation, start recording, and exceptional cleanup. It preserves control-specific result handling, waiting/final-answer behavior, and ordinary-tool tracing and metering. Message metadata carries minimal call attribution, including ordered sources for aggregated questions. Execution context is enriched on copies so pending-call identity and existing checkpoint contents remain intact.
This is the stage A prerequisite for #2145. It does not implement durable attempt identity, message idempotency, or crash recovery; those still require integration in 3.2. The included design document and diagram describe the bounded scope.
Validation:
--follow-imports=silent.