Skip to content

bug(frontend): ChatController.enableAutoSave() leaks setInterval — saves continue indefinitely after unmount #3749

@mrveiss

Description

@mrveiss

Summary

`ChatController.enableAutoSave()` calls `setInterval()` but never stores the return value. The interval ID is immediately lost, making it impossible to cancel. When `ChatInterface.vue` unmounts, its `onUnmounted` hook clears `autoSaveInterval` and `heartbeatInterval` — but cannot clear the controller's interval because there is no reference.

Evidence

Session `82feb428-c4fa-4e4d-ab89-f94c7ca056b2`: last message at 10:02, but `POST /api/chats/{id}/save` continues firing every ~60s at 13:24, 13:25, 13:26, 13:27, 13:28 — 3+ hours after session was abandoned.

Root Cause

```ts
// ChatController.ts:943 — interval ID is never stored
enableAutoSave(intervalMs: number = 30000): void {
setInterval(() => { // ← leaked: no way to clearInterval() this
if (this.chatStore.settings.autoSave && this.chatStore.currentSessionId) {
this.saveChatSession().catch(...)
}
}, intervalMs)
}
```

```ts
// ChatInterface.vue onUnmounted — only clears its own interval, not the controller's
if (autoSaveInterval.value) {
clearInterval(autoSaveInterval.value) // ← this ref was never set for the controller interval
}
```

Fix

Option A (preferred): Remove `ChatController.enableAutoSave()` entirely — `ChatInterface.vue` already has its own properly-managed auto-save interval (see related issue). The controller method is redundant.

Option B: Store the interval ID in `ChatController`, expose a `disableAutoSave()` method, and call it from `onUnmounted`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions