fix(server): abort behavior in sse stream (#12211)

fix AI-121
fix AI-118

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Bug Fixes**
- Improved handling of connection closures and request abortion for
streaming and non-streaming chat endpoints, ensuring session data is
saved appropriately even if the connection is interrupted.
- **Refactor**
- Streamlined internal logic for managing request signals and connection
events, resulting in more robust and explicit session management during
streaming interactions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
DarkSky
2025-07-04 14:07:45 +08:00
committed by GitHub
parent 1b9ed2fb6d
commit 5a49d5cd24
5 changed files with 146 additions and 74 deletions
@@ -36,6 +36,9 @@ test.describe('AIAction/GenerateAnImageWithImage', () => {
await expect(answer.getByTestId('ai-answer-image')).toBeVisible();
const insert = answer.getByTestId('answer-insert-below');
await insert.click();
await page.waitForSelector('.affine-image-container');
await page.reload();
await utils.chatPanel.waitForHistory(page, [
{
role: 'action',
@@ -71,11 +71,15 @@ test.describe('AIAction/GenerateAnImageWithText', () => {
const { answer } = await generateImage();
const insert = answer.getByTestId('answer-insert-below');
await insert.click();
await page.waitForSelector('.affine-image-container');
await page.reload();
await utils.chatPanel.waitForHistory(page, [
{
role: 'action',
},
]);
const { answer: panelAnswer, actionName } =
await utils.chatPanel.getLatestAIActionMessage(page);
await expect(