Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changes/498.fixed.md
Original file line number Diff line number Diff line change
@@ -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".
9 changes: 7 additions & 2 deletions sentient/agent/outcomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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() + "..."
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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))):
Expand Down
3 changes: 3 additions & 0 deletions tests/tasks/test_outcome_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
17 changes: 17 additions & 0 deletions tests/test_agent_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
Loading