managed-deepagents 0.9.3.dev1__py3-none-win_amd64.whl → 0.9.3.dev3__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -34,6 +34,7 @@ from managed_deepagents._identity_runtime import (
34
34
  resolve_runtime_configurable,
35
35
  )
36
36
  from managed_deepagents._schedule_auth import (
37
+ SCHEDULE_LIMIT_MESSAGE,
37
38
  ExecutionUser,
38
39
  ScheduleAccess,
39
40
  schedule_request_config,
@@ -249,6 +250,12 @@ async def _request(ctx: _Context, method: str, path: str, body: object = None) -
249
250
  if response.status_code == HTTPStatus.NOT_FOUND:
250
251
  raise ScheduleNotFoundError
251
252
  if not response.is_success:
253
+ try:
254
+ detail = json.loads(await response.aread()).get("detail")
255
+ except (ValueError, AttributeError):
256
+ detail = None
257
+ if detail == SCHEDULE_LIMIT_MESSAGE:
258
+ raise ValueError(SCHEDULE_LIMIT_MESSAGE)
252
259
  raise RuntimeError(f"Schedule request failed ({response.status_code})")
253
260
  if response.status_code == HTTPStatus.NO_CONTENT:
254
261
  return None
@@ -479,16 +486,6 @@ class RuntimeSchedules:
479
486
  context: dict[str, JsonValue] | None = None,
480
487
  ) -> ScheduleRecord:
481
488
  configurable = _run_configurable(self._runtime)
482
- user = resolve_auth_user(configurable) or {}
483
- # A scheduled run that can create schedules can replicate itself on every
484
- # fire. Channel schedules replace the source provider, so the cron identity
485
- # carries its own marker. Any stamp blocks; a forged one only blocks its caller.
486
- if (
487
- user.get("mda_scheduled_run") is True
488
- or user.get("mda_source_provider") == "schedule"
489
- or "mda_schedule" in configurable
490
- ):
491
- raise ValueError("Schedules cannot be created from a scheduled run")
492
489
  spec = _Spec(
493
490
  cron=cron,
494
491
  at=at,
@@ -5,10 +5,12 @@ import json
5
5
  import os
6
6
  import re
7
7
  from collections.abc import Mapping
8
+ from datetime import UTC, datetime
8
9
  from typing import TYPE_CHECKING, Literal, NotRequired, cast
9
10
  from uuid import NAMESPACE_URL, UUID, uuid5
10
11
 
11
12
  import httpx
13
+ from langgraph_sdk import Auth
12
14
  from pydantic import ConfigDict, TypeAdapter, ValidationError, with_config
13
15
  from typing_extensions import TypedDict
14
16
 
@@ -31,6 +33,12 @@ if TYPE_CHECKING:
31
33
  _MAX_HANDOFF_SIZE = 8192
32
34
 
33
35
  SCHEDULE_HANDOFF_HEADER = "x-mda-schedule-handoff"
36
+ _MAX_RUNTIME_SCHEDULES = 20
37
+ _SEARCH_PAGE = 100
38
+ SCHEDULE_LIMIT_MESSAGE = (
39
+ f"Each owner can have at most {_MAX_RUNTIME_SCHEDULES} schedules that have not expired, "
40
+ "paused ones included; delete one before creating another"
41
+ )
34
42
 
35
43
 
36
44
  @with_config(ConfigDict(extra="forbid"))
@@ -68,9 +76,15 @@ class ScheduleHandoffUser(ExecutionUser, total=False):
68
76
  mda_schedule_access: ScheduleAccess
69
77
 
70
78
 
79
+ class _CronRow(TypedDict, total=False):
80
+ cron_id: str
81
+ end_time: str | None
82
+
83
+
71
84
  _EXECUTION = TypeAdapter(ExecutionUser)
72
85
  _ACCESS = TypeAdapter(ScheduleAccess)
73
86
  _CHANNEL = TypeAdapter(ChannelContext)
87
+ _CRON_ROWS = TypeAdapter(list[_CronRow])
74
88
 
75
89
 
76
90
  def schedule_request_config(access: ScheduleAccess) -> tuple[str, dict[str, str]]:
@@ -155,7 +169,7 @@ def schedule_access(user: object) -> ScheduleAccess | None:
155
169
  return None
156
170
 
157
171
 
158
- async def authorize_schedule(
172
+ async def authorize_schedule( # noqa: C901 - one branch per cron event check
159
173
  user: BaseUser,
160
174
  action: str,
161
175
  value: CronsCreate | CronsRead | CronsUpdate | CronsDelete | CronsSearch,
@@ -186,6 +200,7 @@ async def authorize_schedule(
186
200
  raise ValueError("Schedule access is not permitted")
187
201
  metadata.update(filters)
188
202
  metadata["mda_managed"] = True
203
+ await _check_schedule_limit(access)
189
204
  _check_context(payload, access["execution"], "runtime")
190
205
  if action == "create" or (
191
206
  action == "update" and isinstance(payload, dict) and "config" in payload
@@ -199,6 +214,8 @@ async def authorize_schedule(
199
214
  and any(key.startswith("mda_") and key != "mda_schedule_spec" for key in metadata)
200
215
  ):
201
216
  raise ValueError("Schedule access is not permitted")
217
+ if action == "update" and data.get("schedule") is not None:
218
+ await _check_schedule_limit(access, str(data.get("cron_id")))
202
219
  return filters
203
220
 
204
221
 
@@ -304,3 +321,40 @@ async def _check_persistent_thread(access: ScheduleAccess) -> None:
304
321
  ):
305
322
  if not response.is_success:
306
323
  raise ValueError("Schedule access is not permitted")
324
+
325
+
326
+ async def _check_schedule_limit(access: ScheduleAccess, cron_id: str | None = None) -> None:
327
+ """Reject once the owner has the maximum active runtime schedules, not counting ``cron_id``.
328
+
329
+ A timing update can make an expired schedule active again.
330
+ """
331
+ base, headers = schedule_request_config(access)
332
+ now = datetime.now(UTC)
333
+ active = offset = 0
334
+ async with httpx.AsyncClient(timeout=15, follow_redirects=False) as client:
335
+ while True:
336
+ response = await client.post(
337
+ f"{base}/runs/crons/search",
338
+ headers=headers,
339
+ json={
340
+ "assistant_id": access["assistant"],
341
+ "metadata": {"mda_managed_by": "runtime"},
342
+ "select": ["cron_id", "end_time"],
343
+ "limit": _SEARCH_PAGE,
344
+ "offset": offset,
345
+ },
346
+ )
347
+ if not response.is_success:
348
+ raise ValueError("Schedule access is not permitted")
349
+ rows = _CRON_ROWS.validate_python(response.json())
350
+ active += sum(
351
+ 1
352
+ for row in rows
353
+ if row.get("cron_id") != cron_id
354
+ and not ((end := row.get("end_time")) and datetime.fromisoformat(end) < now)
355
+ )
356
+ if active >= _MAX_RUNTIME_SCHEDULES:
357
+ raise Auth.exceptions.HTTPException(status_code=409, detail=SCHEDULE_LIMIT_MESSAGE)
358
+ if len(rows) < _SEARCH_PAGE:
359
+ return
360
+ offset += _SEARCH_PAGE
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: managed-deepagents
3
- Version: 0.9.3.dev1
3
+ Version: 0.9.3.dev3
4
4
  Summary: Managed Deep Agents — the define_deep_agent authoring interface plus the CLI that compiles and deploys a code-first Deep Agent repository to a managed LangGraph runtime.
5
5
  Author: LangChain
6
6
  License: MIT
@@ -535,9 +535,9 @@ Set `new_thread` to choose whether a run starts a new thread or continues the
535
535
  current thread. When a schedule is created from a channel such as Slack,
536
536
  each run posts its final answer to that channel. Runtime schedules stay when you deploy again.
537
537
 
538
- A run started by a schedule cannot create schedules, so a schedule cannot
539
- replicate itself. It can still list, get, update, and delete schedules, for
540
- example to reschedule or remove the schedule that started it.
538
+ Each owner can have at most 20 runtime schedules per agent, paused ones
539
+ included. Expired one-time schedules and schedules defined in code do not count. A run started by
540
+ a schedule can create, list, get, update, and delete schedules like any other run.
541
541
 
542
542
  ## Sandbox
543
543
 
@@ -24,9 +24,9 @@ managed_deepagents/_managed_middleware.py,sha256=LijT0XmqR6lYvg8oiweq63C1bjSjBUZ
24
24
  managed_deepagents/_managed_tools.py,sha256=fr_fJkk8wN0PZrRnihBsLTLW2Q3L-sFnRz54vD2cBzY,11120
25
25
  managed_deepagents/_memory_instructions.py,sha256=s69Shu6vGCXbynozC-SRSJeZrpH5PNowh0sIRKH65XQ,6763
26
26
  managed_deepagents/_run_input.py,sha256=heaTTLd9i9D-1blrH-GIi5KmSpQrhrD9_mrtz9bhy48,6613
27
- managed_deepagents/_runtime_schedules.py,sha256=0peqKXz3IT_B9b8BI5f3Won97aopvaTUe48MQmITXAA,25507
27
+ managed_deepagents/_runtime_schedules.py,sha256=DG40VLIyDodKI0SpE8xf0-BvlkbsCLKsQQEUGxrOaD0,25241
28
28
  managed_deepagents/_sandbox_proxy.py,sha256=zhtiTxJSAV0WS4RJBy7hh8dGAAbFONfj4yjaMtfmxw8,9388
29
- managed_deepagents/_schedule_auth.py,sha256=GDWiHphp8lvBPj1Uo5oS6O-qZqO6yPizCLCUJpiaDe8,11521
29
+ managed_deepagents/_schedule_auth.py,sha256=VS-bL9wHnRZhubDH44hmHnp75gy0VzPq0mPQ43gHQCE,13724
30
30
  managed_deepagents/_schedule_channel.py,sha256=P--isfzDBxJ4C2smFS-uuM3A5IwHn9byJxxVXgWDseo,998
31
31
  managed_deepagents/_schedule_time.py,sha256=uNyULRjoD0HzPVvV-W772HPb3BYCt0fwEbbT9Ec__Jc,3710
32
32
  managed_deepagents/_static_entry.py,sha256=vWVDXb_RwFhHIT4c8fJpUaCqxS_SAJ9Md5IKA8GDrv4,624
@@ -40,7 +40,7 @@ managed_deepagents/run_context.py,sha256=1Nc3pew_nROgKi18PAKhn7vOAed-PmxArqUTpce
40
40
  managed_deepagents/runtime.py,sha256=f6B6JsMSsHJct-e1bVWaKgLmzXhgB8Pm0lFFHH9ysqg,94046
41
41
  managed_deepagents/sandbox.py,sha256=8qaswX6F2LYJX1uGq_7XwAGHZjGOD9VQ0WISqPK_ohs,4734
42
42
  managed_deepagents/schedules.py,sha256=XROsDs-QwCWH0yEwakIN5Rhl5aM06eZX5-JFJ-KG1To,5898
43
- managed_deepagents/_binaries/mda.exe,sha256=YpCoRLiJk8PZMoE5em7MfB4AdMrChtjwcP57rquRjDI,4513792
43
+ managed_deepagents/_binaries/mda.exe,sha256=2IeXkzw18-x7vVQdvu6la2v3ucrr3YtpNuTwefok4ZU,4513792
44
44
  managed_deepagents/_channels/__init__.py,sha256=tY94zltWKNw-FIzbGjrh0cSAc2JIHCEAvcY7hzoRED0,801
45
45
  managed_deepagents/_channels/assistant_text.py,sha256=ZLYAF1MQVE5_EN49MoPJdB8Ckf3vNPpXNBhkdA4egF0,3414
46
46
  managed_deepagents/_channels/binding.py,sha256=DnxB7FXkbY5B3PCEAGz3JJBCCnQSdWz8PU8ze4fdcZU,5302
@@ -101,9 +101,9 @@ managed_deepagents/identity/__init__.py,sha256=YMB5p2DRyyY_82gGNVfGHjfjnUFRTtMne
101
101
  managed_deepagents/identity/claims.py,sha256=prby7r_8Lww3MmoBm8PX6PsSGE3GwSHkr8mVIz_08nU,1180
102
102
  managed_deepagents/identity/options.py,sha256=x_yMbXEFR7zXyehEjDHG2qjAlukXjrRBcQLcM6IndLM,2550
103
103
  managed_deepagents/identity/supabase.py,sha256=8uobl3WCrQL_ieSXG8KTLf1th7Qjim9liZT50HeaJE0,6026
104
- managed_deepagents-0.9.3.dev1.dist-info/licenses/LICENSE,sha256=WnPZQQ608ojZUkXl7BW6VbKloIAibZiGm1K6cjeZOL8,1066
105
- managed_deepagents-0.9.3.dev1.dist-info/METADATA,sha256=dH0GbQkCxELDNFiyPcMd9xSur41Ls_MiI7-45Ip97xg,33424
106
- managed_deepagents-0.9.3.dev1.dist-info/WHEEL,sha256=3I5VVWZdsFlU417aCS2bMRuerS8wsfvBq99MyatBV3A,97
107
- managed_deepagents-0.9.3.dev1.dist-info/entry_points.txt,sha256=ziZqkKuaDO3qHCjKmBhrx9cm3ok8bZ9xcEDpUTj4unM,53
108
- managed_deepagents-0.9.3.dev1.dist-info/top_level.txt,sha256=fdBo4O0Hlol_w022tTLB5ftZpamb4yJoQ3MUvjgTGfA,19
109
- managed_deepagents-0.9.3.dev1.dist-info/RECORD,,
104
+ managed_deepagents-0.9.3.dev3.dist-info/licenses/LICENSE,sha256=WnPZQQ608ojZUkXl7BW6VbKloIAibZiGm1K6cjeZOL8,1066
105
+ managed_deepagents-0.9.3.dev3.dist-info/METADATA,sha256=hm3PMbQv6sy99-1owZZpPaePqVCjDBhcsnJYMbxhi5s,33465
106
+ managed_deepagents-0.9.3.dev3.dist-info/WHEEL,sha256=3I5VVWZdsFlU417aCS2bMRuerS8wsfvBq99MyatBV3A,97
107
+ managed_deepagents-0.9.3.dev3.dist-info/entry_points.txt,sha256=ziZqkKuaDO3qHCjKmBhrx9cm3ok8bZ9xcEDpUTj4unM,53
108
+ managed_deepagents-0.9.3.dev3.dist-info/top_level.txt,sha256=fdBo4O0Hlol_w022tTLB5ftZpamb4yJoQ3MUvjgTGfA,19
109
+ managed_deepagents-0.9.3.dev3.dist-info/RECORD,,