fix(gateway): refresh prompt policy in long-lived sessions - #46181
fix(gateway): refresh prompt policy in long-lived sessions#46181BeliefanX wants to merge 2 commits into
Conversation
|
Verification: reviewed diff + tests — no issues found. Checked:
Architectural concern noted: |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for isolating the gateway, background, and API propagation paths. This needs re-scoping before salvage.
Problems
gateway/run.py:14192-14193reloads and replaces the prompt on every turn; the new signature keys atgateway/run.py:12468-12473then rebuild the cached agent after edits. That conflicts with the byte-stable prompt/cache requirement inAGENTS.md:19-23,88-91.- The new fallback at
gateway/run.py:3431makesdisplay.personalityactive for the gateway, but current main labels it CLI-only (gateway/display_config.py:30-31) and explicitly tests that it remains inactive withoutagent.system_prompt(tests/tui_gateway/test_make_agent_provider.py:160-195). gateway/run.py:1853only tries a lowercase key, so it is not generally case-insensitive.
Suggested changes
- Defer prompt-policy changes to a new session/restart or explicit user-confirmed invalidation; do not alter a live conversation's cached prompt.
- Remove the display-personality fallback unless the cross-surface contract is intentionally changed, then normalize all personality keys for lookup.
Automated hermes-sweeper review.
| # settings. Gateway processes are long-lived, and manual edits to | ||
| # config.yaml / personalities should take effect on the next turn | ||
| # rather than waiting for a restart or cache eviction. | ||
| _reload_runtime_env_preserving_config_authority() |
There was a problem hiding this comment.
This reload plus the new prompt-policy signature keys changes the prompt and reconstructs the cached agent within an existing conversation. AGENTS.md:19-23,88-91 requires the system prompt to remain byte-stable for the conversation; defer this to a new session/restart or an explicit cache-invalidating user action.
| prompt = str(cfg_get(cfg, "agent", "system_prompt", default="") or "").strip() | ||
| if prompt: | ||
| return prompt | ||
| return _resolve_display_personality_prompt(cfg) |
There was a problem hiding this comment.
This activates display.personality for gateway agents, but current main defines that display setting as CLI-only (gateway/display_config.py:30-31) and tests the same inactive-until-agent.system_prompt contract for the TUI (tests/tui_gateway/test_make_agent_provider.py:160-195). Please remove this fallback unless the cross-surface behavior is intentionally being redesigned.
| return "" | ||
| value = personalities.get(name) | ||
| if value is None: | ||
| value = personalities.get(name.lower()) |
There was a problem hiding this comment.
This is only a lowercase fallback, not a case-insensitive lookup: display.personality: MIXEDCASE will not find an agent.personalities key named MixedCase. If this resolver remains, normalize and compare all configured keys.
|
Closing this version after re-review against current main. Its per-turn prompt replacement/cache-key rebuild conflicts with the byte-stable per-conversation system-prompt invariant, and |
Summary
Notes
This intentionally keeps scope small and uses the local repair diff only for gateway prompt/cache/personality behavior. It does not include user-local SOUL/profile default changes, delegate result slimming/default behavior, auto-continue resume markers, or unrelated API profile/session/job routing changes.
Related/extends #32007. Also complements the cache-signature cluster: #37880, #39022, #39284, #39454, and #28078.
API server prompt ordering is configured/global prompt first, then request instructions, matching the normal gateway "platform/config first, request-specific last" composition and covered by test.
Tests
uv run pytest tests/gateway/test_runtime_config_env_expansion.py tests/gateway/test_background_command.py::TestRunBackgroundTask::test_successful_task_sends_result tests/gateway/test_api_server.py::TestAdapterInit -q— 24 passedulimit -n 4096; uv run pytest tests/gateway/test_runtime_config_env_expansion.py tests/gateway/test_background_command.py tests/gateway/test_api_server.py— 196 passed, 1 failed: existing macOS/varvs/private/vartemp path assertion intest_media_files_routed_by_type(unrelated to this prompt change)python -m pytest tests/gateway/test_discord_channel_prompts.py -q— 10 passedpython -m pytest tests/gateway/test_runtime_config_env_expansion.py -q— 17 passedpython scripts/run_tests_parallel.py --slice 4/6(local system env) — blocked by missing optionalacp, missingmcp.server.auth, local kanban/test_run_agent timeouts; CI slice was re-run after the fixture fix