mainsequence 9.0.38.dev88__tar.gz → 9.0.39__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.
Files changed (124) hide show
  1. {mainsequence-9.0.38.dev88/mainsequence.egg-info → mainsequence-9.0.39}/PKG-INFO +1 -1
  2. mainsequence-9.0.39/agent_scaffold/skills/application_surfaces/release_calls/SKILL.md +179 -0
  3. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/agent_scaffold/skills/platform_operations/orchestration_and_releases/SKILL.md +2 -0
  4. mainsequence-9.0.39/mainsequence/_request_deadline.py +58 -0
  5. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/client/models_helpers.py +128 -0
  6. mainsequence-9.0.39/mainsequence/client/release_calls.py +633 -0
  7. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/server/fastapi.py +52 -1
  8. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39/mainsequence.egg-info}/PKG-INFO +1 -1
  9. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence.egg-info/SOURCES.txt +3 -0
  10. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/pyproject.toml +1 -1
  11. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_fastapi_request_identity.py +31 -0
  12. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_scaffold_skills.py +1 -0
  13. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/LICENSE +0 -0
  14. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/README.md +0 -0
  15. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/agent_scaffold/skills/a2a_sdk_execution/SKILL.md +0 -0
  16. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/agent_scaffold/skills/application_surfaces/api_surfaces/SKILL.md +0 -0
  17. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/agent_scaffold/skills/mainsequence-inference/SKILL.md +0 -0
  18. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/agent_scaffold/skills/maintenance/bug_auditor/SKILL.md +0 -0
  19. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/agent_scaffold/skills/maintenance/code_repository_maintenance/SKILL.md +0 -0
  20. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/agent_scaffold/skills/maintenance/metatables_transition/SKILL.md +0 -0
  21. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/agent_scaffold/skills/platform_operations/access_control_and_sharing/SKILL.md +0 -0
  22. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/agent_scaffold/skills/sdk_code_repository_execution/SKILL.md +0 -0
  23. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/__init__.py +0 -0
  24. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/__main__.py +0 -0
  25. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/_local_callers.py +0 -0
  26. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/_request_identity.py +0 -0
  27. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/_team_memberships.py +0 -0
  28. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/_transport.py +0 -0
  29. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/bootstrap.py +0 -0
  30. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/cli/__init__.py +0 -0
  31. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/cli/api.py +0 -0
  32. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/cli/browser_auth.py +0 -0
  33. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/cli/cli.py +0 -0
  34. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/cli/code_repository_status.py +0 -0
  35. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/cli/config.py +0 -0
  36. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/cli/docker_utils.py +0 -0
  37. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/cli/doctor.py +0 -0
  38. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/cli/local_ops.py +0 -0
  39. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/cli/model_filters.py +0 -0
  40. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/cli/pydantic_cli.py +0 -0
  41. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/cli/sdk_utils.py +0 -0
  42. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/cli/ssh_utils.py +0 -0
  43. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/cli/ui.py +0 -0
  44. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/client/__init__.py +0 -0
  45. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/client/access_catalog.py +0 -0
  46. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/client/agent_runtime_models.py +0 -0
  47. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/client/base.py +0 -0
  48. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/client/client.py +0 -0
  49. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/client/compute_validation.py +0 -0
  50. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/client/exceptions.py +0 -0
  51. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/client/github_issues.py +0 -0
  52. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/client/inference.py +0 -0
  53. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/client/models_foundry.py +0 -0
  54. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/client/models_user.py +0 -0
  55. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/client/object_access.py +0 -0
  56. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/client/observability.py +0 -0
  57. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/client/utils.py +0 -0
  58. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/client/value_sets.py +0 -0
  59. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/code_repository_context.py +0 -0
  60. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/code_repository_skills.py +0 -0
  61. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/defaults.py +0 -0
  62. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/instrumentation/__init__.py +0 -0
  63. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/instrumentation/utils.py +0 -0
  64. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/logconf.py +0 -0
  65. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/repository_identity_security.py +0 -0
  66. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/runtime_credential_exchange.py +0 -0
  67. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/runtime_flags.py +0 -0
  68. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/scaffold_skills.py +0 -0
  69. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/server/__init__.py +0 -0
  70. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/server/_mcp_skills_upstream/__init__.py +0 -0
  71. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/server/_mcp_skills_upstream/server.py +0 -0
  72. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/server/_mcp_skills_upstream/shared.py +0 -0
  73. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/server/caller_assertions.py +0 -0
  74. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/server/mcp_skills.py +0 -0
  75. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence/workload_identity.py +0 -0
  76. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence.egg-info/dependency_links.txt +0 -0
  77. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence.egg-info/entry_points.txt +0 -0
  78. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence.egg-info/requires.txt +0 -0
  79. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/mainsequence.egg-info/top_level.txt +0 -0
  80. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/setup.cfg +0 -0
  81. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_access_catalog_client.py +0 -0
  82. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_auth_bootstrap.py +0 -0
  83. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_auth_precedence.py +0 -0
  84. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_caller_assertions.py +0 -0
  85. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_caller_context.py +0 -0
  86. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_canonical_api_route_contract.py +0 -0
  87. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_cli_auth_contract.py +0 -0
  88. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_cli_browser_auth.py +0 -0
  89. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_cli_request_budget.py +0 -0
  90. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_cli_secure_storage.py +0 -0
  91. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_client.py +0 -0
  92. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_code_repository_branch_contract.py +0 -0
  93. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_code_repository_documentation_contract.py +0 -0
  94. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_code_repository_runtime_context.py +0 -0
  95. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_code_repository_skills.py +0 -0
  96. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_credential_repr.py +0 -0
  97. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_dependency_extras.py +0 -0
  98. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_dev_release_version.py +0 -0
  99. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_environment_resource_context.py +0 -0
  100. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_environment_response_contracts.py +0 -0
  101. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_fastapi_mcp.py +0 -0
  102. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_github_issues_client.py +0 -0
  103. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_http_retry_budget.py +0 -0
  104. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_independent_context.py +0 -0
  105. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_inference_client.py +0 -0
  106. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_instrumentation.py +0 -0
  107. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_job_client.py +0 -0
  108. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_local_caller_cache.py +0 -0
  109. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_local_ops.py +0 -0
  110. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_logconf.py +0 -0
  111. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_mcp_skills.py +0 -0
  112. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_models_user_request_bound_auth.py +0 -0
  113. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_notification_uid_contract.py +0 -0
  114. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_object_access_client.py +0 -0
  115. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_observability_client.py +0 -0
  116. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_runtime_credential_exchange.py +0 -0
  117. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_secret_client_model.py +0 -0
  118. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_source_ownership.py +0 -0
  119. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_ssh_utils.py +0 -0
  120. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_team_memberships.py +0 -0
  121. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_tolerant_response_reading.py +0 -0
  122. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_tolerant_value_sets.py +0 -0
  123. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_user_application_facts.py +0 -0
  124. {mainsequence-9.0.38.dev88 → mainsequence-9.0.39}/tests/test_workload_identity.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mainsequence
