Skip to content

The agent that grows with you

fix(clarify): choices that display alike stay distinct so a pick maps back to its own raw

Tekniuma4994d4ead8f
diff --git a/tests/agent/test_approval_display_sanitize.py b/tests/agent/test_approval_display_sanitize.py
index d1db82e8c44..b6f319197ba 100644
--- a/tests/agent/test_approval_display_sanitize.py
+++ b/tests/agent/test_approval_display_sanitize.py
@@ -101,3 +101,9 @@ def test_first_render_surfaces_get_the_display_copy_while_values_stay_raw(monkey
assert asked[0]["question"] == prose + "rm -rf ./build\u200b-cache\u27e8\\u2028 \u00d760\u27e9; " + _TAIL
assert asked[0]["choices"][0] == "go\\u202edab (Recommended)" and asked[0]["choices_offered"][1] == "ok"
assert result["responses"][0]["question"] == prose + raw and result["responses"][0]["user_response"] == "go\u202edab"
+ # Choices that display alike (a literal "\\u202e" beside a real U+202E) stay distinct, so each pick maps back to its own raw.
+ twins = ["go\u202edab", "go\\u202edab"]
+ result = json.loads(clarify_tool([{"question": "which?", "choices": twins}], callback=lambda qs: asked.append(qs[0]) or {
+ "answers": {qs[0]["qid"]: qs[0]["choices_offered"][1]}, "outcome": "submitted"}))
+ assert asked[-1]["choices_offered"] == ["go\\u202edab", "go\\u202edab (2)"]
+ assert result["responses"][0]["user_response"] == twins[1]
diff --git a/tools/clarify_tool.py b/tools/clarify_tool.py
index f823265bf84..c5798b463a4 100644
--- a/tools/clarify_tool.py
+++ b/tools/clarify_tool.py
@@ -124,10 +124,22 @@ def clarify_tool(questions, callback: Optional[Callable] = None) -> str:
from tools.human_input_hooks import human_input_request
def prose(texts):
- return [redact_approval_display(t, prose=True) for t in texts] if texts else texts
+ if not texts:
+ return texts
+ out: list[str] = []
+ for text in (redact_approval_display(t, prose=True) for t in texts):
+ label, n = text, 1
+ while label in out: # choices that redact alike (two `***` secrets) stay distinct, so a pick maps back to its own raw
+ n += 1
+ label = f"{text} ({n})"
+ out.append(label)
+ return out
# Every surface renders the prose display copy of the question and choices; the result echoes the raw text.
- shown = [{**q, "question": prose([q["question"]])[0], "choices": prose(q["choices"]),
- "choices_offered": prose(q["choices_offered"])} for q in normalized]
+ shown = []
+ for q in normalized:
+ offered = prose(q["choices_offered"])
+ shown.append({**q, "question": prose([q["question"]])[0], "choices_offered": offered,
+ "choices": mark_recommended(list(offered)) if offered else None})
# Observers see the questions only; the answers stay in the tool result.
with human_input_request("clarify", prompt="\n".join(q["question"] for q in shown)) as human:
try: