harness-sdk-python 0.40.2__tar.gz → 0.40.3__tar.gz
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.
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/PKG-INFO +2 -2
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/pyproject.toml +2 -2
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/run_manager.py +137 -39
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/run_helpers.py +2 -1
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_prioritize.py +218 -9
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/.gitignore +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/README.md +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/examples/__init__.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/examples/runs_app.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/__init__.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/checkpoints.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/deepagents.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/deepagents_host.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/fenced_postgres.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/interest.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/langgraph.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/linear_thread.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/messages.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/parts.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/prioritize.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/protocol.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/providers/__init__.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/providers/gpt_live.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/threads.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/voice.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/voice_thread.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/wire.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_admit_steer.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_applied_visibility.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_batches.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_branch_anchor.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_checkpoints.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_deepagents_approval.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_deepagents_files.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_deepagents_outcome.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_deepagents_thread.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_deepagents_voice.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_dispatching.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_durability.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_edit_dispatched.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_edit_reload.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_enqueue.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_fenced_postgres.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_gpt_live.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_imports.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_input_required.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_interest.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_langgraph.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_linear_thread.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_meta.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_mint_concurrency.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_outcomes.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_parts.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_placement.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_prepare_hooks.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_prioritize_builtins.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_restore.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_rewind_during_run.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_run_admission.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_run_crash_sweep.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_run_eviction.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_run_id_bounds.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_run_ownership.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_run_sync.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_settle.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_steer.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_stop_continue.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_stopping_window.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_threads.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_undo.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_voice.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_voice_delegation.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_voice_events.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/test_wire.py +0 -0
- {harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/tests/voice_helpers.py +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: harness-sdk-python
|
|
3
|
-
Version: 0.40.
|
|
3
|
+
Version: 0.40.3
|
|
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
8
|
Requires-Dist: pinned>=0.17.0
|
|
9
|
-
Requires-Dist: statewire<0.24,>=0.23.
|
|
9
|
+
Requires-Dist: statewire<0.24,>=0.23.5
|
|
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'
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "harness-sdk-python"
|
|
3
|
-
version = "0.40.
|
|
3
|
+
version = "0.40.3"
|
|
4
4
|
description = "RunManager: the harness-sdk runs subsystem for Python Statewire hosts"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
7
7
|
requires-python = ">=3.12,<4.0"
|
|
8
|
-
dependencies = ["statewire>=0.23.
|
|
8
|
+
dependencies = ["statewire>=0.23.5,<0.24", "pinned>=0.17.0"]
|
|
9
9
|
|
|
10
10
|
[project.optional-dependencies]
|
|
11
11
|
postgres = ["langgraph-checkpoint-postgres>=2.0.0"]
|
|
@@ -89,7 +89,12 @@ from pinned.trays import Tray, TrayDescriptor, TrayCtx, TrayMapNamespace, inbox
|
|
|
89
89
|
from pinned.trays import persistent, persistent_outbox, persistent_queue
|
|
90
90
|
from statepatch import observable
|
|
91
91
|
from statewire import StatewireReject
|
|
92
|
-
from statewire.api import
|
|
92
|
+
from statewire.api import (
|
|
93
|
+
_admission_key,
|
|
94
|
+
_release_admission,
|
|
95
|
+
_response_of,
|
|
96
|
+
_settle_parked,
|
|
97
|
+
)
|
|
93
98
|
from statewire.ops import encode_envelope
|
|
94
99
|
|
|
95
100
|
logger = logging.getLogger(__name__)
|
|
@@ -333,8 +338,8 @@ class _Send:
|
|
|
333
338
|
principal: Any = None
|
|
334
339
|
version: str | None = None
|
|
335
340
|
preempt: bool = False
|
|
336
|
-
#
|
|
337
|
-
decided: Callable[[], None] | None = None
|
|
341
|
+
# records the verdict over the pending-decision record; None: still pending
|
|
342
|
+
decided: Callable[[dict[str, Any] | None], None] | None = None
|
|
338
343
|
future: "asyncio.Future[Any]" = field(default_factory=_future)
|
|
339
344
|
|
|
340
345
|
|
|
@@ -402,9 +407,14 @@ class _Effects:
|
|
|
402
407
|
steer_added: bool = False
|
|
403
408
|
continue_requested: bool = False
|
|
404
409
|
continue_meta: Any = None
|
|
405
|
-
staged_sends: list[
|
|
406
|
-
|
|
407
|
-
|
|
410
|
+
staged_sends: list[
|
|
411
|
+
tuple[
|
|
412
|
+
"asyncio.Future[Any]",
|
|
413
|
+
Callable[[], None],
|
|
414
|
+
Any,
|
|
415
|
+
Callable[[dict[str, Any] | None], None] | None,
|
|
416
|
+
]
|
|
417
|
+
] = field(default_factory=list)
|
|
408
418
|
continues: list["asyncio.Future[Any]"] = field(default_factory=list)
|
|
409
419
|
|
|
410
420
|
|
|
@@ -434,7 +444,7 @@ class RunManager(Tray):
|
|
|
434
444
|
stopReason = persistent(None)
|
|
435
445
|
dispatchedIds = persistent([])
|
|
436
446
|
deciding = persistent([]) # sends released ahead of their decision; off the wire
|
|
437
|
-
|
|
447
|
+
verdicts = persistent([]) # decided sends' {key, response, delivered}; off the wire
|
|
438
448
|
status = observable("ready") # view: derived by _publish_status
|
|
439
449
|
stopping = observable(None) # view: the open stop window, derived
|
|
440
450
|
dispatching = observable(None) # view: the unconfirmed batch record
|
|
@@ -474,6 +484,7 @@ class RunManager(Tray):
|
|
|
474
484
|
self._fresh = False
|
|
475
485
|
self._closing = False
|
|
476
486
|
self._idle = asyncio.Event()
|
|
487
|
+
self._verdict_waiters: dict[str, "asyncio.Future[dict[str, Any]]"] = {}
|
|
477
488
|
self._reroute: Callable[[list[Any]], Coroutine[Any, Any, None]] | None = None
|
|
478
489
|
|
|
479
490
|
async def lifecycle(self) -> AsyncIterator[None]:
|
|
@@ -575,8 +586,26 @@ class RunManager(Tray):
|
|
|
575
586
|
if not self._in_flight():
|
|
576
587
|
self._idle.set()
|
|
577
588
|
self._publish_status()
|
|
589
|
+
if any("durable" not in r for r in self.deciding.value):
|
|
590
|
+
# a 0.40.2 record released its frame: no parked seq waits on its verdict
|
|
591
|
+
self.deciding.value = [
|
|
592
|
+
r if "durable" in r else {**r, "durable": False}
|
|
593
|
+
for r in self.deciding.value
|
|
594
|
+
]
|
|
578
595
|
for record in self.deciding.value:
|
|
579
|
-
self.
|
|
596
|
+
entry = self._undecided(record)
|
|
597
|
+
entry.future.add_done_callback(lambda f: f.cancelled() or f.exception())
|
|
598
|
+
self._admit(entry)
|
|
599
|
+
if any(v["response"] is None for v in self.verdicts.value):
|
|
600
|
+
self.verdicts.value = [
|
|
601
|
+
{**v, "response": {"type": "result-unavailable"}}
|
|
602
|
+
if v["response"] is None
|
|
603
|
+
else v
|
|
604
|
+
for v in self.verdicts.value
|
|
605
|
+
]
|
|
606
|
+
for verdict in self.verdicts.value:
|
|
607
|
+
if not verdict["delivered"]:
|
|
608
|
+
self._deliver(verdict["key"], verdict["response"])
|
|
580
609
|
self._schedule(self._advance) # reconcile a torn advance segment
|
|
581
610
|
|
|
582
611
|
# ─── State access ───────────────────────────────────────
|
|
@@ -689,7 +718,7 @@ class RunManager(Tray):
|
|
|
689
718
|
self._check_id_capacity((entry.message["id"],))
|
|
690
719
|
except StatewireReject as exc:
|
|
691
720
|
if isinstance(entry, _Send) and entry.decided is not None:
|
|
692
|
-
entry.decided()
|
|
721
|
+
entry.decided(_response_of(exc))
|
|
693
722
|
if not entry.future.done():
|
|
694
723
|
entry.future.set_exception(exc)
|
|
695
724
|
return
|
|
@@ -708,31 +737,78 @@ class RunManager(Tray):
|
|
|
708
737
|
return result
|
|
709
738
|
|
|
710
739
|
# A send waiting for a decision (its own, or an earlier send's) records
|
|
711
|
-
# itself here and
|
|
712
|
-
# commands start at once. The
|
|
713
|
-
#
|
|
714
|
-
#
|
|
715
|
-
#
|
|
716
|
-
#
|
|
717
|
-
#
|
|
740
|
+
# itself here and parks its Statewire command, so the client's later
|
|
741
|
+
# commands start at once. The segment that applies the send swaps the
|
|
742
|
+
# record for its verdict, and the verdict answers the parked seq after
|
|
743
|
+
# the effects' flush; the tray outlives undelivered verdicts. After a
|
|
744
|
+
# restart a record stages as if no prioritizer answered: "auto" steers
|
|
745
|
+
# while a run is live and queues otherwise, and undelivered verdicts
|
|
746
|
+
# answer again. Records are keyed by the command's admission (client,
|
|
747
|
+
# lane, seq): a frame redelivered after a crash cut answers with its
|
|
748
|
+
# record's verdict and stages nothing.
|
|
718
749
|
|
|
719
750
|
def _hold_decision(self, record: dict[str, Any], key: str | None) -> str:
|
|
751
|
+
durable = key is not None
|
|
720
752
|
if key is None:
|
|
721
753
|
key = self.handler.__self__.domain.token_hex(8)
|
|
722
|
-
self.deciding.value = [
|
|
754
|
+
self.deciding.value = [
|
|
755
|
+
*self.deciding.value,
|
|
756
|
+
{**record, "key": key, "durable": durable},
|
|
757
|
+
]
|
|
723
758
|
return key
|
|
724
759
|
|
|
725
|
-
def
|
|
726
|
-
return key in self.decided.value or any(
|
|
727
|
-
r["key"] == key for r in self.deciding.value
|
|
728
|
-
)
|
|
729
|
-
|
|
730
|
-
def _drop_decision(self, key: str) -> None:
|
|
760
|
+
def _decide(self, key: str, response: dict[str, Any] | None) -> None:
|
|
731
761
|
records = self.deciding.value
|
|
732
|
-
|
|
733
|
-
if
|
|
734
|
-
self.deciding.value =
|
|
735
|
-
|
|
762
|
+
record = next((r for r in records if r["key"] == key), None)
|
|
763
|
+
if record is not None:
|
|
764
|
+
self.deciding.value = [r for r in records if r is not record]
|
|
765
|
+
if not record["durable"]:
|
|
766
|
+
return
|
|
767
|
+
elif not any(
|
|
768
|
+
v["key"] == key and v["response"] is None for v in self.verdicts.value
|
|
769
|
+
):
|
|
770
|
+
return
|
|
771
|
+
self._keep_verdict({"key": key, "response": response, "delivered": False})
|
|
772
|
+
if response is not None:
|
|
773
|
+
self._deliver(key, response)
|
|
774
|
+
|
|
775
|
+
def _keep_verdict(self, verdict: dict[str, Any]) -> None:
|
|
776
|
+
kept = [v for v in self.verdicts.value if v["key"] != verdict["key"]]
|
|
777
|
+
delivered = [v for v in kept if v["delivered"]]
|
|
778
|
+
stale = delivered[: max(0, len(delivered) + 1 - _DECIDED_KEYS)]
|
|
779
|
+
self.verdicts.value = [
|
|
780
|
+
*(v for v in kept if not any(v is s for s in stale)),
|
|
781
|
+
verdict,
|
|
782
|
+
]
|
|
783
|
+
|
|
784
|
+
def _deliver(self, key: str, response: dict[str, Any]) -> None:
|
|
785
|
+
waiter = self._verdict_waiters.pop(key, None)
|
|
786
|
+
if waiter is not None and not waiter.done():
|
|
787
|
+
waiter.set_result(response)
|
|
788
|
+
self._spawn(self._delivered(key, response))
|
|
789
|
+
|
|
790
|
+
async def _delivered(self, key: str, response: dict[str, Any]) -> None:
|
|
791
|
+
await self.storage._frontier.receipt()
|
|
792
|
+
await _settle_parked(self.handler.__self__, key, response)
|
|
793
|
+
if self._retirement is None and any(
|
|
794
|
+
v["key"] == key and not v["delivered"] for v in self.verdicts.value
|
|
795
|
+
):
|
|
796
|
+
self._keep_verdict({"key": key, "response": response, "delivered": True})
|
|
797
|
+
self._maybe_self_delete()
|
|
798
|
+
|
|
799
|
+
async def _verdict(self, key: str) -> dict[str, Any] | None:
|
|
800
|
+
"""A held decision's verdict once it is known; None when ``key`` holds none."""
|
|
801
|
+
stored = next(
|
|
802
|
+
(v["response"] for v in self.verdicts.value if v["key"] == key), _ABSENT
|
|
803
|
+
)
|
|
804
|
+
if stored is _ABSENT and not any(r["key"] == key for r in self.deciding.value):
|
|
805
|
+
return None
|
|
806
|
+
if stored is _ABSENT or stored is None:
|
|
807
|
+
waiter = self._verdict_waiters.get(key)
|
|
808
|
+
if waiter is None:
|
|
809
|
+
waiter = self._verdict_waiters[key] = _future()
|
|
810
|
+
stored = await asyncio.shield(waiter)
|
|
811
|
+
return stored
|
|
736
812
|
|
|
737
813
|
def _undecided(self, record: dict[str, Any]) -> _Send:
|
|
738
814
|
behavior = record["behavior"]
|
|
@@ -761,7 +837,7 @@ class RunManager(Tray):
|
|
|
761
837
|
principal=record["principal"],
|
|
762
838
|
version=record["version"],
|
|
763
839
|
preempt=mode == "preempt",
|
|
764
|
-
decided=lambda: self.
|
|
840
|
+
decided=lambda response: self._decide(key, response),
|
|
765
841
|
)
|
|
766
842
|
|
|
767
843
|
def _apply_intake(self) -> _Effects:
|
|
@@ -779,8 +855,10 @@ class RunManager(Tray):
|
|
|
779
855
|
future.set_result(retracted)
|
|
780
856
|
|
|
781
857
|
def _settle_applied(self, fx: _Effects) -> None:
|
|
782
|
-
for future, applied, result in fx.staged_sends:
|
|
858
|
+
for future, applied, result, decided in fx.staged_sends:
|
|
783
859
|
applied()
|
|
860
|
+
if decided is not None:
|
|
861
|
+
decided(_response_of(result))
|
|
784
862
|
if not future.done():
|
|
785
863
|
future.set_result(result)
|
|
786
864
|
for future in fx.continues:
|
|
@@ -855,8 +933,6 @@ class RunManager(Tray):
|
|
|
855
933
|
return
|
|
856
934
|
try:
|
|
857
935
|
if isinstance(entry, _Send):
|
|
858
|
-
if entry.decided is not None:
|
|
859
|
-
entry.decided()
|
|
860
936
|
result = self._apply_send(entry, fx)
|
|
861
937
|
elif isinstance(entry, _Dequeue):
|
|
862
938
|
result = self._apply_dequeue(entry)
|
|
@@ -867,9 +943,25 @@ class RunManager(Tray):
|
|
|
867
943
|
else:
|
|
868
944
|
result = self._apply_reload(entry)
|
|
869
945
|
except StatewireReject as exc:
|
|
946
|
+
if isinstance(entry, _Send) and entry.decided is not None:
|
|
947
|
+
entry.decided(_response_of(exc))
|
|
870
948
|
if not entry.future.done():
|
|
871
949
|
entry.future.set_exception(exc)
|
|
872
950
|
return
|
|
951
|
+
if isinstance(entry, _Send) and entry.decided is not None:
|
|
952
|
+
decided = entry.decided
|
|
953
|
+
if result is _PARKED:
|
|
954
|
+
decided(None)
|
|
955
|
+
entry.future.add_done_callback(
|
|
956
|
+
lambda f: f.cancelled()
|
|
957
|
+
or decided(
|
|
958
|
+
_response_of(
|
|
959
|
+
f.exception() if f.exception() is not None else f.result()
|
|
960
|
+
)
|
|
961
|
+
)
|
|
962
|
+
)
|
|
963
|
+
else:
|
|
964
|
+
decided(_response_of(result))
|
|
873
965
|
if result is not _PARKED and not entry.future.done():
|
|
874
966
|
entry.future.set_result(result)
|
|
875
967
|
|
|
@@ -1196,6 +1288,7 @@ class RunManager(Tray):
|
|
|
1196
1288
|
or self.inputRequests.value
|
|
1197
1289
|
or self.halted.value is not None
|
|
1198
1290
|
or self.deciding.value
|
|
1291
|
+
or any(not v["delivered"] for v in self.verdicts.value)
|
|
1199
1292
|
):
|
|
1200
1293
|
return
|
|
1201
1294
|
self.delete()
|
|
@@ -1595,7 +1688,7 @@ class RunManager(Tray):
|
|
|
1595
1688
|
self.authors.value = {**self.authors.value, e.message_id: e.principal}
|
|
1596
1689
|
# A mint racing a live run merges into it; settle carries the surviving id.
|
|
1597
1690
|
result = None if e.minted or e.anchor is _ABSENT else {"runId": self.id}
|
|
1598
|
-
fx.staged_sends.append((e.future, e.applied, result))
|
|
1691
|
+
fx.staged_sends.append((e.future, e.applied, result, e.decided))
|
|
1599
1692
|
return _PARKED
|
|
1600
1693
|
|
|
1601
1694
|
def _apply_move(self, e: _Send, fx: _Effects) -> Any:
|
|
@@ -2335,6 +2428,14 @@ class RunManagerNamespace(TrayMapNamespace):
|
|
|
2335
2428
|
tray, minted = self.live(), False
|
|
2336
2429
|
if tray is None:
|
|
2337
2430
|
raise _reject("unknown-id", f"message {message_id} is not queued")
|
|
2431
|
+
admission = _admission_key(applied)
|
|
2432
|
+
if admission is not None:
|
|
2433
|
+
# a frame redelivered after a crash cut answers with its record's verdict
|
|
2434
|
+
response = await tray._verdict(admission)
|
|
2435
|
+
if response is not None:
|
|
2436
|
+
await tray.storage._frontier.receipt()
|
|
2437
|
+
await _settle_parked(self._api, admission, response)
|
|
2438
|
+
return None
|
|
2338
2439
|
|
|
2339
2440
|
def staged(mode: str) -> _Send:
|
|
2340
2441
|
return _Send(
|
|
@@ -2363,9 +2464,6 @@ class RunManagerNamespace(TrayMapNamespace):
|
|
|
2363
2464
|
# client's stop, edit, input and dequeue don't wait for the decision.
|
|
2364
2465
|
# Parked sends leave Statewire's in-flight capacity; max_queued bounds them.
|
|
2365
2466
|
holder = tray
|
|
2366
|
-
admission = _admission_key(applied)
|
|
2367
|
-
if admission is not None and holder._holds_decision(admission):
|
|
2368
|
-
return None # the frame redelivered after a crash cut: its record stages it
|
|
2369
2467
|
if len(holder.deciding.value) >= holder.max_queued:
|
|
2370
2468
|
raise _reject(
|
|
2371
2469
|
"queue-full",
|
|
@@ -2397,8 +2495,8 @@ class RunManagerNamespace(TrayMapNamespace):
|
|
|
2397
2495
|
record["anchor"] = anchor
|
|
2398
2496
|
key = holder._hold_decision(record, admission)
|
|
2399
2497
|
|
|
2400
|
-
def decided() -> None:
|
|
2401
|
-
holder.
|
|
2498
|
+
def decided(response: dict[str, Any] | None) -> None:
|
|
2499
|
+
holder._decide(key, response)
|
|
2402
2500
|
|
|
2403
2501
|
try:
|
|
2404
2502
|
await holder.storage._frontier.receipt()
|
|
@@ -2417,8 +2515,8 @@ class RunManagerNamespace(TrayMapNamespace):
|
|
|
2417
2515
|
return await tray._stage(entry, release)
|
|
2418
2516
|
except asyncio.CancelledError:
|
|
2419
2517
|
raise # the record stays: a remount stages it
|
|
2420
|
-
except BaseException:
|
|
2421
|
-
decided()
|
|
2518
|
+
except BaseException as exc:
|
|
2519
|
+
decided(_response_of(exc))
|
|
2422
2520
|
raise
|
|
2423
2521
|
finally:
|
|
2424
2522
|
release()
|
|
@@ -333,6 +333,7 @@ async def run_host(
|
|
|
333
333
|
headers=None,
|
|
334
334
|
version=HARNESS_PROTOCOL.version,
|
|
335
335
|
prioritize=None,
|
|
336
|
+
client_id=None,
|
|
336
337
|
):
|
|
337
338
|
"""``version`` is the negotiated protocol date the host passes to sends; None passes none."""
|
|
338
339
|
host_cls = make_host(
|
|
@@ -350,7 +351,7 @@ async def run_host(
|
|
|
350
351
|
)
|
|
351
352
|
async with statewire_client(host_cls, worker=worker) as (app, client):
|
|
352
353
|
# Fresh client id per session, like a production client.
|
|
353
|
-
client_id = f"c-{uuid4().hex[:8]}"
|
|
354
|
+
client_id = client_id or f"c-{uuid4().hex[:8]}"
|
|
354
355
|
async with stream_of(
|
|
355
356
|
app,
|
|
356
357
|
client_id=client_id,
|
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
"""run/send: behaviors, the auto prioritizer, preempt, and the pre-2026-11-04 adapter."""
|
|
2
2
|
|
|
3
3
|
import asyncio
|
|
4
|
-
import
|
|
4
|
+
import copy
|
|
5
|
+
import importlib
|
|
5
6
|
import logging
|
|
6
7
|
|
|
7
8
|
import pytest
|
|
9
|
+
from pinned import PinnedWorker
|
|
8
10
|
from pinned.testing import MemoryStateStore
|
|
9
11
|
from run_helpers import (
|
|
10
12
|
Script,
|
|
11
13
|
add,
|
|
12
14
|
assert_rejected,
|
|
13
15
|
edit_params,
|
|
16
|
+
make_host,
|
|
14
17
|
msg,
|
|
15
18
|
queue_ids,
|
|
16
19
|
run_host,
|
|
17
20
|
target,
|
|
18
21
|
)
|
|
22
|
+
from statewire.protocol import WIRE_VERSION, Offer, VersionRange
|
|
23
|
+
from statewire.protocol import headers as protocol_headers
|
|
24
|
+
from statewire_helpers import apply_ops, attach_of, statewire_client
|
|
19
25
|
|
|
20
|
-
from harness_sdk import RunManager
|
|
26
|
+
from harness_sdk import HARNESS_PROTOCOL, RunManager
|
|
21
27
|
from statewire.limits import MAX_INFLIGHT_COMMANDS_PER_CLIENT
|
|
22
28
|
|
|
23
29
|
|
|
@@ -566,7 +572,7 @@ def pooled_sends(store, message_id):
|
|
|
566
572
|
for row, (_marked, doc) in store.trays.items()
|
|
567
573
|
for frame in doc.get("pool", ())
|
|
568
574
|
if any(
|
|
569
|
-
s["method"] == "run/send" and
|
|
575
|
+
s["method"] == "run/send" and s["params"][0].get("message", {}).get("id") == message_id
|
|
570
576
|
for s in frame["statements"]
|
|
571
577
|
)
|
|
572
578
|
]
|
|
@@ -597,15 +603,17 @@ async def test_a_pending_decision_survives_a_crash_as_a_steer():
|
|
|
597
603
|
|
|
598
604
|
async def test_a_frame_redelivered_with_its_decision_record_stages_once():
|
|
599
605
|
"""A crash between the record's flush and the frame's pop keeps both: the
|
|
600
|
-
record stages the send, and the redelivered frame
|
|
606
|
+
record stages the send, and the redelivered frame answers its verdict."""
|
|
601
607
|
store = MemoryStateStore()
|
|
602
608
|
script = Script()
|
|
603
609
|
prioritize = Prioritizer()
|
|
604
|
-
async with run_host(
|
|
610
|
+
async with run_host(
|
|
611
|
+
script, store=store, prioritize=prioritize, client_id=CLIENT
|
|
612
|
+
) as (drv, host):
|
|
605
613
|
await running(drv, script)
|
|
606
614
|
gate = asyncio.get_running_loop().create_future()
|
|
607
615
|
prioritize.gates.append(gate)
|
|
608
|
-
drv.post("run/send", add("a1"))
|
|
616
|
+
seq = drv.post("run/send", add("a1"))
|
|
609
617
|
pooled = None
|
|
610
618
|
async with asyncio.timeout(5):
|
|
611
619
|
while not prioritize.requests:
|
|
@@ -617,15 +625,21 @@ async def test_a_frame_redelivered_with_its_decision_record_stages_once():
|
|
|
617
625
|
await host.live.frontier.wait()
|
|
618
626
|
await asyncio.sleep(0.01)
|
|
619
627
|
crashed = MemoryStateStore()
|
|
620
|
-
crashed.trays =
|
|
628
|
+
crashed.trays = copy.deepcopy(store.trays)
|
|
621
629
|
row, frame = pooled
|
|
622
630
|
marked, doc = crashed.trays[row]
|
|
623
|
-
crashed.trays[row] = (
|
|
631
|
+
crashed.trays[row] = (
|
|
632
|
+
marked,
|
|
633
|
+
{**doc, "pool": [frame], "parked": []},
|
|
634
|
+
)
|
|
624
635
|
|
|
625
636
|
script2 = Script()
|
|
626
637
|
again = Prioritizer("preempt")
|
|
627
|
-
async with run_host(
|
|
638
|
+
async with run_host(
|
|
639
|
+
script2, store=crashed, prioritize=again, client_id=CLIENT
|
|
640
|
+
) as (drv2, host2):
|
|
628
641
|
redelivered = await script2.next_call()
|
|
642
|
+
assert (await drv2.res(seq))["type"] == "accepted"
|
|
629
643
|
await drv2.wait(lambda s: queue_ids(s, "steerQueue") == ["a1"])
|
|
630
644
|
async with asyncio.timeout(5):
|
|
631
645
|
while pooled_sends(crashed, "a1"):
|
|
@@ -636,6 +650,201 @@ async def test_a_frame_redelivered_with_its_decision_record_stages_once():
|
|
|
636
650
|
assert queue_ids(drv2.replica, "steerQueue") == ["a1"]
|
|
637
651
|
|
|
638
652
|
|
|
653
|
+
CLIENT = "c-decider"
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
def parked_seqs(store):
|
|
657
|
+
"""Parked commands still waiting for their answer."""
|
|
658
|
+
return [
|
|
659
|
+
p
|
|
660
|
+
for _marked, doc in store.trays.values()
|
|
661
|
+
for p in doc.get("parked", ())
|
|
662
|
+
if p["response"] is None
|
|
663
|
+
]
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
def undelivered(store):
|
|
667
|
+
return [
|
|
668
|
+
v
|
|
669
|
+
for _marked, doc in store.trays.values()
|
|
670
|
+
for v in doc.get("verdicts", ())
|
|
671
|
+
if not v["delivered"]
|
|
672
|
+
]
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
async def crash_while_deciding(max_queued=50, steer_first=False):
|
|
676
|
+
"""The store a crash leaves while a1's auto send waits for its decision, and a1's seq."""
|
|
677
|
+
store = MemoryStateStore()
|
|
678
|
+
script = Script()
|
|
679
|
+
prioritize = Prioritizer()
|
|
680
|
+
async with run_host(
|
|
681
|
+
script,
|
|
682
|
+
max_queued=max_queued,
|
|
683
|
+
store=store,
|
|
684
|
+
prioritize=prioritize,
|
|
685
|
+
client_id=CLIENT,
|
|
686
|
+
) as (drv, host):
|
|
687
|
+
await running(drv, script)
|
|
688
|
+
run_id = await drv.run_id()
|
|
689
|
+
if steer_first:
|
|
690
|
+
steer = add("s1", run_id=run_id, behavior="steer")
|
|
691
|
+
assert (await drv.command("run/send", steer))["type"] == "accepted"
|
|
692
|
+
_gate, seq = await deciding(drv, prioritize)
|
|
693
|
+
async with asyncio.timeout(5):
|
|
694
|
+
while deciding_ids(store) != ["a1"] or not parked_seqs(store):
|
|
695
|
+
await host.live.frontier.wait()
|
|
696
|
+
await asyncio.sleep(0.01)
|
|
697
|
+
crashed = MemoryStateStore()
|
|
698
|
+
crashed.trays = copy.deepcopy(store.trays)
|
|
699
|
+
return crashed, seq
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
async def reattached(crashed, seq, max_queued=50):
|
|
703
|
+
"""The restarted host's answers for ``seq`` to a gap-fill reattach, and its steer lane."""
|
|
704
|
+
host_cls = make_host(Script(), max_queued=max_queued, prioritize=Prioritizer())
|
|
705
|
+
worker = PinnedWorker(state_store=crashed)
|
|
706
|
+
cursor = {"res": [{"protocol": "default", "seq": seq - 1}]}
|
|
707
|
+
gap_fill = protocol_headers(
|
|
708
|
+
VersionRange(WIRE_VERSION),
|
|
709
|
+
(Offer("default", VersionRange(HARNESS_PROTOCOL.version)),),
|
|
710
|
+
)
|
|
711
|
+
replica = {}
|
|
712
|
+
answers = []
|
|
713
|
+
async with statewire_client(host_cls, worker=worker) as (app, _client):
|
|
714
|
+
async with attach_of(app, cursor, client_id=CLIENT, headers=gap_fill) as stream:
|
|
715
|
+
async with asyncio.timeout(5):
|
|
716
|
+
while not answers or parked_seqs(crashed):
|
|
717
|
+
event = await stream.next_event(timeout=0.05)
|
|
718
|
+
if event is None:
|
|
719
|
+
continue
|
|
720
|
+
apply_ops(replica, copy.deepcopy(event))
|
|
721
|
+
answers += [
|
|
722
|
+
a for a in event.get("cmd", ()) if a["seq"] == seq and "type" in a
|
|
723
|
+
]
|
|
724
|
+
return answers, queue_ids(replica, "steerQueue")
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
async def test_a_send_parked_across_a_crash_answers_its_verdict():
|
|
728
|
+
"""The gap-fill reads the parked seq pending until the restaged send lands."""
|
|
729
|
+
crashed, seq = await crash_while_deciding()
|
|
730
|
+
answers, steered = await reattached(crashed, seq)
|
|
731
|
+
assert [a["type"] for a in answers] == ["result"]
|
|
732
|
+
assert steered == ["a1"]
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
async def test_a_send_parked_across_a_crash_keeps_its_rejection():
|
|
736
|
+
crashed, seq = await crash_while_deciding(max_queued=1, steer_first=True)
|
|
737
|
+
answers, steered = await reattached(crashed, seq, max_queued=1)
|
|
738
|
+
assert len(answers) == 1
|
|
739
|
+
assert_rejected(answers[0], "queue-full")
|
|
740
|
+
assert steered == ["s1"]
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
async def crash_before_the_answer(monkeypatch, decide, start=deciding):
|
|
744
|
+
"""The store a crash leaves after a send's verdict is recorded but before
|
|
745
|
+
it answers the parked seq, and the seq; ``start`` parks the send,
|
|
746
|
+
``decide`` ends its decision."""
|
|
747
|
+
rm = importlib.import_module("harness_sdk.run_manager")
|
|
748
|
+
answered = rm._settle_parked
|
|
749
|
+
monkeypatch.setattr(rm, "_settle_parked", lambda *args: asyncio.Event().wait())
|
|
750
|
+
store = MemoryStateStore()
|
|
751
|
+
script = Script()
|
|
752
|
+
prioritize = Prioritizer()
|
|
753
|
+
async with run_host(
|
|
754
|
+
script, store=store, prioritize=prioritize, client_id=CLIENT
|
|
755
|
+
) as (drv, host):
|
|
756
|
+
call = await running(drv, script)
|
|
757
|
+
gate, seq = await start(drv, prioritize)
|
|
758
|
+
async with asyncio.timeout(5):
|
|
759
|
+
while not parked_seqs(store):
|
|
760
|
+
await host.live.frontier.wait()
|
|
761
|
+
await asyncio.sleep(0.01)
|
|
762
|
+
await decide(drv, gate, call)
|
|
763
|
+
async with asyncio.timeout(5):
|
|
764
|
+
while not undelivered(store):
|
|
765
|
+
await host.live.frontier.wait()
|
|
766
|
+
await asyncio.sleep(0.01)
|
|
767
|
+
await asyncio.sleep(0.05)
|
|
768
|
+
crashed = MemoryStateStore()
|
|
769
|
+
crashed.trays = copy.deepcopy(store.trays)
|
|
770
|
+
monkeypatch.setattr(rm, "_settle_parked", answered)
|
|
771
|
+
return crashed, seq
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
async def test_a_verdict_a_crash_kept_from_the_client_answers_after_restart(monkeypatch):
|
|
775
|
+
async def decide(drv, gate, call):
|
|
776
|
+
gate.set_result("queue")
|
|
777
|
+
|
|
778
|
+
crashed, seq = await crash_before_the_answer(monkeypatch, decide)
|
|
779
|
+
answers, _steered = await reattached(crashed, seq)
|
|
780
|
+
assert [a["type"] for a in answers] == ["result"]
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
async def test_an_idle_run_keeps_a_verdict_it_has_not_delivered(monkeypatch):
|
|
784
|
+
"""A dequeue voids a waiting move and the run ends: the move rejects
|
|
785
|
+
unknown-id, and the idle run outlives that verdict's delivery."""
|
|
786
|
+
|
|
787
|
+
async def decide(drv, gate, call):
|
|
788
|
+
drv.post("run/dequeue", {"messageId": "q1"})
|
|
789
|
+
await drv.wait(lambda s: queue_ids(s, "queue") == [])
|
|
790
|
+
call.finish(RunManager.Complete())
|
|
791
|
+
await drv.wait_status("ready")
|
|
792
|
+
|
|
793
|
+
async def move(drv, prioritize):
|
|
794
|
+
await drv.command("run/send", add("q1", behavior="queue"), terminal=False)
|
|
795
|
+
gate = asyncio.get_running_loop().create_future()
|
|
796
|
+
prioritize.gates.append(gate)
|
|
797
|
+
seq = drv.post("run/send", {"runId": await drv.run_id(), "messageId": "q1"})
|
|
798
|
+
async with asyncio.timeout(5):
|
|
799
|
+
while not prioritize.requests:
|
|
800
|
+
await asyncio.sleep(0.01)
|
|
801
|
+
return gate, seq
|
|
802
|
+
|
|
803
|
+
crashed, seq = await crash_before_the_answer(monkeypatch, decide, move)
|
|
804
|
+
answers, _steered = await reattached(crashed, seq)
|
|
805
|
+
assert len(answers) == 1
|
|
806
|
+
assert_rejected(answers[0], "unknown-id")
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
async def test_a_decision_record_from_before_verdicts_stages_after_a_restart():
|
|
810
|
+
"""A record written before records carried ``durable`` (0.40.2 and
|
|
811
|
+
earlier) released its frame, so nothing waits on its verdict: it stages
|
|
812
|
+
and keeps none."""
|
|
813
|
+
store = MemoryStateStore()
|
|
814
|
+
script = Script()
|
|
815
|
+
prioritize = Prioritizer()
|
|
816
|
+
async with run_host(
|
|
817
|
+
script, store=store, prioritize=prioritize, client_id=CLIENT
|
|
818
|
+
) as (drv, host):
|
|
819
|
+
await running(drv, script)
|
|
820
|
+
await deciding(drv, prioritize)
|
|
821
|
+
drv.post("run/send", add("q1", behavior="queue")) # waits behind the decision
|
|
822
|
+
async with asyncio.timeout(5):
|
|
823
|
+
while deciding_ids(store) != ["a1", "q1"]:
|
|
824
|
+
await host.live.frontier.wait()
|
|
825
|
+
await asyncio.sleep(0.01)
|
|
826
|
+
crashed = MemoryStateStore()
|
|
827
|
+
crashed.trays = copy.deepcopy(store.trays)
|
|
828
|
+
for row, (marked, doc) in crashed.trays.items():
|
|
829
|
+
if "deciding" in doc:
|
|
830
|
+
old = [{k: v for k, v in r.items() if k != "durable"} for r in doc["deciding"]]
|
|
831
|
+
assert old != doc["deciding"]
|
|
832
|
+
rest = {k: v for k, v in doc.items() if k != "verdicts"}
|
|
833
|
+
crashed.trays[row] = (marked, {**rest, "deciding": old, "decided": []})
|
|
834
|
+
|
|
835
|
+
script2 = Script()
|
|
836
|
+
async with run_host(script2, store=crashed, prioritize=Prioritizer()) as (drv2, host2):
|
|
837
|
+
redelivered = await script2.next_call()
|
|
838
|
+
await drv2.wait(lambda s: queue_ids(s, "steerQueue") == ["a1"])
|
|
839
|
+
assert queue_ids(drv2.replica, "queue") == ["q1"]
|
|
840
|
+
assert [m["id"] for m in redelivered.ctx.steering.take()] == ["a1"]
|
|
841
|
+
async with asyncio.timeout(5):
|
|
842
|
+
while deciding_ids(crashed):
|
|
843
|
+
await host2.live.frontier.wait()
|
|
844
|
+
await asyncio.sleep(0.01)
|
|
845
|
+
assert undelivered(crashed) == []
|
|
846
|
+
|
|
847
|
+
|
|
639
848
|
# ─── pre-2026-11-04 clients ───────────────────────────────
|
|
640
849
|
|
|
641
850
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/providers/__init__.py
RENAMED
|
File without changes
|
{harness_sdk_python-0.40.2 → harness_sdk_python-0.40.3}/src/harness_sdk/providers/gpt_live.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|