3
- Version: 9.0.38.dev88
3
+ Version: 9.0.39
4
4
  Summary: Main Sequence SDK
5
5
  Author-email: Main Sequence GmbH <dev@main-sequence.io>
6
6
  License-Expression: MIT
@@ -0,0 +1,179 @@
1
+ ---
2
+ name: mainsequence-release-calls
3
+ description: Call one Main Sequence release (FastAPI API, MCP application or Agent-backing release) from another with the SDK's cold-start-aware routine. Use when an application, Job or Agent tool makes HTTP requests to another release, when choosing timeouts for such calls, when a call times out and the target may have been scaled to zero, or when a chain of releases (API to API to Agent) needs deadlines, prewarming or a "starting" state.
4
+ ---
5
+
6
+ # Calls Between Main Sequence Releases
7
+
8
+ Releases scale to zero. A request to a release with no replica is held until
9
+ one starts, which can take minutes. From the caller's side a held request and
10
+ a hung application look the same, so a timeout chosen for the application's
11
+ work fires on a healthy call.
12
+
13
+ The SDK solves this in one place. Use it; do not build your own.
14
+
15
+ ## Read First
16
+
17
+ 1. <https://mainsequence-sdk.github.io/mainsequence-sdk/knowledge/infrastructure/resource_releases/>,
18
+ section "Call a release".
19
+ 2. ADR 0041, "Cold-start-aware calls between releases", in the SDK's
20
+ `docs/adr`.
21
+
22
+ If the installed SDK has no `ResourceRelease.request`, report the missing
23
+ capability. Do not replace it with a hand-written wait loop.
24
+
25
+ ## The one way to call a release
26
+
27
+ ```python
28
+ from mainsequence.client import ResourceRelease
29
+
30
+ prices = ResourceRelease.by_uid("<RESOURCE_RELEASE_UID>")
31
+
32
+ response = prices.request("POST", "/v1/prices", timeout=60, json={"symbol": "ABC"})
33
+ response.raise_for_status()
34
+ ```
35
+
36
+ `by_uid` makes a handle from the UID and contacts nothing. Do not use
37
+ `ResourceRelease.get(pk=...)` to call a release: it asks the platform for the
38
+ release's details every time it runs.
39
+
40
+ In asynchronous code, such as a FastAPI handler:
41
+
42
+ ```python
43
+ response = await prices.arequest("POST", "/v1/prices", timeout=60, json={"symbol": "ABC"})
44
+ ```
45
+
46
+ What the routine does:
47
+
48
+ 1. Makes sure the release is ready. It asks the platform, which also starts
49
+ the release, unless this process already knows the release is warm.
50
+ 2. Waits while the release starts, under a separate readiness limit.
51
+ 3. Sends the request. `timeout` starts only now.
52
+
53
+ Never keep the release's URL or token yourself: the routine obtains and renews
54
+ both.
55
+
56
+ `request` asks the platform only when it must: on the first call in the
57
+ process, when the release has shown no sign of serving within its idle window,
58
+ when its token is about to expire, and after a timeout. With steady traffic it
59
+ goes straight to the target.
60
+
61
+ The target sees the call as coming from your application's own identity.
62
+
63
+ ## Rules
64
+
65
+ - **`timeout` is the target's work time.** Pass how long the target's own
66
+ work may take when it is already running. Never add the start time to it.
67
+ - **Leave readiness to the routine.** Pass `ready_timeout` only when the
68
+ product has a real limit on how long a start may take. The default follows
69
+ the start time the platform measures, or 300 seconds
70
+ (`MAINSEQUENCE_RELEASE_READY_TIMEOUT_SECONDS`).
71
+ - **No private clocks or caches.** Do not record "last used" times, ping
72
+ endpoints to keep a release awake, or cache readiness. The SDK keeps one
73
+ cache per process. To decide something from it, read
74
+ `release.runtime_status()`.
75
+ - **No bare HTTP clients for release calls.** Not `requests`, not `httpx`,
76
+ not a URL built from a name or UID.
77
+ - **`idempotent=True` only when a repeat is safe.** With it, a request that
78
+ timed out while the target was starting is sent once more. Without it,
79
+ nothing is ever sent twice. A read is safe. A write is safe only when the
80
+ target deduplicates it.
81
+ - **Do not catch and retry timeouts yourself.** The errors below say what
82
+ happened; a blind retry can run the target's work twice.
83
+
84
+ ## Errors
85
+
86
+ All are `ReleaseCallError`, importable from `mainsequence.client`. The timeout
87
+ ones are also `TimeoutError`.
88
+
89
+ | Error | Meaning | What to do |
90
+ | --- | --- | --- |
91
+ | `ReleaseReadinessTimeoutError` | The release was still starting when the readiness limit ended. Nothing was sent. | Report "starting, try again". Check the release's deployment if it repeats. |
92
+ | `ReleaseUnavailableError` | The platform says the release cannot take requests. Nothing was sent. | Report it. Do not retry in a loop. |
93
+ | `ReleaseDeadlineTooShortError` | Your own caller will not wait long enough for the target to start. Nothing was sent. | The outermost caller's limit is too short for this chain, or the work should be submit-and-poll. |
94
+ | `ReleaseColdStartTimeoutError` | The request was sent and timed out while the target was starting. | Safe to repeat only for an idempotent call. |
95
+ | `ReleaseRequestTimeoutError` | The request was sent and timed out on a running target. | The target is slow or hung. Read its logs. |
96
+
97
+ Each carries `resource_release_uid`, `phase` (`readiness` or `request`),
98
+ `timeout_seconds` and, when known, `runtime_phase`.
99
+
100
+ An HTTP error status is not an exception: the response is returned.
101
+
102
+ ## Show state without calling
103
+
104
+ ```python
105
+ status = prices.runtime_status()
106
+ status.state # "warm", "cold" or "unknown"
107
+ status.last_cold_start_at # when the last observed start began
108
+ status.last_cold_start_seconds # how long it took
109
+ status.expected_cold_start_seconds # from the platform, or None
110
+ ```
111
+
112
+ `runtime_status()` never contacts the platform and never starts the release.
113
+ `unknown` is a normal answer for a release this process has not called
114
+ recently.
115
+
116
+ ## Start dependencies together
117
+
118
+ Declare the releases an application depends on once, and start them when the
119
+ application starts:
120
+
121
+ ```python
122
+ from contextlib import asynccontextmanager
123
+
124
+ from fastapi import FastAPI
125
+ from mainsequence.client import ResourceRelease, prewarm_releases
126
+
127
+ PRICES = ResourceRelease.by_uid("<PRICES_RELEASE_UID>")
128
+ RISK = ResourceRelease.by_uid("<RISK_RELEASE_UID>")
129
+
130
+
131
+ @asynccontextmanager
132
+ async def lifespan(app: FastAPI):
133
+ prewarm_releases([PRICES, RISK])
134
+ yield
135
+
136
+
137
+ app = FastAPI(lifespan=lifespan)
138
+ ```
139
+
140
+ `prewarm_releases` returns at once and never raises. A chain of cold releases
141
+ then costs about the slowest start, not the sum. Call it at the start of a
142
+ request too when the request will reach several releases one after another.
143
+
144
+ ## Deadlines across a chain
145
+
146
+ An application with `install_request_identity(app)` reads how long its own
147
+ caller will still wait. Calls made with `request` inside that handler are
148
+ bounded by it, and what remains is sent on to the next release. Nothing is
149
+ needed in application code.
150
+
151
+ The limit travels in the `Mainsequence-Request-Timeout-Ms` header. A hop that
152
+ does not receive the header is bounded only by its own `timeout`, so do not
153
+ rely on the chain's limit to stop work: keep each call's `timeout` honest.
154
+
155
+ Set the limit once, at the outermost caller, as that caller's `timeout`. It
156
+ must cover the whole chain's work plus one start.
157
+
158
+ ## When to stop holding a request
159
+
160
+ Change the call to submit-and-poll when its warm work time plus a start can
161
+ pass a few minutes, or when `ReleaseDeadlineTooShortError` or
162
+ `ReleaseColdStartTimeoutError` recur:
163
+
164
+ - For an Agent, use the A2A skill
165
+ (`.agents/skills/mainsequence/a2a_sdk_execution/SKILL.md`) with a Task
166
+ response.
167
+ - For an API, expose one endpoint that accepts the work and returns an id,
168
+ and one that reports its state. Call both through `request`.
169
+
170
+ ## Verify
171
+
172
+ - A test calls the code with the target answering `waking` and then `ready`,
173
+ and asserts the request is sent once, after readiness.
174
+ - A test with the target answering `waking` past `ready_timeout` asserts
175
+ `ReleaseReadinessTimeoutError` and that nothing was sent.
176
+ - No module imports `requests` or `httpx` to reach a release.
177
+ - No module stores a release's `rpc_url` or token.
178
+ - Logs show `release.call.cold_start` with the target's UID when a start was
179
+ waited for.
@@ -45,6 +45,8 @@ This skill must not claim ownership of:
45
45
  `.agents/skills/mainsequence/application_surfaces/api_surfaces/SKILL.md`
