From bae7b2e4579645aa23ec65a4485490a386402af3 Mon Sep 17 00:00:00 2001 From: Mangesh Raut Date: Thu, 22 Oct 2026 09:02:45 +0000 Subject: [PATCH] fix(agent): treat curly apostrophes as negations in click-claim checks Co-authored-by: Mangesh Raut --- changes/498.fixed.md | 2 ++ sentient/agent/outcomes.py | 9 +++++++-- tests/tasks/test_outcome_checks.py | 3 +++ tests/test_agent_loop.py | 17 +++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 changes/498.fixed.md diff --git a/changes/498.fixed.md b/changes/498.fixed.md new file mode 100644 index 000000000..ad60d855f --- /dev/null +++ b/changes/498.fixed.md @@ -0,0 +1,2 @@ +**A reply that already says a click did not happen is left as it is.** Sentient was still adding a correction when +that sentence used a curly apostrophe, as in "wasn't clicked". diff --git a/sentient/agent/outcomes.py b/sentient/agent/outcomes.py index 262ae8767..aa5fad405 100644 --- a/sentient/agent/outcomes.py +++ b/sentient/agent/outcomes.py @@ -85,6 +85,11 @@ _ADDRESS = re.compile(r"[^\s,;<>\"']+@[^\s,;<>\"']+") +def _straight_apostrophes(text: str) -> str: + """Fold curly apostrophes to straight ones so negation patterns match either.""" + return (text or "").replace("\u2019", "'").replace("\u2018", "'") + + def _clip(text: Any, limit: int = MAX_DETAIL) -> str: s = " ".join(str(text or "").split()) return s if len(s) <= limit else s[: limit - 3].rstrip() + "..." @@ -175,7 +180,7 @@ def result_problem(res: Any, _depth: int = 0) -> tuple[str, list[str]] | None: if parsed is not None: if found := result_problem(parsed, _depth + 1): return found - elif _ERROR_TEXT.match(content): + elif _ERROR_TEXT.match(_straight_apostrophes(content)): return _clip(content), [] for key, value in res.items(): if key in ("content", "error") or not isinstance(value, dict | list): @@ -421,7 +426,7 @@ def unmade_browser_click_note(text: str, calls: list[dict], history: list[dict] not explicit and clicks and _BROWSER_CLICK_CLAIM.search(claim) - and not _NEGATED_BROWSER_CLICK.search(claim) + and not _NEGATED_BROWSER_CLICK.search(_straight_apostrophes(claim)) and not _OTHER_PERSON_BROWSER_CLICK.search(claim) ) if passive and (note := _click_note(clicks, _claimed_click_target(claim))): diff --git a/tests/tasks/test_outcome_checks.py b/tests/tasks/test_outcome_checks.py index c00b57329..f89b91ca9 100644 --- a/tests/tasks/test_outcome_checks.py +++ b/tests/tasks/test_outcome_checks.py @@ -214,6 +214,9 @@ def test_result_problem_reads_the_usual_shapes(): assert rp({"status": "failed", "to": "a@x.com", "reason": "blocked"}) == ("blocked (a@x.com)", ["a@x.com"]) assert rp({"content": '{"sent": [], "failed": ["b@x.com"]}'}) == ("it couldn't do it for b@x.com", ["b@x.com"]) assert rp({"content": "Error: SMTP 550"}) == ("Error: SMTP 550", []) + assert rp({"content": "Couldn't open the page"}) == ("Couldn't open the page", []) + couldnt = "Couldn\u2019t open the page" + assert rp({"content": couldnt}) == (couldnt, []) assert rp({"content": "Message sent"}) is None assert rp({"results": [{"to": "a", "status": "sent"}, {"to": "b", "status": "error", "error": "x"}]}) == ( "x (b)", ["b"] diff --git a/tests/test_agent_loop.py b/tests/test_agent_loop.py index 1cfe7cb83..8e769f231 100644 --- a/tests/test_agent_loop.py +++ b/tests/test_agent_loop.py @@ -271,6 +271,23 @@ def test_browser_click_correction_uses_the_latest_call(): ) == "I didn't click it: you declined, so nothing changed on the page." +def test_curly_apostrophe_negations_are_not_click_claims(): + """A curly apostrophe in wasn't, didn't, hasn't, or haven't is still a negation (#498).""" + failed = [{"name": "browser_click", "ok": False, "target": 'button "Subscribe"'}] + for reply in ( + "No, the Subscribe button wasn't clicked.", + "I didn't get it clicked.", + "The Subscribe button hasn't been clicked.", + "I haven't clicked the Subscribe button.", + ): + curly = reply.replace("'", "\u2019") + assert outcomes.unmade_browser_click_note(reply, failed) == "", reply + assert outcomes.unmade_browser_click_note(curly, failed) == "", curly + assert outcomes.unmade_browser_click_note( + "I clicked the Subscribe button.", failed + ) == "I couldn't click it, so nothing changed on the page." + + def test_browser_click_history_retains_a_truncated_successful_result(): """A context-truncated result must not turn a recorded click into a false failure.""" history = browser_click_history([