Commit 45ff723
authored
Adopt 0093 nullable provider usage records (#218)
* Adopt 0093 nullable provider usage records
Proposal 0093 gives OA one model for "the provider reported no usage"
across both retrieval responses and both typed events: no usage yields
usage = null, never a fabricated record, zero, or estimate.
The response types and both observers were already correct. The gap was
OpenAIEmbeddingProvider, which recorded EmbeddingUsage(input_tokens=0)
when the usage block was absent or malformed. A zero asserts "zero
tokens billed", a claim the provider never made. It now surfaces
usage = null; a reported zero still yields a record carrying 0.
Reviewing that diff surfaced a second, unrelated defect. Proposal 0092
requires every capped embedding mapping to chunk-and-stitch and names
OpenAI's 2048-input cap, but the 0092 implementation adopted the shared
helper for TEI and Cohere only. An over-2048 embed call sent one
over-cap request the wire rejects, breaking the arbitrary-length input
contract. OpenAI now chunks at 2048. Conformance stayed green because
the spec ships no over-cap fixture for that mapping; tracked. The shared
helper now takes the response identity (id and model) from the first
chunk, so OpenAI keeps reporting the provider-returned model while the
wires that carry none fall back to the bound identifier.
A missing usage figure and a corrupt one were both swallowed silently,
so a gateway sending garbage looked identical to a healthy no-usage
call. The shared nonneg_int reader now logs a warning when a figure is
present but not a non-negative int, while an absent figure stays quiet.
nonneg_int lifts into _wire.py and is adopted by OpenAI, Cohere, and
Jina.
Un-defers observability fixtures 139 and 140. Fixture 143 stays
deferred behind the unimplemented section 11 embedding-metrics path,
not behind anything in 0093.
* Harden 0093 chunk stitching per review
Follow-up to the adversarial and CoPilot review of the 0093 PR.
Usage accounting in chunk_and_stitch_embed is now all-or-nothing: a
total is reported only when EVERY chunk reports a figure. A chunk that
omits usage (absent or corrupt) makes the whole-call total null rather
than a partial sum, which would present a confident undercount and
diverge from the single-request path (which returns null for the same
unaccountable figure). Behaviorally invisible for the reference
providers (hosted OpenAI and Cohere report on every chunk; TEI never
reports), it only changes the unspecified mixed case an inconsistent
gateway could produce. A new unit test pins it and fails under the old
partial-sum logic.
An empty-string wire model or id from an OpenAI-compatible backend now
reads as absent (None) rather than surfacing as "", so the stitch falls
back to the bound model identifier per §4.
Documents that a chunked embed is non-atomic: a mid-call failure may
leave earlier chunks billed by the provider with no usage event, since
there is no rollback over a non-transactional wire.
Corrects the Cohere chunk-closure comment to the 5-tuple return shape
(model always null for Cohere), and notes the per-chunk warning
multiplicity is accepted.
* Correct 0092 note to all-or-nothing usage rule
The conformance note described the pre-hardening per-chunk usage
semantics (sum when reported, else null). chunk_and_stitch_embed now
combines usage all-or-nothing: it sums only when every chunk reports a
figure, and a mixed report yields usage = null rather than a partial
sum. Bring the note in line with the code.
* Close provider in try/finally in usage tests
The nullable-usage unit tests closed the provider after the assertions,
so a failing assert would skip aclose() and leak the httpx client.
Wrap embed() in try/finally to match the sibling tests.1 parent af228ad commit 45ff723
8 files changed
Lines changed: 484 additions & 131 deletions
File tree
- src/openarmature/retrieval
- providers
- tests
- conformance
- unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
887 | 887 | | |
888 | 888 | | |
889 | 889 | | |
890 | | - | |
| 890 | + | |
891 | 891 | | |
892 | 892 | | |
893 | 893 | | |
894 | 894 | | |
895 | | - | |
896 | | - | |
897 | | - | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
898 | 898 | | |
899 | | - | |
| 899 | + | |
900 | 900 | | |
901 | | - | |
| 901 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
21 | 66 | | |
22 | 67 | | |
23 | 68 | | |
| |||
94 | 139 | | |
95 | 140 | | |
96 | 141 | | |
97 | | - | |
98 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
99 | 145 | | |
100 | 146 | | |
101 | 147 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
106 | 157 | | |
107 | 158 | | |
108 | 159 | | |
109 | 160 | | |
110 | 161 | | |
111 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
112 | 166 | | |
113 | 167 | | |
114 | 168 | | |
115 | 169 | | |
116 | | - | |
117 | | - | |
118 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
119 | 180 | | |
120 | 181 | | |
121 | 182 | | |
| |||
130 | 191 | | |
131 | 192 | | |
132 | 193 | | |
133 | | - | |
| 194 | + | |
| 195 | + | |
134 | 196 | | |
| 197 | + | |
135 | 198 | | |
136 | 199 | | |
137 | | - | |
| 200 | + | |
138 | 201 | | |
139 | 202 | | |
140 | 203 | | |
| |||
145 | 208 | | |
146 | 209 | | |
147 | 210 | | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
148 | 214 | | |
149 | 215 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
155 | 230 | | |
156 | 231 | | |
157 | 232 | | |
158 | | - | |
| 233 | + | |
159 | 234 | | |
160 | 235 | | |
161 | 236 | | |
162 | 237 | | |
163 | 238 | | |
164 | 239 | | |
165 | | - | |
| 240 | + | |
166 | 241 | | |
167 | 242 | | |
168 | 243 | | |
| |||
200 | 275 | | |
201 | 276 | | |
202 | 277 | | |
| 278 | + | |
203 | 279 | | |
204 | 280 | | |
0 commit comments