#6051: feat(memory): add Bun sqlite compatibility
## Summary
Add runtime detection and compatibility wrapper for Bun's `bun:sqlite` to work with the existing `node:sqlite` API used in memory search.
## Changes
- Detect Bun runtime via `globalThis.Bun`
- Wrap `bun:sqlite` Database class to match `node:sqlite` DatabaseSync API
- Handle extension loading differences between runtimes
## Why
When running the gateway under Bun, memory search fails with:
```
No such built-in module: node:sqlite
```
Bun has its own `bun:sqlite` with a slightly different API. This patch provides a compatibility layer so memory search works on both Node.js and Bun.
## Testing
- Tested on Bun 1.3.5
- Memory search with custom embeddings endpoint works
- Extension loading (sqlite-vec) compatibility preserved
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Adds runtime detection for Bun (`globalThis.Bun`) and a compatibility shim that returns a `node:sqlite`-shaped module under Bun by wrapping `bun:sqlite`’s `Database` into a `DatabaseSync`-like class, plus a small stubbed export surface (`StatementSync`, `constants`, `backup`). This allows the memory module (e.g. `src/memory/manager.ts` opening the DB and `src/memory/sqlite-vec.ts` loading extensions) to run when `node:sqlite` is unavailable under Bun.
<h3>Confidence Score: 3/5</h3>
- Mostly safe, but the Bun wrapper still has some behavior mismatches that can change runtime semantics in edge cases.
- Change is isolated to the sqlite loader and is straightforward, but the Bun compatibility layer is intentionally type-erased and may diverge from `node:sqlite` semantics; one concrete mismatch is in-memory database path handling. Previous review threads also indicate potential Statement API/constant-value mismatches that could surface at runtime under Bun.
- src/memory/sqlite.ts
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#8706: fix(memory): fall back to better-sqlite3 when node:sqlite lacks FTS5
by ElmerProject · 2026-02-04
71.6%
#6863: feat: add bun runtime support as opt-in feature
by aashishsingla567 · 2026-02-02
64.2%
#15620: fix(memory): await sync in search to prevent database closure race
by superlowburn · 2026-02-13
63.8%
#4231: fix(memory): use sqlite-vec knn (MATCH+k) for vector search
by leonardsellem · 2026-01-29
63.8%
#11860: fix(memory): enable SQLite WAL mode for concurrent access safety
by Sojemand · 2026-02-08
63.1%
#16669: feat(memory-lancedb): add memory_search/memory_get compatibility re...
by ciberponk · 2026-02-15
62.4%
#17123: Add Cloud Run deployment guide and Bun version pinning
by optiflow · 2026-02-15
61.8%
#11179: fix(memory): replace confusing "No API key" errors in memory tools ...
by liuxiaopai-ai · 2026-02-07
61.7%
#22692: fix(memory-lancedb): [P1] add missing runtime deps — plugin broken ...
by mahsumaktas · 2026-02-21
61.5%
#18595: feat: native PostgreSQL + pgvector memory backend
by IrriVisionTechnologies · 2026-02-16
61.2%