Skip to content
69 changes: 69 additions & 0 deletions openadapt/transducer_v3_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,59 @@ def observe_saved(self, state: EpisodeState, observation: Any, task: Any) -> Non
w.confirmed = True
self._reconcile_restored(state, ep, observation)

def _typed_values_gate(
self,
state: EpisodeState,
observation: Any,
task: Any,
history: Sequence[Any] | None,
budget: bool,
commit_idx: int,
action: Any,
) -> Any | None:
"""Hold, then release unverified, while a typed value is not read back."""
unseen = self._unseen_writes(self.ep(state))
if not unseen:
return None
hint = self._unseen_writes_hint(unseen)
held = self._hold(
state, observation, task, history, budget,
commit_idx + 20_000, "TYPED_VALUES_NOT_READ_BACK", hint,
) # fmt: skip
if held is not None:
return held
self._release_unverified(state, commit_idx, hint)
return action

def _unseen_writes(self, ep: V3EpisodeState) -> list[SavedWrite]:
"""Values typed into a saved form that were never read back as saved.

Only with a pinned record identity (field-bound read-back). Every value
the agent typed into the form a commit saved must reappear on a saved
screen of the record, whatever the field is called, before the run can
be verified. A value that was dropped, cut, or rewritten on save is
caught here even when no instruction obligation names it.
"""
if not [v for v in self.owner.pinned.values() if str(v).strip()]:
return []
return [
w for w in ep.writes if w.in_form and w.value.strip() and not w.confirmed
]

@staticmethod
def _unseen_writes_hint(unseen: Sequence[SavedWrite]) -> str:
lines = [
"HOLD_DONE: these values were typed into a saved form but have not been "
"seen as saved on this record yet:"
]
lines += [f"- {w.field_key.split('|', 1)[-1]}: {w.value}" for w in unseen[:12]]
lines.append(
"Open the saved record where they are stored and read them, without "
"changing or saving anything, then finish. If one did not save, enter it "
"again in that field and save once."
)
return "\n".join(lines)

def _hold_hint(
self,
ep: V3EpisodeState,
Expand Down Expand Up @@ -1515,6 +1568,17 @@ def pre_done(
self._met_by_saved_writes(ob, ep.writes)
for ob in diff.missing_obligations
):
gated = self._typed_values_gate(
state,
observation,
task,
history,
budget,
commit_idx,
action,
)
if gated is not None:
return gated
self._verified(
state, commit_idx, 1, "persisted_state_reacquisition",
"Every compiled field obligation is the pinned identity or a "
Expand All @@ -1531,6 +1595,11 @@ def pre_done(
return held
self._release_unverified(state, commit_idx, diff.reason)
return action
gated = self._typed_values_gate(
state, observation, task, history, budget, commit_idx, action
)
if gated is not None:
return gated
self._verified(
state, commit_idx, 1, "persisted_state_reacquisition",
"All compiled field obligations found in the saved read-back.",
Expand Down
59 changes: 59 additions & 0 deletions tests/test_transducer_v3_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,65 @@ def test_hold_hint_names_confirmed_missing_and_where_it_looked():
assert "Enter or correct exactly" not in hint


@pytest.mark.parametrize("click_before_save", [False, True])
def test_typed_value_not_read_back_blocks_verified(click_before_save):
# The task names only the comments; the agent also typed a reference number,
# and the app dropped it on save. Obligations alone would verify.
fill = {
"type": "fill_form",
"raw_action": {
"form_plan": {
"fields": [
{
"selector": "[f.c]",
"name": "Comments",
"value": "CPT 29881; units 1",
},
{"selector": "[f.s]", "name": "From", "value": "2026-12-16"},
{"selector": "[f.n]", "name": "Number", "value": "PA14689226"},
]
}
},
}
dom_blank = _fb_dom() + [
{"selector": "[f.n]", "tag": "input", "text": "Number:", "value": ""}
]
dom_filled = _fb_dom("CPT 29881; units 1", "2026-12-16") + [
{"selector": "[f.n]", "tag": "input", "text": "Number:", "value": "PA14689226"}
]
reopened = _fb_dom("CPT 29881; units 1", "2026-12-16", reopened=True) + [
{
"selector": "[f.n]",
"tag": "input",
"text": "Number:",
"value": "",
"reopened": True,
}
]
before_save = (
[{"type": "click", "target_name": "[f.s]"}] if click_before_save else []
)
wrapped, _ = _wrap(
fill, *before_save, _FB_SAVE, _FB_EDIT, *([{"type": "done"}] * 6),
pinned=_FB_PINNED, config=SupervisorConfig(enable_obligation_compiler=True),
) # fmt: skip
wrapped.act(_fb_obs(dom_blank, _HEADER), _FB_TASK)
wrapped.act(_fb_obs(dom_filled, _HEADER), _FB_TASK)
if click_before_save:
wrapped.act(_fb_obs(dom_filled, _HEADER), _FB_TASK)
wrapped.act(_fb_obs(_fb_dom(), _TRUNCATED), _FB_TASK)
for _ in range(8):
wrapped.act(_fb_obs(reopened, _HEADER), _FB_TASK)
if wrapped.last_receipt is not None:
break
receipt = wrapped.last_receipt
assert receipt is not None # the run finished
assert receipt.outcome != ReceiptOutcome.VERIFIED
state = wrapped.get_state("default-run", "default-task")
assert any("PA14689226" in iv.hint and "typed into a saved form" in iv.hint
for iv in state.intervention_log) # fmt: skip


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

Expand Down
Loading