46
46
  - RBAC and access policies:
47
47
  `.agents/skills/mainsequence/platform_operations/access_control_and_sharing/SKILL.md`
48
+ - HTTP calls from one release to another, their timeouts and cold starts:
49
+ `.agents/skills/mainsequence/application_surfaces/release_calls/SKILL.md`
48
50
 
49
51
  ## Read First
50
52
 
@@ -0,0 +1,58 @@
1
+ """The time a request's caller will still wait, carried from hop to hop (ADR 0041)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import math
6
+ import time
7
+ from contextlib import contextmanager
8
+ from contextvars import ContextVar
9
+
10
+ DEADLINE_HEADER = "Mainsequence-Request-Timeout-Ms"
11
+
12
+ # A monotonic instant, so the wall clock of neither side matters.
13
+ _DEADLINE: ContextVar[float | None] = ContextVar("mainsequence_request_deadline", default=None)
14
+
15
+
16
+ def parse_timeout_ms(value: str | None) -> float | None:
17
+ """Seconds from a header value in milliseconds; ``None`` when absent or unusable."""
18
+ if value is None:
19
+ return None
20
+ try:
21
+ milliseconds = int(value.strip())
22
+ except (ValueError, AttributeError):
23
+ return None
24
+ if milliseconds <= 0:
25
+ return None
26
+ return milliseconds / 1000.0
27
+
28
+
29
+ def format_timeout_ms(seconds: float) -> str:
30
+ return str(max(1, math.floor(seconds * 1000)))
31
+
32
+
33
+ @contextmanager
34
+ def request_deadline(seconds: float | None):
35
+ """Bound the calls made inside the block; ``None`` leaves them unbounded.
36
+
37
+ An enclosing deadline can only be shortened.
38
+ """
39
+ if seconds is None:
40
+ yield
41
+ return
42
+ deadline = time.monotonic() + seconds
43
+ parent = _DEADLINE.get()
44
+ if parent is not None:
45
+ deadline = min(deadline, parent)
46
+ token = _DEADLINE.set(deadline)
47
+ try:
48
+ yield
49
+ finally:
50
+ _DEADLINE.reset(token)
51
+
52
+
53
+ def remaining_request_seconds() -> float | None:
54
+ """Seconds the current request's caller will still wait; ``None`` when it set no limit."""
55
+ deadline = _DEADLINE.get()
56
+ if deadline is None:
57
+ return None
58
+ return deadline - time.monotonic()
@@ -1,11 +1,13 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import asyncio
3
4
  import datetime
