harness-sdk-python 0.40.1__tar.gz → 0.40.2__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.1 → harness_sdk_python-0.40.2}/PKG-INFO +2 -2
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/pyproject.toml +2 -2
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/run_manager.py +112 -1
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_prioritize.py +229 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/.gitignore +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/README.md +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/examples/__init__.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/examples/runs_app.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/__init__.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/checkpoints.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/deepagents.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/deepagents_host.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/fenced_postgres.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/interest.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/langgraph.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/linear_thread.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/messages.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/parts.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/prioritize.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/protocol.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/providers/__init__.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/providers/gpt_live.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/threads.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/voice.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/voice_thread.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/src/harness_sdk/wire.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/run_helpers.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_admit_steer.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_applied_visibility.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_batches.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_branch_anchor.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_checkpoints.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_deepagents_approval.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_deepagents_files.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_deepagents_outcome.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_deepagents_thread.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_deepagents_voice.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_dispatching.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_durability.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_edit_dispatched.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_edit_reload.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_enqueue.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_fenced_postgres.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_gpt_live.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_imports.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_input_required.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_interest.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_langgraph.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_linear_thread.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_meta.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_mint_concurrency.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_outcomes.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_parts.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_placement.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_prepare_hooks.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_prioritize_builtins.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_restore.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_rewind_during_run.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_run_admission.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_run_crash_sweep.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_run_eviction.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_run_id_bounds.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_run_ownership.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_run_sync.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_settle.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_steer.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_stop_continue.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_stopping_window.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_threads.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_undo.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_voice.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_voice_delegation.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_voice_events.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/tests/test_wire.py +0 -0
- {harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/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.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
8
|
Requires-Dist: pinned>=0.17.0
|
|
9
|
-
Requires-Dist: statewire<0.24,>=0.23.
|
|
9
|
+
Requires-Dist: statewire<0.24,>=0.23.3
|
|
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.2"
|
|
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.3,<0.24", "pinned>=0.17.0"]
|
|
9
9
|
|
|
10
10
|
[project.optional-dependencies]
|
|
11
11
|
postgres = ["langgraph-checkpoint-postgres>=2.0.0"]
|
|
@@ -89,6 +89,7 @@ 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 _admission_key, _release_admission
|
|
92
93
|
from statewire.ops import encode_envelope
|
|
93
94
|
|
|
94
95
|
logger = logging.getLogger(__name__)
|
|
@@ -131,6 +132,7 @@ _RESERVED_KEYS = frozenset({"~admit", "~parent"})
|
|
|
131
132
|
_MODES = ("steer", "preempt", "queue")
|
|
132
133
|
_BEHAVIORS = ("auto", *_MODES)
|
|
133
134
|
_LIVE = ("running", "stopping", "input-required")
|
|
135
|
+
_DECIDED_KEYS = 64
|
|
134
136
|
|
|
135
137
|
|
|
136
138
|
def _reject(reason: str, message: str) -> StatewireReject:
|
|
@@ -331,6 +333,8 @@ class _Send:
|
|
|
331
333
|
principal: Any = None
|
|
332
334
|
version: str | None = None
|
|
333
335
|
preempt: bool = False
|
|
336
|
+
# drops the durable pending-decision record, in the apply's own segment
|
|
337
|
+
decided: Callable[[], None] | None = None
|
|
334
338
|
future: "asyncio.Future[Any]" = field(default_factory=_future)
|
|
335
339
|
|
|
336
340
|
|
|
@@ -429,6 +433,8 @@ class RunManager(Tray):
|
|
|
429
433
|
error = persistent(None)
|
|
430
434
|
stopReason = persistent(None)
|
|
431
435
|
dispatchedIds = persistent([])
|
|
436
|
+
deciding = persistent([]) # sends released ahead of their decision; off the wire
|
|
437
|
+
decided = persistent([]) # the latest dropped decision keys: a redelivered frame skips
|
|
432
438
|
status = observable("ready") # view: derived by _publish_status
|
|
433
439
|
stopping = observable(None) # view: the open stop window, derived
|
|
434
440
|
dispatching = observable(None) # view: the unconfirmed batch record
|
|
@@ -569,6 +575,8 @@ class RunManager(Tray):
|
|
|
569
575
|
if not self._in_flight():
|
|
570
576
|
self._idle.set()
|
|
571
577
|
self._publish_status()
|
|
578
|
+
for record in self.deciding.value:
|
|
579
|
+
self._admit(self._undecided(record))
|
|
572
580
|
self._schedule(self._advance) # reconcile a torn advance segment
|
|
573
581
|
|
|
574
582
|
# ─── State access ───────────────────────────────────────
|
|
@@ -680,6 +688,8 @@ class RunManager(Tray):
|
|
|
680
688
|
try:
|
|
681
689
|
self._check_id_capacity((entry.message["id"],))
|
|
682
690
|
except StatewireReject as exc:
|
|
691
|
+
if isinstance(entry, _Send) and entry.decided is not None:
|
|
692
|
+
entry.decided()
|
|
683
693
|
if not entry.future.done():
|
|
684
694
|
entry.future.set_exception(exc)
|
|
685
695
|
return
|
|
@@ -697,6 +707,63 @@ class RunManager(Tray):
|
|
|
697
707
|
await self.storage._frontier.receipt() # the verdict follows the flush
|
|
698
708
|
return result
|
|
699
709
|
|
|
710
|
+
# A send waiting for a decision (its own, or an earlier send's) records
|
|
711
|
+
# itself here and releases its Statewire frame, so the client's later
|
|
712
|
+
# commands start at once. The record drops in the segment that applies the
|
|
713
|
+
# send. After a restart a record stages as if no prioritizer answered:
|
|
714
|
+
# "auto" steers while a run is live and queues otherwise. Records are keyed
|
|
715
|
+
# by the command's admission (client, lane, seq): a crash between the
|
|
716
|
+
# record's flush and the frame's pop redelivers the frame too, and the
|
|
717
|
+
# redelivered send finds its key here or in ``decided`` and stages nothing.
|
|
718
|
+
|
|
719
|
+
def _hold_decision(self, record: dict[str, Any], key: str | None) -> str:
|
|
720
|
+
if key is None:
|
|
721
|
+
key = self.handler.__self__.domain.token_hex(8)
|
|
722
|
+
self.deciding.value = [*self.deciding.value, {**record, "key": key}]
|
|
723
|
+
return key
|
|
724
|
+
|
|
725
|
+
def _holds_decision(self, key: str) -> bool:
|
|
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:
|
|
731
|
+
records = self.deciding.value
|
|
732
|
+
kept = [r for r in records if r["key"] != key]
|
|
733
|
+
if len(kept) != len(records):
|
|
734
|
+
self.deciding.value = kept
|
|
735
|
+
self.decided.value = [*self.decided.value, key][-_DECIDED_KEYS:]
|
|
736
|
+
|
|
737
|
+
def _undecided(self, record: dict[str, Any]) -> _Send:
|
|
738
|
+
behavior = record["behavior"]
|
|
739
|
+
mode = (
|
|
740
|
+
behavior
|
|
741
|
+
if behavior != "auto"
|
|
742
|
+
else "steer" if self._status() in _LIVE else "queue"
|
|
743
|
+
)
|
|
744
|
+
key = record["key"]
|
|
745
|
+
message = record["message"]
|
|
746
|
+
params = record["params"]
|
|
747
|
+
if message is not None:
|
|
748
|
+
params = {**params, "message": message}
|
|
749
|
+
return _Send(
|
|
750
|
+
"queue" if mode == "queue" else "steerQueue",
|
|
751
|
+
params,
|
|
752
|
+
message,
|
|
753
|
+
record["messageId"],
|
|
754
|
+
record["sourceMeta"],
|
|
755
|
+
record["meta"],
|
|
756
|
+
lambda: None,
|
|
757
|
+
run_id=record["runId"],
|
|
758
|
+
anchor=record.get("anchor", _ABSENT),
|
|
759
|
+
anchor_meta=record["anchorMeta"],
|
|
760
|
+
thread_empty=record["threadEmpty"],
|
|
761
|
+
principal=record["principal"],
|
|
762
|
+
version=record["version"],
|
|
763
|
+
preempt=mode == "preempt",
|
|
764
|
+
decided=lambda: self._drop_decision(key),
|
|
765
|
+
)
|
|
766
|
+
|
|
700
767
|
def _apply_intake(self) -> _Effects:
|
|
701
768
|
entries, self._intake = self._intake, []
|
|
702
769
|
fx = _Effects()
|
|
@@ -788,6 +855,8 @@ class RunManager(Tray):
|
|
|
788
855
|
return
|
|
789
856
|
try:
|
|
790
857
|
if isinstance(entry, _Send):
|
|
858
|
+
if entry.decided is not None:
|
|
859
|
+
entry.decided()
|
|
791
860
|
result = self._apply_send(entry, fx)
|
|
792
861
|
elif isinstance(entry, _Dequeue):
|
|
793
862
|
result = self._apply_dequeue(entry)
|
|
@@ -1126,6 +1195,7 @@ class RunManager(Tray):
|
|
|
1126
1195
|
or self._staged_rewind is not None
|
|
1127
1196
|
or self.inputRequests.value
|
|
1128
1197
|
or self.halted.value is not None
|
|
1198
|
+
or self.deciding.value
|
|
1129
1199
|
):
|
|
1130
1200
|
return
|
|
1131
1201
|
self.delete()
|
|
@@ -2289,6 +2359,18 @@ class RunManagerNamespace(TrayMapNamespace):
|
|
|
2289
2359
|
subject = self._subject(tray, behavior, message, message_id, auth_result)
|
|
2290
2360
|
if prior is None and subject is None:
|
|
2291
2361
|
return await tray._stage(staged(self._mode(tray, behavior)))
|
|
2362
|
+
# Record the waiting send durably, then park its Statewire command: the
|
|
2363
|
+
# client's stop, edit, input and dequeue don't wait for the decision.
|
|
2364
|
+
# Parked sends leave Statewire's in-flight capacity; max_queued bounds them.
|
|
2365
|
+
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
|
+
if len(holder.deciding.value) >= holder.max_queued:
|
|
2370
|
+
raise _reject(
|
|
2371
|
+
"queue-full",
|
|
2372
|
+
f"too many sends wait for a decision ({holder.max_queued})",
|
|
2373
|
+
)
|
|
2292
2374
|
link = _future()
|
|
2293
2375
|
self._deciding = link
|
|
2294
2376
|
|
|
@@ -2298,7 +2380,29 @@ class RunManagerNamespace(TrayMapNamespace):
|
|
|
2298
2380
|
if self._deciding is link:
|
|
2299
2381
|
self._deciding = None
|
|
2300
2382
|
|
|
2383
|
+
record: dict[str, Any] = {
|
|
2384
|
+
"behavior": behavior,
|
|
2385
|
+
"params": {k: v for k, v in params.items() if k != "message"},
|
|
2386
|
+
"message": message,
|
|
2387
|
+
"messageId": message_id,
|
|
2388
|
+
"sourceMeta": source_meta,
|
|
2389
|
+
"meta": None if message is None else meta,
|
|
2390
|
+
"runId": run_id,
|
|
2391
|
+
"anchorMeta": anchor_meta,
|
|
2392
|
+
"threadEmpty": thread_empty,
|
|
2393
|
+
"principal": auth_result,
|
|
2394
|
+
"version": version,
|
|
2395
|
+
}
|
|
2396
|
+
if anchor is not _ABSENT:
|
|
2397
|
+
record["anchor"] = anchor
|
|
2398
|
+
key = holder._hold_decision(record, admission)
|
|
2399
|
+
|
|
2400
|
+
def decided() -> None:
|
|
2401
|
+
holder._drop_decision(key)
|
|
2402
|
+
|
|
2301
2403
|
try:
|
|
2404
|
+
await holder.storage._frontier.receipt()
|
|
2405
|
+
_release_admission(applied)
|
|
2302
2406
|
if prior is not None:
|
|
2303
2407
|
await asyncio.wait((prior,))
|
|
2304
2408
|
tray = self.live() or tray
|
|
@@ -2308,7 +2412,14 @@ class RunManagerNamespace(TrayMapNamespace):
|
|
|
2308
2412
|
if subject is None
|
|
2309
2413
|
else await self._prioritized(cls, tray, subject)
|
|
2310
2414
|
)
|
|
2311
|
-
|
|
2415
|
+
entry = staged(mode)
|
|
2416
|
+
entry.decided = decided
|
|
2417
|
+
return await tray._stage(entry, release)
|
|
2418
|
+
except asyncio.CancelledError:
|
|
2419
|
+
raise # the record stays: a remount stages it
|
|
2420
|
+
except BaseException:
|
|
2421
|
+
decided()
|
|
2422
|
+
raise
|
|
2312
2423
|
finally:
|
|
2313
2424
|
release()
|
|
2314
2425
|
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
"""run/send: behaviors, the auto prioritizer, preempt, and the pre-2026-11-04 adapter."""
|
|
2
2
|
|
|
3
3
|
import asyncio
|
|
4
|
+
import json
|
|
4
5
|
import logging
|
|
5
6
|
|
|
6
7
|
import pytest
|
|
8
|
+
from pinned.testing import MemoryStateStore
|
|
7
9
|
from run_helpers import (
|
|
8
10
|
Script,
|
|
9
11
|
add,
|
|
10
12
|
assert_rejected,
|
|
13
|
+
edit_params,
|
|
11
14
|
msg,
|
|
12
15
|
queue_ids,
|
|
13
16
|
run_host,
|
|
@@ -15,6 +18,7 @@ from run_helpers import (
|
|
|
15
18
|
)
|
|
16
19
|
|
|
17
20
|
from harness_sdk import RunManager
|
|
21
|
+
from statewire.limits import MAX_INFLIGHT_COMMANDS_PER_CLIENT
|
|
18
22
|
|
|
19
23
|
|
|
20
24
|
class Prioritizer:
|
|
@@ -407,6 +411,231 @@ async def test_settle_cancels_a_pending_decision():
|
|
|
407
411
|
assert (await drv.res(seq))["type"] == "accepted"
|
|
408
412
|
|
|
409
413
|
|
|
414
|
+
# ─── other commands during a decision (#601) ──────────────
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
async def deciding(drv, prioritize, message_id="a1"):
|
|
418
|
+
"""Posts an auto send and waits until its decision is pending."""
|
|
419
|
+
gate = asyncio.get_running_loop().create_future()
|
|
420
|
+
prioritize.gates.append(gate)
|
|
421
|
+
seq = drv.post("run/send", add(message_id))
|
|
422
|
+
async with asyncio.timeout(5):
|
|
423
|
+
while not prioritize.requests:
|
|
424
|
+
await asyncio.sleep(0.01)
|
|
425
|
+
return gate, seq
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
async def test_stop_applies_while_a_decision_is_pending():
|
|
429
|
+
script = Script()
|
|
430
|
+
prioritize = Prioritizer()
|
|
431
|
+
async with run_host(script, prioritize=prioritize) as (drv, host):
|
|
432
|
+
call = await running(drv, script)
|
|
433
|
+
gate, seq = await deciding(drv, prioritize)
|
|
434
|
+
drv.post("run/stop", {"runId": await drv.run_id()})
|
|
435
|
+
await drv.wait_status("stopping", timeout=1)
|
|
436
|
+
assert call.ctx.stop_requested.is_set()
|
|
437
|
+
assert not gate.done()
|
|
438
|
+
gate.set_result("queue")
|
|
439
|
+
await drv.wait(lambda s: queue_ids(s, "queue") == ["a1"])
|
|
440
|
+
call.finish(RunManager.Stop(dispatch_queue=False))
|
|
441
|
+
assert (await drv.res(seq))["type"] == "accepted"
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
async def test_input_answer_applies_while_a_decision_is_pending():
|
|
445
|
+
script = Script()
|
|
446
|
+
prioritize = Prioritizer()
|
|
447
|
+
request = {"id": "r1", "type": "tool-call", "toolCallId": "t1"}
|
|
448
|
+
async with run_host(script, prioritize=prioritize) as (drv, host):
|
|
449
|
+
call = await running(drv, script)
|
|
450
|
+
call.finish(RunManager.InputRequired((request,)))
|
|
451
|
+
await drv.wait_status("input-required")
|
|
452
|
+
gate, seq = await deciding(drv, prioritize)
|
|
453
|
+
drv.post("run/input", {"requestId": "r1", "response": {"output": "ok"}})
|
|
454
|
+
resumed = await script.next_call() # the answer resumes the run; the decision is cancelled
|
|
455
|
+
assert resumed.ctx.trigger == "input-resume"
|
|
456
|
+
assert prioritize.cancelled == 1
|
|
457
|
+
assert (await drv.res(seq))["type"] in ("pending", "accepted")
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
async def test_dequeue_applies_while_a_decision_is_pending():
|
|
461
|
+
script = Script()
|
|
462
|
+
prioritize = Prioritizer()
|
|
463
|
+
async with run_host(script, prioritize=prioritize) as (drv, host):
|
|
464
|
+
await running(drv, script)
|
|
465
|
+
await drv.command("run/send", add("q1", behavior="queue"), terminal=False)
|
|
466
|
+
gate, _seq = await deciding(drv, prioritize)
|
|
467
|
+
drv.post("run/dequeue", {"messageId": "q1"})
|
|
468
|
+
await drv.wait(lambda s: queue_ids(s, "queue") == [], timeout=1)
|
|
469
|
+
gate.set_result("steer")
|
|
470
|
+
await drv.wait(lambda s: queue_ids(s, "steerQueue") == ["a1"])
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
async def test_edit_applies_while_a_decision_is_pending():
|
|
474
|
+
script = Script()
|
|
475
|
+
prioritize = Prioritizer()
|
|
476
|
+
capabilities = ("rewind", "rewind-during-run")
|
|
477
|
+
async with run_host(script, capabilities, prioritize=prioritize) as (drv, host):
|
|
478
|
+
drv.post("run/send", add("m1"))
|
|
479
|
+
call = await script.next_call()
|
|
480
|
+
script.thread["m1"] = {"parentId": None, "role": "user", "isLeaf": True, "onActiveBranch": True}
|
|
481
|
+
call.applied()
|
|
482
|
+
await drv.wait_status("running")
|
|
483
|
+
gate, _seq = await deciding(drv, prioritize)
|
|
484
|
+
drv.post("run/edit", edit_params("m1", msg("m2"), anchor=None))
|
|
485
|
+
await asyncio.wait_for(call.ctx.stop_requested.wait(), 1)
|
|
486
|
+
await drv.wait(lambda s: s["runs"][0]["stopping"] == {"reason": "message-edit"})
|
|
487
|
+
gate.set_result("queue")
|
|
488
|
+
call.finish(RunManager.Stop(dispatch_queue=False))
|
|
489
|
+
rerun = await script.next_call()
|
|
490
|
+
assert rerun.ctx.trigger == "message-edit"
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
async def test_a_send_waiting_behind_a_decision_does_not_hold_a_stop():
|
|
494
|
+
script = Script()
|
|
495
|
+
prioritize = Prioritizer()
|
|
496
|
+
async with run_host(script, prioritize=prioritize) as (drv, host):
|
|
497
|
+
call = await running(drv, script)
|
|
498
|
+
gate, _seq = await deciding(drv, prioritize)
|
|
499
|
+
drv.post("run/send", add("s2", behavior="steer")) # waits for the decision
|
|
500
|
+
drv.post("run/stop", {"runId": await drv.run_id()})
|
|
501
|
+
await drv.wait_status("stopping", timeout=1)
|
|
502
|
+
assert queue_ids(drv.replica, "steerQueue") == []
|
|
503
|
+
gate.set_result("queue")
|
|
504
|
+
await drv.wait(lambda s: queue_ids(s, "steerQueue") == ["s2"])
|
|
505
|
+
assert queue_ids(drv.replica, "queue") == ["a1"]
|
|
506
|
+
call.finish(RunManager.Stop(dispatch_queue=False))
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
async def test_sends_waiting_for_a_decision_leave_room_for_a_stop():
|
|
510
|
+
"""Parked sends leave Statewire's per-client in-flight capacity (#613)."""
|
|
511
|
+
store = MemoryStateStore()
|
|
512
|
+
script = Script()
|
|
513
|
+
prioritize = Prioritizer()
|
|
514
|
+
cap = MAX_INFLIGHT_COMMANDS_PER_CLIENT
|
|
515
|
+
async with run_host(
|
|
516
|
+
script, max_queued=cap, store=store, prioritize=prioritize
|
|
517
|
+
) as (drv, host):
|
|
518
|
+
call = await running(drv, script)
|
|
519
|
+
gate, _seq = await deciding(drv, prioritize)
|
|
520
|
+
drv.batch([("run/send", add(f"s{i}")) for i in range(1, cap)])
|
|
521
|
+
async with asyncio.timeout(5):
|
|
522
|
+
while len(deciding_ids(store)) < cap:
|
|
523
|
+
await host.live.frontier.wait()
|
|
524
|
+
await asyncio.sleep(0.01)
|
|
525
|
+
drv.post("run/stop", {"runId": await drv.run_id()})
|
|
526
|
+
await drv.wait_status("stopping", timeout=1)
|
|
527
|
+
assert not gate.done()
|
|
528
|
+
call.finish(RunManager.Stop(dispatch_queue=False))
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
async def test_sends_waiting_for_a_decision_are_bounded_by_max_queued():
|
|
532
|
+
store = MemoryStateStore()
|
|
533
|
+
script = Script()
|
|
534
|
+
prioritize = Prioritizer()
|
|
535
|
+
async with run_host(
|
|
536
|
+
script, max_queued=2, store=store, prioritize=prioritize
|
|
537
|
+
) as (drv, host):
|
|
538
|
+
await running(drv, script)
|
|
539
|
+
gate, _seq = await deciding(drv, prioritize)
|
|
540
|
+
drv.post("run/send", add("s2")) # waits behind the decision
|
|
541
|
+
async with asyncio.timeout(5):
|
|
542
|
+
while deciding_ids(store) != ["a1", "s2"]:
|
|
543
|
+
await host.live.frontier.wait()
|
|
544
|
+
await asyncio.sleep(0.01)
|
|
545
|
+
assert_rejected(await drv.command("run/send", add("s3")), "queue-full")
|
|
546
|
+
gate.set_result("queue")
|
|
547
|
+
await drv.wait(
|
|
548
|
+
lambda s: queue_ids(s, "queue") == ["a1"]
|
|
549
|
+
and queue_ids(s, "steerQueue") == ["s2"]
|
|
550
|
+
)
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
def deciding_ids(store):
|
|
554
|
+
"""Message ids of the durable pending-decision records."""
|
|
555
|
+
return [
|
|
556
|
+
r["messageId"]
|
|
557
|
+
for _marked, doc in store.trays.values()
|
|
558
|
+
for r in doc.get("deciding", ())
|
|
559
|
+
]
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
def pooled_sends(store, message_id):
|
|
563
|
+
"""(row, frame) for each durably pooled frame sending ``message_id``."""
|
|
564
|
+
return [
|
|
565
|
+
(row, frame)
|
|
566
|
+
for row, (_marked, doc) in store.trays.items()
|
|
567
|
+
for frame in doc.get("pool", ())
|
|
568
|
+
if any(
|
|
569
|
+
s["method"] == "run/send" and message_id in json.dumps(s["params"])
|
|
570
|
+
for s in frame["statements"]
|
|
571
|
+
)
|
|
572
|
+
]
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
async def test_a_pending_decision_survives_a_crash_as_a_steer():
|
|
576
|
+
store = MemoryStateStore()
|
|
577
|
+
script = Script()
|
|
578
|
+
prioritize = Prioritizer()
|
|
579
|
+
async with run_host(script, store=store, prioritize=prioritize) as (drv, host):
|
|
580
|
+
await running(drv, script)
|
|
581
|
+
gate, _seq = await deciding(drv, prioritize)
|
|
582
|
+
drv.post("run/send", add("q1", behavior="queue")) # waits behind the decision
|
|
583
|
+
async with asyncio.timeout(5):
|
|
584
|
+
while deciding_ids(store) != ["a1", "q1"]:
|
|
585
|
+
await host.live.frontier.wait()
|
|
586
|
+
await asyncio.sleep(0.01)
|
|
587
|
+
crashed = MemoryStateStore()
|
|
588
|
+
crashed.trays = dict(store.trays)
|
|
589
|
+
|
|
590
|
+
script2 = Script()
|
|
591
|
+
async with run_host(script2, store=crashed, prioritize=Prioritizer()) as (drv2, host2):
|
|
592
|
+
redelivered = await script2.next_call()
|
|
593
|
+
await drv2.wait(lambda s: queue_ids(s, "steerQueue") == ["a1"])
|
|
594
|
+
assert queue_ids(drv2.replica, "queue") == ["q1"]
|
|
595
|
+
assert [m["id"] for m in redelivered.ctx.steering.take()] == ["a1"]
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
async def test_a_frame_redelivered_with_its_decision_record_stages_once():
|
|
599
|
+
"""A crash between the record's flush and the frame's pop keeps both: the
|
|
600
|
+
record stages the send, and the redelivered frame stages nothing."""
|
|
601
|
+
store = MemoryStateStore()
|
|
602
|
+
script = Script()
|
|
603
|
+
prioritize = Prioritizer()
|
|
604
|
+
async with run_host(script, store=store, prioritize=prioritize) as (drv, host):
|
|
605
|
+
await running(drv, script)
|
|
606
|
+
gate = asyncio.get_running_loop().create_future()
|
|
607
|
+
prioritize.gates.append(gate)
|
|
608
|
+
drv.post("run/send", add("a1"))
|
|
609
|
+
pooled = None
|
|
610
|
+
async with asyncio.timeout(5):
|
|
611
|
+
while not prioritize.requests:
|
|
612
|
+
pooled = pooled or next(iter(pooled_sends(store, "a1")), None)
|
|
613
|
+
await asyncio.sleep(0)
|
|
614
|
+
assert pooled is not None, "the a1 frame was never seen pooled"
|
|
615
|
+
async with asyncio.timeout(5):
|
|
616
|
+
while deciding_ids(store) != ["a1"]:
|
|
617
|
+
await host.live.frontier.wait()
|
|
618
|
+
await asyncio.sleep(0.01)
|
|
619
|
+
crashed = MemoryStateStore()
|
|
620
|
+
crashed.trays = dict(store.trays)
|
|
621
|
+
row, frame = pooled
|
|
622
|
+
marked, doc = crashed.trays[row]
|
|
623
|
+
crashed.trays[row] = (marked, {**doc, "pool": [*doc.get("pool", ()), frame]})
|
|
624
|
+
|
|
625
|
+
script2 = Script()
|
|
626
|
+
again = Prioritizer("preempt")
|
|
627
|
+
async with run_host(script2, store=crashed, prioritize=again) as (drv2, host2):
|
|
628
|
+
redelivered = await script2.next_call()
|
|
629
|
+
await drv2.wait(lambda s: queue_ids(s, "steerQueue") == ["a1"])
|
|
630
|
+
async with asyncio.timeout(5):
|
|
631
|
+
while pooled_sends(crashed, "a1"):
|
|
632
|
+
await asyncio.sleep(0.01)
|
|
633
|
+
await asyncio.sleep(0.05)
|
|
634
|
+
assert again.requests == []
|
|
635
|
+
assert not redelivered.ctx.stop_requested.is_set()
|
|
636
|
+
assert queue_ids(drv2.replica, "steerQueue") == ["a1"]
|
|
637
|
+
|
|
638
|
+
|
|
410
639
|
# ─── pre-2026-11-04 clients ───────────────────────────────
|
|
411
640
|
|
|
412
641
|
|
|
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.1 → harness_sdk_python-0.40.2}/src/harness_sdk/providers/__init__.py
RENAMED
|
File without changes
|
{harness_sdk_python-0.40.1 → harness_sdk_python-0.40.2}/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
|
|
File without changes
|