Fix ClearToolResults corrupting typed ToolReturnPart subclasses (ToolSearchReturnPart)#383
Open
dsfaccini wants to merge 1 commit into
Open
Fix ClearToolResults corrupting typed ToolReturnPart subclasses (ToolSearchReturnPart)#383dsfaccini wants to merge 1 commit into
ClearToolResults corrupting typed ToolReturnPart subclasses (ToolSearchReturnPart)#383dsfaccini wants to merge 1 commit into
Conversation
`rebuild_with_cleared` matched tool results with `isinstance(part, ToolReturnPart)`, which also caught typed subclasses like `ToolSearchReturnPart`. `dataclasses.replace` preserves the concrete class, so blanking the content produced a `ToolSearchReturnPart` whose structured `TypedDict` content was a plain string. Core's `parse_discovered_tools` trusts that content shape and re-reads it on the next request, raising TypeError. Narrow the request-side clearing predicate to an exact type check so typed subclasses are skipped -- they carry discovery state core re-reads and reclaim little.
This comment was marked as resolved.
This comment was marked as resolved.
ApprovabilityVerdict: Approved Straightforward bug fix with clear intent and minimal scope. The single-line change narrows a type check from You can customize Macroscope's approvability policy. Learn more. |
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.
This pull request was posted by Claude Code using claude-opus-4-8 on behalf of David.
Summary
ClearToolResultsblanks old tool results in place.rebuild_with_clearedselectedthem with
isinstance(part, ToolReturnPart), which also matches typed subclasses suchas
ToolSearchReturnPart(core'ssearch_toolsreturn).dataclasses.replacepreservesthe concrete class, so blanking the content produced a
ToolSearchReturnPartwhosestructured
TypedDictcontent was now a plain placeholder string.Core's
parse_discovered_toolstrusts that content shape (docstring: "No defensiveisinstance walks needed") and re-reads it on every request via
content['discovered_tools'].Once the corrupted history is written back into run state, the run's next request raises
TypeError: string indices must be integers.The fix narrows the request-side clearing predicate to an exact type check
(
type(part) is ToolReturnPart), so typed subclasses are skipped rather than blanked.They carry discovery state core re-reads each request and reclaim little, so skipping
them is both correct and near-free. The response-side
ToolCallPartargs-clearing branchis unchanged (its placeholder is type-valid there). A code comment guards against a future
revert to
isinstance.Linked Issue
Fixes #380
Checklist
make lint && make typecheck && make testpasses locally (don't stress about CI -- we'll help)pyproject.tomloruv.lock(dependency changes require a separate issue)