harness-sdk-python 0.40.12__tar.gz → 0.40.13__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.12 → harness_sdk_python-0.40.13}/PKG-INFO +2 -2
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/pyproject.toml +2 -2
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/deepagents.py +7 -2
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/interest.py +11 -5
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/messages.py +27 -2
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/run_manager.py +26 -12
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/threads.py +3 -7
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_deepagents_thread.py +15 -2
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_interest.py +75 -2
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_prioritize.py +54 -13
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/.gitignore +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/README.md +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/examples/__init__.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/examples/local_origin.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/examples/runs_app.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/__init__.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/checkpoints.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/deepagents_host.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/fenced_postgres.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/langgraph.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/linear_thread.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/parts.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/prioritize.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/protocol.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/providers/__init__.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/providers/gpt_live.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/voice.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/voice_thread.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/wire.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/run_helpers.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_admit_steer.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_applied_visibility.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_batches.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_branch_anchor.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_checkpoints.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_deepagents_approval.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_deepagents_files.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_deepagents_multi_approval.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_deepagents_outcome.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_deepagents_subagent_approval.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_deepagents_user_ids.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_deepagents_voice.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_dispatching.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_durability.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_edit_dispatched.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_edit_reload.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_enqueue.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_example_local_origin.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_fenced_postgres.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_gpt_live.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_imports.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_input_required.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_langgraph.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_linear_thread.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_meta.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_mint_concurrency.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_outcomes.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_parts.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_placement.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_prepare_hooks.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_prioritize_builtins.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_request_options.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_restore.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_rewind_during_run.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_run_admission.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_run_crash_sweep.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_run_eviction.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_run_id_bounds.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_run_ownership.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_run_sync.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_settle.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_stale_redelivery.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_steer.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_stop_continue.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_stopping_window.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_threads.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_undo.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_voice.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_voice_delegation.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_voice_events.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_wire.py +0 -0
- {harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/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.13
|
|
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: pinboard-sdk>=0.18.4
|
|
9
|
-
Requires-Dist: statewire<0.
|
|
9
|
+
Requires-Dist: statewire<0.27,>=0.26.0
|
|
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.13"
|
|
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.
|
|
8
|
+
dependencies = ["statewire>=0.26.0,<0.27", "pinboard-sdk>=0.18.4"]
|
|
9
9
|
|
|
10
10
|
[project.optional-dependencies]
|
|
11
11
|
postgres = ["langgraph-checkpoint-postgres>=2.0.0"]
|
|
@@ -19,7 +19,7 @@ from .checkpoints import (
|
|
|
19
19
|
langgraph_checkpoints,
|
|
20
20
|
langgraph_snapshot,
|
|
21
21
|
)
|
|
22
|
-
from .messages import MAIN_NS, MessageTree
|
|
22
|
+
from .messages import MAIN_NS, MessageTree, iso
|
|
23
23
|
from .parts import PartsAssembler, text_of
|
|
24
24
|
from .voice_thread import upsert_voice_turn
|
|
25
25
|
|
|
@@ -85,6 +85,11 @@ def _checkpoint_ns(ns: str) -> str:
|
|
|
85
85
|
return "" if ns == MAIN_NS else ns
|
|
86
86
|
|
|
87
87
|
|
|
88
|
+
def _row_value(message: dict[str, Any]) -> dict[str, Any]:
|
|
89
|
+
value = plain(message)
|
|
90
|
+
return {**value, "createdAt": iso(value["createdAt"])}
|
|
91
|
+
|
|
92
|
+
|
|
88
93
|
def _root_of(ns: str) -> str:
|
|
89
94
|
return ns.split("|", 1)[0]
|
|
90
95
|
|
|
@@ -509,7 +514,7 @@ class DeepagentsThread:
|
|
|
509
514
|
"message_id": message_id,
|
|
510
515
|
"parent_id": self.tree.get(ns, message_id)["parentId"],
|
|
511
516
|
"seq": self.tree.get(ns, message_id)["seq"],
|
|
512
|
-
"value":
|
|
517
|
+
"value": _row_value(self.tree.get(ns, message_id)),
|
|
513
518
|
}
|
|
514
519
|
for ns, message_id in sorted(touched, key=lambda t: self.tree.get(*t)["seq"])
|
|
515
520
|
]
|
|
@@ -89,11 +89,17 @@ def _window(thread: Thread, anchor: str | None, before: int, after: int) -> dict
|
|
|
89
89
|
|
|
90
90
|
def spawned_ns(message: Any) -> list[str]:
|
|
91
91
|
"""Subagent namespaces named by a message's tool parts."""
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if part.get("type")
|
|
96
|
-
|
|
92
|
+
out: list[str] = []
|
|
93
|
+
for part in plain(message)["parts"]:
|
|
94
|
+
metadata = part.get("metadata")
|
|
95
|
+
if part.get("type") != "tool" or not isinstance(metadata, dict):
|
|
96
|
+
continue
|
|
97
|
+
namespaces = metadata.get("namespaces")
|
|
98
|
+
for ns in [metadata.get("ns"), *(namespaces if isinstance(namespaces, list) else [])]:
|
|
99
|
+
# statewire refuses `__proto__` as a document key, so it names nothing to follow
|
|
100
|
+
if isinstance(ns, str) and ns and ns != "__proto__":
|
|
101
|
+
out.append(ns)
|
|
102
|
+
return out
|
|
97
103
|
|
|
98
104
|
|
|
99
105
|
def resolve(tree: MessageTree, request: dict[str, Any]) -> dict[str, Any]:
|
|
@@ -4,6 +4,7 @@ streaming writes flush as ops.
|
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
6
|
from dataclasses import dataclass, field
|
|
7
|
+
from datetime import datetime, timezone
|
|
7
8
|
from typing import Any, Iterator
|
|
8
9
|
|
|
9
10
|
MAIN_NS = "main"
|
|
@@ -11,6 +12,23 @@ MAIN_NS = "main"
|
|
|
11
12
|
_ROLES = ("user", "assistant")
|
|
12
13
|
|
|
13
14
|
|
|
15
|
+
def iso(at: datetime) -> str:
|
|
16
|
+
return at.astimezone(timezone.utc).isoformat(timespec="milliseconds").replace("+00:00", "Z")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def iso_now() -> str:
|
|
20
|
+
return iso(datetime.now(timezone.utc))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _check_created_at(value: Any) -> None:
|
|
24
|
+
try:
|
|
25
|
+
canonical = datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%fZ").isoformat(timespec="milliseconds") + "Z" == value
|
|
26
|
+
except (TypeError, ValueError):
|
|
27
|
+
canonical = False
|
|
28
|
+
if not canonical:
|
|
29
|
+
raise ValueError(f"createdAt must be ISO-8601 UTC with milliseconds (2026-10-14T09:00:00.000Z): {value!r}")
|
|
30
|
+
|
|
31
|
+
|
|
14
32
|
def _check_message(message: dict[str, Any]) -> None:
|
|
15
33
|
if not isinstance(message, dict):
|
|
16
34
|
raise TypeError(f"message must be an object, got {message!r}")
|
|
@@ -89,7 +107,7 @@ class MessageTree:
|
|
|
89
107
|
}
|
|
90
108
|
|
|
91
109
|
def add(self, ns: str, message: dict[str, Any], *, head: bool = True) -> dict[str, Any]:
|
|
92
|
-
"""Add a message; ``seq``
|
|
110
|
+
"""Add a message; ``seq`` and ``createdAt`` are assigned unless present; the head moves to it by default."""
|
|
93
111
|
_check_message(message)
|
|
94
112
|
thread = self.thread(ns)
|
|
95
113
|
if message["id"] in thread.messages:
|
|
@@ -102,8 +120,15 @@ class MessageTree:
|
|
|
102
120
|
seq = thread.next_seq
|
|
103
121
|
elif not isinstance(seq, int) or isinstance(seq, bool) or seq < 1:
|
|
104
122
|
raise ValueError(f"seq must be a positive integer: {seq!r}")
|
|
123
|
+
created_at = message["createdAt"] if "createdAt" in message else datetime.now(timezone.utc)
|
|
124
|
+
if isinstance(created_at, str):
|
|
125
|
+
_check_created_at(created_at)
|
|
126
|
+
created_at = datetime.strptime(created_at, "%Y-%m-%dT%H:%M:%S.%fZ").replace(tzinfo=timezone.utc)
|
|
127
|
+
elif not isinstance(created_at, datetime) or created_at.tzinfo is None:
|
|
128
|
+
raise ValueError(f"createdAt must be an aware datetime or ISO-8601 string: {created_at!r}")
|
|
129
|
+
created_at = created_at.replace(microsecond=created_at.microsecond // 1000 * 1000)
|
|
105
130
|
thread.next_seq = max(thread.next_seq, seq + 1)
|
|
106
|
-
stored = {**message, "seq": seq}
|
|
131
|
+
stored = {**message, "seq": seq, "createdAt": created_at}
|
|
107
132
|
thread.messages[stored["id"]] = stored
|
|
108
133
|
thread.children.setdefault(parent, []).append(stored["id"])
|
|
109
134
|
thread.children[parent].sort(key=lambda i: thread.messages[i]["seq"])
|
|
@@ -604,8 +604,14 @@ class RunManager(Tray):
|
|
|
604
604
|
r if "durable" in r else {**r, "durable": False}
|
|
605
605
|
for r in self.deciding.value
|
|
606
606
|
]
|
|
607
|
+
# the queue lane as earlier replayed records leave it; they apply later
|
|
608
|
+
queued = {i["id"] for i in self._lane_items("queue")}
|
|
607
609
|
for record in self.deciding.value:
|
|
608
|
-
entry = self._undecided(record)
|
|
610
|
+
entry = self._undecided(record, queued)
|
|
611
|
+
if entry.lane == "queue":
|
|
612
|
+
queued.add(entry.message_id)
|
|
613
|
+
else:
|
|
614
|
+
queued.discard(entry.message_id)
|
|
609
615
|
entry.future.add_done_callback(lambda f: f.cancelled() or f.exception())
|
|
610
616
|
self._admit(entry)
|
|
611
617
|
if any(v["response"] is None for v in self.verdicts.value):
|
|
@@ -741,9 +747,9 @@ class RunManager(Tray):
|
|
|
741
747
|
# record for its verdict, and the verdict answers the parked seq after
|
|
742
748
|
# the effects' flush; the tray outlives undelivered verdicts. After a
|
|
743
749
|
# restart a record stages as if no prioritizer answered: "auto" steers
|
|
744
|
-
# while a run is live and
|
|
745
|
-
# answer again. Records are keyed by the command's
|
|
746
|
-
# lane, seq): a frame redelivered after a crash cut answers with its
|
|
750
|
+
# while a run is live and nothing is queued ahead, and queues otherwise;
|
|
751
|
+
# undelivered verdicts answer again. Records are keyed by the command's
|
|
752
|
+
# admission (client, lane, seq): a frame redelivered after a crash cut answers with its
|
|
747
753
|
# record's verdict and stages nothing.
|
|
748
754
|
|
|
749
755
|
def _hold_decision(self, record: dict[str, Any], key: str | None) -> str:
|
|
@@ -809,15 +815,20 @@ class RunManager(Tray):
|
|
|
809
815
|
stored = await asyncio.shield(waiter)
|
|
810
816
|
return stored
|
|
811
817
|
|
|
812
|
-
def _undecided(self, record: dict[str, Any]) -> _Send:
|
|
818
|
+
def _undecided(self, record: dict[str, Any], queued: set[str]) -> _Send:
|
|
813
819
|
behavior = record["behavior"]
|
|
820
|
+
message = record["message"]
|
|
821
|
+
behind = (
|
|
822
|
+
self.prioritize is not None
|
|
823
|
+
and message is not None
|
|
824
|
+
and bool(queued - {message["id"]})
|
|
825
|
+
)
|
|
814
826
|
mode = (
|
|
815
827
|
behavior
|
|
816
828
|
if behavior != "auto"
|
|
817
|
-
else "steer" if self._status() in _LIVE else "queue"
|
|
829
|
+
else "steer" if self._status() in _LIVE and not behind else "queue"
|
|
818
830
|
)
|
|
819
831
|
key = record["key"]
|
|
820
|
-
message = record["message"]
|
|
821
832
|
params = record["params"]
|
|
822
833
|
if message is not None:
|
|
823
834
|
params = {**params, "message": message}
|
|
@@ -2555,11 +2566,14 @@ class RunManagerNamespace(TrayMapNamespace):
|
|
|
2555
2566
|
await asyncio.wait((prior,))
|
|
2556
2567
|
tray = self.live() or tray
|
|
2557
2568
|
subject = self._subject(tray, behavior, message, message_id, auth_result)
|
|
2558
|
-
|
|
2559
|
-
self._mode(tray, behavior)
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
)
|
|
2569
|
+
if subject is None:
|
|
2570
|
+
mode = self._mode(tray, behavior)
|
|
2571
|
+
elif message is not None and any(
|
|
2572
|
+
i["id"] != message_id for i in tray._lane_items("queue")
|
|
2573
|
+
):
|
|
2574
|
+
mode = "queue"
|
|
2575
|
+
else:
|
|
2576
|
+
mode = await self._prioritized(cls, tray, subject)
|
|
2563
2577
|
entry = staged(mode)
|
|
2564
2578
|
entry.decided = decided
|
|
2565
2579
|
return await tray._stage(entry, release)
|
|
@@ -7,7 +7,6 @@ instance is the store's only writer.
|
|
|
7
7
|
.. versionadded:: alpha
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
|
-
from datetime import datetime, timezone
|
|
11
10
|
from typing import Any, Literal, NotRequired, Protocol, TypedDict, get_args
|
|
12
11
|
|
|
13
12
|
from fastapi import HTTPException, Request
|
|
@@ -15,6 +14,7 @@ from pinboard import Attestation, AuthRejected, attestation, route
|
|
|
15
14
|
from starlette.requests import HTTPConnection
|
|
16
15
|
from statewire import Statewire, StatewireReject, command
|
|
17
16
|
|
|
17
|
+
from .messages import iso_now
|
|
18
18
|
from .protocol import HARNESS_THREADS_PROTOCOL
|
|
19
19
|
|
|
20
20
|
ThreadStatus = Literal["regular", "archived"]
|
|
@@ -61,10 +61,6 @@ class ThreadStore(Protocol):
|
|
|
61
61
|
...
|
|
62
62
|
|
|
63
63
|
|
|
64
|
-
def _now() -> str:
|
|
65
|
-
return datetime.now(timezone.utc).isoformat(timespec="milliseconds").replace("+00:00", "Z")
|
|
66
|
-
|
|
67
|
-
|
|
68
64
|
class MemoryThreadStore:
|
|
69
65
|
"""In-process ``ThreadStore``.
|
|
70
66
|
|
|
@@ -86,7 +82,7 @@ class MemoryThreadStore:
|
|
|
86
82
|
async def create(self, thread_id: str) -> None:
|
|
87
83
|
if thread_id in self._threads:
|
|
88
84
|
raise DuplicateThread(thread_id)
|
|
89
|
-
self._threads[thread_id] = {"id": thread_id, "status": "regular", "updatedAt":
|
|
85
|
+
self._threads[thread_id] = {"id": thread_id, "status": "regular", "updatedAt": iso_now()}
|
|
90
86
|
|
|
91
87
|
async def rename(self, thread_id: str, title: str) -> None:
|
|
92
88
|
self._get(thread_id)["title"] = title
|
|
@@ -102,7 +98,7 @@ class MemoryThreadStore:
|
|
|
102
98
|
self, thread_id: str, *, title: str | None = None, activity: ThreadActivity | Literal["idle"] | None = None
|
|
103
99
|
) -> None:
|
|
104
100
|
record = self._threads.setdefault(thread_id, {"id": thread_id, "status": "regular", "updatedAt": ""})
|
|
105
|
-
record["updatedAt"] =
|
|
101
|
+
record["updatedAt"] = iso_now()
|
|
106
102
|
if title is not None and "title" not in record:
|
|
107
103
|
record["title"] = title
|
|
108
104
|
if activity == "idle":
|
|
@@ -2,6 +2,7 @@ import asyncio
|
|
|
2
2
|
import copy
|
|
3
3
|
import uuid
|
|
4
4
|
from dataclasses import dataclass, field
|
|
5
|
+
from datetime import datetime, timezone
|
|
5
6
|
from typing import Any
|
|
6
7
|
|
|
7
8
|
import pytest
|
|
@@ -22,7 +23,7 @@ from voice_helpers import NEGOTIATION, VoiceDriver
|
|
|
22
23
|
from harness_sdk import DeepagentsHost, MemoryCheckpointIndex
|
|
23
24
|
from harness_sdk.deepagents import DeepagentsThread
|
|
24
25
|
from harness_sdk.interest import check_request, resolve
|
|
25
|
-
from harness_sdk.messages import MAIN_NS, MessageTree
|
|
26
|
+
from harness_sdk.messages import MAIN_NS, MessageTree, iso
|
|
26
27
|
|
|
27
28
|
pytestmark = pytest.mark.anyio
|
|
28
29
|
|
|
@@ -123,15 +124,27 @@ async def test_send_streams_parts_and_persists_rows():
|
|
|
123
124
|
assert [r["message_id"] for r in rows] == ids and rows[1]["parent_id"] == ids[0]
|
|
124
125
|
|
|
125
126
|
|
|
126
|
-
|
|
127
|
+
class _Frozen(datetime):
|
|
128
|
+
@classmethod
|
|
129
|
+
def now(cls, tz=None):
|
|
130
|
+
return datetime(2000, 1, 1, tzinfo=timezone.utc)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
async def test_reboot_hydrates_tree_from_rows(monkeypatch):
|
|
127
134
|
saver, index = InMemorySaver(), MemoryCheckpointIndex()
|
|
128
135
|
agent, thread = await build(saver, index)
|
|
129
136
|
await run_turn(agent, thread, Ctx(messages=(user("one two"),)))
|
|
130
137
|
head = thread.tree.thread(MAIN_NS).head
|
|
138
|
+
created = {i: thread.tree.get(MAIN_NS, i)["createdAt"] for i in chain(thread)}
|
|
139
|
+
assert all(isinstance(at, datetime) and at.tzinfo is not None for at in created.values())
|
|
140
|
+
rows = await index.read_messages("t1")
|
|
141
|
+
assert {r["message_id"]: r["value"]["createdAt"] for r in rows} == {i: iso(at) for i, at in created.items()}
|
|
142
|
+
monkeypatch.setattr("harness_sdk.messages.datetime", _Frozen)
|
|
131
143
|
_agent, rebooted = await build(saver, index)
|
|
132
144
|
assert chain(rebooted) == chain(thread)
|
|
133
145
|
assert rebooted.tree.thread(MAIN_NS).head == head
|
|
134
146
|
assert rebooted.tree.get(MAIN_NS, head)["parts"][1]["text"] == "answer: 2"
|
|
147
|
+
assert {i: rebooted.tree.get(MAIN_NS, i)["createdAt"] for i in chain(rebooted)} == created
|
|
135
148
|
|
|
136
149
|
|
|
137
150
|
async def test_edit_forks_a_sibling_and_reload_regenerates():
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
from datetime import datetime, timezone
|
|
2
|
+
|
|
1
3
|
import pytest
|
|
2
4
|
|
|
3
|
-
from harness_sdk.interest import InterestError, check_request, covered, resolve
|
|
4
|
-
from harness_sdk.messages import MessageTree
|
|
5
|
+
from harness_sdk.interest import InterestError, check_request, covered, resolve, spawned_ns
|
|
6
|
+
from harness_sdk.messages import MessageTree, iso
|
|
5
7
|
|
|
6
8
|
|
|
7
9
|
def _tree():
|
|
@@ -66,6 +68,57 @@ def test_follow_expands_spawned_namespaces():
|
|
|
66
68
|
assert covered(request, r) == {("main", "a3"), ("sub-1", "s2")}
|
|
67
69
|
|
|
68
70
|
|
|
71
|
+
|
|
72
|
+
def _tool(metadata):
|
|
73
|
+
return {"type": "tool", "toolInvocationId": "t", "toolName": "task", "input": {}, "state": "done", "metadata": metadata}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def test_spawned_ns_reads_ns_then_namespaces_in_order():
|
|
77
|
+
message = {"parts": [_tool({"ns": "b", "namespaces": ["a", "c"]}), _tool({"namespaces": ["d"]})]}
|
|
78
|
+
assert spawned_ns(message) == ["b", "a", "c", "d"]
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_spawned_ns_keeps_duplicates_for_resolve_to_collapse():
|
|
82
|
+
assert spawned_ns({"parts": [_tool({"ns": "b", "namespaces": ["b", "a", "a"]})]}) == ["b", "b", "a", "a"]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@pytest.mark.parametrize(
|
|
86
|
+
"metadata",
|
|
87
|
+
[
|
|
88
|
+
{"namespaces": "a"},
|
|
89
|
+
{"namespaces": {"a": True}},
|
|
90
|
+
{"namespaces": None},
|
|
91
|
+
{"namespaces": ["", 7, None, ["a"], {"ns": "a"}]},
|
|
92
|
+
{"ns": 7},
|
|
93
|
+
{"ns": ""},
|
|
94
|
+
],
|
|
95
|
+
)
|
|
96
|
+
def test_spawned_ns_ignores_non_string_empty_and_non_list_values(metadata):
|
|
97
|
+
assert spawned_ns({"parts": [_tool(metadata)]}) == []
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_spawned_ns_skips_the_reserved_proto_namespace():
|
|
101
|
+
message = {"parts": [_tool({"ns": "__proto__", "namespaces": ["__proto__", "a"]})]}
|
|
102
|
+
assert spawned_ns(message) == ["a"]
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def test_spawned_ns_ignores_namespaces_outside_tool_parts():
|
|
106
|
+
message = {"parts": [{"type": "text", "text": "hi", "state": "done", "metadata": {"namespaces": ["a"]}}]}
|
|
107
|
+
assert spawned_ns(message) == []
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def test_follow_expands_every_namespace_in_metadata_namespaces_after_metadata_ns():
|
|
111
|
+
tree = _tree()
|
|
112
|
+
tree.get("main", "a3")["parts"].append(_tool({"ns": "b", "namespaces": ["a", "", 7, "b"]}))
|
|
113
|
+
for ns in ("a", "b"):
|
|
114
|
+
tree.add(ns, {"id": f"{ns}1", "parentId": None, "role": "assistant", "parts": []})
|
|
115
|
+
request = check_request({"ns": "main", "before": 1, "follow": {"before": 1}})
|
|
116
|
+
r = resolve(tree, request)
|
|
117
|
+
assert list(r["follows"]) == ["b", "a"]
|
|
118
|
+
assert r["follows"]["a"] == {"chain": [{"id": "a1", "siblings": ["a1"]}], "more": {"before": False, "after": False}}
|
|
119
|
+
assert covered(request, r) == {("main", "a3"), ("b", "b1"), ("a", "a1")}
|
|
120
|
+
|
|
121
|
+
|
|
69
122
|
@pytest.mark.parametrize(
|
|
70
123
|
"req, code",
|
|
71
124
|
[
|
|
@@ -100,3 +153,23 @@ def test_tree_rejects_unknown_parent_and_duplicates():
|
|
|
100
153
|
with pytest.raises(ValueError):
|
|
101
154
|
tree.add("main", {"id": "x", "parentId": None, "role": "user", "parts": []})
|
|
102
155
|
assert tree.get("main", "x")["seq"] == 1
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def test_tree_stamps_created_at_unless_present():
|
|
159
|
+
tree = MessageTree()
|
|
160
|
+
stamped = tree.add("main", {"id": "x", "parentId": None, "role": "user", "parts": []})
|
|
161
|
+
assert isinstance(stamped["createdAt"], datetime) and stamped["createdAt"].tzinfo is not None
|
|
162
|
+
assert stamped["createdAt"].microsecond % 1000 == 0
|
|
163
|
+
kept = tree.add("main", {"id": "y", "parentId": "x", "role": "assistant", "parts": [], "createdAt": datetime(2026, 10, 13, 8, 0, 0, 123456, tzinfo=timezone.utc)})
|
|
164
|
+
assert kept["createdAt"] == datetime(2026, 10, 13, 8, 0, 0, 123000, tzinfo=timezone.utc)
|
|
165
|
+
for bad in (1, None, datetime(2026, 10, 13, 8), "yesterday", "2026-10-13", "2026-10-13T08:00:00Z", "2026-10-13T08:00:00.000+00:00", "2026-02-30T08:00:00.000Z"):
|
|
166
|
+
with pytest.raises(ValueError):
|
|
167
|
+
tree.add("main", {"id": "z", "parentId": None, "role": "user", "parts": [], "createdAt": bad})
|
|
168
|
+
assert tree.get("main", "z") is None
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def test_tree_loads_a_stored_iso_created_at_as_a_datetime():
|
|
172
|
+
tree = MessageTree()
|
|
173
|
+
legacy = tree.add("main", {"id": "x", "parentId": None, "role": "user", "parts": [], "createdAt": "2026-10-13T08:00:00.000Z"})
|
|
174
|
+
assert legacy["createdAt"] == datetime(2026, 10, 13, 8, tzinfo=timezone.utc)
|
|
175
|
+
assert iso(legacy["createdAt"]) == "2026-10-13T08:00:00.000Z"
|
|
@@ -111,7 +111,6 @@ async def test_auto_follows_the_prioritizer(mode, lane):
|
|
|
111
111
|
prioritize = Prioritizer(mode)
|
|
112
112
|
async with run_host(script, prioritize=prioritize) as (drv, host):
|
|
113
113
|
call = await running(drv, script)
|
|
114
|
-
await drv.command("run/send", add("q1", behavior="queue"), terminal=False)
|
|
115
114
|
await drv.command("run/send", add("s1", behavior="steer"), terminal=False)
|
|
116
115
|
await drv.command(
|
|
117
116
|
"run/send", add("a1", meta={"secret": 1}), terminal=False
|
|
@@ -126,7 +125,25 @@ async def test_auto_follows_the_prioritizer(mode, lane):
|
|
|
126
125
|
messages=(msg("m1"),),
|
|
127
126
|
steer_queue=(msg("s1"),),
|
|
128
127
|
)
|
|
129
|
-
assert req.queue == (
|
|
128
|
+
assert req.queue == ()
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
async def test_auto_with_steers_and_a_queued_message_asks_again_once_the_queue_empties():
|
|
132
|
+
script = Script()
|
|
133
|
+
prioritize = Prioritizer("steer")
|
|
134
|
+
async with run_host(script, prioritize=prioritize) as (drv, host):
|
|
135
|
+
await running(drv, script)
|
|
136
|
+
await drv.command("run/send", add("s1", behavior="steer"), terminal=False)
|
|
137
|
+
await drv.command("run/send", add("q2", behavior="queue"), terminal=False)
|
|
138
|
+
await drv.command("run/send", add("a3"), terminal=False)
|
|
139
|
+
assert prioritize.requests == []
|
|
140
|
+
assert queue_ids(drv.replica, "queue") == ["q2", "a3"]
|
|
141
|
+
assert queue_ids(drv.replica, "steerQueue") == ["s1"]
|
|
142
|
+
for message_id in ("q2", "a3"):
|
|
143
|
+
await drv.command("run/dequeue", {"messageId": message_id}, terminal=False)
|
|
144
|
+
await drv.command("run/send", add("a4"), terminal=False)
|
|
145
|
+
assert [r.message["id"] for r in prioritize.requests] == ["a4"]
|
|
146
|
+
assert queue_ids(drv.replica, "steerQueue") == ["s1", "a4"]
|
|
130
147
|
|
|
131
148
|
|
|
132
149
|
async def test_request_lists_taken_steers_as_run_messages():
|
|
@@ -337,10 +354,11 @@ async def test_auto_move_consults_the_prioritizer_on_the_queued_item():
|
|
|
337
354
|
async with run_host(script, prioritize=prioritize) as (drv, host):
|
|
338
355
|
call = await running(drv, script)
|
|
339
356
|
await drv.command("run/send", add("q1", behavior="queue"), terminal=False)
|
|
357
|
+
await drv.command("run/send", add("q2", behavior="queue"), terminal=False)
|
|
340
358
|
await drv.command("run/send", target(drv.run["runId"], messageId="q1"), terminal=False)
|
|
341
359
|
(req,) = prioritize.requests
|
|
342
360
|
assert req.message == msg("q1")
|
|
343
|
-
assert req.queue == ()
|
|
361
|
+
assert req.queue == (msg("q2"),)
|
|
344
362
|
assert queue_ids(drv.replica, "steerQueue") == ["q1"]
|
|
345
363
|
assert call.ctx.stop_requested.is_set()
|
|
346
364
|
|
|
@@ -392,10 +410,9 @@ async def test_decisions_stage_in_arrival_order():
|
|
|
392
410
|
gate.set_result("queue")
|
|
393
411
|
for seq in (first, second, third):
|
|
394
412
|
assert (await drv.res(seq, terminal=False))["type"] in ("pending", "accepted")
|
|
395
|
-
await drv.wait(lambda s: queue_ids(s, "steerQueue") == ["
|
|
396
|
-
assert queue_ids(drv.replica, "queue") == ["a1"]
|
|
397
|
-
assert [r.message["id"] for r in prioritize.requests] == ["a1"
|
|
398
|
-
assert prioritize.requests[1].queue == (msg("a1"),)
|
|
413
|
+
await drv.wait(lambda s: queue_ids(s, "steerQueue") == ["s3"])
|
|
414
|
+
assert queue_ids(drv.replica, "queue") == ["a1", "a2"]
|
|
415
|
+
assert [r.message["id"] for r in prioritize.requests] == ["a1"]
|
|
399
416
|
|
|
400
417
|
|
|
401
418
|
async def test_settle_cancels_a_pending_decision():
|
|
@@ -468,10 +485,10 @@ async def test_dequeue_applies_while_a_decision_is_pending():
|
|
|
468
485
|
prioritize = Prioritizer()
|
|
469
486
|
async with run_host(script, prioritize=prioritize) as (drv, host):
|
|
470
487
|
await running(drv, script)
|
|
471
|
-
await drv.command("run/send", add("q1", behavior="
|
|
488
|
+
await drv.command("run/send", add("q1", behavior="steer"), terminal=False)
|
|
472
489
|
gate, _seq = await deciding(drv, prioritize)
|
|
473
490
|
drv.post("run/dequeue", {"messageId": "q1"})
|
|
474
|
-
await drv.wait(lambda s: queue_ids(s, "
|
|
491
|
+
await drv.wait(lambda s: queue_ids(s, "steerQueue") == [], timeout=1)
|
|
475
492
|
gate.set_result("steer")
|
|
476
493
|
await drv.wait(lambda s: queue_ids(s, "steerQueue") == ["a1"])
|
|
477
494
|
|
|
@@ -551,10 +568,8 @@ async def test_sends_waiting_for_a_decision_are_bounded_by_max_queued():
|
|
|
551
568
|
await asyncio.sleep(0.01)
|
|
552
569
|
assert_rejected(await drv.command("run/send", add("s3")), "queue-full")
|
|
553
570
|
gate.set_result("queue")
|
|
554
|
-
await drv.wait(
|
|
555
|
-
|
|
556
|
-
and queue_ids(s, "steerQueue") == ["s2"]
|
|
557
|
-
)
|
|
571
|
+
await drv.wait(lambda s: queue_ids(s, "queue") == ["a1", "s2"])
|
|
572
|
+
assert [r.message["id"] for r in prioritize.requests] == ["a1"]
|
|
558
573
|
|
|
559
574
|
|
|
560
575
|
def deciding_ids(store):
|
|
@@ -602,6 +617,32 @@ async def test_a_pending_decision_survives_a_crash_as_a_steer():
|
|
|
602
617
|
assert [m["id"] for m in redelivered.ctx.steering.take()] == ["a1"]
|
|
603
618
|
|
|
604
619
|
|
|
620
|
+
async def test_after_a_crash_auto_sends_follow_the_replayed_queue():
|
|
621
|
+
store = MemoryStateStore()
|
|
622
|
+
script = Script()
|
|
623
|
+
prioritize = Prioritizer()
|
|
624
|
+
async with run_host(script, store=store, prioritize=prioritize) as (drv, host):
|
|
625
|
+
await running(drv, script)
|
|
626
|
+
await deciding(drv, prioritize)
|
|
627
|
+
drv.post("run/send", add("q2", behavior="queue"))
|
|
628
|
+
drv.post("run/send", target(drv.run["runId"], messageId="q2"))
|
|
629
|
+
drv.post("run/send", add("a3"))
|
|
630
|
+
drv.post("run/send", add("q4", behavior="queue"))
|
|
631
|
+
drv.post("run/send", add("a5"))
|
|
632
|
+
async with asyncio.timeout(5):
|
|
633
|
+
while deciding_ids(store) != ["a1", "q2", "q2", "a3", "q4", "a5"]:
|
|
634
|
+
await host.live.frontier.wait()
|
|
635
|
+
await asyncio.sleep(0.01)
|
|
636
|
+
crashed = MemoryStateStore()
|
|
637
|
+
crashed.trays = dict(store.trays)
|
|
638
|
+
|
|
639
|
+
script2 = Script()
|
|
640
|
+
async with run_host(script2, store=crashed, prioritize=Prioritizer()) as (drv2, host2):
|
|
641
|
+
await script2.next_call()
|
|
642
|
+
await drv2.wait(lambda s: queue_ids(s, "queue") == ["q4", "a5"])
|
|
643
|
+
assert queue_ids(drv2.replica, "steerQueue") == ["a1", "q2", "a3"]
|
|
644
|
+
|
|
645
|
+
|
|
605
646
|
async def test_a_frame_redelivered_with_its_decision_record_stages_once():
|
|
606
647
|
"""A crash between the record's flush and the frame's pop keeps both: the
|
|
607
648
|
record stages the send, and the redelivered frame answers its verdict."""
|
|
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.12 → harness_sdk_python-0.40.13}/src/harness_sdk/deepagents_host.py
RENAMED
|
File without changes
|
{harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/fenced_postgres.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/src/harness_sdk/providers/__init__.py
RENAMED
|
File without changes
|
{harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/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
|
{harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_deepagents_multi_approval.py
RENAMED
|
File without changes
|
|
File without changes
|
{harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_deepagents_subagent_approval.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
|
{harness_sdk_python-0.40.12 → harness_sdk_python-0.40.13}/tests/test_example_local_origin.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
|