Chunked text processing silently drops the end of long texts

Abierto
#478 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@nonofr91 ya está trabajando en esto.

Desde el 2/12/2026.

  • #479 de @nonofr91 — abierto

Evaluación

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

Línea de trabajo

Start with ChunkService::chunkSplitPrompt() and trace how its paragraph, sentence, and word split patterns handle text that lacks a trailing separator. The issue reports that the author is preparing a fix with unit tests for all three split levels and fall-through behavior. Done means concatenating the chunks reproduces the full input, including its final text.

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

Descripción

Which version of integration_openai are you using?

main (6.0.0-dev), the bug exists in released versions as well

Which version of Nextcloud are you using?

stable35

Which browser are you using? In case you are using the phone App, specify the Android or iOS version and device please.

not relevant

Describe the Bug

When a text is long enough to be split into chunks, the end of the text can be silently dropped before anything is sent to the AI service. The truncated output looks successful, part of the source text is just missing.

ChunkService::chunkSplitPrompt() splits by paragraph, then by sentence, then by word, using patterns anchored on a trailing separator (\n, [!.?\n], \W). Each level returns as soon as it produces at least one chunk. Whatever part of the text does not end with that level's separator is never matched, and it is not passed down to the finer levels either, so it is lost:

input:  "aaaa bbbb cccc\ndddd eeee ffff\ngggg hhhh"   (maxChars = 20)
chunks: "aaaa bbbb cccc\n" + "dddd eeee ffff\n"
        -> "gggg hhhh" never appears in any chunk

The same loss happens one level down when the text does not end with sentence punctuation, and one level further down for the last word of a text ending with a word character.

The affected call sites include translation, summary, proofread, context write, topics, reformat, improve, reformulate and change tone. Translation is the easiest to hit in practice: with the default configuration it chunks at min(chunk_size, max_tokens) * 3 ≈ 3000 characters, so translating a few paragraphs is enough. A translated document can simply miss its ending.

Expected Behavior

Every chunk contains a part of the input and concatenating the chunks gives back the full input, whatever characters the text ends with. The split should fall through to the finer level for the unmatched tail instead of dropping it.

To Reproduce

Reproduced end to end on a live Nextcloud 35.0.3 instance with the translation task, using a local mock provider that echoes back exactly what it receives. A 3491-character input whose final line has no trailing newline:

  • input sent to translation: 3491 characters
  • concatenated text actually received by the provider: 3441 characters
  • the entire final line (50 characters) never reached the provider

A control input identical but ending with a newline went through without any loss (3492 characters in, 3492 out), confirming that the loss depends on the trailing separator.

The split logic itself is deterministic and runs entirely before the API call, so it can also be demonstrated without a provider:

$maxChars = 20;
$prompt = "aaaa bbbb cccc\ndddd eeee ffff\ngggg hhhh";
preg_match_all("/.{1,{$maxChars}}\n/su", $prompt, $chunks);
// implode('', $chunks[0]) is 30 chars long, the input is 39:
// the tail after the last newline is missing from the chunks

I am preparing a fix with unit tests covering the three split levels and the fall-through behaviour.

Assisted by Devin:SWE-2.1

Lenguaje dominante
PHP
Estrellas
78
Forks
42
Merge medio
2 d 21 h
PR fusionados (30 d)
5

Preparar el entorno

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 nextcloud/integration_openai

Todos los issues de nextcloud/integration_openai

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.