4
5
  import time
5
6
  from decimal import Decimal
6
7
  from typing import Any, ClassVar, Literal
7
8
  from uuid import UUID
8
9
 
10
+ import requests
9
11
  from pydantic import BaseModel, ConfigDict, Field, PositiveInt
10
12
 
11
13
  from .base import (
@@ -25,6 +27,36 @@ from .observability import (
25
27
  OwnerResourceUsageMixin,
26
28
  PublicLogLevel,
27
29
  )
30
+ from .release_calls import (
31
+ ReleaseCallError as ReleaseCallError,
32
+ )
33
+ from .release_calls import (
34
+ ReleaseColdStartTimeoutError as ReleaseColdStartTimeoutError,
35
+ )
36
+ from .release_calls import (
37
+ ReleaseDeadlineTooShortError as ReleaseDeadlineTooShortError,
38
+ )
39
+ from .release_calls import (
40
+ ReleaseReadinessTimeoutError as ReleaseReadinessTimeoutError,
41
+ )
42
+ from .release_calls import (
43
+ ReleaseRequestTimeoutError as ReleaseRequestTimeoutError,
44
+ )
45
+ from .release_calls import (
46
+ ReleaseRuntimeStatus as ReleaseRuntimeStatus,
47
+ )
48
+ from .release_calls import (
49
+ ReleaseUnavailableError as ReleaseUnavailableError,
50
+ )
51
+ from .release_calls import (
52
+ prewarm_releases as prewarm_releases,
53
+ )
54
+ from .release_calls import (
55
+ release_runtime_cache as release_runtime_cache,
56
+ )
57
+ from .release_calls import (
58
+ request_release as _request_release,
59
+ )
28
60
  from .utils import make_request
29
61
  from .value_sets import OpenStrEnum, OpenValueSet
30
62
 
@@ -838,6 +870,26 @@ class ResourceReleaseRuntimePresence(BasePydanticModel):
838
870
  wake: ResourceReleaseRuntimeWake | None = None
839
871
 
840
872
 
873
+ class ResourceReleaseScaling(BasePydanticModel):
874
+ """How a release scales, as the platform states it (ADR 0041).
875
+
876
+ Every field is ``None`` when the platform does not state it.
877
+ """
878
+
879
+ min_instances: int | None = Field(
880
+ default=None, ge=0, description="Replicas kept when idle. 0 scales to zero."
881
+ )
882
+ idle_timeout_seconds: float | None = Field(
883
+ default=None, ge=0, description="How long the last replica stays after its last request."
884
+ )
885
+ expected_cold_start_seconds: float | None = Field(
886
+ default=None, ge=0, description="The platform's measured time from wake to serving."
887
+ )
888
+ serving_since: datetime.datetime | None = Field(
889
+ default=None, description="When the oldest current replica began serving."
890
+ )
891
+
892
+
841
893
  class ResourceReleaseRuntimeAccess(BasePydanticModel):
842
894
  # `access` holds the runtime's bearer token, so neither repr() nor a
843
895
  # validation error shows it.
@@ -850,6 +902,7 @@ class ResourceReleaseRuntimeAccess(BasePydanticModel):
850
902
  routing: ResourceReleaseRuntimeRouting
851
903
  runtime_access: ResourceReleaseRuntimeAdmission
852
904
  runtime_presence: ResourceReleaseRuntimePresence
905
+ scaling: ResourceReleaseScaling | None = None
853
906
  access: dict[str, Any] | None = Field(default=None, repr=False)
854
907
 
855
908
 
@@ -1044,6 +1097,81 @@ class ResourceRelease(
1044
1097
  raise RuntimeError("Transient runtime access response is missing retry_after_ms.")
1045
1098
  time.sleep(min(remaining, max(0.1, retry_after_ms / 1000.0)))
1046
1099
 
1100
+ @classmethod
1101
+ def by_uid(cls, uid: str | UUID) -> ResourceRelease:
1102
+ """A handle to call a release by its UID, without asking the platform for it.
1103
+
1104
+ Only ``uid`` is set: use it for ``request``, ``arequest``,
1105
+ ``runtime_status`` and the runtime access methods. Use ``get(pk=...)``
1106
+ to read the release's details.
1107
+ """
1108
+ if uid in (None, ""):
1109
+ raise ValueError("A release UID is required")
1110
+ return cls.model_construct(uid=str(uid))
1111
+
1112
+ def request(
1113
+ self,
1114
+ method: str,
1115
+ path: str,
1116
+ *,
1117
+ timeout: float | tuple[float, float],
1118
+ ready_timeout: float | None = None,
1119
+ idempotent: bool = False,
1120
+ headers: dict[str, str] | None = None,
1121
+ **kwargs: Any,
1122
+ ) -> requests.Response:
1123
+ """Send one HTTP request to this release's application (ADR 0041).
1124
+
1125
+ The release may be scaled to zero. The call first makes sure it is
1126
+ ready, asking the platform, which also starts it, unless this process
1127
+ knows it is warm. Only then is the request sent, so ``timeout`` measures
1128
+ the application's own work and never its start. ``timeout`` is a total
1129
+ in seconds, or a ``(connect, read)`` tuple.
1130
+
1131
+ ``ready_timeout`` limits the wait for a starting release. By default it
1132
+ is twice the start time the platform expects, at least 30 seconds, or
1133
+ ``MAINSEQUENCE_RELEASE_READY_TIMEOUT_SECONDS`` (300) when the platform
1134
+ states none.
1135
+
1136
+ The request is sent once. ``idempotent=True`` allows one more send, and
1137
+ only when the first timed out while the release was starting. Pass it
1138
+ only for a call that is safe to repeat.
1139
+
1140
+ Inside a request handled by an application with
1141
+ ``install_request_identity``, the time the handler's own caller will
1142
+ still wait bounds both limits, and what remains is sent on.
1143
+
1144
+ ``kwargs`` go to ``requests`` (``json``, ``params``, ``data``, …). The
1145
+ response is returned whatever its status. Raises
1146
+ ``ReleaseReadinessTimeoutError``, ``ReleaseUnavailableError``,
1147
+ ``ReleaseDeadlineTooShortError``, ``ReleaseColdStartTimeoutError`` or
1148
+ ``ReleaseRequestTimeoutError``, all ``ReleaseCallError``.
1149
+ """
1150
+ return _request_release(
1151
+ self,
1152
+ method,
1153
+ path,
1154
+ timeout=timeout,
1155
+ ready_timeout=ready_timeout,
1156
+ idempotent=idempotent,
1157
+ headers=headers,
1158
+ **kwargs,
1159
+ )
1160
+
1161
+ async def arequest(self, method: str, path: str, **kwargs: Any) -> requests.Response:
1162
+ """``request`` for asynchronous code: it runs on a worker thread."""
1163
+ return await asyncio.to_thread(self.request, method, path, **kwargs)
1164
+
1165
+ def runtime_status(self) -> ReleaseRuntimeStatus:
1166
+ """What this process knows about the release's runtime, without asking the platform.
1167
+
1168
+ Read it to decide something from the release's state, such as showing
1169
+ "starting". It never starts the release.
1170
+ """
1171
+ if self.uid is None:
1172
+ raise ValueError("ResourceRelease.uid is required to read its runtime status")
1173
+ return release_runtime_cache.status(str(self.uid))
1174
+
1047
1175
 
1048
1176
  uid: str | None = Field(
1049
1177
  None,