fix(coding-agent): make setThinkingLevel idempotent

switchSession() was appending spurious thinking_level_change entries
to session log on resume because setThinkingLevel() unconditionally
persisted. Now only persists if the level actually changes.

fixes #1118
This commit is contained in:
Mario Zechner 2026-02-01 00:14:49 +01:00
parent c9fa28e626
commit 7eae0a7d30
2 changed files with 11 additions and 3 deletions

View file

@ -1236,14 +1236,21 @@ export class AgentSession {
/**
* Set thinking level.
* Clamps to model capabilities based on available thinking levels.
* Saves to session and settings.
* Saves to session and settings only if the level actually changes.
*/
setThinkingLevel(level: ThinkingLevel): void {
const availableLevels = this.getAvailableThinkingLevels();
const effectiveLevel = availableLevels.includes(level) ? level : this._clampThinkingLevel(level, availableLevels);
// Only persist if actually changing
const isChanging = effectiveLevel !== this.agent.state.thinkingLevel;
this.agent.setThinkingLevel(effectiveLevel);
this.sessionManager.appendThinkingLevelChange(effectiveLevel);
this.settingsManager.setDefaultThinkingLevel(effectiveLevel);
if (isChanging) {
this.sessionManager.appendThinkingLevelChange(effectiveLevel);
this.settingsManager.setDefaultThinkingLevel(effectiveLevel);
}
}
/**