fix(tui): persist model switch marker as user message - #48355
fix(tui): persist model switch marker as user message#48355lucas-nicolas wants to merge 1 commit into
Conversation
|
Duplicate of #48346 — both fix |
c1232c2 to
af89638
Compare
Sorry did not see the PR at the time I started trying to fix this issue. Was hoping to make my first contribution with this PR :). There is an assertion failing on the previously opened PR that needs to be changed. changed it here and left a comment on the other PR. Have a nice day and thank you for working on Hermes Agent |
|
Note: This is NOT a duplicate of the prior closed PRs (#48346, #48346, #48338, #20866). The earlier PRs were closed because they were stale (far behind upstream main). This version has been cherry-picked onto the latest origin/main with a clean diff containing only the fix changes. No conflicts. CI green. Ready for review. |
af89638 to
8e5b1cc
Compare
|
Rebased this branch onto current upstream/main and re-ran the focused checks: |
What does this PR do?
Fixes a gateway/TUI model-switch bug where
_append_model_switch_marker()persisted an informational model-switch marker asrole: "system"after prior conversation turns.Strict OpenAI-compatible providers such as vLLM reject message arrays with system messages outside the beginning of the conversation, returning:
The marker is runtime metadata for the next model, not a privileged instruction. This PR persists it as a
usermessage instead, so it can safely appear mid-history and later be merged with adjacent user messages by the existing sanitizer.Related Issue
Fixes #48338
Type of Change
Changes Made
tui_gateway/server.pyrole: "user"instead ofrole: "system"in both in-memory history and SQLite session persistence.tests/tui_gateway/test_model_switch_marker.pyHow to Test
[ {"role": "system", "content": "..."}, {"role": "user", "content": "hello"}, {"role": "assistant", "content": "hi"}, {"role": "system", "content": "[System: The active model ...]"}, {"role": "user", "content": "say hi again"}, ]HTTP 400: System message must be at the beginning.With this change, the gateway no longer creates that mid-history system role.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/ATest Results
Passed:
Full-suite note:
I attempted a full
scripts/run_tests.shrun after installing[all,dev]per CONTRIBUTING. The full suite is very large; I stopped it after the relevant suites had already passed and the run had progressed past 22k passing tests with several failures in unrelated test files. I am not claiming full-suite green for this PR.Screenshots / Logs
Relevant failure reproduced before the fix: