The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(computer-use): dedup keyed by the scoped session, cleared on release
teknium131964ff4c6f5
diff --git a/tests/tools/test_computer_use_screenshot_dedup.py b/tests/tools/test_computer_use_screenshot_dedup.pyindex 53ad997dbc5..6ba0653c320 100644--- a/tests/tools/test_computer_use_screenshot_dedup.py+++ b/tests/tools/test_computer_use_screenshot_dedup.py@@ -73,6 +73,8 @@ class TestScreenshotDedup:data = json.loads(resp)assert data["screen_unchanged"] is Trueassert "screen unchanged" in data["summary"]+ # Text metadata is still complete: the model can keep acting by element index.+ assert data["app"] == "kate" and "elements" in datadef test_changed_pixels_deliver_image_again(self):cu_tool._capture_response(_cap(seed=1), session_id="s1")@@ -123,3 +125,23 @@ class TestScreenshotDedup:resp = cu_tool._capture_response(cap, session_id="s1")assert not _is_multimodal(resp)assert "screen_unchanged" not in json.loads(resp)++ def test_explicit_capture_action_after_input_is_subject_to_dedup(self):+ """The dispatch path (explicit `capture` and `capture_after`) carries the session key; an unchanged+ frame is reported as unchanged rather than re-sent, and the streak cap still forces re-delivery."""+ backend = cu_tool._NoopBackend()+ frame = _cap(seed=1)+ backend.capture = lambda **kw: frame+ first = cu_tool._dispatch(backend, "capture", {"mode": "som"}, session_id="s1")+ assert _is_multimodal(first)+ after_click = cu_tool._dispatch(backend, "click", {"element": 1, "capture_after": True}, session_id="s1")+ assert not _is_multimodal(after_click) and json.loads(after_click)["screen_unchanged"] is True+ assert json.loads(after_click)["ok"] is True # action payload merged into the text capture+ explicit = cu_tool._dispatch(backend, "capture", {"mode": "som"}, session_id="s1")+ assert not _is_multimodal(explicit)+ assert _is_multimodal(cu_tool._dispatch(backend, "capture", {"mode": "som"}, session_id="s1"))++ def test_release_session_forgets_dedup_state(self):+ cu_tool._capture_response(_cap(seed=1), session_id="s1")+ cu_tool.release_computer_use_session("s1")+ assert _is_multimodal(cu_tool._capture_response(_cap(seed=1), session_id="s1"))diff --git a/tools/computer_use/tool.py b/tools/computer_use/tool.pyindex d0a2e5c5c86..58860cb996a 100644--- a/tools/computer_use/tool.py+++ b/tools/computer_use/tool.py@@ -221,6 +221,7 @@ def release_computer_use_session(session_id: str) -> bool:Cache entries are removed BEFORE stopping so new lookups cannot retain the stale target/ref namespace. Approvalgrants are not touched here: they live in the shared store and die with ``tools.approval.clear_session``."""sid = _scoped_sid(session_id)+ _reset_screenshot_dedup(sid) # the next capture of a re-created session must deliver pixelswith _backend_lock:backend, call_lock = _detach_locked(sid)if backend is None:@@ -593,12 +594,12 @@ def _capture_response(cap: CaptureResult, max_elements: int = _DEFAULT_MAX_ELEMElines = _capture_summary_lines(v)summary, extra = "\n".join(lines), None # multimodal/aux paths use this; text paths append notes and rebuildif v.has_image and session_id and _screenshot_dedup_check(- session_id, _capture_digest(cap), (str(cap.app or ""), str(cap.window_title or ""))):+ _scoped_sid(session_id), _capture_digest(cap), (str(cap.app or ""), str(cap.window_title or ""))):# Unchanged frame: same pixels for the same target in this session — no image (and no aux-vision call);- # the text metadata is fresh and the note says which screenshot still applies.- lines.append(" (screen unchanged since the previous screenshot — image omitted to save context; the prior "- "screenshot still shows the current state. Element indices below are fresh and remain the "- "preferred way to act.)")+ # the text metadata is fresh and the note says which earlier result still applies.+ lines.append(" (screen unchanged since the previous capture — image omitted to save context; the previous "+ "capture's screenshot/analysis still shows the current state. Element indices below are fresh "+ "and remain the preferred way to act.)")extra = {"screen_unchanged": True}elif v.has_image:# Hand the screenshot to auxiliary.vision (text-only result) when the main model may not consume images