Commit 2a0c6d2
committed
feat(sdks/python): resilient SDK transport (OSEP-0016)
Implement the Python side of OSEP-0016 for the sandbox and
code-interpreter SDKs. Adds a shared retry policy, extended
exception hierarchy, and async/sync httpx transport wrappers.
Retry policy
- New `RetryPolicy` value type on `ConnectionConfig` /
`ConnectionConfigSync`; defaults enable retry for idempotent
methods only, `POST`/`PATCH` status-code retry is opt-in.
- Default idempotent retryable status set: `{429, 502, 503}`.
- Decorrelated jitter (default), full jitter, and deterministic
exponential; `Retry-After` honored with a fixed 60s ceiling.
- `RetryPolicy.disabled()` gives end-to-end fast-fail semantics
and suppresses fresh-connection recovery.
- `HTTPStatus` used at the public API surface so callers get
type checking and IDE completion for the status sets.
Exception hierarchy
- Extend `SandboxException` with an `is_retryable` accessor
reflecting the SDK's actual retry decision at emission time.
- New subclasses: `SandboxRateLimitException` (carries
`retry_after`), `SandboxTimeoutException`,
`SandboxConnectionException`. Existing classes and their
public fields are unchanged.
Transport wrappers
- `RetryAsyncTransport` (httpx.AsyncBaseTransport) and
`RetrySyncTransport` (httpx.BaseTransport) install the retry
engine at the same layer the SDK already uses for transport
concerns. Generated OpenAPI code is not touched.
- `ConnectionConfig` exposes a `sse_transport` property so SSE
bootstraps bypass retry while sharing the underlying pool.
Command / isolated / code-interpreter SSE clients now use it.
- `lifecycle_metrics` keeps its own short-lived httpx.Client;
sharing the SDK transport would let the metrics client's
`close()` tear down every other adapter's connection pool.
Tests
- Retry policy defaults, validation, and `HTTPStatus` usage.
- Pure decision function: status matrix, transport branch,
budget/deadline/cancellation predicates, opt-in rules,
jitter algorithms, and `Retry-After` parsing/clamping.
- Async + sync httpx transport integration via scripted mock
transports covering success, 4xx pass-through, budget
exhaustion, pre-send vs. post-send classification, opt-in,
and observability callback invariants.
- `ConnectionConfig` wiring: default wraps, `disabled()` skips
wrapping, user-supplied transports are used verbatim.
- SSE clients use the raw inner transport, verified end-to-end.1 parent b4011b3 commit 2a0c6d2
27 files changed
Lines changed: 2678 additions & 136 deletions
File tree
- sdks
- code-interpreter/python
- src/code_interpreter
- adapters
- sync/adapters
- sandbox/python
- src/opensandbox
- adapters
- converter
- config
- exceptions
- internal
- sync/adapters
- transport
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
133 | 139 | | |
134 | 140 | | |
135 | 141 | | |
| |||
138 | 144 | | |
139 | 145 | | |
140 | 146 | | |
141 | | - | |
| 147 | + | |
142 | 148 | | |
143 | 149 | | |
144 | 150 | | |
| |||
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
121 | 127 | | |
122 | 128 | | |
123 | 129 | | |
124 | 130 | | |
125 | 131 | | |
126 | | - | |
| 132 | + | |
127 | 133 | | |
128 | 134 | | |
129 | 135 | | |
| |||
Lines changed: 7 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
187 | 190 | | |
188 | 191 | | |
189 | 192 | | |
| |||
192 | 195 | | |
193 | 196 | | |
194 | 197 | | |
195 | | - | |
| 198 | + | |
196 | 199 | | |
197 | 200 | | |
198 | 201 | | |
| |||
228 | 231 | | |
229 | 232 | | |
230 | 233 | | |
231 | | - | |
232 | 234 | | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
| 235 | + | |
239 | 236 | | |
| 237 | + | |
240 | 238 | | |
241 | 239 | | |
242 | 240 | | |
| |||
Lines changed: 88 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
| 39 | + | |
37 | 40 | | |
38 | 41 | | |
| 42 | + | |
39 | 43 | | |
40 | 44 | | |
41 | 45 | | |
| |||
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| 53 | + | |
49 | 54 | | |
50 | 55 | | |
51 | 56 | | |
| 57 | + | |
| 58 | + | |
52 | 59 | | |
| 60 | + | |
53 | 61 | | |
54 | 62 | | |
55 | 63 | | |
56 | 64 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| |||
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
104 | | - | |
105 | | - | |
106 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
107 | 111 | | |
108 | 112 | | |
109 | 113 | | |
110 | 114 | | |
111 | | - | |
112 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
113 | 132 | | |
114 | 133 | | |
115 | 134 | | |
116 | 135 | | |
117 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
118 | 144 | | |
119 | 145 | | |
120 | 146 | | |
| |||
154 | 180 | | |
155 | 181 | | |
156 | 182 | | |
157 | | - | |
158 | | - | |
159 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
160 | 222 | | |
161 | 223 | | |
162 | 224 | | |
163 | 225 | | |
164 | 226 | | |
165 | 227 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
173 | 233 | | |
174 | | - | |
175 | 234 | | |
176 | 235 | | |
177 | 236 | | |
| |||
181 | 240 | | |
182 | 241 | | |
183 | 242 | | |
| 243 | + | |
184 | 244 | | |
185 | 245 | | |
186 | 246 | | |
187 | 247 | | |
| 248 | + | |
188 | 249 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
195 | 253 | | |
196 | | - | |
197 | 254 | | |
| 255 | + | |
198 | 256 | | |
199 | 257 | | |
200 | 258 | | |
| |||
0 commit comments