fix(web): keep context usage live on the v2 engine#1601
Conversation
The v2 server's v1-compatible status bridge reported the measured-only context token count, which reads 0 until the first model response of a session completes; v1 reports the live (measured + estimated) size. The web client then compounded this by replacing cached sessions with wire records whose usage is an all-zero placeholder on snapshot syncs and session-list reloads. - kap-server legacyStatus: report max(live size, measured) and watch context-append Ops so the status line moves as soon as a prompt lands - kimi-web: preserve the accumulated live usage when an incoming session record carries the placeholder (snapshot sync + list reloads)
🦋 Changeset detectedLatest commit: 056717d The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 830cdfb08e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // The wire session's usage is a placeholder (both engines return zeros | ||
| // for the heavy fields); keep the live usage folded in from /status and | ||
| // the WS status stream instead of zeroing it on every snapshot sync. | ||
| usage: isPlaceholderSessionUsage(snap.session.usage) ? s.usage : snap.session.usage, |
There was a problem hiding this comment.
Refresh status when preserving placeholder snapshots
When syncSessionFromSnapshot is invoked from the WS resync path (onResync/snapshotSyncRunner) rather than through selectSession, the cached s.usage can be the stale value precisely because the volatile status frames were missed. Since the snapshot's session usage is the all-zero placeholder, this line keeps that stale usage and the resync path does not run the sidecar status refresh that selectSession runs after snapshots; after a reconnect/buffer overflow following a turn, compaction, or undo with no later status event, the context ring can remain at the pre-resync value indefinitely. Please refresh /status (or otherwise fetch live usage) when preserving placeholder usage on resync paths.
Useful? React with 👍 / 👎.
…r usage The resync and stale-socket recovery paths reach syncSessionFromSnapshot without selectSession's sidecar refresh, and the volatile status frames that would update usage are exactly what the resync replaced. Re-read /status after applying a snapshot whose usage is the all-zero placeholder so a preserved-but-stale reading converges on the live value.
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Related Issue
No linked issue — the problem is explained below.
Problem
On the web UI connected to the v2 engine (kap-server), the composer's context usage indicator stays at 0:
agent.status.updatedbridge reported the measured-only context token count, which is 0 until the first model response completes (v1 reports the live measured + estimated size, so it grows from the first request).What changed
packages/kap-server(legacyStatus bridge): reportmax(live measured+estimated size, measured tokens)— the live size matches the REST/statusrollup and v1 semantics, while the measured total floors the transient window where a post-step context fold leaves the context shorter than the measured prefix (every real shrink — undo/clear/compaction — rebases the measured model first, so the max only wins in that window). The derived model also watches context-append Ops so the status line moves as soon as a prompt or step event lands.apps/kimi-web: addisPlaceholderSessionUsageand preserve the accumulated live usage whenever an incoming session record carries the placeholder — in snapshot sync (mirroring the existingmodelpreservation) and in wholesale session-list replaces (initial load + search-triggered full reload).apps/kimi-web/test/workspace-state.test.tscovering list-reload usage preservation. The server-side fix was verified live against a kap-server instance: frames go 0 (empty context) → single-digit estimate on prompt append → measured total after the response, with no zero frames after the first non-zero one and no end-of-turn dip.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.