Skip to content

Studio on Windows floods the Recycle Bin with sqlite WAL/SHM temp files every second during training #15552

Closed

Description

@fr303388

Summary

Unsloth Studio (Windows desktop) floods the Windows Recycle Bin with *.db-wal / *.db-shm files every second while a training run is active. In ~90 minutes of training it wrote well over 10,000 entries (~40 MB) into C:\$Recycle.Bin\<SID>\. The behaviour looks like malware-style file thrashing, but it is Unsloth Studio's own temporary-file cleanup deleting sidecar files into the Recycle Bin instead of unlinking them.

Environment

  • OS: Windows 11 x64, local install
  • Studio backend: many instances of unsloth.exe studio --api-only -H 127.0.0.1 -p 8888..8908
  • Packages: unsloth / unsloth_zoo installed in Studio's venv at C:\Users\ANGEL\.unsloth\studio\unsloth_studio
  • Reproduced during an active training job (trainer summary written every second, step ~268/3357, ETA ~85 min)

Reproduction

  1. Start any training run in Studio that touches a sqlite-backed component (knowledge / RAG index).
  2. Watch C:\$Recycle.Bin\<SID>\ while training runs: roughly every second a new $R*.db-wal (0 bytes) + $R*.db-shm (32 KB) pair appears with its $I metadata.

Evidence (decoded $I metadata, Win10 v2 format)

  • Original path recorded in $I: C:\Users\ANGEL\.unsloth\...
  • Deleted-at timestamps: batches all stamped per-second during training (e.g. 2026-10-27 13:10:34)
  • 1,299 $I files present in one sample; measured +~50 files per 30 s while training was live
  • The files are not removed permanently — they are recoverable-deleted into the Recycle Bin, which is exactly the bug: Studio's cleanup path sends temporary sqlite WAL/SHM sidecars to the Recycle Bin instead of a permanent unlink.

Root-cause hypothesis

A sqlite database under .unsloth is opened/closed repeatedly during training (likely the studio knowledge/RAG index). SQLite WAL mode creates <db>-wal / <db>-shm sidecars on each connection; a Studio cleanup path treats them as deletable and removes them via the Recycle Bin (recoverable delete) rather than unlink(). At per-second churn this explodes the Recycle Bin and adds double I/O per step.

Code search notes: the unsloth package has no trash-API hits; the studio package only mentions $Recycle.Bin in a protection list (library.py:1766), so the actual move-to-trash call is likely in a helper or the Tauri/Rust side.

Impact

  • Recycle Bin grows by tens of thousands of entries per training run; when the per-volume cap is hit, older (possibly user-recoverable) items get silently purged.
  • Unnecessary disk I/O on every training step.
  • Antivirus / EDR may flag the mass-delete pattern as ransomware behaviour.

Suggested fixes

  1. Delete temp sqlite sidecars (and other temp files the app itself creates) with os.remove() / unlink — only user-initiated deletions should be recoverable.
  2. Keep the sqlite connection open for the whole run instead of per-step open/close, or use journal_mode=DELETE / :memory: for transient data.
  3. At minimum, skip the Recycle Bin for anything under the app's own temp/staging directories.

Workaround for affected users

A scheduled task that empties Recycle Bin entries whose original path is under .unsloth every few minutes stops the growth; manually deleted files under other paths can still be kept with a retention window. This is a stopgap, not a fix.

Activity

  1. fr303388 commented on Oct 27, 2026

    @fr303388
    Author
    Image
  2. danielhanchen commented on Oct 28, 2026

    @danielhanchen
    Member

    Sorry will fix this asap

  3. self-assigned this
    on Oct 28, 2026
  4. fr303388 commented on Oct 28, 2026

    @fr303388
    Author

    Title: Read-Only Flag on rag.db — Why and What It Does

    Context

    • File: C:\Users\ANGEL.unsloth\studio\rag\rag.db (SQLite database, 152 KB)
    • Used by: Unsloth Studio's RAG (retrieval) feature.
    • SQLite runs in WAL (Write-Ahead Logging) mode, so any write to the
      database also creates two companion files:
      • rag.db-wal — the write-ahead log holding uncommitted pages
      • rag.db-shm — the shared-memory index for WAL access
    • These companion files get created, modified, and left behind repeatedly
      during normal use; when they are cleaned up (or the app is restarted),
      Windows treats each deletion as "send to Recycle Bin", which floods the
      Recycle Bin with junk entries.

    What was done

    • The Read-only (R) file attribute was enabled on rag.db.

    Effect (temporary)

    • Any process attempting to open rag.db for writing now fails, so no new
      write transactions can start.
    • Therefore no new rag.db-wal / rag.db-shm junk is generated, and no more
      repeated "delete → Recycle Bin" debris is produced.
    • This is a stop-gap measure, not a permanent fix.

    Important notes

    • Existing rag.db-wal (0 KB) and rag.db-shm (32 KB) files are still
      present; read-only on the .db does not remove them.
    • Even a read-only open of the database can still touch rag.db-shm
      (last modified 2026-10-28 16:50), so the files are not guaranteed to
      stay untouched while any process merely opens the DB.
    • To let the RAG feature write again (e.g., updating the index), you must
      clear the Read-only attribute first, otherwise writes will fail.

    Status check (verified 2026-10-28)

    • rag.db 155,648 B Read-only = True (attribute active)
    • rag.db-wal 0 B Read-only = False
    • rag.db-shm 32,768 B Read-only = False (still being touched)
    Image
  5. danielhanchen commented on Oct 28, 2026

    @danielhanchen
    Member

    Fixed! Each idle Studio backend opened and closed its knowledge-base database (rag.db) several times every 30 seconds, and every close made SQLite delete and recreate rag.db-wal and rag.db-shm. With many backends running, that turned into a delete every second or so, and your system sent each one to the Recycle Bin. Studio now keeps one quiet connection open, so those files stay in place instead of being thrown away and remade. Fixed in #15719.
    To update: Unsloth Desktop will have an update banner. For Studio, use unsloth studio update. For Docker, use docker exec <container> unsloth-studio-update. Reopen if it still happens.

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

Metadata

Metadata

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