Skip to content

fix(agent): prevent GLM stop-to-length heuristic false positives (#14572)#25991

Closed
aj-nt wants to merge 1 commit into
NousResearch:mainfrom
aj-nt:fix/glm-stop-heuristic-14572-v2
Closed

fix(agent): prevent GLM stop-to-length heuristic false positives (#14572)#25991
aj-nt wants to merge 1 commit into
NousResearch:mainfrom
aj-nt:fix/glm-stop-heuristic-14572-v2

Conversation

@aj-nt

@aj-nt aj-nt commented May 14, 2026

Copy link
Copy Markdown

Problem

The Ollama/GLM stop-to-length heuristic in _should_treat_stop_as_truncated() produces false positives for agents using emoji sign-offs (💛 ✨ 🙌) and short conversational replies, wasting up to 60 turns per user message.

Fix

Three changes:

  1. _has_natural_response_ending() now recognises emoji and Unicode symbols as natural endings using unicodedata categories (So/Sk/Sm) and the Extended_Pictographic codepoint range. Also strips trailing Unicode combining marks (variation selectors, ZWJ) before checking the last real glyph so emoji+VS16 is recognised correctly.

  2. _should_treat_stop_as_truncated() enforces a 500-character minimum gate on visible text. Short replies are almost certainly not truncated and cannot hit meaningful token limits.

  3. Config opt-out: new agent.glm_truncation_heuristic flag (default true) lets users disable the heuristic entirely.

Changes

  • run_agent.py: Expanded _has_natural_response_ending() (+42 lines) and _should_treat_stop_as_truncated() (+18 lines) with config opt-out
  • cli-config.yaml.example: Documented new config flag
  • tests/run_agent/test_glm_stop_heuristic.py: 17 new tests (emoji/symbol recognition, 500-char gate, integration)
  • tests/run_agent/test_run_agent.py: Updated existing test for 500-char gate

Testing

  • 17 new tests all pass
  • All 325 existing run_agent tests pass (zero regressions)
  • Manually verified: emoji sign-offs (💛 ✨ 🙌 🚀 ✅), math symbols (→ ∞), and warning symbols (⚠ ★) correctly classified as natural endings

Closes #14572

…sResearch#14572)

The Ollama/GLM stop-to-length heuristic in _should_treat_stop_as_truncated()
produced false positives for agents using emoji sign-offs and short
conversational replies. Three changes:

1. _has_natural_response_ending() now recognises emoji and Unicode symbols
   as natural endings using unicodedata categories (So/Sk/Sm) and the
   Extended_Pictographic codepoint range. Also strips trailing Unicode
   combining marks (variation selectors, ZWJ) before checking the last
   real glyph so emoji+VS16 is recognised correctly.

2. _should_treat_stop_as_truncated() enforces a 500-character minimum
   gate on visible text. Short replies are almost certainly not truncated
   and cannot hit meaningful token limits.

3. New config flag agent.glm_truncation_heuristic (default true) lets
   users opt out of the heuristic entirely.

Includes 17 new tests covering emoji/symbol recognition, 500-char gate
behaviour, and integration-level short-response detection.
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists labels May 14, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #14574 (and previously closed as #15463 with the same fix). #14574 and #15363 are both open PRs addressing #14572. Please coordinate with those authors to avoid duplicate effort.

@aj-nt

aj-nt commented May 14, 2026

Copy link
Copy Markdown
Author

Closing in favor of #14574 which was submitted first. Will contribute the 500-char gate and config opt-out as suggestions there.

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 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