optimize technical truth

This commit is contained in:
team 1
2026-04-29 17:42:37 +02:00
parent 06f192b28a
commit 19c0f612dc
10 changed files with 454 additions and 307 deletions

View File

@@ -12,6 +12,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\Routing\Annotation\Route;
use Throwable;
final readonly class AskSseController
{
@@ -70,7 +71,7 @@ final readonly class AskSseController
'createdAt' => $now,
'updatedAt' => $now,
]);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return new JsonResponse(
['error' => 'Stream job could not be created: ' . $this->formatThrowableForClient($e)],
Response::HTTP_INTERNAL_SERVER_ERROR
@@ -86,7 +87,7 @@ final readonly class AskSseController
return $response;
}
#[Route('/ask-jobs/{jobId}', name: 'ask_job_status', methods: ['GET'], requirements: ['jobId' => '[a-f0-9]{48}'])]
#[Route('/ask-jobs/{jobId}', name: 'ask_job_status', requirements: ['jobId' => '[a-f0-9]{48}'], methods: ['GET'])]
public function jobStatus(string $jobId): JsonResponse
{
$job = $this->readJob($jobId);
@@ -233,7 +234,7 @@ final readonly class AskSseController
$eventId = $this->appendJobOutput($jobId, $chunk);
$this->sendData($chunk, $eventId);
}
} catch (\Throwable $e) {
} catch (Throwable $e) {
$message = 'Stream abgebrochen: ' . $this->formatThrowableForClient($e);
$this->markJobStatus($jobId, self::JOB_STATUS_FAILED, $message);
$this->sendEvent(
@@ -267,7 +268,7 @@ final readonly class AskSseController
$prompt,
'Systemhinweis: Antwort konnte nicht abgeschlossen werden. Ursache: ' . $message
);
} catch (\Throwable) {
} catch (Throwable) {
// History persistence must never break the SSE error response.
}
}
@@ -318,7 +319,7 @@ final readonly class AskSseController
return trim($contextHint);
}
private function formatThrowableForClient(\Throwable $e): string
private function formatThrowableForClient(Throwable $e): string
{
$message = trim($e->getMessage());
@@ -412,6 +413,7 @@ final readonly class AskSseController
/**
* @param array<string, mixed> $payload
* @throws \JsonException
*/
private function writeJob(string $jobId, array $payload): void
{
@@ -518,7 +520,7 @@ final readonly class AskSseController
'result' => ['ok' => true],
];
});
} catch (\Throwable) {
} catch (Throwable) {
// Job status persistence must never break the already-running stream.
}
}
@@ -581,9 +583,8 @@ final readonly class AskSseController
flock($handle, LOCK_UN);
return $result;
} catch (\Throwable $e) {
} catch (Throwable $e) {
@flock($handle, LOCK_UN);
throw $e;
} finally {
if (is_resource($handle)) {
@fclose($handle);
@@ -785,7 +786,7 @@ final readonly class AskSseController
if (file_put_contents($this->jobOutputPath($jobId), $line, FILE_APPEND | LOCK_EX) === false) {
return null;
}
} catch (\Throwable) {
} catch (Throwable) {
return null;
}