Message-box context indicator shows the previous model's window after switching models in the picker #5353
Replies: 1 comment
|
Verified all three references against current master (4e84901 = 0.1.2-alpha.4) — the mechanism is unchanged since alpha.3, and the report is accurate. I also found one fact that changes the fix calculus a little, so let me lay out the full picture. Verification (alpha.4)
The picker change is not invisible to the session — it just carries no window The important extra fact: the picker's selection does reach the durable session log immediately, as
Fix refinement Your sketch (append A slightly more design-faithful variant, all server-side:
That keeps event ownership where the window is actually resolved, updates every Test gap confirmed
This is a clean, well-scoped report — a PR along these lines would be welcome, and I'd be happy to look at the specific diff if you open one. |
Uh oh!
There was an error while loading. Please reload this page.
Message-box context indicator stays on the previous model's window after switching models in the picker
Summary
The context-window number rendered inside the message input box (token-meter) keeps showing the previous model's window after the user switches models in the picker. It only updates when the next outgoing request fires a
request/contextevent.The picker change itself does not refresh the indicator, even though the selected model's
contextWindowis already resolved at that point.Environment
0.1.2-alpha.3(commitdd6322d604)http://127.0.0.1:3080llm-pi-aiadapter)<MODEL_A_ID>(advertised<WINDOW_A>) and<MODEL_B_ID>(advertised<WINDOW_B>) — I left the real IDs out of this template, see the note at the bottomReproduction
<MODEL_A_ID>in the model picker. Send a message. The indicator in the message box shows<WINDOW_A>. ✅<MODEL_B_ID>. The indicator still shows<WINDOW_A>. ❌<MODEL_B_ID>, the agent loop appends a newrequest/context, and only now does the indicator jump to<WINDOW_B>.Expected
The indicator should reflect the currently selected model's window, not the window of the most recent completed request. Either of these is fine:
contextPressureprojection) when the picker changes, using the already-resolvedmodel.contextWindowfrom the catalog, orrequest/contextevent at resolve-time so the projection's "last-wins" rule picks it up before the next outgoing request.Where in the code
The projection only updates
contextWindowonrequest/contextevents:packages/llm/token-meter/src/usage-projection.ts:188— thecontextPressureprojection'sapplyonly changesstate.contextWindowwhenevent.type === 'request/context'.request/contextis only appended per outgoing request, not on model change:packages/core/agent-loop/src/agent.ts:531— the agent loop appends arequest/contextevent just before issuing a request, and only when the resolvedprovider/model/contextWindowdiffers from the previous one. The picker change never reaches this path because no request has been issued yet.The picker change does have the data it needs but does not push it to the session's token-meter projection:
packages/llm/llm/src/index.ts:774—LlmResolvedModelInfo.contextis computed and validated at resolve time, but the resolved value is not written back to the session until the agent loop runs.Suggested fix (sketch)
A small, low-risk change would be to append a
request/contextevent from the model-picker'sonChangehandler (or from the resolve path itself) using the already-knownmodel.contextWindow. Because the projection is "last-wins" and dedupes on equality (agent.ts:528-532), a duplicate that matches the last request is a no-op, so over-emit on the picker side is safe.Tests
packages/llm/token-meter/tests/token-usage-projection.spec.ts:313covers the "stays correct across successive requests" case. There is no equivalent test for "picker changed, no new request yet" — adding one would lock the desired behavior in.Workaround
None on the client. The "stale until next request" behavior is by design but is not documented in the message-box UI.
Note
This report is filed from a DSH checkout where I have redacted the exact model IDs. The two models are both surfaced through OpenRouter, with advertised context windows that differ by a factor of ~4. The bug is the same regardless of which pair of models is used: the indicator follows the last
request/contextevent, not the picker's current value.All reactions