UAT: TUI PersonaState.set_active_persona() does not reset preset to "default" when session already has a tracked preset #4732

Open
opened 2026-04-08 18:12:44 +00:00 by HAL9000 · 1 comment
Owner

Bug Report

Feature Area: TUI persona system — PersonaState preset management
Severity: Medium — stale preset from previous persona persists after persona switch
Source: src/cleveragents/tui/persona/state.py set_active_persona()
Spec reference: docs/specification.md §29262–29269 (Persona Cycling)


What Was Tested

Code-level analysis of PersonaState.set_active_persona() in src/cleveragents/tui/persona/state.py.

Expected Behavior

When a user switches to a different persona (via tab cycling or /persona:set), the active preset for that session should reset to "default". This is the natural expected behavior: each persona has its own preset list, and switching personas should start fresh at the default preset.

The spec (§29262–29269) describes persona cycling as updating "the actor binding for the session" — implying a clean switch to the new persona's default state.

Actual Behavior

src/cleveragents/tui/persona/state.py set_active_persona():

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 NOT already tracked
        self.preset_by_session[session_id] = "default"
    return persona

The condition if session_id not in self.preset_by_session means:

  • First persona switch for a session: preset is correctly set to "default"
  • Subsequent persona switches: the preset is NOT reset — it retains whatever preset was active before the switch

Concrete example:

state.set_active_persona("s1", "persona_a")  # preset → "default" ✓
state.cycle_preset("s1")                      # preset → "think: high"
state.set_active_persona("s1", "persona_b")  # preset stays "think: high" ✗
# But persona_b may not even have a "think: high" preset!

After switching to persona_b, current_preset("s1") returns "think: high". If persona_b doesn't have a "think: high" preset, cycle_preset() will fall back to names[0] (the first preset), but effective_arguments() will silently return base arguments only (since the preset lookup returns None).

Code Location

  • src/cleveragents/tui/persona/state.py lines ~40–50 — set_active_persona() conditional preset reset

Fix

The condition should unconditionally reset the preset:

# Correct behavior:
self.preset_by_session[session_id] = "default"

Impact

After cycling presets and then switching personas, the new persona starts with a stale preset name. If the new persona doesn't have a preset with that name, effective_arguments() silently returns only base arguments, ignoring the intended preset. This is a subtle correctness bug that could cause unexpected actor behavior.


Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: uat-tester

## Bug Report **Feature Area:** TUI persona system — PersonaState preset management **Severity:** Medium — stale preset from previous persona persists after persona switch **Source:** `src/cleveragents/tui/persona/state.py` `set_active_persona()` **Spec reference:** docs/specification.md §29262–29269 (Persona Cycling) --- ## What Was Tested Code-level analysis of `PersonaState.set_active_persona()` in `src/cleveragents/tui/persona/state.py`. ## Expected Behavior When a user switches to a different persona (via `tab` cycling or `/persona:set`), the active preset for that session should reset to `"default"`. This is the natural expected behavior: each persona has its own preset list, and switching personas should start fresh at the default preset. The spec (§29262–29269) describes persona cycling as updating "the actor binding for the session" — implying a clean switch to the new persona's default state. ## Actual Behavior `src/cleveragents/tui/persona/state.py` `set_active_persona()`: ```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 NOT already tracked self.preset_by_session[session_id] = "default" return persona ``` The condition `if session_id not in self.preset_by_session` means: - **First persona switch for a session**: preset is correctly set to `"default"` - **Subsequent persona switches**: the preset is **NOT reset** — it retains whatever preset was active before the switch **Concrete example:** ```python state.set_active_persona("s1", "persona_a") # preset → "default" ✓ state.cycle_preset("s1") # preset → "think: high" state.set_active_persona("s1", "persona_b") # preset stays "think: high" ✗ # But persona_b may not even have a "think: high" preset! ``` After switching to `persona_b`, `current_preset("s1")` returns `"think: high"`. If `persona_b` doesn't have a `"think: high"` preset, `cycle_preset()` will fall back to `names[0]` (the first preset), but `effective_arguments()` will silently return base arguments only (since the preset lookup returns `None`). ## Code Location - `src/cleveragents/tui/persona/state.py` lines ~40–50 — `set_active_persona()` conditional preset reset ## Fix The condition should unconditionally reset the preset: ```python # Correct behavior: self.preset_by_session[session_id] = "default" ``` ## Impact After cycling presets and then switching personas, the new persona starts with a stale preset name. If the new persona doesn't have a preset with that name, `effective_arguments()` silently returns only base arguments, ignoring the intended preset. This is a subtle correctness bug that could cause unexpected actor behavior. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: uat-tester
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Medium — spec compliance bug identified by UAT testing
  • Story Points: 3 (M) — targeted fix to align implementation with spec
  • MoSCoW: Must Have — spec compliance is required for correct system behavior

Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner

Issue triaged by project owner: - **State**: Verified - **Priority**: Medium — spec compliance bug identified by UAT testing - **Story Points**: 3 (M) — targeted fix to align implementation with spec - **MoSCoW**: Must Have — spec compliance is required for correct system behavior --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner
HAL9000 added this to the v3.7.0 milestone 2026-04-09 03:05:29 +00:00
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#4732
No description provided.