Skip to content

fix: resolve "default" persona_id the same way in both lookup paths - #10285

Open
AmirF194 wants to merge 1 commit into
AstrBotDevs:masterfrom
AmirF194:fix/10281-default-persona-resolution-collision
Open

AmirF194 wants to merge 1 commit into
AstrBotDevs:masterfrom
AmirF194:fix/10281-default-persona-resolution-collision

Conversation

@AmirF194

@AmirF194 AmirF194 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #10281.

Confirmed the mismatch: get_persona_v3_by_id treats "default" as reserved for the built-in persona, but resolve_selected_persona does its own scan over personas_v3 and finds the user's own persona named "default" instead. That's why subagent registration and the main conversation path disagree on the same persona_id. git log -G on DEFAULT_PERSONALITY shows #5672 added that special case specifically to unify this lookup; resolve_selected_persona was just missed.

Modifications / 改动点

  • astrbot/core/persona_mgr.py: resolve_selected_persona now calls get_persona_v3_by_id(persona_id) instead of repeating the lookup, so both paths agree.

  • tests/unit/test_persona_resolution.py: reproduces the mismatch (fails on master, passes here) plus a control test for a normal, non-"default" persona.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

tests/unit/test_persona_resolution.py::test_resolve_selected_persona_agrees_with_get_persona_v3_by_id_for_default PASSED
tests/unit/test_persona_resolution.py::test_resolve_selected_persona_still_finds_a_non_default_persona PASSED

Ran the full suite on python 3.12 too: 3615 passed, 24 skipped, same skip count as master, so nothing else moved. ruff format/ruff check clean. Coverage reporting hung on this file's import order for me, so I didn't get a coverage number out of it, but reverting just this one hunk is what turns the new test red, so it's exercising the right line either way.

Two other open PRs touch this file (#9147, #6325) but both are stale, already conflicting with master, and neither changes this lookup, so should be an easy rebase for either if they ever come back to life.


Checklist / 检查清单

  • If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • I have ensured that no new dependencies are introduced.
  • My changes do not introduce malicious code.

Summary by Sourcery

Resolve selected personas through the canonical persona lookup so all persona_id paths agree on reserved and user-defined personas.

Bug Fixes:

  • Ensure the built-in "default" persona is resolved consistently across conversation and subagent lookup paths, preventing user personas with the same name from shadowing it.

Tests:

  • Add regression coverage for reserved "default" persona resolution and lookup of ordinary user personas.

resolve_selected_persona() looked up persona_id via its own linear scan
over personas_v3, bypassing get_persona_v3_by_id()'s special case that
maps "default" to the built-in DEFAULT_PERSONALITY. A user persona
literally named "default" therefore resolved to two different
Personality objects depending on call site: astr_main_agent.py's
subagent registration (get_persona_v3_by_id) saw the built-in default,
its main conversation path (resolve_selected_persona) saw the user's
own "default" persona.

Route resolve_selected_persona through get_persona_v3_by_id so both
paths agree, matching the unified-lookup intent get_persona_v3_by_id
was already written for.

Fixes AstrBotDevs#10281

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 建立名为 default 的人格并选择时,UI和实际行为不一致

1 participant