Skip to content

chore(bun): run Orbit on Bun end to end - #24

Merged
pulkitxm merged 8 commits into
mainfrom
chore/bun-everywhere
Jul 23, 2026
Merged

pulkitxm merged 8 commits into
mainfrom
chore/bun-everywhere

Conversation

@pulkitxm

Copy link
Copy Markdown
Member

Replace pnpm, Turbo, tsx, esbuild, vitest, jsdom, ioredis, ws, the AWS S3 SDK and ulid with Bun built-ins across the workspace, the tests, the images and the deploy.

pulkitxm added 5 commits July 23, 2026 20:28
Replace pnpm and Turbo with bun workspaces and bun run --filter. Run every
script, and the repo tooling in scripts/, on the bun runtime instead of node
and tsx. Bundle the services with bun build instead of esbuild.

bun install drops from 1047 to 796 packages by removing turbo, tsx, esbuild,
vitest, jsdom, ioredis, ws, the AWS S3 SDK and ulid. pg stays as a build time
only devDependency because drizzle-kit cannot use Bun's SQL client.
Replace the pg pool with Bun.SQL through drizzle-orm/bun-sql, ioredis with
Bun.RedisClient including its pub/sub, the ws server with Bun.serve websockets,
the AWS S3 SDK with Bun.S3Client, and ulid with Bun.randomUUIDv7.

Sanitize rendered markdown with Bun's HTMLRewriter instead of isomorphic
dompurify, which removes jsdom. jsdom was also the one dependency Turbopack
could not resolve when building on the bun runtime, and the web build has to
run there now that the source imports bun built-ins.

The S3 driver builds its client from explicit configuration and refuses to
start when an ambient AWS session token has leaked into the signature, which
is how a presigned upload fails in a pod that also has IRSA credentials.
Move 62 suites from vitest to bun:test. Per package bunfig.toml with a
tests-preload.ts carries what each vitest config used to provide: the test
database url, redis url, happy-dom for the DOM suites in place of jsdom, and
the matchMedia, ResizeObserver and scrollIntoView shims.

scripts/test-env.ts keeps the guard that refuses to run against a database
whose name does not contain test. Each preload caps DATABASE_POOL_MAX at 2 so
eight suites running in parallel cannot exhaust postgres connections.

Add regression tests for the two sanitizer bypasses an adversarial audit
found: a scheme hidden behind html entities, and a repeated href attribute.

615 tests pass.
Base all four images on oven/bun and run bun as the container command. There
is no turbo prune, so each Dockerfile copies the root manifest, bun.lock and
every workspace manifest, installs with a frozen lockfile, then copies source.
Each one asserts the lockfile exists first, because bun install
--frozen-lockfile exits 0 when there is no lockfile at all.

CI installs with oven-sh/setup-bun and asserts every image actually runs bun.

Raise the web pod to 512Mi requested and 2Gi limit. Bun has no equivalent of
--max-old-space-size, so the old 768Mi heap ceiling is gone and its resident
memory sits well above node's.
Rule one is now that bun is the runtime, the package manager and the script
runner, with a table of which built-in replaces which package so new work does
not reintroduce an SDK. Record the three Bun behaviours that cost real time:
process.loadEnvFile does not exist, a subdirectory cwd cannot see the root
.env, and S3Client snapshots ambient AWS credentials at process start so an
explicit endpoint fails with InvalidTokenId.

Note that rolling web back to node means editing the Dockerfile, because in
oven/bun images node is a symlink to bun and the manifest command would
silently keep running bun.
@pulkitxm

Copy link
Copy Markdown
Member Author

What was verified, and how

Every replacement below was exercised against the real local stack (postgres 5434, redis 6380, minio 9010) rather than taken from documentation.

Was Now Evidence
pnpm + Turbo bun install, bun run --filter 1047 to 796 packages, 8.9s install
pg Bun.SQL via drizzle-orm/bun-sql real query, transaction and relational query against postgres
ioredis Bun.RedisClient subscribe, publish, unsubscribe round trip, both messages delivered
ws Bun.serve websockets 25 realtime tests pass, client package unchanged
@aws-sdk/client-s3 + presigner Bun.S3Client presigned PUT and GET of a PDF round tripped through minio
tsx, esbuild bun, bun build --target=bun realtime 0.47 MB in 20ms, mcp 0.80 MB in 27ms
vitest, jsdom bun test, happy-dom 615 tests, 0 failures
ulid Bun.randomUUIDv7 storage keys stay time sortable
isomorphic-dompurify Bun.HTMLRewriter see the sanitizer section

Next.js 16 compiles, typechecks and serves on the Bun runtime. The standalone server was booted with bun apps/web/server.js and returned {"status":"ok","service":"web"} from /api/health.

Net change: 143 files, about 6,300 fewer lines.

Three things worth reviewing carefully

1. The sanitizer is new code, and it is security critical.

