Skip to content

feat(files): a lastTouchedBefore cutoff for cleaning up recent files - #437

Open
robelest wants to merge 2 commits into
mainfrom
feat/361-ignore-grace-period
Open

robelest wants to merge 2 commits into
mainfrom
feat/361-ignore-grace-period

Conversation

@robelest

@robelest robelest commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #361.

getFilesToDelete and deleteFiles take an optional lastTouchedBefore (ms since epoch) in place of the fixed Date.now() - 24h. Passing the same cutoff to both keeps any file used at or after it, and files with a reference are always kept. NaN and future cutoffs are rejected, since a future one would delete a file reused between listing and deleting. force is unchanged.

Only for resets: files from before the cutoff that aren't in a saved message yet (uploads, or a running generation's files) are deleted too, since the grace period is what reserves them until then.

@pkg-pr-new

pkg-pr-new Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@convex-dev/agent@437

commit: 5e36f03

@robelest

robelest commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

@ianmacartney want your read on direction here. The 24-hour grace period is the only thing reserving a file between storeFile and the message that references it (useExistingFile bumps lastTouchedAt without adding a reference). I tried three shapes:

  • ignoreGracePeriod: boolean: deletes anything unreferenced, including files reused between listing and deleting.
  • deleteFiles({ files }) with the listed docs, deleting only ones unchanged since: deleteFiles gets a second input form, and same-millisecond reuse slips past it.
  • lastTouchedBefore: number, one cutoff passed to both, which is what this PR now does: the cleanest code (it just replaces Date.now() - FILE_CLEANUP_GRACE_MS), and it keeps files touched after listing, but it's an untyped epoch-ms number in the API.

None is safe for a file stored before the cutoff whose message isn't saved yet, so it's documented as reset-only, which is the case in #361. The root fix would be reserving the file under its pending message so cleanup needs no grace period at all.

@robelest robelest changed the title feat(files): ignoreGracePeriod cleans up recent files but keeps referenced ones feat(files): a lastTouchedBefore cutoff for cleaning up recent files Oct 29, 2026
@robelest
robelest force-pushed the feat/361-ignore-grace-period branch from 8bc1791 to c3d7396 Compare October 30, 2026 19:43
@robelest
robelest marked this pull request as ready for review October 30, 2026 19:44
@robelest
robelest force-pushed the feat/361-ignore-grace-period branch from c3d7396 to e85f6e3 Compare October 30, 2026 19:45

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/component/files.test.ts Resolved
@robelest
robelest force-pushed the feat/361-ignore-grace-period branch from f750c59 to 86d808c Compare October 30, 2026 21:51
…teFiles (#361)

Passing the same cutoff to both cleans up recent unreferenced files, such
as in a dev reset, while keeping any file used at or after it.
@robelest
robelest force-pushed the feat/361-ignore-grace-period branch from 86d808c to 5e36f03 Compare October 30, 2026 22:58

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose age-only orphan-file cleanup without bypassing the final reference check

1 participant