Commit ed3c742
refactor: generalize ZMQ pub/sub over message type via MessageCodec (#300)
* refactor: generalize ZMQ pub/sub over message type via MessageCodec
Replace EventRecord-specific publisher/subscriber classes with generic
ZmqMessagePublisher[T] / ZmqMessageSubscriber[T] parameterized by a
MessageCodec[T] Protocol. EventRecordCodec preserves existing wire format
and decode-error wrapping behavior. Sets up the generic transport that
the upcoming MetricsSnapshot publisher will reuse.
- protocol.py: drop EventRecordPublisher/Subscriber ABCs; add MessageCodec,
MessagePublisher[T], MessageSubscriber[T].
- pubsub.py: rewrite as ZmqMessagePublisher[T]/ZmqMessageSubscriber[T];
expose sndhwm/linger/conflate so future callers (e.g. live snapshots)
can choose drop-old vs. delivery-guarantee semantics.
- record.py: add EventRecordCodec next to encode/decode helpers.
- Update EventPublisherService, EventLoggerService,
MetricsAggregatorService and tests to use the generic classes.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor: keep MessageSubscriber catch generic; narrow per-codec
Per Gemini review on PR #300: catching only msgspec.DecodeError in
MessageSubscriber._on_readable bakes the codec implementation into the
supposedly-generic base class. A future codec backed by json, pickle,
etc. raises different exception types and would bypass on_decode_error,
crashing the reader.
- protocol.py: widen the catch back to Exception so the base class makes
no assumption about which decoder library a codec uses; drop the now-
unused msgspec import.
- record.py: tighten EventRecordCodec.on_decode_error to wrap only
msgspec.DecodeError and re-raise other exceptions. Preserves the
previous behavior parity (only malformed-payload errors become
ErrorEventType.GENERIC records; programmer bugs in the decode path
still surface).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test: cover EventRecordCodec.on_decode_error branches
Address PR #300 review feedback: on_decode_error has two distinct
branches and neither was exercised. The re-raise branch in particular
is the behavior MessageSubscriber._on_readable relies on to surface
decode-path bugs — a non-DecodeError must propagate, otherwise it
escapes the asyncio reader callback and silently de-registers the
subscriber.
- test_wraps_msgspec_decode_error_into_generic_error_record: forces a
real msgspec.DecodeError through the codec's own decoder (not a
hand-constructed exception), then asserts on_decode_error returns
a wrapped EventRecord(ErrorEventType.GENERIC, ErrorData(...)).
- test_reraises_non_decode_error: passes a ValueError and asserts it
propagates unchanged.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 9ee015e commit ed3c742
10 files changed
Lines changed: 309 additions & 181 deletions
File tree
- src/inference_endpoint
- async_utils
- services
- event_logger
- metrics_aggregator
- transport
- zmq
- core
- load_generator
- tests/unit
- async_utils
- core
- transport
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | | - | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
47 | | - | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| 58 | + | |
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
| |||
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
55 | | - | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
72 | | - | |
| 73 | + | |
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
| |||
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
84 | | - | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| |||
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
102 | | - | |
| 103 | + | |
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
| |||
Lines changed: 98 additions & 93 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | | - | |
32 | 31 | | |
33 | 32 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
41 | 36 | | |
42 | 37 | | |
43 | 38 | | |
| |||
235 | 230 | | |
236 | 231 | | |
237 | 232 | | |
238 | | - | |
239 | | - | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
240 | 263 | | |
241 | 264 | | |
242 | 265 | | |
| 266 | + | |
243 | 267 | | |
244 | 268 | | |
245 | 269 | | |
246 | | - | |
| 270 | + | |
247 | 271 | | |
248 | 272 | | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
254 | 280 | | |
| 281 | + | |
255 | 282 | | |
256 | 283 | | |
257 | 284 | | |
258 | 285 | | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
| 286 | + | |
| 287 | + | |
265 | 288 | | |
266 | 289 | | |
267 | | - | |
268 | | - | |
| 290 | + | |
269 | 291 | | |
270 | 292 | | |
271 | 293 | | |
272 | 294 | | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
| 295 | + | |
| 296 | + | |
280 | 297 | | |
281 | 298 | | |
282 | 299 | | |
283 | 300 | | |
284 | 301 | | |
285 | | - | |
| 302 | + | |
286 | 303 | | |
287 | 304 | | |
288 | 305 | | |
| |||
291 | 308 | | |
292 | 309 | | |
293 | 310 | | |
294 | | - | |
| 311 | + | |
295 | 312 | | |
296 | 313 | | |
297 | | - | |
298 | | - | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
299 | 321 | | |
300 | 322 | | |
301 | 323 | | |
| 324 | + | |
302 | 325 | | |
303 | 326 | | |
304 | 327 | | |
305 | 328 | | |
306 | | - | |
| 329 | + | |
307 | 330 | | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
316 | 334 | | |
317 | 335 | | |
318 | | - | |
319 | | - | |
320 | | - | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
321 | 342 | | |
| 343 | + | |
322 | 344 | | |
323 | 345 | | |
324 | 346 | | |
| |||
328 | 350 | | |
329 | 351 | | |
330 | 352 | | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
| 353 | + | |
335 | 354 | | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
340 | 358 | | |
341 | | - | |
| 359 | + | |
342 | 360 | | |
343 | 361 | | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
351 | 366 | | |
352 | 367 | | |
353 | | - | |
354 | | - | |
355 | | - | |
| 368 | + | |
356 | 369 | | |
357 | 370 | | |
358 | 371 | | |
| |||
361 | 374 | | |
362 | 375 | | |
363 | 376 | | |
364 | | - | |
| 377 | + | |
365 | 378 | | |
366 | 379 | | |
367 | 380 | | |
368 | | - | |
| 381 | + | |
369 | 382 | | |
370 | 383 | | |
371 | 384 | | |
372 | 385 | | |
373 | 386 | | |
374 | | - | |
375 | | - | |
376 | 387 | | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
387 | 398 | | |
388 | | - | |
389 | 399 | | |
390 | 400 | | |
391 | | - | |
392 | | - | |
393 | | - | |
| 401 | + | |
| 402 | + | |
394 | 403 | | |
395 | 404 | | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
| 405 | + | |
401 | 406 | | |
402 | 407 | | |
403 | | - | |
404 | 408 | | |
405 | 409 | | |
406 | 410 | | |
| |||
410 | 414 | | |
411 | 415 | | |
412 | 416 | | |
413 | | - | |
414 | | - | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
415 | 420 | | |
0 commit comments