Skip to content

fix(llm): stop 'role: fact' 422 that broke terminal chat#240

Merged
AVADSA25 merged 1 commit into
mainfrom
claude/fix-role-422
Jul 13, 2026
Merged

fix(llm): stop 'role: fact' 422 that broke terminal chat#240
AVADSA25 merged 1 commit into
mainfrom
claude/fix-role-422

Conversation

@AVADSA25

Copy link
Copy Markdown
Owner

Terminal/voice chat 422'd on every message (role='fact' invalid) → surfaced as 'Qwen busy'. The conversations table holds 77 fact rows and the session bootstrap replayed them verbatim as messages. Fixed at two layers: the replay now keeps only real turns; codec_llm sanitizes any stray non-standard role to 'user' at the shared chokepoint. Verified live against Qwen. 4 tests.

Every message in the terminal/voice chat 422'd — the LLM server rejected
role="fact" ("Input should be 'user'|'assistant'|'system'|'developer'|'tool'"),
and the repeated failure surfaced to the user as "Qwen busy".

Cause: the `conversations` memory table holds role="fact" rows (77 of them —
written by fact_extract / memory_save alongside real user/assistant turns), and
the session bootstrap replayed the last 10 rows verbatim as chat messages. A
fact row became an invalid message.

Fixed at two layers:
- codec_core.py (generated launch script) + codec_session.py (runtime): the
  previous-session replay now keeps only real turns (role in user/assistant/
  system). Facts stay in the DB for the memory system; they were never chat turns.
- codec_llm._build_request (the single chokepoint call() and stream() share):
  _sanitize_roles() relabels any non-standard role to 'user' — valid at ANY
  position, so it can't 422 (bad role) nor 500 ('system message must be first'
  if a stray fact lands mid-conversation). Content preserved.

Verified LIVE against the Qwen server: a messages array containing a role="fact"
entry now returns a clean answer (previously 422). 4 new tests. ruff clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@AVADSA25
AVADSA25 merged commit d54e720 into main Jul 13, 2026
1 check passed
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.

2 participants