feat: add local hardware approval leases
This commit is contained in:
@@ -64,6 +64,9 @@ from cognitive_agent.infrastructure.can.hardware import ( # noqa: E402
|
||||
PHYSICAL_BENCH_COORDINATOR,
|
||||
SeatHardwareSettings,
|
||||
)
|
||||
from cognitive_agent.infrastructure.can.access import ( # noqa: E402
|
||||
PHYSICAL_BENCH_ACCESS,
|
||||
)
|
||||
from cognitive_agent.runtime.contracts import ContractValidator # noqa: E402
|
||||
|
||||
|
||||
@@ -140,6 +143,7 @@ class SeatDemoService:
|
||||
)
|
||||
self.hardware_settings = SeatHardwareSettings.from_env(repository_root)
|
||||
self.hardware_execution = PHYSICAL_BENCH_COORDINATOR
|
||||
self.hardware_access = PHYSICAL_BENCH_ACCESS
|
||||
# Shared by the short-lived hardware executor instances. A process must
|
||||
# establish a fresh physical four-axis reference before trusting stored
|
||||
# Hall counts, and a firmware replacement invalidates it again.
|
||||
@@ -181,6 +185,7 @@ class SeatDemoService:
|
||||
default_vehicle = self.vehicle_profiles.default()
|
||||
hardware_info = self.hardware_settings.public_info()
|
||||
hardware_info.update(self.hardware_execution.public_info())
|
||||
hardware_info.update(self.hardware_access.public_info())
|
||||
return {
|
||||
"service": "cabin-cognitive-orchestrator",
|
||||
"domain": "cabin",
|
||||
@@ -247,11 +252,19 @@ class SeatDemoService:
|
||||
self,
|
||||
conversation_id: str,
|
||||
vehicle_id: str | None = None,
|
||||
*,
|
||||
hardware_client_id: str | None = None,
|
||||
hardware_access_bypass: bool = True,
|
||||
) -> dict[str, Any]:
|
||||
"""Read the bench only when no physical execution currently owns it."""
|
||||
|
||||
if hardware_access_bypass:
|
||||
with self.hardware_execution.reserve():
|
||||
return self._synchronize_hardware_state_once(conversation_id, vehicle_id)
|
||||
authorized_client_id = self.hardware_access.ensure_authorized(hardware_client_id)
|
||||
with self.hardware_execution.reserve():
|
||||
return self._synchronize_hardware_state_once(conversation_id, vehicle_id)
|
||||
with self.hardware_access.use(authorized_client_id):
|
||||
return self._synchronize_hardware_state_once(conversation_id, vehicle_id)
|
||||
|
||||
def _synchronize_hardware_state_once(
|
||||
self,
|
||||
@@ -322,6 +335,9 @@ class SeatDemoService:
|
||||
approval_token: str | None = None,
|
||||
vehicle_id: str | None = None,
|
||||
simulation_fault: str = "normal",
|
||||
*,
|
||||
hardware_client_id: str | None = None,
|
||||
hardware_access_bypass: bool = True,
|
||||
) -> dict[str, Any]:
|
||||
if execution_mode != "hardware":
|
||||
return self._process_once(
|
||||
@@ -333,16 +349,29 @@ class SeatDemoService:
|
||||
vehicle_id,
|
||||
simulation_fault,
|
||||
)
|
||||
if hardware_access_bypass:
|
||||
with self.hardware_execution.reserve():
|
||||
return self._process_once(
|
||||
utterance,
|
||||
provider,
|
||||
conversation_id,
|
||||
execution_mode,
|
||||
approval_token,
|
||||
vehicle_id,
|
||||
simulation_fault,
|
||||
)
|
||||
authorized_client_id = self.hardware_access.ensure_authorized(hardware_client_id)
|
||||
with self.hardware_execution.reserve():
|
||||
return self._process_once(
|
||||
utterance,
|
||||
provider,
|
||||
conversation_id,
|
||||
execution_mode,
|
||||
approval_token,
|
||||
vehicle_id,
|
||||
simulation_fault,
|
||||
)
|
||||
with self.hardware_access.use(authorized_client_id):
|
||||
return self._process_once(
|
||||
utterance,
|
||||
provider,
|
||||
conversation_id,
|
||||
execution_mode,
|
||||
approval_token,
|
||||
vehicle_id,
|
||||
simulation_fault,
|
||||
)
|
||||
|
||||
def _process_once(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user