Skip to content

chat: make trailing newline optional after assistant tag in Laguna pa… - #59

Closed
ghost wants to merge 1 commit into
feature/turboquant-kv-cachefrom
unknown repository
Closed

chat: make trailing newline optional after assistant tag in Laguna pa…#59
ghost wants to merge 1 commit into
feature/turboquant-kv-cachefrom
unknown repository

Conversation

@ghost

@ghost ghost commented Jul 28, 2026

Copy link
Copy Markdown

Overview

This PR relaxes the Laguna assistant generation prompt parsing template in common/chat.cpp to make the trailing newline after the <assistant> tag optional instead of strictly required.

Symptoms / Issues Resolved

Without this patch:

  1. Parser Stalls: If a client tool or system template formats prompts slightly differently (e.g., omitting the trailing newline after <assistant> or adding spaces), the PEG parser fails to match the template.
  2. Infinite Generation Hangs: When the parser fails to match the expected <assistant>\n literal, the server hangs indefinitely or fails to return the reasoning block.

This fix makes the Laguna parser robust against formatting differences, allowing successful prompt template matching whether a trailing newline, trailing spaces, or nothing follows the <assistant> tag.

Technical Changes

  • Replaces the strict const std::string GEN_PROMPT = "<assistant>\n" string literal matching with a flexible regex-style pattern:
    auto gen_prompt = p.literal("<assistant>") + p.optional(p.space());
  • Updates the reasoning and assistant output head matches (extract_reasoning) to use the new gen_prompt parser rule.

Requirements

  • I have read and agree with the contributing guidelines.
  • AI usage disclosure: YES - An AI assistant was used to locate the parsing expression boundaries and rewrite the PEG template rules in C++.

…rser

Strictly requiring a trailing newline after <assistant> causes parsing
stalls when client templates format prompts differently or when the model
omits the newline. Allowing optional spacing/newlines prevents parser locks.
Repository owner closed this by deleting the head repository Jul 29, 2026
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