runtime_contract.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. """Gateway launch decisions independent of operating-system probes."""
  2. from dataclasses import dataclass
  3. from typing import Literal
  4. RuntimeState = Literal[
  5. "absent", "starting", "ready", "draining", "incompatible", "inaccessible", "conflict"
  6. ]
  7. @dataclass(frozen=True)
  8. class RuntimeObservation:
  9. state: RuntimeState
  10. installed_service: bool = False
  11. service_may_start: bool = False
  12. update_paused: bool = False
  13. def next_start_action(observation: RuntimeObservation) -> str:
  14. if observation.update_paused:
  15. return "wait-update"
  16. actions = {
  17. "ready": "attach",
  18. "starting": "wait-owner",
  19. "draining": "wait-owner",
  20. "incompatible": "reject-version",
  21. "inaccessible": "reject-access",
  22. "conflict": "reject-conflict",
  23. }
  24. if observation.state in actions:
  25. return actions[observation.state]
  26. if observation.state != "absent":
  27. raise ValueError("unknown runtime state")
  28. if observation.service_may_start:
  29. return "wait-service"
  30. return "start-service" if observation.installed_service else "spawn-unmanaged"