isomorphic-dompurify had to go: it pulls in jsdom, and jsdom is the one dependency Turbopack cannot resolve when the build runs on the Bun runtime. The build has to run there now, because the source imports Bun built-ins. Sanitizing is now done with Bun's native HTMLRewriter against a tag and attribute allowlist.

That new code was then attacked by four independent adversarial passes, 358 vectors total. Three of them converged on the same two real bypasses:

  • [click me](javascript:alert(1)) survived, because HTMLRewriter hands handlers the raw attribute value rather than the entity decoded one.
  • A repeated href let javascript: through while the first, safe value was the one that got removed.

Both are fixed. URL handling moved from a scheme blocklist to an allowlist of http, https and mailto, with entity decoding and control character stripping before the check, and attributes are now rebuilt from validated values so a duplicate cannot win. Five regression tests cover both vectors plus raw text element dropping and external link rel handling.

2. pg is still here, on purpose. drizzle-kit cannot talk to Bun's SQL client, so it stays as a build time only devDependency of @orbit/db. Runtime is pure Bun. Verified by running drizzle-kit push with and without it.

3. The web pod got more memory. Bun has no equivalent of --max-old-space-size, so the previous 768Mi heap ceiling no longer exists, and Bun's resident memory for the Next server sits well above Node's. Requests moved to 512Mi and the limit to 2Gi. Worth watching RSS for a day after the first deploy.

Two operational notes recorded in CLAUDE.md

bun install --frozen-lockfile exits 0 when there is no lockfile at all, so a .dockerignore slip would silently produce a floating dependency tree. Every Dockerfile now asserts test -s bun.lock first.

Rolling the web service back to Node means editing apps/web/Dockerfile. Editing only the k8s manifest does nothing, because in oven/bun images node is a symlink to bun, so command: [..., "node", ...] keeps running Bun without any error.

Possibly the cause of the S3 upload failures

Bun's S3Client reads ambient AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN and snapshots them at process start. Deleting them from process.env or Bun.env afterwards has no effect, and passing an empty sessionToken does not suppress them. When explicit keys are also configured, the ambient session token is still attached to the signature and every request fails with InvalidTokenId, which is exactly how a broken PDF upload presents in a pod that also carries IRSA credentials. The driver now presigns a probe URL at construction and refuses to start with an actionable message instead of failing later at upload time.

Separately, and not fixed here: there is no S3 bucket CORS configuration anywhere in k8s/, which would make every cross origin presigned PUT fail at the browser preflight. That is queued as its own change.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The repository migrates tooling, applications, tests, database access, storage, Markdown handling, Docker images, CI, and deployment commands from Node, pnpm, and Vitest to Bun. Realtime networking and several typed utility scripts are also updated.

Changes

Bun platform migration

