Agent host: BYOK Chat Completions adapter records cached input tokens as zero in Copilot session history

Đang mở Phù hợp với người mới
#349,634 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
62/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
ollama, typescript
Lĩnh vực
api

Hướng nghiên cứu

Lỗi nằm ở bộ chuyển đổi BYOK Chat Completions trong bundle agent-host đã cài đặt agentHostMain.js, nơi đối tượng usage theo định dạng Responses đặt input_tokens_details.cached_tokens thành số 0 cố định. Bắt đầu bằng việc tìm chỗ bộ chuyển đổi ánh xạ prompt_tokens_details.cached_tokens từ chunk usage cuối cùng vào đối tượng đó. Hoàn thành khi số lượng cache do nhà cung cấp trả về được giữ nguyên trong cacheReadTokens, được xác minh bằng một test hồi quy với chunk usage cuối cùng tổng hợp có số lượng cache khác 0.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Description

On VS Code 1.147.0 (macOS), a custom OpenAI-compatible Chat Completions endpoint reported a cache hit, but Copilot session history recorded cacheReadTokens: 0. The input and output counts matched for the same request:

Source Input tokens Output tokens Cached input tokens
Endpoint (Ollama) 39,228 144 30,592
Copilot session history 39,228 144 0
Steps to reproduce
  1. Configure a custom OpenAI-compatible Chat Completions model in VS Code and use it in a Copilot agent-host session.
  2. Send a streaming request with usage reporting enabled. Use a provider or mock that returns a known nonzero usage.prompt_tokens_details.cached_tokens value in the final usage chunk.
  3. Compare that value with data.usage.cacheReadTokens in the saved session.usage_record for the same call.

Expected: A provider-reported value of 30592 is saved as cacheReadTokens: 30592.

Actual: The saved value is 0. This is not just a display issue: the zero is present in the session record itself.

Likely fix and regression test

In the installed agent-host bundle (agentHostMain.js), the BYOK adapter constructs a Responses-format usage object. It copies the input and output counts but sets input_tokens_details.cached_tokens to a literal 0.

Please preserve the provider’s cached-token count through that conversion. A regression test using a synthetic final usage chunk with a nonzero cache count would verify the fix without requiring a live provider or relying on a real cache hit.

Ngôn ngữ chính
TypeScript
Star
196k
Fork
43.9k
Merge trung bình
12 giờ 49 phút
Pull request đã merge (30 ngày)
682

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/vscode

Tất cả issue của microsoft/vscode

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.