harness-sdk-python 0.36.0__py3-none-any.whl → 0.36.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -67,6 +67,7 @@ import logging
67
67
  from dataclasses import dataclass, field
68
68
  from typing import Any, AsyncIterator, Callable, Coroutine, Iterable, Protocol
69
69
 
70
+ from pinned import EvictionRequested
70
71
  from pinned.trays import Tray, TrayDescriptor, TrayCtx, TrayMapNamespace, inbox
71
72
  from pinned.trays import persistent, persistent_outbox, persistent_queue
72
73
  from statepatch import observable
@@ -845,6 +846,12 @@ class RunManager(Tray):
845
846
 
846
847
  def _make_run_ctx(self, item: Any) -> "RunManager.RunContext":
847
848
  record = item["record"]
849
+ root_meta = record.get("rootMeta")
850
+ if "rootMeta" not in record:
851
+ if record["messages"]:
852
+ root_meta = record["messages"][0].get("meta")
853
+ elif record.get("inputOutcomes"):
854
+ root_meta = record["inputOutcomes"][0]["meta"]
848
855
  messages = [
849
856
  {k: v for k, v in message.items() if k not in ("meta", "~admit")}
850
857
  for message in record["messages"]
@@ -857,7 +864,7 @@ class RunManager(Tray):
857
864
  _manager=self,
858
865
  _rollback_to=record["rollbackTo"] if "rollbackTo" in record else _ABSENT,
859
866
  _message_meta={m["id"]: m.get("meta") for m in record["messages"]},
860
- _root_meta=record.get("rootMeta"),
867
+ _root_meta=root_meta,
861
868
  _input_outcomes=tuple(
862
869
  (o["request"], o["response"], o["meta"])
863
870
  for o in record.get("inputOutcomes", ())
@@ -877,6 +884,8 @@ class RunManager(Tray):
877
884
  self._sync_steering()
878
885
  try:
879
886
  await task
887
+ except EvictionRequested:
888
+ raise
880
889
  except asyncio.CancelledError:
881
890
  current = asyncio.current_task()
882
891
  if current is not None and current.cancelling():
@@ -886,6 +895,8 @@ class RunManager(Tray):
886
895
  # user cancel: _execute already converged on the settle discipline
887
896
  finally:
888
897
  self._active = None
898
+ if self._run_live is ctx:
899
+ self._run_live = None
889
900
 
890
901
  async def _execute(self, ctx: "RunManager.RunContext", fn: Any) -> None:
891
902
  try:
@@ -905,34 +916,25 @@ class RunManager(Tray):
905
916
  )
906
917
  if isinstance(outcome, RunManager.Complete) and self.dispatching.value is not None:
907
918
  raise RuntimeError("run returned Complete with an unconfirmed batch")
919
+ except EvictionRequested:
920
+ self._advance()
921
+ if self._stop_staged or ctx._tray_ctx.consumed:
922
+ self._cancel_run(ctx)
923
+ return
924
+ raise
908
925
  except asyncio.CancelledError:
909
- if self._closing or self._retirement is not None:
910
- raise # teardown: the un-acked outbox redelivers next activation
911
- self.outcome.value = {
912
- "kind": "cancel",
913
- "epoch": self.epoch.value,
914
- "dispatchQueue": False,
915
- }
916
- self._settle(ctx)
917
- fx = self._apply_intake()
918
- rewind = self._staged_rewind
919
- if rewind is not None and not rewind.applied_sent:
920
- # park the in-drain rewind durably; a cancel starts no dispatch
921
- self.nextDispatch.value = self._record_of(
922
- rewind.type,
923
- list(rewind.messages),
924
- rollback_to=rewind.rollback_to,
925
- root_meta=rewind.root_meta,
926
+ if (
927
+ self._closing
928
+ or self._retirement is not None
929
+ or (
930
+ self._evicting()
931
+ and not self._stop_staged
932
+ and not ctx._tray_ctx.consumed
926
933
  )
927
- rewind.applied()
928
- rewind.applied_sent = True
929
- self.halted.value = "stop"
930
- self.outcome.value = None
931
- self._resolve_stop_waiters()
932
- self._publish_status()
933
- self._settle_applied(fx)
934
- self._idle.set()
935
- raise # staged intake settled; a cancelled run starts no dispatch
934
+ ):
935
+ raise # teardown: the un-acked outbox redelivers next activation
936
+ self._cancel_run(ctx)
937
+ raise
936
938
  except Exception as exc:
937
939
  if not isinstance(exc, StatewireReject):
938
940
  logger.exception(
@@ -957,6 +959,31 @@ class RunManager(Tray):
957
959
  self._outcome = self.outcome.value
958
960
  self._advance()
959
961
 
962
+ def _cancel_run(self, ctx: "RunManager.RunContext") -> None:
963
+ self.outcome.value = {
964
+ "kind": "cancel",
965
+ "epoch": self.epoch.value,
966
+ "dispatchQueue": False,
967
+ }
968
+ self._settle(ctx)
969
+ fx = self._apply_intake()
970
+ rewind = self._staged_rewind
971
+ if rewind is not None and not rewind.applied_sent:
972
+ self.nextDispatch.value = self._record_of(
973
+ rewind.type,
974
+ list(rewind.messages),
975
+ rollback_to=rewind.rollback_to,
976
+ root_meta=rewind.root_meta,
977
+ )
978
+ rewind.applied()
979
+ rewind.applied_sent = True
980
+ self.halted.value = "stop"
981
+ self.outcome.value = None
982
+ self._resolve_stop_waiters()
983
+ self._publish_status()
984
+ self._settle_applied(fx)
985
+ self._idle.set()
986
+
960
987
  def _maybe_self_delete(self) -> None:
961
988
  """A settled machine with no durable obligations deletes its tray; the
962
989
  next send recreates it fresh."""
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: harness-sdk-python
3
- Version: 0.36.0
3
+ Version: 0.36.2
4
4
  Summary: RunManager: the harness-sdk runs subsystem for Python Statewire hosts
5
5
  Project-URL: Repository, https://github.com/assistant-ui/harness-sdk
6
6
  License-Expression: MIT
7
7
  Requires-Python: <4.0,>=3.12
8
- Requires-Dist: pinned<0.16,>=0.15.0
9
- Requires-Dist: statewire<0.17,>=0.16.0
8
+ Requires-Dist: pinned<0.16,>=0.15.1
9
+ Requires-Dist: statewire<0.18,>=0.17.2
10
10
  Provides-Extra: deepagents
11
11
  Requires-Dist: deepagents>=0.6.12; extra == 'deepagents'
12
12
  Requires-Dist: langchain-core>=0.3; extra == 'deepagents'
@@ -4,8 +4,8 @@ harness_sdk/deepagents.py,sha256=3iWadYjG-Yv0fli4x8s5n3jOTs11JHS2cK6tj8foyvk,145
4
4
  harness_sdk/fenced_postgres.py,sha256=hbbrMR1WaqrHTNgd4wFrXfRrzQFGnyim-c8nZXgwWp4,13235
5
5
  harness_sdk/linear_thread.py,sha256=laDRXKLFsMlyWS4snqNAM6t38wO26gevLWXRNivhHSM,1810
6
6
  harness_sdk/protocol.py,sha256=4diqaWeYIVEKRjyKkqzeMMHJb7zrOQCvPkjQzkeIku8,140
7
- harness_sdk/run_manager.py,sha256=9yfxzelb5Ugs3qbsKiWDPfASljjlc0BbmoQv-8Bw72Y,81438
7
+ harness_sdk/run_manager.py,sha256=gcd4nfXJ8ssD-v0yP2FF4WsUE-xWzgrChdG4RQV_UqA,82165
8
8
  harness_sdk/voice.py,sha256=bRloaKSS1d0mFvfIM4Bhp50ADBK_7GpdarGvmDBubjg,32370
9
- harness_sdk_python-0.36.0.dist-info/METADATA,sha256=rDfjbNchuYQEZzstgtiaspw-lFXIvBChAHPYSOH0s1E,2488
10
- harness_sdk_python-0.36.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
11
- harness_sdk_python-0.36.0.dist-info/RECORD,,
9
+ harness_sdk_python-0.36.2.dist-info/METADATA,sha256=aJPyd884khPDjcycx20eL8ZrLZSw1voyTkoIEajTCKs,2488
10
+ harness_sdk_python-0.36.2.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
11
+ harness_sdk_python-0.36.2.dist-info/RECORD,,