fix(agent): respect ephemeral_system_prompt over stored DB prompt (#58774) - #59363
Closed
isheng-eqi wants to merge 4 commits into
Closed
fix(agent): respect ephemeral_system_prompt over stored DB prompt (#58774)#59363isheng-eqi wants to merge 4 commits into
isheng-eqi wants to merge 4 commits into
Conversation
…usResearch#58774) _restore_or_build_system_prompt unconditionally restored the session-DB stored prompt when it matched the current runtime identity, even when the caller set an explicit ephemeral_system_prompt (e.g. /personality). Check ephemeral_system_prompt before the stored-prompt fast path so a deliberate personality switch takes effect immediately instead of being silently ignored until the next fresh session.
tonydwb
reviewed
Jul 6, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Changes
Fixes #58774: when an agent has an explicit ephemeral_system_prompt set (e.g., via /personality), the stored prompt matching logic now short-circuits and uses the ephemeral override instead of reusing the cached prefix. This ensures personality switches take effect immediately rather than waiting for the cache to expire.
Quality
- Clean fix: the
getattr(agent, "ephemeral_system_prompt", None)guard is placed correctly after the_stored_prompt_matches_runtimecheck, so existing session continuity is preserved when no explicit personality override exists - The comment explains the cache-miss trade-off explicitly
- Test guard with explicit
Noneon MagicMock is correct
Suggestions
- None — this is a well-scoped, well-documented fix
Reviewed by Hermes Agent
Contributor
|
Thanks for investigating the session-prompt path. This is an automated hermes-sweeper review; current
The cache-safe implementation was introduced in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
/personalitysaves to config but does not affect the current CLI session because_restore_or_build_system_prompt()unconditionally restores the session-DB stored prompt when it matches the current runtime identity — even when the caller explicitly setephemeral_system_prompt.Root Cause
In
agent/conversation_loop.py,_restore_or_build_system_promptat the stored-prompt fast path (L326-330):No check for
ephemeral_system_prompt— stored prompt always wins.Fix
Check
ephemeral_system_promptbefore the stored-prompt fast path. When set (truthy), it takes precedence. The prefix cache will miss for that turn, but that is the expected trade-off for a deliberate personality switch.Test plan
tests/agent/test_system_prompt_restore.py:Related
Closes #58774