Skip to content

fix(agent): recognize emoji as natural response endings in stop-to-length heuristic (#14572)#15363

Closed
Tranquil-Flow wants to merge 1 commit into
NousResearch:mainfrom
Tranquil-Flow:fix/emoji-stop-to-length-false-positive
Closed

fix(agent): recognize emoji as natural response endings in stop-to-length heuristic (#14572)#15363
Tranquil-Flow wants to merge 1 commit into
NousResearch:mainfrom
Tranquil-Flow:fix/emoji-stop-to-length-false-positive

Conversation

@Tranquil-Flow

@Tranquil-Flow Tranquil-Flow commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

_has_natural_response_ending() checks whether the last character of a response is in a hardcoded punctuation charset. Emoji characters (common sign-offs like 🌙, , 👍, 🎉) are not in this charset, so responses ending with emoji are incorrectly classified as "truncated" by _should_treat_stop_as_truncated(). This causes silent retry loops for Ollama/GLM users whose responses naturally end with emoji.

The fix adds a Unicode category check — characters in categories starting with S (Symbol: So, Sk, Sm, Sc) are treated as natural endings.

Related Issue

Fixes #14572

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • run_agent.py: After the existing punctuation check, add a Unicode category check — characters in categories starting with S (Symbol: So, Sk, Sm, Sc) are treated as natural endings.

How to Test

  1. Run the targeted test:
    python -m pytest tests/run_agent/test_emoji_stop_detection.py -v
  2. 18 parametrized cases cover emoji, CJK punctuation, code blocks, and non-endings.

Validation table:

Input Before After
"Thank you! 🌙" False → retried as truncated True → accepted
"Done ✅" False → retried True → accepted
"Normal ending." True True (unchanged)
"No ending here" False False (unchanged)

Tested on macOS (Python 3.14).

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS 15 (Darwin 24.6.0)

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

python -m pytest tests/run_agent/test_emoji_stop_detection.py -v
# 18 parametrized cases pass

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder provider/ollama Ollama / local models labels Apr 24, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #14574 — Same fix for #14572: emoji sign-offs as natural response endings. Superseded by #14574.

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

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists provider/ollama Ollama / local models type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Ollama/GLM stop-to-length heuristic false-triggers on responses ending with emoji sign-offs

2 participants