Layer / File(s) Summary
Repository tooling and validation
.github/workflows/*, package.json, lefthook.yml, scripts/*, README.md, CLAUDE.md
CI, workspace commands, hooks, documentation, and utility scripts use Bun commands and APIs.
Database and test infrastructure
packages/db/*, packages/core/*, packages/services/*, packages/shared/*
Database access uses Bun SQL; package test commands, preload files, typings, and test imports use Bun.
Realtime and MCP runtimes
apps/realtime/*, apps/mcp/*, packages/core/src/realtime/*
Realtime networking, Redis clients, MCP shutdown handling, Docker builds, and runtime startup use Bun APIs.
Web runtime and tests
apps/web/*, k8s/02-web.yaml
Web builds, startup, E2E setup, browser preloads, Next configuration, and component tests are adapted to Bun.
Services storage and content
packages/services/src/storage/*, packages/services/src/markdown/*, packages/services/src/notifications/*, packages/services/src/email/*
S3 operations use Bun’s client, Markdown uses local HTML rewriting utilities, and selected identifiers use UUIDv7.
Container and deployment runtime
apps/*/Dockerfile, packages/db/Dockerfile, k8s/*, buildspec.yml
Container images are based on Bun, deployment commands invoke Bun, and CI validates Bun availability in built images.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

  • Noveum/orbit#3: Both changes modify the Next configuration and its pg externalization behavior.
  • Noveum/orbit#9: Both changes modify MCP server lifecycle behavior.
  • Noveum/orbit#22: Both changes modify Kubernetes container startup commands for the web, realtime, and MCP services.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: moving Orbit to a Bun-based end-to-end runtime.
Description check ✅ Passed The description is directly related to the PR and correctly lists the Bun replacements across the workspace and deploy.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/bun-everywhere

Comment @coderabbitai help to get the list of available commands.

…ain text

An adversarial audit of the new sanitizer ran 584 vectors across four lenses
and reproduced every finding in headless Chromium. No XSS bypass survived, but
three real defects did.

A protocol relative link was treated as internal, because the absolute url test
required an explicit scheme, so an external link got no target or rel. The same
line read the raw href while the safety check read the decoded one, so an entity
encoded absolute url was misclassified too. Both now test the decoded value.

renderPlainText returned HTML escaped text, so a document excerpt or a project
description containing an ampersand or a quote reached the reader as a literal
entity. Plain text is now decoded at that boundary. htmlToText stays escaped,
because callers that interpolate it into HTML depend on that.
@pulkitxm

Copy link
Copy Markdown
Member Author

Adversarial audit of the new sanitizer: no bypass survived

Because the sanitizer is new, security critical, and this repository is public, I had four independent attackers try to break it before asking anyone to review it.

584 vectors across four lenses: scheme smuggling (100), parser confusion (226), attribute escape (128), and the markdown layer (130).

The consolidation pass did not take those reports on trust. It re-ran every claimed bypass in real headless Chromium, setting the output as innerHTML (the dangerouslySetInnerHTML path the app actually uses), hooking window.alert, and reading back protocol, hostname, src and every on* attribute from the live DOM. A positive control fed raw <img src=x onerror=...> did fire, which proves the harness detects execution rather than reporting silence as safety.

Result: zero confirmed bypasses. Nothing executed. No event handler attribute and no non http, https or mailto URL reached the DOM in any vector.

The two bypasses that were real, an entity encoded scheme and a duplicate href, were found and fixed earlier in this branch, before this consolidation ran. Both have regression tests.

What the audit did find, and what this commit fixes

Three genuine defects, none of them XSS:

  1. A protocol relative link was treated as internal. The absolute URL test required an explicit scheme, so //example.com/x got no target or rel. The same line read the raw href while the safety check read the decoded one, so &#104;ttps://example.com was misclassified too. Both now test the decoded value.

  2. renderPlainText returned HTML escaped text. This one is a real user visible regression I introduced when replacing DOMPurify, whose textContent decoded automatically. A document excerpt or project description containing an ampersand or a quote reached the reader as a literal &amp;. It is now decoded at that boundary, while htmlToText stays escaped because callers that interpolate it into HTML depend on that.

  3. End tags carrying attributes pass through verbatim, because HTMLRewriter only fires its element handler on start tags. Reproduced and confirmed inert: Chromium discards them, and both consumers here are spec HTML parsers. Left as is deliberately rather than paying a per element closure for a contract nicety, and recorded so the next person does not rediscover it.

Also worth recording: three of the four attackers recommended reverting to isomorphic-dompurify. That advice was written against the pre-fix revision and the consolidation pass rejected it after reproducing the current behaviour. Reverting is not possible anyway, since jsdom is what blocks the Bun build.

623 tests pass.

@coderabbitai coderabbitai 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.

Actionable comments posted: 12

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/services/src/test-database.ts (1)

1-17: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Close the shared DB pool at process exit

The test preload already points DATABASE_URL at a test database; the remaining gap is a process-level pool.close() for @orbit/db so Bun test exits cleanly instead of keeping the SQL handle open.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/services/src/test-database.ts` around lines 1 - 17, Update the test
database setup around the imported db instance and exported testDb to register a
process-exit handler that closes the shared `@orbit/db` pool via its pool.close()
API, ensuring Bun tests release the SQL handle before exiting.
.github/workflows/ci.yml (1)

120-129: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Exercise the image’s default command and pin Bun exactly.

  • --entrypoint bun bypasses the container’s CMD (/usr/bin/doppler run -- bun apps/web/server.js), so this smoke test doesn’t cover the actual startup path.
  • case "$VERSION" in 1.*) is too loose for a version pinned to $BUN_VERSION; require an exact match instead.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/ci.yml around lines 120 - 129, Update the web image smoke
test to remove the `--entrypoint bun` override so `docker run` exercises the
image’s default `CMD` startup path. In the Bun version validation, replace the
loose `1.*` pattern with an exact comparison against `$BUN_VERSION`.

Source: Coding guidelines

🧹 Nitpick comments (7)
apps/web/src/lib/api/dev-login.test.ts (1)

2-2: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use @/ aliases for local test imports.

  • apps/web/src/lib/api/dev-login.test.ts#L2-L2: replace ./dev-login.ts with @/lib/api/dev-login.ts.
  • apps/web/src/lib/query/fetcher.test.ts#L3-L3: replace ./fetcher.ts with @/lib/query/fetcher.ts.

As per coding guidelines, “Use @/ imports inside apps/web.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/lib/api/dev-login.test.ts` at line 2, Replace the relative
import in apps/web/src/lib/api/dev-login.test.ts at lines 2-2 with the
`@/lib/api/dev-login.ts` alias, and replace the relative fetcher import in
apps/web/src/lib/query/fetcher.test.ts at lines 3-3 with `@/lib/query/fetcher.ts`,
preserving the imported symbols.

Source: Coding guidelines

packages/services/src/markdown/sanitize.ts (1)

134-190: 🔒 Security & Privacy | 🔵 Trivial | 🏗️ Heavy lift

Hand-rolled sanitizer replacing DOMPurify.

This custom HTMLRewriter-based sanitizer replaces the previously used isomorphic-dompurify. The default-deny URL scheme check and tag/attribute allowlists look sound against the attack vectors exercised in markdown.test.ts, but a hand-rolled sanitizer inherently lacks the ongoing security research and bypass-technique tracking that a widely used library like DOMPurify benefits from. Since this renders untrusted user content, consider whether this warrants periodic re-audits or fuzz testing as new bypass techniques emerge, given it is no longer backed by an actively-patched upstream library.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/services/src/markdown/sanitize.ts` around lines 134 - 190, Harden
the custom sanitizer around the sanitizer implementation anchored by isSafeUrl
and sanitizeHtml by adding ongoing security coverage for untrusted HTML, such as
fuzz tests and/or a documented periodic re-audit process. Preserve the existing
allowlists and default-deny URL behavior while ensuring newly discovered parser
or bypass techniques can be detected and addressed.
CLAUDE.md (2)

46-48: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add language identifiers to the Markdown fences.

Markdownlint reports MD040 for these blocks. Use sh for command blocks and text for the layout tree.

Suggested fix
-```
+```sh
...
-```
+```text
...
-```
+```sh

Also applies to: 54-62, 129-131

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@CLAUDE.md` around lines 46 - 48, Update the Markdown fences in CLAUDE.md
around the environment command and the additional referenced blocks to include
language identifiers: use sh for shell command blocks and text for the layout
tree. Preserve the existing block contents.

Source: Linters/SAST tools


7-8: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Narrow the “every command starts with bun” rule.

The same document contains env, Docker, and deployment commands that intentionally do not start with bun. Limit this rule to repository runtime and script commands.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@CLAUDE.md` around lines 7 - 8, Revise the first guideline in CLAUDE.md to
require a bun prefix only for repository runtime, package-management, and
script-runner commands. Do not apply this requirement to env, Docker,
deployment, or other infrastructure commands that intentionally use their own
executables.
scripts/fetch-plane.ts (2)

304-318: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Cycle/module issue fetches run sequentially; consider mapConcurrent for consistency.

Comments, links, and page details all use the in-file mapConcurrent helper for concurrency, but cycleIssues/moduleIssues are fetched one at a time in a plain for...of loop, serializing N+M round trips per project.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/fetch-plane.ts` around lines 304 - 318, Update the cycleIssues and
moduleIssues fetch loops to use the existing mapConcurrent helper, while
preserving each endpoint, fallback behavior, and assignment keyed by item.id.
Keep the resulting issue maps unchanged and avoid serializing requests across
cycles and modules.

283-293: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Fragile 403 detection via string matching.

String(error).includes('403') relies on the error message text (\${status} on ${path}``) coincidentally containing "403" as a substring; a path containing "403" (e.g. a project identifier) could cause an unrelated error to be misclassified as a permissions issue, silently skipping a project that actually failed for another reason.

♻️ Suggested typed error
+class HttpStatusError extends Error {
+  constructor(readonly status: number, path: string) {
+    super(`${status} on ${path}`);
+  }
+}

Then throw new HttpStatusError(response.status, path) in get<T> and check error instanceof HttpStatusError && error.status === 403 here instead of string matching.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/fetch-plane.ts` around lines 283 - 293, Replace the fragile
String(error) check in the collect call with typed status handling: update
get<T> to throw HttpStatusError with the response status and path, then in this
catch classify the error as inaccessible only when it is an HttpStatusError
whose status equals 403; rethrow all other errors unchanged.
scripts/strip-comments.ts (1)

612-623: 🔒 Security & Privacy | 🔵 Trivial | 💤 Low value

Manual character-by-character escaping flagged by static analysis.

codeCell chain-replaces \, |, &, <, > for embedding into a Markdown table cell wrapped in <code>. This is scoped correctly for its actual usage, but static analysis flags hand-rolled escaping as a general CWE-79 risk pattern; worth a second look given this text ends up in GITHUB_STEP_SUMMARY, which is rendered as HTML/Markdown.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/strip-comments.ts` around lines 612 - 623, Review the codeCell
function in buildSummary and replace its manual character-by-character escaping
with the repository’s established Markdown/HTML escaping utility, if available.
Preserve escaping for all characters required to safely render findings in a
GITHUB_STEP_SUMMARY Markdown table code cell, including backslashes, pipes,
ampersands, and angle brackets.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/mcp/Dockerfile`:
- Line 39: Update the final CMD in the Dockerfile to invoke Bun directly as the
container entrypoint, removing /usr/bin/doppler from the command. Preserve the
existing dist/index.js startup target and leave Doppler environment injection to
deployment or an external wrapper.

In `@apps/mcp/README.md`:
- Around line 28-30: Declare the fenced command’s language in the README by
changing the code fence around the create-key example to use the sh identifier,
while leaving the command itself unchanged.

In `@apps/mcp/src/server.ts`:
- Around line 142-149: Update the shutdown flow around http.closeAllConnections
and http.close so http.close() initiates graceful draining first; only invoke
closeAllConnections after a shutdown timeout if active requests remain. Preserve
the existing error handling for http.close, and add an in-flight MCP RPC test
verifying requests drain normally before any forced connection closure.

In `@apps/realtime/src/server.test.ts`:
- Around line 76-81: Update the upgrade response handling in the test’s data
callback to accumulate chunks across fragmented reads until the HTTP header
terminator \r\n\r\n is received. Then inspect the complete response: call
markUpgraded for a 101 status, reject via failUpgrade for non-upgrade responses,
and also reject when the socket closes before a complete valid upgrade response
arrives.
- Around line 66-70: Update the upgraded promise setup in server.test.ts to
store the setTimeout handle, then clear that timeout in the upgrade flow’s
finally block after the socket upgrades or fails. Preserve the existing timeout
rejection and resolve/reject behavior while ensuring the timer is always cleaned
up.

In `@apps/realtime/tests-preload.ts`:
- Line 4: Update the REDIS_URL initialization in tests-preload so empty or
whitespace-only environment values are treated as unset and replaced with the
localhost Redis fallback. Validate the external environment input with the
project’s Zod schema or established validation helper, rather than relying only
on nullish coalescing.

In `@apps/web/e2e/account-and-workspaces.spec.ts`:
- Line 16: Update the error message in the seed-user validation around the owner
check to remove the trailing period from the suggested command, so copying “bun
run db:seed” executes the correct script.

In `@packages/core/package.json`:
- Line 11: Update the test scripts in packages/core/package.json at lines 11-11
and packages/db/package.json at lines 19-19 to invoke Bun with
--env-file=../../.env before test, ensuring both package test commands load the
repository environment file.

In `@packages/core/src/test-support.ts`:
- Around line 9-12: Update the database-name validation in resetDatabase to
require the supplied test-database prefix or an equivalent strict test-only
pattern, such as orbit_test_. Do not use substring matching via includes; reject
names like contest before any destructive truncation SQL executes.

In `@packages/db/src/client.ts`:
- Around line 5-16: Validate DATABASE_POOL_MAX with a positive-integer Zod
schema before constructing SQL, rejecting missing, malformed, non-integer, zero,
and negative values with a clear configuration error. Replace the
Number.parseInt usage in the pool initialization while preserving the existing
default of 10 when the environment variable is absent.

In `@scripts/strip-comments.ts`:
- Around line 30-32: Update the scan flow around trackedFiles() to honor
positional file arguments when provided: restrict the files passed to comment
stripping to those paths while preserving the existing hardcoded-glob scan when
no paths are supplied. Ensure --check and related dry-run modes report only the
requested staged files.

In `@scripts/test-env.ts`:
- Around line 15-27: Update resolveTestDatabaseUrl to validate fallbackDatabase
and enforce the strict test-database naming policy on every return path. Replace
the substring check on databaseNameOf(ambient) with an exact
allowlist/predicate, and validate both explicit and constructed URLs before
returning them so resetDatabase cannot target non-test databases.

---

Outside diff comments:
In @.github/workflows/ci.yml:
- Around line 120-129: Update the web image smoke test to remove the
`--entrypoint bun` override so `docker run` exercises the image’s default `CMD`
startup path. In the Bun version validation, replace the loose `1.*` pattern
with an exact comparison against `$BUN_VERSION`.

In `@packages/services/src/test-database.ts`:
- Around line 1-17: Update the test database setup around the imported db
instance and exported testDb to register a process-exit handler that closes the
shared `@orbit/db` pool via its pool.close() API, ensuring Bun tests release the
SQL handle before exiting.

---

Nitpick comments:
In `@apps/web/src/lib/api/dev-login.test.ts`:
- Line 2: Replace the relative import in apps/web/src/lib/api/dev-login.test.ts
at lines 2-2 with the `@/lib/api/dev-login.ts` alias, and replace the relative
fetcher import in apps/web/src/lib/query/fetcher.test.ts at lines 3-3 with
`@/lib/query/fetcher.ts`, preserving the imported symbols.

In `@CLAUDE.md`:
- Around line 46-48: Update the Markdown fences in CLAUDE.md around the
environment command and the additional referenced blocks to include language
identifiers: use sh for shell command blocks and text for the layout tree.
Preserve the existing block contents.
- Around line 7-8: Revise the first guideline in CLAUDE.md to require a bun
prefix only for repository runtime, package-management, and script-runner
commands. Do not apply this requirement to env, Docker, deployment, or other
infrastructure commands that intentionally use their own executables.

In `@packages/services/src/markdown/sanitize.ts`:
- Around line 134-190: Harden the custom sanitizer around the sanitizer
implementation anchored by isSafeUrl and sanitizeHtml by adding ongoing security
coverage for untrusted HTML, such as fuzz tests and/or a documented periodic
re-audit process. Preserve the existing allowlists and default-deny URL behavior
while ensuring newly discovered parser or bypass techniques can be detected and
addressed.

In `@scripts/fetch-plane.ts`:
- Around line 304-318: Update the cycleIssues and moduleIssues fetch loops to
use the existing mapConcurrent helper, while preserving each endpoint, fallback
behavior, and assignment keyed by item.id. Keep the resulting issue maps
unchanged and avoid serializing requests across cycles and modules.
- Around line 283-293: Replace the fragile String(error) check in the collect
call with typed status handling: update get<T> to throw HttpStatusError with the
response status and path, then in this catch classify the error as inaccessible
only when it is an HttpStatusError whose status equals 403; rethrow all other
errors unchanged.

In `@scripts/strip-comments.ts`:
- Around line 612-623: Review the codeCell function in buildSummary and replace
its manual character-by-character escaping with the repository’s established
Markdown/HTML escaping utility, if available. Preserve escaping for all
characters required to safely render findings in a GITHUB_STEP_SUMMARY Markdown
table code cell, including backslashes, pipes, ampersands, and angle brackets.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2b85c337-cd5e-43fe-8eb8-c2ce4c977e43

📥 Commits

Reviewing files that changed from the base of the PR and between 1868e14 and b70568f.

⛔ Files ignored due to path filters (2)
  • bun.lock is excluded by !**/*.lock
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (141)
  • .github/workflows/ci.yml
  • .gitignore
  • CLAUDE.md
  • README.md
  • apps/mcp/Dockerfile
  • apps/mcp/README.md
  • apps/mcp/bunfig.toml
  • apps/mcp/package.json
  • apps/mcp/src/auth.test.ts
  • apps/mcp/src/server.ts
  • apps/mcp/src/test-helpers.ts
  • apps/mcp/src/tools.test.ts
  • apps/mcp/tests-preload.ts
  • apps/mcp/tsconfig.json
  • apps/mcp/vitest.config.ts
  • apps/realtime/Dockerfile
  • apps/realtime/bunfig.toml
  • apps/realtime/package.json
  • apps/realtime/src/active-organization.test.ts
  • apps/realtime/src/client-reconnect.test.ts
  • apps/realtime/src/connection.test.ts
  • apps/realtime/src/connection.ts
  • apps/realtime/src/server.test.ts
  • apps/realtime/src/server.ts
  • apps/realtime/src/test-helpers.ts
  • apps/realtime/tests-preload.ts
  • apps/realtime/tsconfig.json
  • apps/realtime/vitest.config.ts
  • apps/web/Dockerfile
  • apps/web/bunfig.toml
  • apps/web/e2e/account-and-workspaces.spec.ts
  • apps/web/e2e/global-setup.ts
  • apps/web/e2e/second-workspace-realtime.spec.ts
  • apps/web/next.config.ts
  • apps/web/package.json
  • apps/web/playwright.config.ts
  • apps/web/src/components/layout/workspace-switcher.test.tsx
  • apps/web/src/components/theme-provider.test.tsx
  • apps/web/src/components/ui/ui.test.tsx
  • apps/web/src/features/account/connected-accounts.test.tsx
  • apps/web/src/features/account/credentials.test.ts
  • apps/web/src/features/account/profile-form.test.tsx
  • apps/web/src/features/charts/geometry.test.ts
  • apps/web/src/features/comments/comment-composer.test.tsx
  • apps/web/src/features/cycles/burn-up.test.ts
  • apps/web/src/features/docs/docs.test.ts
  • apps/web/src/features/filters/filter-bar.test.tsx
  • apps/web/src/features/filters/grouping.test.ts
  • apps/web/src/features/filters/view-config.test.ts
  • apps/web/src/features/issues/issue-card.test.tsx
  • apps/web/src/features/issues/issue-row.test.tsx
  • apps/web/src/features/issues/my-issues-view.test.tsx
  • apps/web/src/features/projects/series.test.ts
  • apps/web/src/features/settings/invite-panel.test.tsx
  • apps/web/src/features/settings/members-table.test.tsx
  • apps/web/src/features/settings/notification-matrix.test.tsx
  • apps/web/src/features/workspaces/create-workspace-form.test.tsx
  • apps/web/src/lib/api/content-disposition.test.ts
  • apps/web/src/lib/api/dev-login.test.ts
  • apps/web/src/lib/cn.test.ts
  • apps/web/src/lib/keyboard/binding.test.ts
  • apps/web/src/lib/query/fetcher.test.ts
  • apps/web/src/lib/query/sync.test.ts
  • apps/web/src/lib/realtime/delta-bridge.test.tsx
  • apps/web/src/tests/setup.ts
  • apps/web/tests-preload.ts
  • apps/web/tsconfig.json
  • apps/web/vitest.config.ts
  • biome.json
  • buildspec.yml
  • k8s/02-web.yaml
  • k8s/03-realtime.yaml
  • k8s/04-mcp.yaml
  • lefthook.yml
  • package.json
  • packages/core/bunfig.toml
  • packages/core/package.json
  • packages/core/src/activity/activity-service.test.ts
  • packages/core/src/content/doc-service.test.ts
  • packages/core/src/org/active-organization.test.ts
  • packages/core/src/org/invite-service.test.ts
  • packages/core/src/org/member-service.test.ts
  • packages/core/src/org/organization-service.test.ts
  • packages/core/src/org/profile-service.test.ts
  • packages/core/src/realtime/publisher.test.ts
  • packages/core/src/realtime/publisher.ts
  • packages/core/src/sync/sync-id.ts
  • packages/core/src/test-support.ts
  • packages/core/src/work/cycle-service.test.ts
  • packages/core/src/work/issue-predicates.test.ts
  • packages/core/src/work/issue-service.test.ts
  • packages/core/src/work/project-service.test.ts
  • packages/core/src/work/workflow-state-service.test.ts
  • packages/core/tests-preload.ts
  • packages/core/tsconfig.json
  • packages/db/Dockerfile
  • packages/db/package.json
  • packages/db/src/client.ts
  • packages/db/src/import/plane-mapping.test.ts
  • packages/db/src/import/plane-source.test.ts
  • packages/db/src/schema/index.test.ts
  • packages/db/src/seed/data.ts
  • packages/db/tsconfig.json
  • packages/realtime-client/bunfig.toml
  • packages/realtime-client/package.json
  • packages/realtime-client/src/react.test.tsx
  • packages/realtime-client/tests-preload.ts
  • packages/realtime-client/tsconfig.json
  • packages/realtime-client/vitest.config.ts
  • packages/services/bunfig.toml
  • packages/services/package.json
  • packages/services/src/email/email.test.ts
  • packages/services/src/email/index.ts
  • packages/services/src/markdown/index.ts
  • packages/services/src/markdown/markdown.test.ts
  • packages/services/src/markdown/sanitize.ts
  • packages/services/src/notifications/index.ts
  • packages/services/src/notifications/notifications.test.ts
  • packages/services/src/slack/slack.test.ts
  • packages/services/src/storage/index.ts
  • packages/services/src/storage/s3.ts
  • packages/services/src/storage/storage.test.ts
  • packages/services/src/storage/validate.ts
  • packages/services/src/test-database.ts
  • packages/services/tests-preload.ts
  • packages/services/tsconfig.json
  • packages/services/vitest.config.ts
  • packages/shared/package.json
  • packages/shared/src/events/events.test.ts
  • packages/shared/src/events/index.test.ts
  • packages/shared/src/filters/filters.test.ts
  • packages/shared/src/policy/policy.test.ts
  • packages/shared/src/utils/utils.test.ts
  • packages/shared/src/validators/validators.test.ts
  • packages/shared/tsconfig.json
  • pnpm-workspace.yaml
  • scripts/fetch-plane.ts
  • scripts/strip-comments.ts
  • scripts/test-env.ts
  • scripts/tsconfig.json
  • turbo.json
