feat: add trustworthy model-level token controls - #1
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 09593568a5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| total = addBuckets(total, usage, 1) | ||
| adjustModel(models, route, usage, 1, 'assistant') | ||
| adjustDay(days, day, usage, 1) | ||
| adjustModelDay(modelDays, route, day, usage, 1) |
There was a problem hiding this comment.
Reattribute identical samples when their UTC day changes
When an assistant/chunk usage sample arrives just before UTC midnight and the final assistant/message arrives afterward with the same route and bucket values, the existing equality fast path returns before this new adjustModelDay call. The newly exported date-by-model record therefore remains on the earlier day, and the conservation checks still accept it because the ordinary daily record is stale in exactly the same way. Include the day in the equality check so the final event moves both aggregates to its authoritative reporting date.
Useful? React with 👍 / 👎.
| const configurableModels = useMemo( | ||
| () => models.filter(model => !isUnattributed(model) && totalTokens(model.usage) > 0), | ||
| [models], |
There was a problem hiding this comment.
Exclude fallback identities from exact-route controls
For assistant usage recorded before any request route is available, assistantRoute stores the fallback identity unknown/unknown; isUnattributed only recognizes the empty-string legacy fallback, so this filter exposes unknown/unknown as a configurable exact provider/model budget (and the analogous trend filter exposes it as an exact model). Such a budget pools unattributed calls rather than controlling a real route and can report a misleading healthy or exceeded state. Treat the projection's fallback identity as unattributed or otherwise require an authoritative route before offering these controls.
Useful? React with 👍 / 👎.
|
@codex address the two unresolved review threads and update this PR branch. Please make the fixes narrowly and add regression coverage:
|
|
To use Codex here, create an environment for this repo. |
|
@codex address that feedback 请同时补充两类回归测试:
|
|
To use Codex here, create an environment for this repo. |
Summary
Verification
..\deepseek-harness\node_modules\.bin\vitest.cmd run— 19 files, 116 tests passedtsc --noEmit— passedtsdown --config tsdown.config.ts— host/client bundles builtgit diff --checkandgit diff --cached --check— passednpm pack --dry-run --json— 0.2.0 payload validatedNotes
dsh-token-usage/export-v3.