Skip to content

fix(agent): respect ephemeral_system_prompt over stored DB prompt (#58774) - #59363

Closed
isheng-eqi wants to merge 4 commits into
NousResearch:mainfrom
isheng-eqi:fix/58774-personality-ephemeral
Closed

fix(agent): respect ephemeral_system_prompt over stored DB prompt (#58774)#59363
isheng-eqi wants to merge 4 commits into
NousResearch:mainfrom
isheng-eqi:fix/58774-personality-ephemeral

Conversation

@isheng-eqi

Copy link
Copy Markdown
Contributor

Problem

/personality saves 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 set ephemeral_system_prompt.

Root Cause

In agent/conversation_loop.py, _restore_or_build_system_prompt at the stored-prompt fast path (L326-330):

if stored_prompt and _stored_prompt_matches_runtime(agent, stored_prompt):
    agent._cached_system_prompt = stored_prompt
    return

No check for ephemeral_system_prompt — stored prompt always wins.

Fix

Check ephemeral_system_prompt before 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

  • 3 new tests in tests/agent/test_system_prompt_restore.py:
    • ephemeral overrides stored prompt
    • ephemeral=None falls through to stored (default behavior preserved)
    • ephemeral="" falls through to stored (empty string is falsy, not an override)
  • All 11 existing tests continue to pass (14/14 total)

Related

Closes #58774

…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.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint area/config Config system, migrations, profiles sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Jul 6, 2026

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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_runtime check, 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 None on MagicMock is correct

Suggestions

  • None — this is a well-scoped, well-documented fix

Reviewed by Hermes Agent

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

COMMENT: fix(agent): respect ephemeral_system_prompt over stored DB prompt (#58774)

Clean fix (56 additions). Prior COMMENT review present. No security concerns, well-scoped.


Reviewed by Hermes Agent

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for investigating the session-prompt path. This is an automated hermes-sweeper review; current main already provides the requested behavior through the cache-safe ephemeral-overlay design.

  • agent/system_prompt.py:456-457 intentionally keeps ephemeral_system_prompt out of the cached and stored prompt.
  • agent/conversation_loop.py:851-870 adds the ephemeral prompt only while constructing the API request, after restoring the byte-stable base prompt.
  • The /personality CLI path persists the selected overlay and recreates the agent (hermes_cli/cli_commands_mixin.py:1023-1026), while agent setup passes it as ephemeral_system_prompt (hermes_cli/cli_agent_setup_mixin.py:359).
  • Promoting the overlay into _cached_system_prompt would conflict with the existing API assembly, which appends that same overlay, resulting in duplicate personality text.

The cache-safe implementation was introduced in d682f320b35a13084371a541a835e1d988c982b8 and is present in v2026.7.1.

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

Labels

area/config Config system, migrations, profiles comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists sweeper:implemented-on-main Sweeper: behavior already present on current main sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/personality command saves to config but doesn't affect current CLI session — ephemeral_system_prompt ignored when session DB has stored prompt

4 participants