Commit 77467e1
Codec: address PR review — async dispatch, cached registry, hardened varint
Mirrors the sglang fork PR fixes (sgl-project/sglang#25544):
1. codec_frame.py: numpy-free LE-uint32 unpack now uses
`struct.unpack('<NI', b)` (~10× faster than the per-element
list comprehension) and rejects buffers whose length is not a
multiple of 4 instead of silently corrupting.
2. codec_frame.py: `_decode_varint` gains bounds-check +
shift-cap (35 bits = 5 bytes, the max uint32 varint width).
Used by every length-delimited field decode including the
packed `prompt_ids` loop. Malformed or malicious input fails
fast with a clear ValueError instead of looping unbounded.
3. codec_dispatcher.py: add `dispatch_call_async`, a
`asyncio.to_thread`-wrapping variant of `dispatch_call`. The
sync form does a blocking `urllib.request.urlopen` POST that
would freeze the event loop if called from an `async def`
request handler.
4. openai/chat_completion/serving.py: cache the `ToolRegistry`
on `OpenAIServingChat` rather than calling
`ToolRegistry.from_env` per request. `from_env` performs
blocking HTTP fetches against manifest URLs; the first request
after process start pays the cost (off-loop via
`asyncio.to_thread`) and every subsequent request reuses the
cached registry. Same site now uses `dispatch_call_async` so
tool dispatches don't block the worker either.
Wire format unchanged. No new dependencies.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: William Dunn <wdunn001@gmail.com>1 parent 509e9b7 commit 77467e1
3 files changed
Lines changed: 75 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
200 | | - | |
201 | | - | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
202 | 205 | | |
203 | 206 | | |
204 | 207 | | |
| |||
218 | 221 | | |
219 | 222 | | |
220 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
221 | 242 | | |
222 | 243 | | |
223 | 244 | | |
| |||
244 | 265 | | |
245 | 266 | | |
246 | 267 | | |
| 268 | + | |
247 | 269 | | |
248 | 270 | | |
249 | 271 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
66 | 69 | | |
67 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
68 | 75 | | |
69 | 76 | | |
70 | 77 | | |
| |||
121 | 128 | | |
122 | 129 | | |
123 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
124 | 139 | | |
125 | 140 | | |
| 141 | + | |
| 142 | + | |
126 | 143 | | |
127 | 144 | | |
128 | 145 | | |
129 | 146 | | |
130 | 147 | | |
131 | 148 | | |
| 149 | + | |
| 150 | + | |
132 | 151 | | |
133 | 152 | | |
134 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
188 | 189 | | |
189 | 190 | | |
190 | 191 | | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
191 | 201 | | |
192 | 202 | | |
193 | 203 | | |
| |||
1081 | 1091 | | |
1082 | 1092 | | |
1083 | 1093 | | |
1084 | | - | |
1085 | | - | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
1086 | 1107 | | |
1087 | 1108 | | |
1088 | 1109 | | |
| |||
1119 | 1140 | | |
1120 | 1141 | | |
1121 | 1142 | | |
1122 | | - | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
1123 | 1151 | | |
1124 | 1152 | | |
1125 | 1153 | | |
| |||
0 commit comments