Skip to content

chore: add pruning for orphaned chat file_ids entries #23910

@johnstcn

Description

@johnstcn

Context

PR #23537 adds a file_ids uuid[] column to chats. File IDs are appended when messages reference uploaded files, but no code path ever removes entries from this array.

Problem

  • Editing a message to replace file A with file B leaves A in file_ids (phantom reference).
  • Soft-deleted messages' file references persist in the array.
  • Over time, chats accumulate stale entries (capped at 20 by MaxChatFileIDs).
  • No dbpurge job exists to clean up orphaned chat_files rows.

Suggested approach

  1. Add a dbpurge job that periodically scans for chat_files rows not referenced by any chat's file_ids array.
  2. Optionally, add a RemoveChatFileIDs query to scrub stale entries when messages are soft-deleted.

The current cap of 20 limits the practical impact, but this should be addressed before the feature leaves experimental.

Ref: #23537 (comment)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions