Skip to content

feat(cli): add native Bun backend support and Dockerfile.bun - #11039

Merged
diegosouzapw merged 9 commits into
cheaper-inference:release/v3.8.50from
rqzbeh:feat/bun-backend-support
Aug 22, 2026
Merged

diegosouzapw merged 9 commits into
cheaper-inference:release/v3.8.50from
rqzbeh:feat/bun-backend-support

Conversation

@rqzbeh

@rqzbeh rqzbeh commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds native Bun backend runtime support, multi-stage Docker build configuration (Dockerfile.bun), dynamic driver fallback logic, and resolves DAST CI workflow stability.

Key Changes

  1. Bun Runtime Detection & Container Support (Dockerfile.bun):

    • Added multi-stage Dockerfile.bun for native Bun production deployments.
    • Added runtime detection utilities (bin/nodeRuntimeSupport.mjs, src/shared/utils/nodeRuntimeSupport.ts).
  2. SQLite Driver Adapter Prioritization (bin/cli/sqlite.mjs, src/lib/db/adapters/driverFactory.ts):

    • Enforces native better-sqlite3 driver prioritization under Bun with smooth fallback to bun:sqlite and sqlite3.
    • Updated native dependency loader (bin/cli/runtime/nativeDeps.mjs) for cross-runtime binary loading.
  3. Build & Dev Tooling Adaptation (scripts/build/build-next-isolated.mjs, scripts/dev/run-next.mjs):

    • Automatically switches Next.js build engine to Webpack when executing under Bun (since Turbopack requires V8 Node bindings).
    • Added export const dynamic = "force-dynamic"; annotations to API routes to prevent static generation build failures under Bun.
  4. DAST Smoke CI Workflow Fixes (.github/workflows/dast-smoke.yml):

    • Auth Guard Test Seam: Added REQUIRE_API_KEY: "false" to server start env so Promptfoo can test injectionGuard on POST /v1/chat/completions without failing early at routeGuard authorization with HTTP 401 (AUTH_002).
    • Rate-Limit Exclusion: Excluded brute-force rate-limited password login (/api/auth/login) from Schemathesis payload fuzzing (--exclude-path-regex '^/api/auth/(oidc/|login)') to avoid HTTP 429 status code assertions.
    • CLI Tool Pinning: Pinned promptfoo@0.122.0 global installation to prevent npx package resolution failures.
  5. Test & Documentation Coverage:

    • Unit tests: tests/unit/bun-support.test.ts asserting Bun detection and SQLite driver resolution order.
    • Updated README.md with Bun deployment and container build instructions.

Verification

  • npm run typecheck:core (0 errors)
  • node --import tsx/esm --test tests/unit/bun-support.test.ts (3/3 passed)
  • Local DAST smoke suite run: Schemathesis 7/7 passed, Promptfoo 2/2 passed (100% green)

@rqzbeh
rqzbeh requested a review from diegosouzapw as a code owner August 21, 2026 17:45
@rqzbeh
rqzbeh marked this pull request as draft August 21, 2026 20:19
@rqzbeh
rqzbeh marked this pull request as ready for review August 21, 2026 21:05
@diegosouzapw

Copy link
Copy Markdown
Collaborator

Solid, well-documented effort — the runtime detection, Webpack-under-Bun switch, update-notifier hardening, and DAST workflow fixes are all reasonable. Two blocking issues, both verified on real Bun 1.3.14:

  1. [MANDATORY] driverFactory.ts:224-227 breaks the native bun:sqlite open. new Database(filePath, {}) throws "bad parameter or other API misuse" on Bun 1.3.14; the pre-change form new Database(filePath, { readwrite: true, create: ... }) opens fine. As written, every non-readonly open under Bun falls back to sql.js, so "native Bun backend" never actually uses native sqlite. Fix by keeping the explicit options (e.g. const bunOptions = options?.readonly ? { readonly: true } : { readwrite: true, create: options?.create !== false }; for :memory: skip the empty-object arg). Validate by running bun test tests/unit/db-adapters/driverFactory.test.ts under real Bun and asserting the sync driver resolves to bun:sqlite (currently it logs "bun:sqlite failed to open" and drops to sql.js). Note tests/unit/bun-support.test.ts:47-88 injects a dummy Database that ignores options, so it never detects this — add a real-Bun case or assert that opening a real in-memory DB via the factory yields driver bun:sqlite.

  2. [MANDATORY] Dockerfile.bun:89 ENTRYPOINT runs bun bin/omniroute.mjs serve, but the standalone output the image copies does not contain bin/omniroute.mjs (assembleStandalone.mjs:37 lists the CLI esbuild as prepublish-only; the runner only COPYs .build/next/standalone, better-sqlite3, healthcheck.mjs). The container will fail at start. Match the Node Dockerfile's approach (CMD node dev/run-standalone.mjs) — dev/run-standalone.mjs IS shipped into the standalone (assembleStandalone.mjs:162-164) — i.e. ENTRYPOINT ["bun", "dev/run-standalone.mjs"], and validate a docker build -f Dockerfile.bun + run end-to-end.

