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
まだ誰も着手していません。
評価
調査の方向性
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 DeepSeek —
authKind: api_key,baseUrl: https://api.deepseek.com,
wireApi: responses; model iddeepseek-flash(provider idab5a407d-9560-461f-9e02-a63c36bd4c08) - Model config: Max prompt tokens 840,000, Max output tokens 128,000,
reasoning effortsnone / 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
- Configure a custom provider whose model accepts 1,048,576 input tokens; set Max prompt
tokens = 840,000 and Max output tokens = 128,000. - Run one long agentic session (hundreds of turns with large tool outputs and several MCP servers).
- 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:
systemTokens15,768 +conversationTokens590,768 +toolDefinitionsTokens51,304
=currentTokens657,843, withtokenLimit840,000 → 78.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/sessionEndhook payloads and the runtime stack.)
- 2026-09-14T08:25:35.172Z —
- Undercount factor: 921,487 / 657,843 = 1.400.
- The manual compaction itself worked:
messagesRemoved1,322,tokensRemoved572,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
SessionContextAttributiondocuments 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
receivescompactionTokensUsed.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 commandcompact, 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 はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
github/app のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix impact:other issue-rating: 🌊 off-meta tidepool no-stale P2
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
0xPlaygrounds/rig#2584 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
danielmiessler/LifeOS#2232 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
datalayer/mcp-compose#42 ·