[Engine] serve/frontend.py: recover missing '>' before newline and minor low-bit tool-name stutters in <function=NAME> (including streaming _scan)

Abierto Apto para principiantes
#7,403 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 4 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
88/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
api, backend

Línea de trabajo

Comienza con terminal/serve/frontend.py, centrándote en parse_tool_call(), _callable(), _scan() y _finish_call(), y luego ejecuta las pruebas unitarias existentes de terminal/serve. Implementa la recuperación de nombres basada en la lista blanca del schema propuesta y tolera que falte > antes del primer parámetro. La tarea está completa cuando los casos malformados de streaming y no streaming pasan, los nombres no declarados siguen siendo rechazados y todas las pruebas existentes de terminal/serve siguen pasando.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Problem

When serving low-bit quantizations (e.g. Qwen3.8-Flash-Next IQ3_S) to OpenAI-compatible tool-calling clients / coding agents with recover=True, two minor, unambiguously repairable <function=NAME> formatting glitches still fail parsing in terminal/serve/frontend.py and leak raw <tool_call> markup into assistant text (terminating the agent turn):

  1. Missing > before newline in <function=NAME>:

    <tool_call>
    <function=bash
    <parameter=command>echo ok</parameter>
    </function>
    </tool_call>
    

    Both parse_tool_call() and _finish_call() require > to exist and appear before the first <parameter=...>. When the model omits > and immediately emits \n<parameter=...>, parse_tool_call() raises malformed tool call (or splits on the > inside <parameter=...>), corrupting the tool name and dropping the call.

  2. Minor quantization stutters in <function=NAME> (and missing recovery in streaming _scan()):
    Under low-bit quantizations, the model occasionally emits a single-character stutter or trailing delimiter on an otherwise valid declared tool name, such as:

    • Trailing punctuation or accidental =param: <function=bash,>, <function=bash=command>
    • Doubled leading character: <function=ggrep_text> (for declared grep_text)
    • Single-letter + underscore stutter prefix: <function=p_present_files> (for declared present_files)

    Currently _callable(), streaming _scan(), and _finish_call() only do .strip() + alias lookup, so these calls are rejected and leaked as plain text even when the repaired name uniquely matches a declared tool in self.schemas.

(Related to but distinct from #6022 [hallucinated undeclared names] and #6979 [argument name typos]. Checked v0.2.23: neither fix is present in terminal/serve/frontend.py yet.)

Proposed Fix (minimal, strictly whitelisted to schemas)

Add a conservative helper _recover_declared_name(raw, schemas, aliases) that only accepts a repaired name when it matches a declared tool in schemas (never invents an undeclared tool), and wire it into parse_tool_call(), _callable(), streaming _scan(), and _finish_call() when recover=True:

def _recover_declared_name(raw: str, schemas: dict | None, aliases: dict | None = None) -> str:
    """Safely repair minor low-bit quantization stutters in `<function=NAME>` ONLY when the repaired name
    uniquely matches a declared tool in `schemas` (e.g. `ggrep_text` -> `grep_text`, `p_present_files` -> `present_files`,
    `bash,` or `bash=command` -> `bash`). Never invents an undeclared tool."""
    name = raw.strip()
    if aliases:
        name = aliases.get(name, name)
    if not schemas or name in schemas:
        return name
    # 1. Strip stray trailing punctuation or `=param` (e.g. `bash,`, `bash=command`)
    cand = re.split(r"[,;:\s=]", name, maxsplit=1)[0].strip()
    if cand and cand in schemas:
        return cand
    # 2. Doubled leading letter stutter (e.g. `ggrep_text` -> `grep_text`)
    if len(name) >= 3 and name[0] == name[1] and name[1:] in schemas:
        return name[1:]
    # 3. Single-letter + underscore stutter prefix (e.g. `p_present_files` -> `present_files`)
    if len(name) >= 4 and name[1] == "_" and name[2:] in schemas and name[0] == name[2]:
        return name[2:]
    return name

Key wiring changes (diff against v0.2.17 terminal/serve/frontend.py):

  • parse_tool_call() & _finish_call(): when recover=True and \n occurs before > (or > is missing before \n), slice the function name at \n instead of failing or slicing into <parameter=...>.
  • _callable(): return True if self.recover and _recover_declared_name(name, self.schemas, self.aliases) in self.schemas.
  • Streaming _scan() & _finish_call(): resolve name = _recover_declared_name(raw_name, self.schemas, self.aliases) if self.recover else ....
Verification
  • Running in daily production for 1 week on Windows 11 + RTX 4070 Ti (12 GB) + Qwen3.8-Flash-Next IQ3_S (strata 0.1.63 -> 0.1.65 -> 0.1.70) with OpenAI-compatible coding agents.
  • Passed 12/12 new malformed-call unit cases (both streaming and non-streaming, including negative cases verifying undeclared names are still rejected) and 72/72 existing terminal/serve unit tests.
  • Zero leaked <tool_call> blocks observed since applying this patch.
Lenguaje dominante
C++
Estrellas
11.6k
Forks
1k
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Niko1221/Strata

Todos los issues de Niko1221/Strata

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.