-
Notifications
You must be signed in to change notification settings - Fork 311
fix(websocket): avoid fresh retry for tool-output deltas #1042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -396,6 +396,34 @@ def _websocket_continuity_anchor_for_payload( | |
| ) | ||
|
|
||
|
|
||
| _WEBSOCKET_TOOL_CALL_ITEM_TYPES_BY_OUTPUT_TYPE = { | ||
| "function_call_output": "function_call", | ||
| "custom_tool_call_output": "custom_tool_call", | ||
| "apply_patch_call_output": "apply_patch_call", | ||
| } | ||
| _WEBSOCKET_TOOL_CALL_ITEM_TYPES = frozenset(_WEBSOCKET_TOOL_CALL_ITEM_TYPES_BY_OUTPUT_TYPE.values()) | ||
|
|
||
|
|
||
| def _websocket_input_items_are_self_contained_fresh_replay(input_items: list[JsonValue]) -> bool: | ||
| seen_call_ids_by_type: dict[str, set[str]] = {item_type: set() for item_type in _WEBSOCKET_TOOL_CALL_ITEM_TYPES} | ||
| for item in input_items: | ||
| if not isinstance(item, dict): | ||
| continue | ||
| item_type = _websocket_input_item_type(item) | ||
| call_id_value = item.get("call_id") | ||
| call_id = call_id_value if isinstance(call_id_value, str) and call_id_value else None | ||
| if item_type in _WEBSOCKET_TOOL_CALL_ITEM_TYPES: | ||
| if call_id is not None: | ||
| seen_call_ids_by_type[item_type].add(call_id) | ||
| continue | ||
| call_item_type = _WEBSOCKET_TOOL_CALL_ITEM_TYPES_BY_OUTPUT_TYPE.get(item_type or "") | ||
| if call_item_type is None: | ||
| continue | ||
| if call_id is None or call_id not in seen_call_ids_by_type[call_item_type]: | ||
| return False | ||
| return True | ||
|
|
||
|
|
||
| def _websocket_client_previous_response_full_resend_is_retry_safe( | ||
| *, | ||
| previous_response_id: str | None, | ||
|
|
@@ -407,6 +435,8 @@ def _websocket_client_previous_response_full_resend_is_retry_safe( | |
| input_items = cast(list[JsonValue], input_value) | ||
| if len(input_items) <= 1: | ||
| return False | ||
| if not _websocket_input_items_are_self_contained_fresh_replay(input_items): | ||
| return False | ||
|
Comment on lines
+438
to
+439
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This self-contained check only runs for client-supplied Useful? React with 👍 / 👎. |
||
| if ( | ||
| continuity_state is not None | ||
| and continuity_state.last_completed_response_id == previous_response_id | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.