Skip to content

Commit 3af6e63

Browse files
ethanperezzclaude
andcommitted
fix: update sessionEntry.contextTokens on model switch
When switching models via inline directive, applyModelOverrideToSessionEntry updated the model/provider override but left contextTokens unchanged. This caused contextTokens to get stuck at a lower value after switching to a model with a smaller context window and back. Now persistInlineDirectives explicitly updates sessionEntry.contextTokens to match the new model's context window, keeping session state consistent. Fixes #35372 Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent cc5dad8 commit 3af6e63

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/auto-reply/reply/directive-handling.persist.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ export async function persistInlineDirectives(params: {
173173
});
174174
provider = resolved.ref.provider;
175175
model = resolved.ref.model;
176+
// Update contextTokens to match the new model so session state
177+
// reflects the correct context window after a model switch (#35372).
178+
const newContextTokens =
179+
agentCfg?.contextTokens ?? lookupContextTokens(model) ?? DEFAULT_CONTEXT_TOKENS;
180+
if (sessionEntry.contextTokens !== newContextTokens) {
181+
sessionEntry.contextTokens = newContextTokens;
182+
updated = true;
183+
}
176184
const nextLabel = `${provider}/${model}`;
177185
if (nextLabel !== initialModelLabel) {
178186
enqueueSystemEvent(formatModelSwitchEvent(nextLabel, resolved.alias), {

0 commit comments

Comments
 (0)