[OPTIONAL] The PR mixes unrelated cleanup (virtualFactory.ts:610 Number(), as Record<string, unknown> casts in src/app/api/v1/moderations/route.ts:71 and src/lib/embeddings/service.ts:332, open-sse-typecheck-baseline.json prune). The baseline prune is legitimate (both pruned files typecheck clean at head) but splitting these into a separate chore PR keeps this one focused on Bun. Also note AGENTS.md frames Bun as best-effort/unsupported — elevating Bun to a first-class supported runtime + README claim is a roadmap decision worth an explicit owner sign-off, and a real test:bun:db entry is the repo's required Bun-change gate.

@diegosouzapw
diegosouzapw merged commit 7ddbaf6 into cheaper-inference:release/v3.8.50 Aug 22, 2026
4 of 7 checks passed
diegosouzapw pushed a commit to rqzbeh/OmniRoute that referenced this pull request Aug 22, 2026
diegosouzapw pushed a commit that referenced this pull request Aug 22, 2026
…antiation (#11039) (#11163)

Cherry-picked onto the current tip (authorship preserved), noise stripped. Validated on BOTH runtimes: bun test tests/unit/db-adapters/ 44/44 under the pinned Bun 1.3.14 (native bun:sqlite path), and node --test on the same suite 52 pass / 0 fail / 1 skip (Bun-only adapter skips under Node, as designed). Dockerfile.bun entrypoint now matches the standalone runner shape. Follow-up to #11039. Thank you @rqzbeh!
diegosouzapw pushed a commit to rqzbeh/OmniRoute that referenced this pull request Aug 22, 2026
diegosouzapw pushed a commit that referenced this pull request Aug 22, 2026
…workflow (#11039) (#11168)

Cherry-picked onto the current tip (authorship preserved, Dockerfile.bun conflict with the just-merged #11163 resolved additively — runner-web stage after the new entrypoint). Three pre-merge fixes on the branch: (1) generated-count noise stripped; (2) runner-web stage now returns to the non-root bun user after the apt install (mirrors the Node Dockerfile runner-web re-asserting USER node — the stage previously ended as root); (3) the 6 new build/manifest steps SHA-pinned so the zizmor ratchet stays at 191<=192 findings instead of regressing to 197 (actionlint clean). Workflow YAML parses; runner-base/runner-web targets cross-checked against the Dockerfile stages. Thank you @rqzbeh!
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…-inference#11039)

⭐4 — Suporte de backend nativo Bun + Dockerfile.bun multi-stage + fallback dinâmico de driver SQLite (better-sqlite3 prioritário sob Bun, bun:sqlite fallback; Node preservado) + correção de estabilidade do DAST CI smoke.
Validado a fundo (worktree board sobre tip): bun-support 4/4, typecheck:core limpo, dashboard-typecheck OK (220 dentro do baseline), open-sse-typecheck OK (5 pré-existentes), gate de runtime OK sob Node, changelog-integrity OK, file-size/complexity/cognitive/dead-code OK. Verificado que o driver preserva a cadeia Node/falback conforme AGENTS.md; teste bun-support presente. Baselines de typecheck removidos são ratchet honesto (erros não existem mais).
OBS: destravei 2 base-reds do tip neste turno (push direto c4ce593): movi o changelog fragment da cheaper-inference#11050 da seção inválida breaking/ para fixes/, e rebaselinei AddApiKeyModal 1067->1073 (crescimento da cheaper-inference#11056). Sem isso a cheaper-inference#11039 e o resto da fila ficariam vermelhos.
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…antiation (cheaper-inference#11039) (cheaper-inference#11163)

Cherry-picked onto the current tip (authorship preserved), noise stripped. Validated on BOTH runtimes: bun test tests/unit/db-adapters/ 44/44 under the pinned Bun 1.3.14 (native bun:sqlite path), and node --test on the same suite 52 pass / 0 fail / 1 skip (Bun-only adapter skips under Node, as designed). Dockerfile.bun entrypoint now matches the standalone runner shape. Follow-up to cheaper-inference#11039. Thank you @rqzbeh!
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…workflow (cheaper-inference#11039) (cheaper-inference#11168)

Cherry-picked onto the current tip (authorship preserved, Dockerfile.bun conflict with the just-merged cheaper-inference#11163 resolved additively — runner-web stage after the new entrypoint). Three pre-merge fixes on the branch: (1) generated-count noise stripped; (2) runner-web stage now returns to the non-root bun user after the apt install (mirrors the Node Dockerfile runner-web re-asserting USER node — the stage previously ended as root); (3) the 6 new build/manifest steps SHA-pinned so the zizmor ratchet stays at 191<=192 findings instead of regressing to 197 (actionlint clean). Workflow YAML parses; runner-base/runner-web targets cross-checked against the Dockerfile stages. Thank you @rqzbeh!
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.

3 participants