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
18 changes: 18 additions & 0 deletions openadapt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,20 @@ def __getattr__(name: str):

return locals()[name]

# Concurrent-worker lease and settle primitives (stdlib-only at import time)
if name in (
"BoundedSettleAndReconcile",
"SettleOutcome",
"SharedWorkLease",
):
from openadapt.transducer_concurrency import ( # noqa: F401
BoundedSettleAndReconcile,
SettleOutcome,
SharedWorkLease,
)

return locals()[name]

# Demo library lives in openadapt-evals
if name == "DemoLibrary":
try:
Expand Down Expand Up @@ -238,6 +252,10 @@ def __getattr__(name: str):
"TransducerReceipt",
"TrustLevel",
"WriteAheadSagaLog",
# Concurrent-worker lease and settle primitives
"BoundedSettleAndReconcile",
"SettleOutcome",
"SharedWorkLease",
# From kernel (canonical runtime)
"CommitInterceptor",
"ObligationLedger",
Expand Down
19 changes: 17 additions & 2 deletions openadapt/simplex_transducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from pathlib import Path
from typing import Any, Literal, TypeVar

from openadapt.transducer_concurrency import SharedWorkLease, WorkLeaseHooks
from openadapt.transducer_fact_ledger import (
FactLedgerHooks,
FormCommitLatch,
Expand Down Expand Up @@ -1766,6 +1767,7 @@ def __init__(
sop_contract: Any = None,
dual_egress: Any = None,
compounding_handoff: Any = None,
work_lease: SharedWorkLease | None = None,
) -> None:
if not callable(getattr(agent, "act", None)):
raise TypeError(
Expand Down Expand Up @@ -1817,6 +1819,8 @@ def __init__(
self.finalize_episode = self._v3.finalize_episode
self._facts = FactLedgerHooks(self)
self.finalize_on_step_cap = self._facts.finalize_on_step_cap
self.work_lease = work_lease
self._lease = WorkLeaseHooks(self, work_lease)

@property
def last_receipt(self) -> TransducerReceipt | None:
Expand Down Expand Up @@ -1860,6 +1864,7 @@ def reset(
**kwargs: Any,
) -> None:
"""Reset episode state and respect ``isolation_mode`` on cartridge store."""
self._lease.forget(run_id, task_id)
with self._states_lock:
if run_id is not None and task_id is not None:
self._states.pop((run_id, task_id), None)
Expand Down Expand Up @@ -3321,6 +3326,7 @@ def _mark_verified(
state.next_commit_index = self.wal.resume_point(
state.run_id, state.task_id
)
self._lease.on_verified(state)

def _check_stream_disconnect(
self, state: EpisodeState, observation: Any
Expand Down Expand Up @@ -3354,9 +3360,14 @@ def _check_stream_disconnect(
return None

def _build_wait_action(
self, state: EpisodeState, observation: Any, reason: str
self,
state: EpisodeState,
observation: Any,
reason: str,
*,
guard: str = "STREAM_DISCONNECTED",
) -> Any:
meta = {"guard": "STREAM_DISCONNECTED", "reason": reason}
meta = {"guard": guard, "reason": reason}
with state._lock:
action_cls = state.action_cls
if action_cls is not None:
Expand Down Expand Up @@ -3643,6 +3654,7 @@ def _act_supervised(
self._v3.on_context(state, observation, task)
self._v3.observe_saved(state, observation, task)
self._facts.on_observation(state, observation)
self._lease.on_step(state)

# Native BenchmarkObservation surface guard: stream/VDI disconnect.
# Hold commits and return a wait action directly without burning an LLM call.
Expand Down Expand Up @@ -3875,6 +3887,9 @@ def _route_action_inner(
fast_forward_obs=observation,
)
return self._reenter(state, observation, task, history)
leased = self._lease.gate(state, action, observation, task)
if leased is not action:
return leased
self._v3.note_commit(state, action)
fp = _commit_fingerprint(action, observation=observation)
safe_summary = {
Expand Down
Loading
Loading