feat(server): allow cleanup session for deleted docs (#13720)

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

## Summary by CodeRabbit

* **Bug Fixes**
* Resolved occasional errors when removing document links from sessions,
ensuring cleanup completes reliably.
* Improved reliability during maintenance actions by preventing
unnecessary validation failures in system-initiated updates, while
preserving existing checks for user-initiated changes.

* **Chores**
* Internal adjustments to the session update flow to better support
maintenance operations without affecting user-facing behavior.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
DarkSky
2025-10-10 12:43:21 +08:00
committed by GitHub
parent d80ca57e94
commit 0063f039a7
2 changed files with 18 additions and 14 deletions

View File

@@ -396,7 +396,10 @@ export class CopilotSessionModel extends BaseModel {
}
@Transactional()
async update(options: UpdateChatSessionOptions): Promise<string> {
async update(
options: UpdateChatSessionOptions,
internalCall = false
): Promise<string> {
const { userId, sessionId, docId, promptName, pinned, title } = options;
const session = await this.getExists(
sessionId,
@@ -415,14 +418,16 @@ export class CopilotSessionModel extends BaseModel {
}
// not allow to update action session
if (session.prompt.action) {
throw new CopilotSessionInvalidInput(
`Cannot update action: ${session.id}`
);
} else if (docId && session.parentSessionId) {
throw new CopilotSessionInvalidInput(
`Cannot update docId for forked session: ${session.id}`
);
if (!internalCall) {
if (session.prompt.action) {
throw new CopilotSessionInvalidInput(
`Cannot update action: ${session.id}`
);
} else if (docId && session.parentSessionId) {
throw new CopilotSessionInvalidInput(
`Cannot update docId for forked session: ${session.id}`
);
}
}
if (promptName) {

View File

@@ -636,11 +636,10 @@ export class ChatSessionService {
})
.then(s => s.map(s => [s.userId, s.id]));
for (const [userId, sessionId] of sessionIds) {
await this.models.copilotSession.update({
userId,
sessionId,
docId: null,
});
await this.models.copilotSession.update(
{ userId, sessionId, docId: null },
true
);
}
}