[Bug]: token usage rows always have model=NULL for local-runtime-v2 sessions (modelIdentity reads id, projected model carries model_id)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- sqlite, typescript
Hướng nghiên cứu
Đọc packages/local-runtime-v2/src/service/session-system/owner.ts quanh modelIdentity() và theo dõi cách kết quả của nó đi tới các hàng usage trong pi-usage.ts. Kiểm tra cấu trúc model được chiếu trong packages/local-runtime-v2/src/service/turn-system/agent-host/assembly-context.ts; issue xác định sự không khớp ở trường model_id. Xác nhận bản sửa bằng cách chạy luồng ghi nhận usage v2 và kiểm tra các hàng local_runtime_token_usage mới có chứa model.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Product or interface
Desktop app (also affects CLI TUI / headless / ACP — all paths that record usage through local-runtime-v2)
Version
Desktop 3.1.3 (macOS); source analysis at main 9a93560 (v0.6.5)
Platform
macOS
OS version and architecture
macOS 26 arm64
Issue area
Other (local usage ledger / local_runtime_token_usage)
Steps to reproduce
- Use MiniMax Code desktop 3.1.3 (or any build recording usage via
local-runtime-v2) for a normal coding session with a MiniMax model (e.g.minimax/MiniMax-M3.1-Flash). - Inspect
~/.minimax/v2/sqlite/runtime-state.sqlite:
SELECT model, count(*) FROM local_runtime_token_usage GROUP BY model;
-- after upgrading to 3.1.3: every new row has model = NULL
On my machine: 1314 rows written by the previous version all have model = 'minimax/MiniMax-M3'; all 7 rows written after the 3.1.3 upgrade have model = NULL (session layout v2-final-dated-session, so they went through the v2 runtime).
Expected and actual behavior
Expected: the model column records the model used for each turn (as the v1 runtime path did, and as the model column, the idx_local_runtime_token_usage_model_ts index, and the group=model query path in usage/repo/drizzle.ts all imply).
Actual: rows written by local-runtime-v2 always have model = NULL.
Downstream impact: every tool that reads this table for statistics (including the built-in summarizeGroupBy('model') API, which falls back to coalesce(model, 'unknown')) can only show "unknown" for new sessions. See also cc-switch #7705 where a third-party importer hits the same thing ("mcode session 用量导入模型恒为 unknown").
Root cause analysis (source at main 9a93560)
The v2 write chain feeds modelIdentity() a model object whose keys can never match:
packages/local-runtime-v2/src/service/turn-system/agent-host/assembly-context.ts—projectResolvedModel()returns{ provider, model_id: resolved.id, context_window, max_tokens, … }.MODEL_ALLOWLIST(lines 42–58) containsmodel_id/modelIdbut noidkey, so the projected object can never carryid.- That object flows to
executionModel(local-agent-host.ts:231) and then to the usage projector (committed-history-writer.ts:321→owner.ts:697). packages/local-runtime-v2/src/service/session-system/owner.ts:802-808—modelIdentity()readsReflect.get(model, 'id')only. With themodel_id-shaped object it always returnsnull, andpi-usage.tswritesmodel: nullintolocal_runtime_token_usage.
modelIdentity() matches the pi framework's Model shape ({ id, provider, … }, third_party/pi-mono/packages/ai/src/types.ts:593), which is why the compat layer's modelIdentity(turn.model) calls still produce correct provider/id strings. Only the v2 projected shape is broken — the same function consumes two shapes and one of them silently degrades to null.
Additional notes:
- Both files are unchanged since the initial import commit (c59cf53, 2026-09-18), so this is not a recent regression in the public history — it has been there since the first snapshot.
- The assistant messages themselves carry the model (e.g.
messages.jsonlentries have"model": "MiniMax-M3.1-Flash"keyed by the sameturnId), so a fallback atcommittedPiUsageRowswould also work.
Suggested fix (either or both)
// owner.ts
function modelIdentity(model: unknown): string | null {
if (!model || typeof model !== 'object') return null;
const provider = Reflect.get(model, 'provider');
const id = Reflect.get(model, 'id') ?? Reflect.get(model, 'model_id') ?? Reflect.get(model, 'modelId');
if (typeof provider === 'string' && typeof id === 'string') return `${provider}/${id}`;
return typeof id === 'string' ? id : null;
}
or in pi-usage.ts committedPiUsageRows: fall back to the assistant message's own model field when input.model is null.
Before submitting
- I have searched existing issues.
- I have included my version and removed sensitive information.
- Ngôn ngữ chính
- TypeScript
- Star
- 2k
- Fork
- 259
- Merge trung bình
- 10 giờ 38 phút
- Pull request đã merge (30 ngày)
- 88
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của MiniMax-AI/minimax-code
-
bug needs-triage tui
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
MiniMax-AI/minimax-code#481 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug cli documentation needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
MiniMax-AI/minimax-code#299 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
MiniMax-AI/minimax-code#521 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
MiniMax-AI/minimax-code#520 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
desktop
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
MiniMax-AI/minimax-code#519 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của MiniMax-AI/minimax-code
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
cursor/community-plugins#465 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
vetro-protocol/vetro-monorepo#978 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ai-generated bug category:security effort:s priority:p3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
LanternOps/breeze#9697 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
maniator/verticopolis#1303 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
components-web-app/docs#297 ·