From e3645ba908f448cf9edb72809a4c596e66985e5b Mon Sep 17 00:00:00 2001 From: davegilligan Date: Fri, 22 May 2026 19:26:45 +0200 Subject: [PATCH] Fix Korrespond stream disconnect: emit progress before legal check The dbnToolsRunLegalCheck call blocks for 30-120s with no output, causing the H2 idle stream timeout (~60s) to drop the connection. Fix: emit 'Verifying legal authorities...' progress event just before the legal check to reset the idle timer. Also reduce legal check timeouts from 120s/60s to 45s/30s so the call completes within the new 60s window even if LiteLLM is slow. Co-Authored-By: Claude Sonnet 4.6 --- includes/KorrespondAgent.php | 11 ++++++++++- includes/bootstrap.php | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/includes/KorrespondAgent.php b/includes/KorrespondAgent.php index f4fec25..1662ee7 100644 --- a/includes/KorrespondAgent.php +++ b/includes/KorrespondAgent.php @@ -91,6 +91,12 @@ final class DbnKorrespondAgent 'pl' => 'Sprawdzanie jakości projektu…', 'uk' => 'Перевірка якості чернетки…', ], + 'legal_check' => [ + 'en' => 'Verifying legal authorities…', + 'no' => 'Verifiserer rettskilder…', + 'pl' => 'Weryfikacja źródeł prawnych…', + 'uk' => 'Перевірка правових джерел…', + ], 'translating_to' => [ 'en' => 'Translating to {lang}…', 'no' => 'Oversetter til {lang}…', @@ -257,7 +263,9 @@ PROMPT; if ($emit) { $emit('progress', ['detail' => self::L('quality_check', $userLang)]); } $checked = $this->selfCheck($draftNo, $retrieval['sources'], $classify, $goal, $tone); - // ── Legal check: dbn-legal-agent-v2 threshold verification ──────────────── + // ── Legal check: dbn-legal-agent-v3 threshold verification ──────────────── + // Emit progress to keep H2 stream alive during the blocking LiteLLM call (60s idle timeout) + if ($emit) { $emit('progress', ['detail' => self::L('legal_check', $userLang)]); } $legalCheck = []; try { $legalCheck = dbnToolsRunLegalCheck($checked['draft'], $body); @@ -775,6 +783,7 @@ EOT, if ($emit) { $emit('progress', ['detail' => self::L('check_and_authorities', $userLang)]); } $checked = $this->selfCheck($refinedNo, $retrieval['sources'], $classify, $goal, $tone); + if ($emit) { $emit('progress', ['detail' => self::L('legal_check', $userLang)]); } $legalCheckRefine = []; try { $legalCheckRefine = dbnToolsRunLegalCheck($checked['draft'], $body); diff --git a/includes/bootstrap.php b/includes/bootstrap.php index e2869c6..88fecdf 100644 --- a/includes/bootstrap.php +++ b/includes/bootstrap.php @@ -949,7 +949,7 @@ function dbnToolsRunLegalCheck(string $brief, string $docType): array 'model' => 'dbn-legal-agent-v3', 'temperature' => 0.1, 'max_tokens' => 350, - 'timeout' => 120, + 'timeout' => 45, // No 'json' key — plain narrative, no response_format flag ]; @@ -977,7 +977,7 @@ function dbnToolsRunLegalCheck(string $brief, string $docType): array ['role' => 'system', 'content' => $sysMsg], ['role' => 'user', 'content' => $question], ], - array_merge($opts, ['model' => 'qwen2.5:7b', 'timeout' => 60]) + array_merge($opts, ['model' => 'qwen2.5:7b', 'timeout' => 30]) ); $text = trim((string)($fallback['choices'][0]['message']['content'] ?? '')); } catch (Throwable $e) {