qwen-code/packages
易良 3fd059368b
fix(core): invalidate token counts recorded for a switched model route (#9506)
* fix(core): invalidate token counts recorded for a switched model route

`/model` switches rebuild the content generator but keep the same
GeminiChat instance, so API-reported prompt/output token counts from the
previous route survived and anchored admission, output clamping, and
compression decisions for a different serialization (#9454).

Attribute the counts to the route that produced them
(Config.getModelRouteIdentity) and invalidate them on a route change so
all safety decisions fall back to the history-walk estimate.

Closes #9454

* fix(core): keep token counts scoped to producing route

* fix(core): close round-2 route-scoping findings (#9454)

- C1: client.test.ts session-token-limit gate test now seeds the chat
  mock's getLastPromptTokenCount (the gate's new source) instead of
  relying on the telemetry stub alone.
- C2: goal-turn-integration.test.ts passes the routeKey positional
  added to processStreamResponse and widens the local cast.
- S1: fix stale rationale comment — no session token-limit gate reads
  the telemetry mirror anymore; UI context counters and compression
  banners do.
- S2: pin tryCompress's entry invalidation with a focused test; manual
  /compress reaches it without sendMessageStream's entry reset.
- S3: direct config tests for getModelRouteIdentity — call stability,
  model@<sha-prefix> shape, and the guard keeping the registry baseUrl
  out of non-active model identities.
- R2-3: sendMessageStream now resolves the request route first and
  invalidates counts against IT (deriving the key from the actual model
  param on the non-exact branch), so an active-route count can no longer
  anchor an exact `\0` route's output clamp; regression test added.

* fix(core): close round-3 route-scoping findings (#9454)

- R3-1: hard-rescue rollback now restores tokenCountsRouteKey alongside the counts; tryCompress re-stamps the key to the active route mid-rescue, which left the resurrected request-route count riding the active key past the next entry invalidation (regression test: active-route read after failed rescue must not inherit the override count).

- R3-2(2): invalidation zeroes the telemetry cached-content mirror together with the prompt mirror so /context stops rendering a foreign cached count beside a zeroed prompt count; the mirror is documented as best-effort display state between a switch and the next guarded read (R3-2(1)).

- R3-4: collapse the requestRouteKey ternary into one getModelRouteIdentity call (the non-exact arm passed exactly the default parameter value).

- R3-5: resolve the active-route default lazily after the zero-count fast path instead of eagerly in the default parameter.

- R1-3: add the missing compressFast route-invalidation test (third entrypoint; mutation-verified).

* fix(core): preserve route-scoped token guards (#9454)

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

* fix(core): resolve full-turn route selectors at the session token limit gate (#9454)

* fix(core): stamp fallback-served token counts under the request route (#9454)

* fix(core): retain route-scoped token counts across route crossings (#9454)

* fix(core): keep route-scoped token counts consistent through compression (#9454)

* fix(core): keep rescued output counts and compression stamps route-scoped (#9454)

---------

Co-authored-by: yiliang114 <yiliang114@users.noreply.github.com>
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-08-24 05:00:16 +00:00
..
acp-bridge fix(web-shell): show reasoning effort before session creation (#9599) 2026-08-23 19:11:19 +00:00
audio-capture chore(release): v0.22.0 (#9736) 2026-08-22 15:23:02 +00:00
channels fix(dingtalk): parse forwarded chat records (#9339) 2026-08-23 18:21:41 +00:00
chrome-extension chore(release): v0.22.0 (#9736) 2026-08-22 15:23:02 +00:00
cli fix(cli): skip terminal redraw optimizer on WSL/ConPTY (#7897) 2026-08-24 03:58:48 +00:00
core fix(core): invalidate token counts recorded for a switched model route (#9506) 2026-08-24 05:00:16 +00:00
cua-driver feat(cua-driver): add versioned Computer Use SDK and release pipeline (#9587) 2026-08-23 14:20:14 +00:00
desktop feat(mcp): add MCP 2026 core and WebShell Apps host (#8992) 2026-08-23 18:34:30 +00:00
desktop-shell feat: consolidate Local Control into one daemon-owned implementation (#9106) 2026-08-17 16:44:48 +00:00
mobile-mcp chore(deps): Clear high-severity CVE baseline and harden the security gate (#9584) 2026-08-21 07:43:32 +00:00
node-repl refactor(node-repl)!: deliver the persistent Node REPL as a standalone MCP server (#9499) 2026-08-23 14:20:39 +00:00
sdk-java feat(mcp): add MCP 2026 core and WebShell Apps host (#8992) 2026-08-23 18:34:30 +00:00
sdk-python fix(sdk): support "auto" permission mode (#9003) 2026-08-22 14:25:40 +00:00
sdk-typescript fix(web-shell): show reasoning effort before session creation (#9599) 2026-08-23 19:11:19 +00:00
vscode-ide-companion fix(vscode): preserve Windows file links in session exports (#8953) 2026-08-24 01:59:32 +00:00
web-shell feat(web-shell): expose agent task changes (#9637) 2026-08-24 03:54:49 +00:00
web-templates chore(release): v0.22.0 (#9736) 2026-08-22 15:23:02 +00:00
webui feat(scheduled-tasks): allow creating a task with an existing session (#9361) 2026-08-24 02:23:45 +00:00
zed-extension