💤 Files with no reviewable changes (11)
  • apps/realtime/vitest.config.ts
  • apps/web/vitest.config.ts
  • buildspec.yml
  • packages/realtime-client/vitest.config.ts
  • packages/services/vitest.config.ts
  • turbo.json
  • apps/web/playwright.config.ts
  • apps/mcp/vitest.config.ts
  • pnpm-workspace.yaml
  • apps/web/next.config.ts
  • .gitignore

Comment thread apps/mcp/Dockerfile Resolved
Comment thread apps/mcp/README.md Resolved
Comment thread apps/mcp/src/server.ts Resolved
Comment thread apps/realtime/src/server.test.ts Resolved
Comment thread apps/realtime/src/server.test.ts Resolved
Comment thread packages/core/package.json Resolved
Comment thread packages/core/src/test-support.ts Resolved
Comment thread packages/db/src/client.ts Resolved
Comment thread scripts/strip-comments.ts Resolved
Comment thread scripts/test-env.ts Resolved
Harden the destructive test guard: resetDatabase and resolveTestDatabaseUrl
now require the database name to match orbit_test(_suffix), so a name like
contest can no longer reach a truncate of every public table.

Validate DATABASE_POOL_MAX with Zod instead of Number.parseInt, which accepted
12abc and could hand NaN to the pool.

