Commit c02e906
authored
RequestContextHTTPClient + Server implementation in local mode (#457)
RequestContextHTTPClient is a picklable RequestContext implementation
that provides
all RequestContext functionality in any Python thread and subprocess.
It exchanges small http requests with an HTTP Server which implements:
presigning of read/write blobs, commiting multipart uploads to blob
store,
adding request metrics, sending function progress updates. The BLOBs
are not sent to the Server. BLOB store client is directly invoked
by RequestContextHTTPClient.
User code can use RequestContextHTTPClient in a thread or subprocess by
passing the result of RequestContext.get()
as an argument when creating a Thread or Process. This usage scenario is
demonstrated
in the added tests.
When user passes RequestContextHTTPClient into a Thread the context is
passed by reference.
RequestContextHTTPClient is thread safe so this is okay. When user
passes RequestContextHTTPClient
into a Process, Python runtime pickles RequestContextHTTPClient and then
unpickles its clone
in the subprocess so the subprocess uses a clone of the original
RequestContextHTTPClient.
RequestContextHTTPClient has all the data required to reestablish http
connection to the
HTTP Server and tell the Server which allocation and request the http
requests are for.
This PR adds implementation of the HTTP Server in local mode.
Remote (FE) side HTTP Server implementation will be done in a
separate PR. New integration tests are covering all RequestContext
functionaility working correctly when accessed from a user function,
a thread and a subprocess.
Each LocalRunner (one per request) uses its own HTTP Server. Each
HTTP Server uses a unique ephemeral port where the LocalRunner
request's RequestContextHTTPClient connects to. So multiple local
runners
can exist at the same time without any problems.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Introduces a picklable RequestContext HTTP client/server for local
mode with thread/process support, refactors BLOB store and internal
logging, and updates FE/local runner and tests accordingly.
>
> - **Request Context (Local mode)**:
> - Add `RequestContextHTTPClient` (picklable, thread-safe) and
lightweight local HTTP server/router with handlers for `progress`,
`metrics`, and request state (`prepare_read`, `prepare_write`,
`commit_write`).
> - Local handlers print progress/metrics and serve file-backed BLOBs
for request state.
> - **BLOB Store**:
> - Introduce SDK `BLOB`/`BLOBChunk` pydantic models and `BLOBStore`
with local FS and S3 backends; parallel chunked `get/put` with
`InternalLogger`.
> - Remove old local blob store; add local `SerializedValueStore`
wrapper.
> - **Logging**:
> - Replace `FunctionExecutorLogger` with picklable `InternalLogger`;
unify usage across SDK/FE.
> - **Local Runner**:
> - Use per-request local HTTP server + `RequestContextHTTPClient`, new
value store, cleanup lifecycle; set multiprocessing start method via
`setup_multiprocessing`.
> - **Function Executor**:
> - Migrate to new `InternalLogger`/`BLOBStore`; add blob proto↔SDK
converters; validate progress attributes; minor proto doc tweak.
> - **Runtime hooks & multiprocessing**:
> - Add `_raise_multiprocessing_usage_error`; initialize spawn method;
improved SDK usage errors outside function threads.
> - **Cloud events**:
> - Move CloudEvents helpers under `applications` and update imports;
clarify JSON serialization errors.
> - **Tests**:
> - Add/adjust tests for blob store (local/S3), request context
(metrics/progress/state/request_id) in function, thread, and subprocess
scenarios; update benchmarks.
> - **Version**: bump to `0.2.89`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
e487a23. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 2781c43 commit c02e906
File tree
59 files changed
+2205
-522
lines changed- src/tensorlake
- applications
- blob_store
- interface
- local
- request_context
- handlers
- request_state
- request_context
- http_client
- http_server
- handlers
- request_state
- function_executor
- allocation_runner
- proto
- tests/applications
- blob_store
- exceptions
- request_context
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
59 files changed
+2205
-522
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
Lines changed: 31 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
6 | 7 | | |
7 | | - | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
| 31 | + | |
31 | 32 | | |
32 | | - | |
| 33 | + | |
33 | 34 | | |
| 35 | + | |
| 36 | + | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
| |||
40 | 43 | | |
41 | 44 | | |
42 | 45 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
47 | 57 | | |
48 | 58 | | |
49 | | - | |
50 | | - | |
51 | | - | |
| 59 | + | |
52 | 60 | | |
53 | 61 | | |
54 | 62 | | |
| |||
60 | 68 | | |
61 | 69 | | |
62 | 70 | | |
63 | | - | |
| 71 | + | |
64 | 72 | | |
65 | 73 | | |
66 | 74 | | |
| |||
110 | 118 | | |
111 | 119 | | |
112 | 120 | | |
113 | | - | |
| 121 | + | |
114 | 122 | | |
115 | 123 | | |
116 | 124 | | |
| |||
127 | 135 | | |
128 | 136 | | |
129 | 137 | | |
130 | | - | |
131 | | - | |
132 | | - | |
| 138 | + | |
133 | 139 | | |
134 | 140 | | |
135 | 141 | | |
| |||
150 | 156 | | |
151 | 157 | | |
152 | 158 | | |
153 | | - | |
154 | | - | |
| 159 | + | |
| 160 | + | |
155 | 161 | | |
156 | 162 | | |
157 | 163 | | |
158 | 164 | | |
159 | 165 | | |
160 | | - | |
| 166 | + | |
161 | 167 | | |
162 | 168 | | |
163 | 169 | | |
| |||
198 | 204 | | |
199 | 205 | | |
200 | 206 | | |
| 207 | + | |
201 | 208 | | |
202 | 209 | | |
203 | 210 | | |
| |||
206 | 213 | | |
207 | 214 | | |
208 | 215 | | |
209 | | - | |
210 | | - | |
| 216 | + | |
211 | 217 | | |
212 | 218 | | |
213 | 219 | | |
| |||
218 | 224 | | |
219 | 225 | | |
220 | 226 | | |
221 | | - | |
222 | | - | |
| 227 | + | |
| 228 | + | |
223 | 229 | | |
224 | 230 | | |
225 | 231 | | |
| |||
Lines changed: 4 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
| 6 | + | |
| 7 | + | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
| |||
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
19 | | - | |
| 18 | + | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
43 | | - | |
| 42 | + | |
44 | 43 | | |
45 | 44 | | |
46 | 45 | | |
| |||
Lines changed: 23 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | | - | |
9 | | - | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
| |||
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
38 | | - | |
| 37 | + | |
39 | 38 | | |
40 | 39 | | |
41 | 40 | | |
| |||
57 | 56 | | |
58 | 57 | | |
59 | 58 | | |
60 | | - | |
| 59 | + | |
61 | 60 | | |
62 | 61 | | |
63 | | - | |
| 62 | + | |
64 | 63 | | |
65 | 64 | | |
66 | 65 | | |
| |||
105 | 104 | | |
106 | 105 | | |
107 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
108 | 120 | | |
109 | 121 | | |
110 | | - | |
111 | | - | |
| 122 | + | |
| 123 | + | |
112 | 124 | | |
113 | 125 | | |
114 | 126 | | |
| |||
129 | 141 | | |
130 | 142 | | |
131 | 143 | | |
132 | | - | |
| 144 | + | |
133 | 145 | | |
134 | 146 | | |
135 | 147 | | |
| |||
152 | 164 | | |
153 | 165 | | |
154 | 166 | | |
155 | | - | |
| 167 | + | |
156 | 168 | | |
157 | 169 | | |
158 | | - | |
| 170 | + | |
159 | 171 | | |
160 | 172 | | |
161 | 173 | | |
| |||
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
59 | | - | |
| 61 | + | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
0 commit comments