Context-window percentage fluctuates during streaming updates
Description
On the mobile/remote web UI, the context-window usage indicator (circle and percentage text) can visibly fluctuate or jump while an assistant response is streaming. The percentage may move up and down, or briefly disappear and reappear, instead of representing a stable snapshot of the current context usage.
This was observed on the Go/Svelte version @ygncode/pi-web (v0.0.1-beta.36) through the remote browser endpoint.
Reproduction steps
- Run
@ygncode/pi-web and open a session from a mobile browser.
- Select a model with a normal context window and open a session that already contains some conversation history.
- Send a prompt that produces a streamed response with multiple tool calls or a relatively long answer.
- Watch the context usage circle/percentage in the chat composer while the response is streaming.
- Repeat with the same session or reload the session while output is still arriving.
Expected behavior
The indicator should update monotonically or remain stable for a given context snapshot. Intermediate streaming updates should not make the percentage regress or flicker. If usage is temporarily unavailable, the UI should retain the last known value or show an explicit loading state rather than hiding the indicator.
Actual behavior
The displayed percentage can jump between values and/or disappear and reappear during live session updates. This makes it difficult to tell the actual context remaining, especially on a mobile screen.
Suspected cause
The current implementation appears vulnerable to transient/incomplete session entries during SSE/live updates:
collectContextUsage() sums assistant usage entries, but derives contextTokens from the last assistant message containing usage (web/src/components/session/chat/context-usage.js:77-91). If that message is temporarily incomplete or replaced while a streamed response is being written, the selected totalTokens can change or briefly be zero.
- The displayed percentage is recalculated directly from that value (
context-usage.js:131-145), so each live entry update can visibly change the indicator.
- The context-window limit is populated asynchronously from
/api/models (context-usage.js:1-27, context-usage.js:163-178 in the current source), then update() is called again. A change from the fallback model limit to the registry value can also cause a visible jump in the percentage.
- When both
contextTokens and aggregate I/O usage are temporarily zero, the element is hidden (context-usage.js:131-135).
Possible fix directions
- Use the latest complete/authoritative context usage snapshot rather than an incomplete streaming entry.
- Keep the last valid context percentage while a live response is incomplete; only replace it when the new usage data is valid.
- Avoid hiding the indicator during transient zero/empty updates.
- Resolve and pin the model context limit before rendering the first percentage, or avoid changing the denominator after the indicator is visible.
- Add a regression test that feeds incremental session entries and verifies that the displayed value does not regress/flicker during streaming.
A related but separate symptom was reported in agegr/pi-web#637 (the percentage disappears and reappears after a session has been running for a while), but this report concerns the Go/Svelte implementation in this repository.
Context-window percentage fluctuates during streaming updates
Description
On the mobile/remote web UI, the context-window usage indicator (circle and percentage text) can visibly fluctuate or jump while an assistant response is streaming. The percentage may move up and down, or briefly disappear and reappear, instead of representing a stable snapshot of the current context usage.
This was observed on the Go/Svelte version
@ygncode/pi-web(v0.0.1-beta.36) through the remote browser endpoint.Reproduction steps
@ygncode/pi-weband open a session from a mobile browser.Expected behavior
The indicator should update monotonically or remain stable for a given context snapshot. Intermediate streaming updates should not make the percentage regress or flicker. If usage is temporarily unavailable, the UI should retain the last known value or show an explicit loading state rather than hiding the indicator.
Actual behavior
The displayed percentage can jump between values and/or disappear and reappear during live session updates. This makes it difficult to tell the actual context remaining, especially on a mobile screen.
Suspected cause
The current implementation appears vulnerable to transient/incomplete session entries during SSE/live updates:
collectContextUsage()sums assistant usage entries, but derivescontextTokensfrom the last assistant message containingusage(web/src/components/session/chat/context-usage.js:77-91). If that message is temporarily incomplete or replaced while a streamed response is being written, the selectedtotalTokenscan change or briefly be zero.context-usage.js:131-145), so each live entry update can visibly change the indicator./api/models(context-usage.js:1-27,context-usage.js:163-178in the current source), thenupdate()is called again. A change from the fallback model limit to the registry value can also cause a visible jump in the percentage.contextTokensand aggregate I/O usage are temporarily zero, the element is hidden (context-usage.js:131-135).Possible fix directions
A related but separate symptom was reported in
agegr/pi-web#637(the percentage disappears and reappears after a session has been running for a while), but this report concerns the Go/Svelte implementation in this repository.