Commit a6b6f26
authored
Implement wire-byte stability (proposal 0047) (#145)
* Implement wire-byte stability (proposal 0047)
Add intra-impl wire-byte stability to the OpenAI provider so
equivalent OA inputs produce byte-identical wire output regardless
of dict insertion order. A new ``_canonicalize_dict_keys`` helper
recursively sorts dict keys at every nesting level while preserving
caller-supplied array ordering (the spec's split: object keys are
sorted, array order is caller-controlled).
The helper applies at four user-supplied-dict boundaries: tool
definitions (the ``function`` record top-level plus the parameters
JSON Schema), ``response_format.json_schema.schema``, RuntimeConfig
extras, and the JSON encoding of ``tool_call.arguments``. A top-
level belt-and-suspenders pass over the assembled body catches
anything the per-field passes miss.
Closes proposal 0047 end-to-end: pieces 1 and 2 (Response.usage
cache fields sourced from prompt_tokens_details + OTel observer
emits the cache attributes) landed in v0.12.0; this is piece 3.
Prompt-management §13 cross-variable substring stability is
satisfied by the existing Jinja2 strict-undefined render path on
both TextPrompt and ChatPrompt; pinned by new tests.
A new ``docs/concepts/prompts.md`` section explains APC, what OA
handles for users (wire-byte canonicalization, deterministic
rendering), what users own (the spec's five informative authoring
patterns), and a vLLM debugging callout for the cache-attribute-
not-appearing case (server-side ``--enable-prefix-caching`` plus
``--enable-prompt-tokens-details``).
Scope is the Chat Completions endpoint only. The OpenAI Responses
API endpoint and the Anthropic / Gemini wire-format mappings are
deferred (no python consumer today).
Behavior change worth flagging: ``tool_call.arguments`` JSON
encoding now uses ``sort_keys=True``. Functionally equivalent
(parses to the same dict) but byte-different from the previous
insertion-order encoding.
* Address PR 145 review
Two dead-pointer fixes flagged by CoPilot, both review-round-rename
casualties:
1. CHANGELOG entry referenced ``_canonicalize_json_schema``; the
helper was renamed to ``_canonicalize_dict_keys`` because it
canonicalizes every user-supplied dict on the wire, not just
JSON Schemas.
2. ``conformance.toml`` 0047 leading-comment block pointed at
``test_cross_variable_substring_stability``; that test got
split into ``..._text_prompt`` and ``..._chat_prompt`` when
coverage extended to the ChatPrompt variant.1 parent d2d387a commit a6b6f26
6 files changed
Lines changed: 683 additions & 16 deletions
File tree
- docs/concepts
- src/openarmature/llm/providers
- tests/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
269 | | - | |
270 | | - | |
271 | | - | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
272 | 296 | | |
273 | | - | |
| 297 | + | |
| 298 | + | |
274 | 299 | | |
275 | 300 | | |
276 | 301 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
368 | 435 | | |
369 | 436 | | |
370 | 437 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
714 | 714 | | |
715 | 715 | | |
716 | 716 | | |
717 | | - | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
718 | 721 | | |
719 | 722 | | |
720 | | - | |
| 723 | + | |
721 | 724 | | |
722 | 725 | | |
723 | 726 | | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
724 | 730 | | |
725 | 731 | | |
726 | 732 | | |
727 | 733 | | |
728 | | - | |
| 734 | + | |
729 | 735 | | |
730 | 736 | | |
731 | 737 | | |
| |||
752 | 758 | | |
753 | 759 | | |
754 | 760 | | |
755 | | - | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
756 | 767 | | |
757 | 768 | | |
758 | 769 | | |
| |||
1132 | 1143 | | |
1133 | 1144 | | |
1134 | 1145 | | |
1135 | | - | |
1136 | | - | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
1137 | 1151 | | |
1138 | 1152 | | |
1139 | 1153 | | |
| |||
1169 | 1183 | | |
1170 | 1184 | | |
1171 | 1185 | | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
1172 | 1221 | | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
1173 | 1226 | | |
1174 | 1227 | | |
1175 | | - | |
1176 | | - | |
1177 | | - | |
1178 | | - | |
1179 | | - | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
1180 | 1235 | | |
1181 | 1236 | | |
1182 | 1237 | | |
| |||
0 commit comments