Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/core/src/services/chatRecordingService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,13 @@ describe('ChatRecordingService', () => {
expect(fs.existsSync(logFile)).toBe(false);
});

it('should not throw if session file does not exist', async () => {
it('should throw if session file does not exist', async () => {
const chatsDir = path.join(testTempDir, 'chats');
fs.mkdirSync(chatsDir, { recursive: true });

await expect(
chatRecordingService.deleteSession('non-existent'),
).resolves.not.toThrow();
).rejects.toThrow('No session file found for non-existent');
});
});

Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/services/chatRecordingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,10 @@ export class ChatRecordingService {
chatsDir,
shortId,
);
if (matchingFiles.length === 0) {
throw new Error(`No session file found for ${sessionIdOrBasename}`);
}
Comment on lines +698 to +700

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This change breaks the idempotency of the deleteSession method and introduces inconsistent behavior regarding the 'session not found' state.

  1. Inconsistency: If the chats directory is missing, the method returns successfully (line 691). However, if the directory exists but no matching session file is found, it now throws an error. This makes the result of deleting a non-existent session dependent on whether other sessions have been created or if the directory was manually initialized.
  2. Idempotency: Standard delete operations are typically idempotent. Throwing an error when a session is already deleted (or never existed) can cause issues for callers or UI logic that expects a successful outcome if the target resource is absent. If a user or script calls delete twice, the second call will now fail.
  3. Subagent Deletion: Subagent files are stored in subdirectories and do not use the session- prefix (see line 404). Because getMatchingSessionFiles only searches the top-level directory and filters for the prefix, it will never find subagent files. Attempting to delete a subagent session directly will now result in a hard error instead of a silent no-op, which may prevent the UI from cleaning up stale entries if it allows individual subagent deletion.

Consider whether the 'not found' case should remain a successful no-op to maintain idempotency, or if the search logic should be expanded to be more inclusive before failing.


for (const file of matchingFiles) {
await this.deleteSessionAndArtifacts(chatsDir, file, tempDir);
}
Expand Down