You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit bed36d8
Browse filesBrowse the repository at this point in the historyBrowse files
fix(api,cost): hash long cache keys, clamp TTL splits, harden the TTL specs
What:
- openai-native: hash over-long task ids with sha256 hex instead of slicing to
64 chars. A slice drops the distinguishing tail, so two ids sharing a 64-char
prefix collapsed into one routing bucket. sha256 hex is exactly 64 chars, so
the result still fits OpenAI's cap.
- openai-native: clamp the 12h write subset at zero as well as at the write
total. A negative `ttl_12h_tokens` from a misbehaving gateway used to reach
the Task accumulator and the webview as a negative count.
- cost: cap the 1h and 12h write subsets at the remaining aggregate write total.
A malformed split (1h + 12h > total) billed the excess; 150k reported 1h
writes against a 100k total cost 0.9 instead of 0.6.
- Task.spec: replace the fixed 50ms sleep with `vi.waitFor` on the captured
telemetry call. The drain is fire-and-forget and touches the filesystem, so a
fixed sleep races it on a loaded worker.
- vercel-ai-gateway.spec: assert the TTL argument of the `addCacheBreakpoints`
mock call. The transform is file-mocked, so `JSON.stringify(mockCreate)` can
never contain `cache_control` and the old assertion could not fail.
- ttl.spec: compare raw `JSON.stringify` output against literal expected strings
in the byte-identical test. `toEqual` on round-tripped objects ignores key
insertion order, so a key reorder passed while the wire bytes changed.
Why:
Seven CodeRabbit "Minor" threads on the C5a/C5b stack. Three are production
correctness (cache-key collision, negative token count, overbilled split); three
are assertions that could not fail. The seventh thread's premise, forwarding the
TTL split into the telemetry recompute, already landed in b647ec7.
Impact:
Long task ids keep distinct cache buckets; malformed TTL splits can no longer
over- or under-bill or leak negative counts. No request shape changes for the
default path: the aggregate-only case still derives both subsets as zero.
// Compare the raw serialized bytes, not parsed objects: `toEqual` ignores key
120
+
// insertion order, so a transform that reorders request keys would pass while
121
+
// the bytes on the wire changed. The expected strings are literals for the
122
+
// same reason: building them from the same helper would re-derive the order.
123
+
expect(JSON.stringify(anthropicMessages)).toBe(
124
+
'[{"role":"system","content":[{"type":"text","text":"You are a helpful assistant.","cache_control":{"type":"ephemeral"}}]},{"role":"user","content":[{"type":"text","text":"First message","cache_control":{"type":"ephemeral"}}]},{"role":"assistant","content":"First response"},{"role":"user","content":[{"type":"text","text":"Second message","cache_control":{"type":"ephemeral"}}]}]',
'[{"role":"system","content":"You are a helpful assistant.","cache_control":{"type":"ephemeral"}},{"role":"user","content":[{"type":"text","text":"First message","cache_control":{"type":"ephemeral"}}]},{"role":"assistant","content":"First response"},{"role":"user","content":[{"type":"text","text":"Second message","cache_control":{"type":"ephemeral"}}]}]',
0 commit comments