Drain the MCP server on shutdown rather than resetting in-flight requests.
close now closes idle connections, waits a grace period, and only then forces
the rest. Bun's http.close callback does not reliably fire once connections
have been open, so the grace timer also settles the promise, which bounds
shutdown instead of hanging. The grace is configurable and the tests use a
short one.

Treat an empty REDIS_URL as unset in the realtime test preload, buffer the raw
socket handshake before matching the status line, clear its timeout, pass the
repository env file to every test script, honour positional paths in
strip-comments so the pre-commit hook only scans staged files, and fix a stray
period and a missing fence language in the docs.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/mcp/src/server.ts`:
- Line 112: Validate and clamp the shutdownGraceMs value used by the server
shutdown timer to a positive finite duration before passing it to setTimeout.
Update the shutdown configuration handling around shutdownGraceMs so negative,
NaN, and Infinity values cannot produce an unintended near-immediate timer,
while preserving valid configured durations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8256dc98-b7aa-4f82-9a05-e08afac14281

📥 Commits

Reviewing files that changed from the base of the PR and between a92cefb and cf64af1.

📒 Files selected for processing (19)
  • apps/mcp/README.md
  • apps/mcp/package.json
  • apps/mcp/src/server.ts
  • apps/mcp/src/test-helpers.ts
  • apps/realtime/package.json
  • apps/realtime/src/server.test.ts
  • apps/realtime/tests-preload.ts
  • apps/web/e2e/account-and-workspaces.spec.ts
  • apps/web/e2e/second-workspace-realtime.spec.ts
  • apps/web/package.json
  • packages/core/package.json
  • packages/core/src/test-support.ts
  • packages/db/package.json
  • packages/db/src/client.ts
  • packages/realtime-client/package.json
  • packages/services/package.json
  • packages/shared/package.json
  • scripts/strip-comments.ts
  • scripts/test-env.ts
🚧 Files skipped from review as they are similar to previous changes (15)
  • apps/realtime/tests-preload.ts
  • apps/web/e2e/second-workspace-realtime.spec.ts
  • packages/core/package.json
  • packages/realtime-client/package.json
  • scripts/test-env.ts
  • apps/web/e2e/account-and-workspaces.spec.ts
  • packages/shared/package.json
  • apps/realtime/package.json
  • packages/db/package.json
  • apps/mcp/package.json
  • packages/services/package.json
  • apps/mcp/README.md
  • packages/db/src/client.ts
  • apps/realtime/src/server.test.ts
  • scripts/strip-comments.ts

Comment thread apps/mcp/src/server.ts Resolved
The Playwright runner executes on Node, which cannot resolve the bun module
that packages/db now imports, so every spec died at import. test:e2e now runs
under bun --bun, and the global setup uses node:child_process because that file
is loaded by the Node runner rather than by bun.

Clamp shutdownGraceMs to a positive finite value, since a negative, NaN or
Infinity input would otherwise become a 1ms timer and make shutdown immediate.

Measured against main on the same machine, same database and a fresh seed, the
end to end suite goes from 3 passed and 4 failed to 4 passed and 3 failed. The
three that still fail are the same three that fail on main.
@pulkitxm

Copy link
Copy Markdown
Member Author

End to end verification, measured against main

The unit suite, typecheck, lint and the container builds were all green while I had not actually watched the UI load a single issue. So I ran the real application on both branches and compared.

The migration did break the end to end suite, at the import level. Playwright's runner executes on Node, and Node cannot resolve the bun module that packages/db/src/client.ts now imports, so every spec died before it started. global-setup.ts had the mirror problem: I had converted it to Bun.spawn, which is undefined under the Node runner. Fixed by running bun --bun playwright test and putting the global setup back on node:child_process. Worth knowing that CI has no end to end job, which is exactly why four green checks coexisted with a suite that could not even import.

With that fixed, same machine, same Postgres, fresh seed, nothing else competing:

branch passed failed
main 3 4
chore/bun-everywhere 4 3

The three that still fail here (filters:8, issues:14, same-user-tabs:12) are a strict subset of the four that fail on main, and account-and-workspaces fails on main but passes here. So the branch is not a regression against main on this suite, it is slightly ahead of it. The three remaining failures are pre-existing and are picked up by the data loading and realtime streams.

I also confirmed the client behaves identically on both branches: loading /team/DES/issues fires the same two API calls, /api/bootstrap and /api/issues, and the grouped list renders with counts, priority icons, labels, estimates and avatars.

One methodology note, since it nearly caused a wrong call. My first comparison showed zero API calls on this branch against two on main, which looked like a hydration regression. It was not: NEXT_PUBLIC_APP_URL is baked into the client bundle at build time, .env sets it to port 3001, and I had run this branch on 3010 while running the baseline on 3001. Once both ran on 3001 the behaviour was identical. Nothing in the migration touches hydration.

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/e2e/global-setup.ts (1)

1-8: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Use Bun’s native process API here instead of node:child_process.
global-setup.ts is already part of the Bun e2e flow, so this can use Bun.spawnSync and keep the same inherited output and exit-code behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/e2e/global-setup.ts` around lines 1 - 8, Replace the execFileSync
usage in globalSetup with Bun.spawnSync, removing the node:child_process import
while preserving the repoRoot working directory, inherited stdio, command
arguments, and existing exit-code behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@apps/web/e2e/global-setup.ts`:
- Around line 1-8: Replace the execFileSync usage in globalSetup with
Bun.spawnSync, removing the node:child_process import while preserving the
repoRoot working directory, inherited stdio, command arguments, and existing
exit-code behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3ecd37c8-af94-4cd2-905e-f0af095ad686

📥 Commits

Reviewing files that changed from the base of the PR and between cf64af1 and 6d2f5d8.

📒 Files selected for processing (3)
  • apps/mcp/src/server.ts
  • apps/web/e2e/global-setup.ts
  • apps/web/package.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/package.json
  • apps/mcp/src/server.ts

@pulkitxm
pulkitxm merged commit 5fa3ac9 into main Jul 23, 2026
5 checks passed
@pulkitxm
pulkitxm deleted the chore/bun-everywhere branch July 23, 2026 16:23
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.

1 participant