Commit 9618889
committed
feat(http): outbound HTTP capability gateway with enforced deadlines
Zig 0.15's std.http.Client.fetch has no timeout and owns its socket, so a
hung VeriSimDB/Steam/Groove endpoint blocked the calling thread forever and
the STEAM_API_TIMEOUT_MS / GROOVE_TIMEOUT_MS constants were inert.
Following the estate's http-capability-gateway direction ("HTTP verbs/routes
become declared capabilities, not accidents" — one policy-driven mediation
layer), this applies the same idea to GSA's OUTBOUND calls. New
src/interface/ffi/src/http_capability.zig is the ONLY caller of fetch in the
FFI layer; every call site declares an OutboundCapability (verb, host_allow,
deadline_ms, purpose/narrative, label, trust — names mirror the gateway DSL)
and call() enforces a host allow-list (default-deny) and a hard wall-clock
deadline.
Deadline mechanism (fetch cannot be cancelled): a worker thread runs the
opaque fetch; the caller waits on std.Thread.Semaphore.timedWait(deadline).
This bounds the caller uniformly for plain HTTP and TLS (Steam) alike, since
it sits above fetch. Ownership is a 2-count refcount on a shared RequestBox
backed by c_allocator (malloc — thread-safe, process-lifetime), so a worker
that outlives a timed-out caller never touches a transient allocator; the
last releaser frees, with no write-after-free and no leak. A bounded
MAX_OUTSTANDING worker cap fails fast (Backpressure) rather than piling up
blocked threads — the client-side echo of the gateway's circuit breaker.
- verisimdb/steam/groove clients: all four fetch sites collapse to one call();
their http.Client fields are removed (the worker owns a fresh client). The
three timeout constants (+ new VERISIMDB_TIMEOUT_MS) are now load-bearing.
A deadline hit maps to probe_timeout; other failures keep their codes. No
new GsaResult variant, so no Types.idr/ABI regen.
- MockHTTP added to the harness (respond_ok / never_respond / slow_respond);
its teardown closes held sockets so abandoned workers unblock and drain
(http_capability.waitQuiescent) before the leak check.
- 5 behavioral tests: hung endpoint returns within the deadline (not forever),
happy-path body, slow-respond passes/fails by deadline, default-deny without
a socket, host-allow matching. 167 tests green across six suites + 104 fuzz.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TaWWedv6VQqeZaPvc94keN1 parent 309accc commit 9618889
7 files changed
Lines changed: 653 additions & 99 deletions
File tree
- src/interface/ffi
- src
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 44 | + | |
| 45 | + | |
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
| |||
177 | 176 | | |
178 | 177 | | |
179 | 178 | | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | | - | |
| 194 | + | |
195 | 195 | | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
| 196 | + | |
204 | 197 | | |
205 | 198 | | |
206 | 199 | | |
| |||
214 | 207 | | |
215 | 208 | | |
216 | 209 | | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
228 | 222 | | |
229 | 223 | | |
230 | 224 | | |
231 | 225 | | |
232 | 226 | | |
233 | | - | |
| 227 | + | |
234 | 228 | | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
| 229 | + | |
243 | 230 | | |
244 | 231 | | |
245 | 232 | | |
| |||
0 commit comments