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
5 changes: 4 additions & 1 deletion openadapt/transducer_obligations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
46 changes: 45 additions & 1 deletion openadapt/transducer_v3_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,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:
Expand Down Expand Up @@ -1481,7 +1524,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
Expand Down
25 changes: 25 additions & 0 deletions tests/test_transducer_v3_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,31 @@ def test_identical_re_save_in_one_session_is_not_released(tmp_path):
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


def _item_run(tmp_path, pinned, header, task):
from openadapt.simplex_transducer import WriteAheadSagaLog

Expand Down
Loading