UAT: PersonaState.set_active_persona() does not reset preset to "default" when switching personas #10499

Open
opened 2026-04-18 10:14:42 +00:00 by HAL9000 · 0 comments
Owner

Metadata

  • Commit message: fix(tui): reset preset to "default" in set_active_persona when switching personas
  • Branch name: bugfix/m8-set-active-persona-preset-reset

Background and Context

The TUI specification (ADR-045, Persona System) requires that PersonaState.set_active_persona() resets the active preset to "default" whenever the user switches to a different persona.

The current implementation in src/cleveragents/tui/persona/state.py only sets the preset to "default" if the session has no preset at all — it does NOT reset an existing preset when switching personas:

def set_active_persona(self, session_id: str, persona_name: str) -> Persona:
    persona = self.registry.get(persona_name)
    if persona is None:
        raise ValueError(f"Unknown persona: {persona_name}")
    self.active_by_session[session_id] = persona.name
    self.registry.set_last_persona(persona.name)
    if session_id not in self.preset_by_session:  # BUG: only sets default if no preset exists
        self.preset_by_session[session_id] = "default"
    return persona

The condition if session_id not in self.preset_by_session means:

  • If the session has never had a preset → preset is set to "default"
  • If the session already has a preset (e.g., "high-effort") → preset is NOT reset

Expected Behavior

Per the spec, set_active_persona() must always reset the preset to "default" when switching personas:

self.preset_by_session[session_id] = "default"  # Always reset to default

Actual Behavior

When a session already has a non-default preset and the user switches personas, the preset is NOT reset to "default". The old preset carries over to the new persona.

Steps to Reproduce

  1. Create two personas: persona-a (with preset high-effort) and persona-b
  2. Set active persona to persona-a and cycle preset to high-effort
  3. Call set_active_persona(session_id, "persona-b")
  4. Check current_preset(session_id) — returns "high-effort" instead of "default"

Acceptance Criteria

  • set_active_persona() always sets preset_by_session[session_id] = "default" when switching personas
  • After calling set_active_persona(), current_preset() returns "default" regardless of previous preset
  • The condition if session_id not in self.preset_by_session is replaced with an unconditional assignment
  • All existing tests continue to pass
  • Coverage >= 97%

Subtasks

  • Change if session_id not in self.preset_by_session: self.preset_by_session[session_id] = "default" to self.preset_by_session[session_id] = "default" in src/cleveragents/tui/persona/state.py
  • Add/update Behave scenarios asserting preset resets to "default" when switching personas
  • Implement step definitions for the new assertions
  • Verify coverage >= 97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.

Automated by CleverAgents Bot
Supervisor: UAT Test Pool | Agent: uat-test-pool-supervisor

## Metadata - **Commit message:** `fix(tui): reset preset to "default" in set_active_persona when switching personas` - **Branch name:** `bugfix/m8-set-active-persona-preset-reset` ## Background and Context The TUI specification (ADR-045, Persona System) requires that `PersonaState.set_active_persona()` **resets the active preset to `"default"`** whenever the user switches to a different persona. The current implementation in `src/cleveragents/tui/persona/state.py` only sets the preset to `"default"` if the session has **no preset at all** — it does NOT reset an existing preset when switching personas: ```python def set_active_persona(self, session_id: str, persona_name: str) -> Persona: persona = self.registry.get(persona_name) if persona is None: raise ValueError(f"Unknown persona: {persona_name}") self.active_by_session[session_id] = persona.name self.registry.set_last_persona(persona.name) if session_id not in self.preset_by_session: # BUG: only sets default if no preset exists self.preset_by_session[session_id] = "default" return persona ``` The condition `if session_id not in self.preset_by_session` means: - If the session has never had a preset → preset is set to `"default"` ✅ - If the session already has a preset (e.g., `"high-effort"`) → preset is **NOT reset** ❌ ## Expected Behavior Per the spec, `set_active_persona()` must **always** reset the preset to `"default"` when switching personas: ```python self.preset_by_session[session_id] = "default" # Always reset to default ``` ## Actual Behavior When a session already has a non-default preset and the user switches personas, the preset is NOT reset to `"default"`. The old preset carries over to the new persona. ## Steps to Reproduce 1. Create two personas: `persona-a` (with preset `high-effort`) and `persona-b` 2. Set active persona to `persona-a` and cycle preset to `high-effort` 3. Call `set_active_persona(session_id, "persona-b")` 4. Check `current_preset(session_id)` — returns `"high-effort"` instead of `"default"` ## Acceptance Criteria - [ ] `set_active_persona()` always sets `preset_by_session[session_id] = "default"` when switching personas - [ ] After calling `set_active_persona()`, `current_preset()` returns `"default"` regardless of previous preset - [ ] The condition `if session_id not in self.preset_by_session` is replaced with an unconditional assignment - [ ] All existing tests continue to pass - [ ] Coverage >= 97% ## Subtasks - [ ] Change `if session_id not in self.preset_by_session: self.preset_by_session[session_id] = "default"` to `self.preset_by_session[session_id] = "default"` in `src/cleveragents/tui/persona/state.py` - [ ] Add/update Behave scenarios asserting preset resets to `"default"` when switching personas - [ ] Implement step definitions for the new assertions - [ ] Verify coverage >= 97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. --- **Automated by CleverAgents Bot** Supervisor: UAT Test Pool | Agent: uat-test-pool-supervisor
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#10499
No description provided.