diff --git a/api/clarify.py b/api/clarify.py index 87834009..8ad750ac 100644 --- a/api/clarify.py +++ b/api/clarify.py @@ -122,6 +122,11 @@ def submit_pending(session_key: str, data: dict) -> _ClarifyEntry: == list(data.get("choices_offered") or []) ): entry = last + # Dedup re-uses the existing entry with its original clarify_id. + # If a future caller pre-populates clarify_id in data, it is + # silently discarded here — the original entry's id wins. + # Today no caller sets clarify_id (it's generated by __init__), + # so this is a non-issue. cb = _gateway_notify_cbs.get(session_key) # Keep _pending aligned to the oldest unresolved entry. _pending[session_key] = gw_queue[0].data diff --git a/api/routes.py b/api/routes.py index 5a523d19..af6599dc 100644 --- a/api/routes.py +++ b/api/routes.py @@ -9080,6 +9080,9 @@ def _handle_clarify_respond(handler, body): ok = _resolve_clarify_legacy(sid, clarify_id, response) if not ok: + # Both the runtime adapter and legacy paths set ok=False for + # stale/expired/wrong-session responses. The 409 status applies + # uniformly regardless of which path resolved the clarify request. return j(handler, { "ok": False, "error": "Clarification prompt expired or not found. The agent may have already proceeded.",