Skip to content

fix(chat): honor model end-of-turn tokens - #163

Merged
FluffyAIcode merged 1 commit into
mainfrom
AgentMemory/grpc-chat-eot-loop-0712
Jul 12, 2026
Merged

fix(chat): honor model end-of-turn tokens#163
FluffyAIcode merged 1 commit into
mainfrom
AgentMemory/grpc-chat-eot-loop-0712

Conversation

@FluffyAIcode

Copy link
Copy Markdown
Owner

Summary

  • resolve the tokenizer's full natural stop set, including Gemma-4 eot_token_id (<turn|>, token 106)
  • keep generic EOS support for other model families
  • add a strict three-consecutive-block repetition guard as a malformed-stream backstop
  • retain unlimited natural-length answers; no fixed response cap is introduced

Root cause

PR #161 registered only tokenizer.eos_token_id (Gemma token 1). Gemma-4 actually closes assistant turns with tokenizer.eot_token_id (token 106), so the runtime ignored the natural turn boundary and generated subsequent thought channels and repeated answers.

Verification

  • PYTHONPATH=.:sdks/python pytest -q tests/scripts/test_chat_grpc.py — 6 passed
  • python -m py_compile scripts/chat_grpc.py
  • live Gemma-4 gRPC runtime: Hello! / 3 tokens / stop=eos / no repetition

Made with Cursor

Register Gemma's end-of-turn token alongside generic EOS so natural answers terminate at the model boundary, with a strict repetition guard for malformed streams.

Co-authored-by: Cursor <cursoragent@cursor.com>
@FluffyAIcode
FluffyAIcode merged commit b4ab9ca into main Jul 12, 2026
7 checks 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.

1 participant