From 9846ac62e0e0e2645392b4afe90b50aef06f4e80 Mon Sep 17 00:00:00 2001 From: abrichr Date: Tue, 1 Dec 2026 02:26:50 -0500 Subject: [PATCH] fix(transducer): hold hint names what is confirmed, what is not, and where wrap looked When the done gate held a correct save, its hint said the values were "not visible in the saved result" and asked the agent to enter them, save and re-check "the saved view". On a web EMR whose record summary cuts values short, agents with the right form already open cancelled it and kept looking until the step cap (one held-out and one dev episode lost this way). With a pinned record identity, the hint now lists the values already confirmed as saved, the ones not seen yet, and the screen wrap looked at (and whether it showed the record). It says to read a saved but hidden or shortened value by reopening the record without changing it, then finish, and never to cancel or redo a correct form. The generic hint drops "enter ... save" for the same advice. --- openadapt/transducer_obligations.py | 5 +++- openadapt/transducer_v3_runtime.py | 46 ++++++++++++++++++++++++++++- tests/test_transducer_v3_runtime.py | 25 ++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/openadapt/transducer_obligations.py b/openadapt/transducer_obligations.py index 79b65a8c30..902a808260 100644 --- a/openadapt/transducer_obligations.py +++ b/openadapt/transducer_obligations.py @@ -517,7 +517,10 @@ def build_hold_done_prompt(missing: Sequence[CompiledFieldObligation]) -> str: ] lines += [f"- {o.label}: {o.expected_value}" for o in missing] lines.append( - "Enter or correct exactly these values, save, then re-check the saved view." + "If a value is wrong or missing, correct that field and save once. If it is " + "saved but not shown on this screen (or shown cut short), open the saved " + "record to show it, without changing or re-saving it, then finish. Do not " + "cancel or redo a form that is already correct." ) return "\n".join(lines) diff --git a/openadapt/transducer_v3_runtime.py b/openadapt/transducer_v3_runtime.py index e261590a70..9b003a2493 100644 --- a/openadapt/transducer_v3_runtime.py +++ b/openadapt/transducer_v3_runtime.py @@ -1176,6 +1176,49 @@ def observe_saved(self, state: EpisodeState, observation: Any, task: Any) -> Non w.confirmed = True self._reconcile_restored(state, ep, observation) + def _hold_hint( + self, + ep: V3EpisodeState, + missing: Sequence[CompiledFieldObligation], + back: Mapping[str, Any] | None, + ) -> str: + """Name what is confirmed, what is not, and where wrap looked. + + Only when the caller pinned a record identity (field-bound read-back). + The hint never tells the agent to cancel or redo a form: a value that + is saved but not shown, or shown cut short, is read by reopening the + saved record. + """ + pins = [str(v).strip() for v in self.owner.pinned.values() if str(v).strip()] + if not pins: + return "" + unmet = [ob for ob in missing if not self._met_by_saved_writes(ob, ep.writes)] + if not unmet: + return "" + saved = _norm_text((back or {}).get("readback_text") or "") + on_screen = bool(saved) and all(_norm_text(p) in saved for p in pins) + seen = sorted({w.value for w in ep.writes if w.confirmed and w.value.strip()}) + where = ( + "the current screen, which shows this record" + if on_screen + else "the current screen, which does not show this record's identity (" + + ", ".join(pins) + + ")" + ) + lines = ["HOLD_DONE: not finished yet."] + if seen: + lines.append("Already confirmed as saved: " + "; ".join(seen)[:400] + ".") + lines.append(f"Not seen as saved yet (looked at {where}):") + lines += [f"- {o.label}: {o.expected_value}" for o in unmet] + lines.append( + "If one of these is saved but not shown, or shown cut short, open the saved " + "record where it is stored (for example its form) and read it there, " + "without changing or saving anything, then finish. If one is wrong or " + "missing, correct that field and save once. Do not cancel or redo a form " + "that is already correct." + ) + return "\n".join(lines) + def _met_by_saved_writes( self, ob: CompiledFieldObligation, writes: Sequence[SavedWrite] ) -> bool: @@ -1345,7 +1388,8 @@ def pre_done( if not diff.all_verified: held = self._hold( state, observation, task, history, budget, - commit_idx + 10_000, "FIELD_OBLIGATIONS_MISSING", diff.reason, + commit_idx + 10_000, "FIELD_OBLIGATIONS_MISSING", + self._hold_hint(ep, diff.missing_obligations, back) or diff.reason, ) # fmt: skip if held is not None: return held diff --git a/tests/test_transducer_v3_runtime.py b/tests/test_transducer_v3_runtime.py index a8cbeea4a4..a7888edabf 100644 --- a/tests/test_transducer_v3_runtime.py +++ b/tests/test_transducer_v3_runtime.py @@ -434,3 +434,28 @@ def test_identical_re_save_in_one_session_is_not_released(tmp_path): hints = " ".join(str(iv) for iv in state.intervention_log) assert "DUPLICATE_SAVE" in hints or "FORM_COMMIT_LATCHED" in hints assert not (isinstance(out, dict) and out.get("is_commit")) + + +def test_hold_hint_names_confirmed_missing_and_where_it_looked(): + # The record view cuts the comments short; the agent says done there. + wrapped, agent = _wrap( + _FB_FILL, + _FB_SAVE, + {"type": "done"}, + _FB_EDIT, + *([{"type": "done"}] * 4), + pinned=_FB_PINNED, + config=SupervisorConfig(enable_obligation_compiler=True), + ) + wrapped.act(_fb_obs(_fb_dom(), _HEADER), _FB_TASK) + wrapped.act(_fb_obs(_fb_dom("CPT 29881; units 1", "2026-12-16"), _HEADER), _FB_TASK) + wrapped.act(_fb_obs(_fb_dom(), _TRUNCATED), _FB_TASK) + state = wrapped.get_state("default-run", "default-task") + hint = next( + iv.hint for iv in state.intervention_log if iv.kind == "HOLD_DONE_REPAIR" + ) + assert "Already confirmed as saved: 2026-12-16" in hint + assert "CPT 29881; units 1" in hint.split("Not seen as saved yet")[1] + assert "which shows this record" in hint + assert "then finish" in hint and "Do not cancel or redo" in hint + assert "Enter or correct exactly" not in hint