Chunked text processing silently drops the end of long texts

オープン
#478 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@nonofr91 がすでに取り組んでいます。

2026年12月2日 から。

  • #479 @nonofr91 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
php
領域
backend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
PHP
スター
78
フォーク
42
平均マージ
2日 21時間
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nextcloud/integration_openai のほかの issue

nextcloud/integration_openai の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。