Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Auto-compaction never fires for a custom (BYOK) model: context meter undercounts ~1.4× (657,843 shown vs 921,487 charged), so the session dies on 400s and cannot self-recover

オープン
#3,862 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
github
領域
ai, backend

調査の方向性

session events.jsonl の行 7523–7549 と、compactionThreshold、promptTokenLimit、bufferTokens、mcpTools に関する rpc.d.ts の生成された定義から始めます。報告されたコンテキストカウンターを、provider のエラーおよびランタイムの compaction チェックポイントと比較します。カスタム provider のセッションが、provider に大きすぎるリクエストを拒否される前に compaction を実行し、buffer のしきい値によって同じ失敗を防止できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Summary

With a custom (BYOK) provider whose tokenizer the app does not model, the local context
meter undercounts tokens by ~40%. Background compaction (trigger "threshold") and the
buffer-exhaustion blocking threshold both evaluate that undercounted number, so neither can
fire before the provider rejects the request. The session hard-fails with 400s until the user
runs /compact manually.

Environment

  • GitHub Copilot desktop app 1.1.20 (github.exe, %LOCALAPPDATA%\Programs\GitHub Copilot), Windows
  • Agent runtime: copilot 1.0.84-5 (%LOCALAPPDATA%\github-copilot-sdk\cli\1.0.84-5\copilot.exe)
  • Provider: custom DeepSeekauthKind: api_key, baseUrl: https://api.deepseek.com,
    wireApi: responses; model id deepseek-flash (provider id ab5a407d-9560-461f-9e02-a63c36bd4c08)
  • Model config: Max prompt tokens 840,000, Max output tokens 128,000,
    reasoning efforts none / low / high / max
  • MCP servers attached: aspire, github, microsoft-learn, nuget, playwright — all "tools": ["*"]
  • Session 53c1a09d-6bdc-407d-b133-b817e4dc0184, 2026-09-14T02:20:32Z → 2026-09-14T14:18:32Z
    (640 assistant turns, 998 tool executions, 18 images, 18 user messages, 86 autopilot objective changes)

Steps to reproduce

  1. Configure a custom provider whose model accepts 1,048,576 input tokens; set Max prompt
    tokens = 840,000 and Max output tokens = 128,000.
  2. Run one long agentic session (hundreds of turns with large tool outputs and several MCP servers).
  3. Compare the app's context meter with the token count the provider reports in its usage/error responses.

Expected

session.compaction_start with "trigger":"threshold" when the meter crosses the compaction
threshold (observed elsewhere at ~80% of tokenLimit; here that would be 672,000), well before
the provider limit — and no 400 "maximum context length" errors.

Actual

  • No threshold compaction ever fired during the 12-hour session. The only compaction is
    user-initiated: session.compaction_start … "trigger":"manual", timestamp
    2026-09-14T14:18:05.353Z (app log: command_name="compact" at 14:18:04.923Z).
  • At that moment the app's meter read:
    • systemTokens 15,768 + conversationTokens 590,768 + toolDefinitionsTokens 51,304
      = currentTokens 657,843, with tokenLimit 840,00078.3%
    • i.e. 14,157 tokens short of the ~80% (672,000) trip point — the trigger never came close.
  • DeepSeek counted the same conversation at 921,487 tokens. Two model calls failed:
    • 2026-09-14T08:25:35.172Z — 400 This model's maximum context length is 1048576 tokens. However, you requested 1049487 tokens (921487 in the messages, 128000 in the completion). Please reduce the length of the messages or completion.
    • 2026-09-14T08:26:11.368Z — same, 1050149 tokens (922149 in the messages, 128000 in the completion)
    • (8 records total, counting the errorOccurred / sessionEnd hook payloads and the runtime stack.)
  • Undercount factor: 921,487 / 657,843 = 1.400.
  • The manual compaction itself worked: messagesRemoved 1,322, tokensRemoved 572,553,
    590,771 → 18,218 — so compaction is functional; only the automatic trigger's input was wrong.

Control: threshold compaction works for hosted models

Ten sessions on hosted models auto-compacted correctly at ~80% of their limit, e.g.:

  • {"currentTokens":102931,"tokenLimit":128000,"trigger":"threshold"}
  • {"currentTokens":104691,"tokenLimit":128000,"trigger":"threshold"}
  • {"currentTokens":105120,"tokenLimit":128000,"trigger":"threshold"}

Range observed: 102,931–105,120 (80.4%–82.1% of 128,000). The trigger logic is fine; the token
input is wrong for the custom model.

Additional metadata mismatch

The session's model metadata carried max_context_window_tokens: 200000 while the endpoint
enforces 1,048,576 (per the provider's own error), alongside max_prompt_tokens: 840000,
max_output_tokens: 128000.

Impact

  • Background compaction and the buffer-exhaustion blocking threshold (documented default 95%,
    SessionContextInfo.bufferTokens) both operate on the undercounted number, so for BYOK models
    they cannot fire before the provider rejects the request.
  • The session cannot self-recover: retries repeat the same request and the same 400.
  • The context meter is misleading near the limit (~78% shown while the real request was already
    over the window once the 128,000 output reserve is counted).

Likely cause / suggested fixes

  • SessionContextAttribution documents that totals are "tokenized against the resolved model
    (feeds the per-model token multiplier)". For this custom model that multiplier does not match
    the provider's tokenizer.
  • Consider: calibrating the multiplier from provider-reported usage (the runtime already
    receives compactionTokensUsed.inputTokens, cacheReadTokens, etc.), applying a conservative
    safety factor for custom providers, and/or gating compaction on provider-reported input tokens.
  • Re-check attribution of tool/MCP schema mass: five MCP servers at "tools": ["*"] were credited
    only 51,304 tokens here, while the meter/actual gap is ~264,000 tokens.

Evidence

  • Session events: %USERPROFILE%\.copilot\session-state\53c1a09d-6bdc-407d-b133-b817e4dc0184\events.jsonl
    (lines 7523–7549: error events, session.compaction_start / session.compaction_complete)
  • Runtime log: %USERPROFILE%\.copilot\logs\process-1789352396024-130936.log
    (Persisted compaction checkpoint, Compacted conversation history {"messages_removed":1322,"tokens_removed":572553.0,"generation":1})
  • App log: %USERPROFILE%\.copilot\logs\github-app.138040.log (session command compact, 14:18:04.923Z)
  • Schema references: %LOCALAPPDATA%\Programs\GitHub Copilot\copilot-sdk\generated\rpc.d.ts
    (SessionContextInfo.compactionThreshold, promptTokenLimit, bufferTokens, categories.mcpTools)

Field Value
App version 1.1.20
OS Windows 10.0.26200
Theme GitHub
Path /chat
Tenure Week 15
主要言語
言語のデータがありません
スター
2.1k
フォーク
157
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

github/app のほかの issue

github/app の issue をすべて見る

似ている issue

AI Infra & Agents の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。