harden history find tokens and shops earch

This commit is contained in:
team 1
2026-04-26 19:59:31 +02:00
parent ff273ff9a0
commit 308e980b4a
11 changed files with 1230 additions and 75 deletions

View File

@@ -92,6 +92,13 @@ final readonly class AskSseController
if (($claimed['ok'] ?? false) !== true) {
$this->prepareStreamRuntime();
echo "retry: 15000\n\n";
if ($this->shouldSilentlyCloseDuplicateJobStream($claimed)) {
$this->sendComment('duplicate-or-finished-stream');
$this->sendEvent('done', '[DONE]');
return;
}
$this->sendEvent('error', $this->jobClaimErrorMessage($claimed));
$this->sendEvent('done', '[DONE]');
return;
@@ -504,6 +511,24 @@ final readonly class AskSseController
}
}
}
/**
* EventSource may reconnect to an already running or already completed job.
* Those duplicate connections should be closed quietly so the UI does not
* append a misleading error after the real stream already produced output.
*
* @param array<string, mixed> $claim
*/
private function shouldSilentlyCloseDuplicateJobStream(array $claim): bool
{
if (($claim['reason'] ?? null) !== 'not_pending') {
return false;
}
$status = (string) ($claim['status'] ?? '');
return $status === self::JOB_STATUS_RUNNING
|| $status === self::JOB_STATUS_COMPLETED;
}
/**
* @param array<string, mixed> $claim
@@ -548,7 +573,6 @@ final readonly class AskSseController
return 'Der Antwort-Job wurde nicht gefunden. Falls deine Verbindung kurz unterbrochen war, sende die Anfrage bitte erneut.';
}
private function cleanupExpiredJobs(): void
{
$directory = $this->jobDirectory();