Skip to content

Keep RAG WAL sidecars between database operations - #15719

Merged
danielhanchen merged 6 commits into
unslothai:mainfrom
Imagineer99:fix/rag-wal-keeper
Oct 28, 2026
Merged

danielhanchen merged 6 commits into
unslothai:mainfrom
Imagineer99:fix/rag-wal-keeper

Conversation

@Imagineer99

@Imagineer99 Imagineer99 commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

An idle Unsloth backend opens and closes the RAG database several times on each linked-folder polling cycle. With no other connection open, SQLite deletes rag.db-wal and rag.db-shm after each operation, then recreates them for the next one—even with an empty knowledge base.

Keep one idle connection per resolved RAG database path, following the existing database keeper pattern. Operation connections remain independent; the keeper holds no transaction and requires no vector extension. Release it before account storage retirement and at backend shutdown, suppress late recreation during shutdown, and re-enable lazy creation for a new lifespan.

Native Windows 11 validation used Python 3.13.17 and SQLite 3.50.4:

  • Before: the exact published Unsloth 2026.10.9 wheel recreated five WAL/SHM pairs per 30-second polling cycle.
  • After: zero repeated sidecar deletions over 10 minutes idle and during a real five-step QLoRA training run. One pair remained until graceful shutdown.
  • Regression coverage includes stable sidecar identity, durable writes, independent writes/checkpoints, concurrent first opens, metadata-only access without sqlite-vec, shutdown/restart, and account retirement.
  • 249 distinct tests passed across the focused RAG/account and linked-folder/lifespan suites; 2 skipped. One existing symlink-path test was blocked by Windows privilege error 1314 before reaching the changed logic.
  • Repository-pinned Ruff lint/format, diff checks, and publication checks passed.

Refs #15552. This removes confirmed unnecessary file churn. The reported Recycle Bin behavior remains under investigation: local native traces showed successful SQLite DeleteFileW calls and no Recycle Bin growth before or after the change. A further 120-second run with three released backends sharing one isolated database produced 61 WAL/SHM deletion pairs, all attributed to successful SQLite DeleteFileW calls in the three listener processes, with zero new Recycle Bin entries through graceful shutdown. The release comparison executed the published backend with existing native dependencies, not a clean reinstall of the packaged Desktop application.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-28T11:36:27.381718Z
We couldn’t complete this review. Comment @codex review to try again.
cd37995 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen danielhanchen self-assigned this Oct 28, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

danielhanchen added a commit to Etherll/unsloth that referenced this pull request Oct 28, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 47f064c into unslothai:main Oct 28, 2026
danielhanchen added a commit that referenced this pull request Oct 28, 2026
## Summary

`(Python 3.13, a-f)` fails on main and on every PR based on it (seen on
the #15693 and #15761 staging runs) with two stale tests. Both product
changes are intentional; the tests had not caught up.

**1.
`test_account_chat_settings.py::test_list_export_and_delete_stay_in_the_account`**

```
assert {'threads': [...Guards': True} == {'threads': []}
  Left contains 1 more item: {'threadPatchGuards': True}
```

#15685 advertises the chat-title repair guards on the thread lists
(`threadPatchGuards` on the `/chat/threads` reply). This test checks
that another account's thread stays invisible, but compared the whole
reply to `{"threads": []}`. It now asserts the thread list itself is
empty, which is the privacy claim.

**2.
`test_checkpoint_compaction.py::test_the_reachability_probe_closes_the_connection_it_opens`**

```
assert _open_archive_handles() <= before + 1
E   assert 4 <= (0 + 1)
```

#15719 keeps one WAL keeper connection per `rag.db` for the life of the
process (`storage/rag_db._ensure_wal_keeper`), holding `rag.db` plus its
`-wal` and `-shm` sidecars. The first probe in a fresh process creates
it, so the test counted the keeper's descriptors as a leak. It also
failed when run alone, not only under xdist.

The test now probes once to warm the keeper up, takes its baseline after
that, and requires no growth at all over 50 probes. That is stricter
than the old `before + 1`, and it is the leak the test exists for: one
leaked probe connection per call.

## Testing

- Both tests fail on main (`75555ccb54`) and pass with this change;
`test_account_chat_settings.py` 93 passed.
- Sabotage: replacing the `conn.close()` in
`conversation_archive.reachable()` with a no-op makes the probe test
fail with `assert 23 <= 5`.
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.

2 participants