holon-sh 0.0.1.dev12__tar.gz → 0.0.1.dev13__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.
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/PKG-INFO +1 -1
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/holon/ext/events/_server.py +26 -31
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/pyproject.toml +1 -1
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/tests/test_events.py +11 -7
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/.gitignore +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/LICENSE +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/README.md +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/holon/client.py +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/holon/context.py +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/holon/ext/__init__.py +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/holon/ext/events/__init__.py +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/holon/ext/events/_client.py +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/holon/ext/events/_wire.py +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/holon/ext/files/__init__.py +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/holon/ext/files/_client.py +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/holon/ext/files/_server.py +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/holon/ext/files/_wire.py +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/holon/py.typed +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/scripts/verify_distribution.py +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/tests/fixtures/caller/holon/apps/__init__.py +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/tests/test_context.py +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/tests/test_elicit.py +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/tests/test_files.py +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/tests/test_package.py +0 -0
- {holon_sh-0.0.1.dev12 → holon_sh-0.0.1.dev13}/tests/test_runtime.py +0 -0
|
@@ -155,6 +155,7 @@ class _Hold:
|
|
|
155
155
|
ended: ErrorData | None = None
|
|
156
156
|
until: int = 0
|
|
157
157
|
lease: asyncio.TimerHandle | None = None
|
|
158
|
+
seen: int = 0
|
|
158
159
|
|
|
159
160
|
|
|
160
161
|
@dataclass(eq=False, repr=False)
|
|
@@ -191,7 +192,7 @@ class EventType(Generic[A, D]):
|
|
|
191
192
|
Args:
|
|
192
193
|
event_id: The source's own id, so a client drops duplicates.
|
|
193
194
|
timestamp: When it happened. Defaults to now.
|
|
194
|
-
subscription_id: Send it to this subscription alone.
|
|
195
|
+
subscription_id: Send it to this subscription alone, and keep it until the subscription's open streams have sent it.
|
|
195
196
|
|
|
196
197
|
Call it on the event loop that serves the events; from another thread, use ``loop.call_soon_threadsafe``.
|
|
197
198
|
"""
|
|
@@ -256,8 +257,14 @@ class EventType(Generic[A, D]):
|
|
|
256
257
|
or self._bytes > _KEEP_BYTES
|
|
257
258
|
or self._kept[dropped].at < kept.at - _KEEP_AGE
|
|
258
259
|
):
|
|
259
|
-
|
|
260
|
-
|
|
260
|
+
oldest = self._kept[dropped]
|
|
261
|
+
if oldest.target is not None and any(
|
|
262
|
+
hold.lease is None and hold.seen < oldest.sequence
|
|
263
|
+
for hold in self._holds(oldest.target)
|
|
264
|
+
):
|
|
265
|
+
break
|
|
266
|
+
self._dropped = oldest.sequence
|
|
267
|
+
self._bytes -= oldest.size
|
|
261
268
|
dropped += 1
|
|
262
269
|
del self._kept[:dropped]
|
|
263
270
|
|
|
@@ -753,7 +760,7 @@ class Events(Extension):
|
|
|
753
760
|
declared = request.type
|
|
754
761
|
await declared._settled(request.id)
|
|
755
762
|
hold = self._open(request)
|
|
756
|
-
seen = declared._sequence
|
|
763
|
+
hold.seen = declared._sequence
|
|
757
764
|
try:
|
|
758
765
|
await self._ready(hold)
|
|
759
766
|
|
|
@@ -771,20 +778,23 @@ class Events(Extension):
|
|
|
771
778
|
if waited.cancelled_caught:
|
|
772
779
|
raise _Stalled
|
|
773
780
|
|
|
781
|
+
async def active(seen: int, truncated: bool) -> None:
|
|
782
|
+
hold.seen = seen
|
|
783
|
+
cursor = declared._position(seen)
|
|
784
|
+
await say("active", {"cursor": cursor, "truncated": truncated})
|
|
785
|
+
|
|
774
786
|
async def send(kept: _Kept) -> None:
|
|
787
|
+
hold.seen = kept.sequence
|
|
775
788
|
try:
|
|
776
789
|
shaped = declared._shape(kept, request)
|
|
777
790
|
except Exception as error: # noqa: BLE001
|
|
778
791
|
await say("error", {"error": _described(error)})
|
|
779
792
|
return
|
|
780
793
|
if shaped is not None:
|
|
781
|
-
cursor = declared._position(
|
|
794
|
+
cursor = declared._position(kept.sequence)
|
|
782
795
|
await say("event", {**shaped, "cursor": cursor}, kept.size)
|
|
783
796
|
|
|
784
|
-
|
|
785
|
-
await say(
|
|
786
|
-
"active", {"cursor": declared._position(seen), "truncated": truncated}
|
|
787
|
-
)
|
|
797
|
+
await active(*declared._resume(params.cursor, params.max_age_ms, hold.seen))
|
|
788
798
|
beat = time.monotonic() + _HEARTBEAT
|
|
789
799
|
while hold.ended is None:
|
|
790
800
|
hold.wake.clear()
|
|
@@ -800,34 +810,19 @@ class Events(Extension):
|
|
|
800
810
|
if not allowed:
|
|
801
811
|
hold.ended = _FORBIDDEN
|
|
802
812
|
break
|
|
803
|
-
await say("heartbeat", {"cursor": declared._position(seen)})
|
|
804
|
-
elif seen < declared._dropped:
|
|
813
|
+
await say("heartbeat", {"cursor": declared._position(hold.seen)})
|
|
814
|
+
elif hold.seen < declared._dropped:
|
|
805
815
|
# Evicted before it was sent: a gap.
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
"active",
|
|
809
|
-
{"cursor": declared._position(seen), "truncated": True},
|
|
810
|
-
)
|
|
811
|
-
elif (kept := declared._next(seen)) is not None:
|
|
812
|
-
seen = kept.sequence
|
|
816
|
+
await active(declared._dropped, True)
|
|
817
|
+
elif (kept := declared._next(hold.seen)) is not None:
|
|
813
818
|
await send(kept)
|
|
814
819
|
else:
|
|
815
820
|
with anyio.move_on_after(beat - time.monotonic()):
|
|
816
821
|
await hold.wake.wait()
|
|
817
|
-
while (
|
|
818
|
-
kept := declared._next(seen)
|
|
819
|
-
) is not None and kept.sequence <= hold.until:
|
|
820
|
-
seen = kept.sequence
|
|
822
|
+
while (kept := declared._next(hold.seen)) and kept.sequence <= hold.until:
|
|
821
823
|
await send(kept)
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
"terminated",
|
|
825
|
-
{
|
|
826
|
-
"error": hold.ended.model_dump(
|
|
827
|
-
by_alias=True, exclude_none=True, mode="json"
|
|
828
|
-
)
|
|
829
|
-
},
|
|
830
|
-
)
|
|
824
|
+
ended = MCPError.from_error_data(hold.ended)
|
|
825
|
+
await say("terminated", {"error": _described(ended)})
|
|
831
826
|
except _Stalled:
|
|
832
827
|
logger.info(
|
|
833
828
|
"Closed a stream of %s whose reader took nothing for two heartbeats",
|
|
@@ -213,17 +213,21 @@ async def test_a_signed_in_caller_has_one_subscription_per_arguments_and_a_calle
|
|
|
213
213
|
assert began[3] == began[0]
|
|
214
214
|
|
|
215
215
|
|
|
216
|
+
@pytest.mark.parametrize("targeted", [False, True])
|
|
216
217
|
@pytest.mark.parametrize("delivery", ["push", "poll"])
|
|
217
218
|
@asynchronous
|
|
218
|
-
async def
|
|
219
|
-
monkeypatch, delivery
|
|
219
|
+
async def test_a_subscription_behind_what_is_kept_is_told_of_the_gap_and_carries_on_but_a_stream_is_sent_all_emitted_to_its_subscription(
|
|
220
|
+
monkeypatch, delivery, targeted
|
|
220
221
|
):
|
|
221
222
|
monkeypatch.setattr(_server, "_KEEP_EVENTS", 2)
|
|
222
|
-
|
|
223
|
-
|
|
223
|
+
ids, heard = [], []
|
|
224
|
+
events, changed = declare(
|
|
225
|
+
on_subscribe=lambda context, arguments, id: ids.append(id)
|
|
226
|
+
)
|
|
227
|
+
owed = delivery == "push" and targeted
|
|
224
228
|
async with (
|
|
225
229
|
served(events) as port,
|
|
226
|
-
client(port).subscribe(
|
|
230
|
+
client(port, user="ann").subscribe(
|
|
227
231
|
"board.changed",
|
|
228
232
|
{"board": "b1"},
|
|
229
233
|
delivery=delivery,
|
|
@@ -231,9 +235,9 @@ async def test_a_subscription_behind_what_is_kept_is_told_of_the_gap_and_carries
|
|
|
231
235
|
) as changes,
|
|
232
236
|
):
|
|
233
237
|
for text in ["a", "b", "c", "d"]:
|
|
234
|
-
say(changed, "b1", text)
|
|
238
|
+
say(changed, "b1", text, to=ids[0] if targeted else None)
|
|
235
239
|
heard.extend(await take(changes, 2))
|
|
236
|
-
assert heard == ["gap", "c", "d"]
|
|
240
|
+
assert heard == (["a", "b"] if owed else ["gap", "c", "d"])
|
|
237
241
|
|
|
238
242
|
|
|
239
243
|
@asynchronous
|
|
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
|