perf(server): background service launcher uses 75% less memory #29284
main fromrefs/pull/29284/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubThe background service runs t3 __service-launcher, a tiny supervisor that keeps the real server alive. It loaded the whole CLI just to reach its handler. In the packaged single executable, that is the full 18 MB module, so the launcher alone held ~260 MiB for as long as the service ran.
Now bin.ts is a 31 KB bootstrap. The service's exact t3 __service-launcher call runs straight from it. Every other command, including the launcher with flags or --help, loads the CLI from binMain.ts as before. In packaged builds, that CLI is a separate bundle embedded as a raw executable asset, so the executable is still one file.
Linux x64 packaged executables, medians of alternating runs against main:
main | This PR | |
|---|---|---|
| Launcher memory (PSS) | 259 MiB | 66 MiB (-75%) |
| Launcher time to start the server | 467 ms | 29 ms |
| Launcher CPU at startup | 590 ms | 20 ms |
acp-mcp-call startup (wall / CPU) | 288 / 294 ms | 283 / 293 ms |
t3 serve memory | 420 MiB | 418 MiB |
Guards:
build:exefails if the bootstrap grows past 1 MiB, so the CLI cannot slip back into it.- Both executable configs pass
--require-module, soNODE_OPTIONS=--no-require-modulecannot break the embedded load. - The release smoke test now also runs
__service-launcheron every platform.
Proof:
check:changed, plus focused tests for the launcher, boot service, CLI loading, and the linux-arm64 executable. The CLI test fails if the bare-argv check or the launcher's full-CLI command is removed.- Linux x64 packaged executable: version, launcher errors, launcher
--helpand flags, symlinked paths,--no-require-module, the speech worker over IPC, and SIGTERM stopping launcher and child. - macOS arm64: built the real release archive on a Mac before the rebase, and the archive smoke test passed. Windows is covered by the release smoke test.
Council review#
Rounds: 3
| Delegate | Round 1 | Round 2 | Round 3 |
|---|---|---|---|
| Claude Opus 5.5 | 7/10 | 8/10 | 9/10 |
| Muse Wonder Full | 7/10 | 9/10 | 9/10 |
| Codex GPT-6.1 Sol | 9/10 | 9/10 | 9/10 |
Created with Claude Opus 5.5 in Claude Code, running in T3 Code.
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅ Codex Live turn messages 1 1 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅ Claude Live turn messages 1 1 0 (0.0%) 8 ✅ Baseline:
59ec1ba· PR result:9c7369f· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
Important
Review skipped#
Review was skipped as selected files did not have any reviewable changes.
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: t3/explore-extreme-performance-wins
- File: .coderabbit.config.ts
- Commit: 9c7369f
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
1a4725ec-4a63-41b1-b4b7-e738414c9c37
Commits-
Reviewing files that changed from the base of the PR and between c7810c2087dab0827df188d46bbfde22d64ef9fc and 9c7369f9e1ba5a8b57de62b98afbb1456e8ed4a5.
You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- Trigger review
No actionable comments were generated in the recent review.
Walkthrough
-
The executable build now creates a separate bootstrap and CLI asset, validates bundle imports and bootstrap size, and embeds the CLI asset in SEA executables. Runtime startup loads the CLI through the bootstrap or runs the service launcher directly. Tests and an archive smoke check cover these paths.
Changes: CLI Bootstrap and Dispatch
Layer / File(s) Summary Build and embed CLI asset
apps/server/vite.config.ts,apps/server/scripts/cli.ts,apps/server/scripts/cliErrors.ts,scripts/lib/linux-arm64-sea.tsExecutable packing creates a CLI bundle and a separate bootstrap. The build checks both bundles for external imports, rejects bootstraps larger than 1 MiB, and embeds the CLI asset in SEA executables. Bootstrap loading and command dispatch
apps/server/src/bin.ts,apps/server/src/binMain.ts,apps/server/src/cli/serviceLauncher.ts,apps/server/src/binCli.tsThe entry point loads the CLI from the embedded asset in SEA runs or imports it directly otherwise. It invokes the service launcher for the exact launcher command with no extra arguments. Other invocations use the CLI dispatcher. The service launcher awaits its work and sets the exit code on failure. CLI startup and archive checks
apps/server/src/cliCompileCache.test.ts,scripts/smoke-cli-archive.tsTests check CLI loading for normal and service-launcher invocations. The archive smoke check verifies the expected missing- T3CODE_HOMEerror.Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Refactor
Sequence Diagram(s)#
sequenceDiagram participant BinEntry as bin.ts participant Launcher as runServiceLauncherCli participant CliMain as binMain.ts participant BinCli as binCli.ts alt Exact __service-launcher invocation BinEntry->>Launcher: run service launcher Launcher->>Launcher: await runServiceLauncher else Other invocation BinEntry->>CliMain: load CLI and call runCliCommand CliMain->>BinCli: import and run CLI endPossibly related issues
- pingdotgg/t3code#19332: The changes separate bootstrap startup from loading the CLI main module, which relates to the issue’s focus on the cost of loading and compiling the full CLI bundle.
Suggested reviewers:
maria-rcks,voltcrash
Merge Risk:
Minimal · previous reviewc7810-
This change moves the background service launcher into a small bootstrap to cut its memory use, and no merge-blocking defect was found. Windows and macOS SEA loading was not run directly and depends on the PR's reported release smoke tests.
Pre-merge checks:
4-
Check name Status Explanation Title check The title describes the launcher memory reduction, which is the main change. Description check The description covers the problem, change, and verification. It does not include the required scope and approval information. Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request.
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: t3/explore-extreme-performance-wins
- File: .coderabbit.config.ts
- Commit: c7810c2
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
fbef11da-1bf9-40fe-90f5-ff75e54e7794
Commits-
Reviewing files that changed from the base of the PR and between f56def233293e4b313ba8430e140317b22afdf50 and c7810c2087dab0827df188d46bbfde22d64ef9fc.
Files selected for processing: 6-
apps/server/scripts/cli.tsapps/server/src/bin.tsapps/server/src/binCli.tsapps/server/src/cliCompileCache.test.tsapps/server/vite.config.tsscripts/lib/linux-arm64-sea.ts
Limit details: You’ve used all 10 included reviews currently available.
-
-
Independent test of this PR on Linux x64 (
build:exeat head 61ccc105bc against base 47f2c8d29e, Node 26.12.1, memory measured as PSS). Your numbers hold.base this PR Launcher, same binary file as the server 215 MB 31 MB Launcher + server 581 MB 405 MB Launcher, separate binary file from the server 248 MB 50 MB Direct t3 serve400 MB 383 MB These also behaved correctly:
- SIGTERM with a live server: launcher exits 0 and the server stops.
kill -9on the server: launcher exits 1, the same as base.- Missing home or state: same errors as base.
- Executable paths containing spaces,
#,%20andé, and a symlink. NODE_OPTIONS=--no-require-module.- PR launcher running a base server.
- The PR merged onto main at a07be97ab0: clean merge and build, launcher at 50 MB.
Two things that aren't in the PR description:
- Existing installs may not get the saving. A launcher pinned by an older service unit stays large. Base launcher with PR server: 248 MB. A 0.0.46 launcher with PR server: 315 MB. Both run and stop cleanly, but the memory saving needs
t3 service installor a fix for #17490. - Small start-up cost on fast paths. About 36 ms (6%):
acp-mcp-callwent from 557 to 593 ms median, andacp-mcp-bridgefrom 557 to 589 ms (10 runs each, one batch per build). This looks like a fair trade, thoughacp-mcp-callpays it on every tool call.
Not tested: update handoff and rollback through the real update flow, Windows, macOS, and the web UI (client not built, so
/returned 503).I ran this with an AI coding agent.
t3dotgg(GitHub profile, opens in a new tab) changed the title
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — The change keeps the full CLI out of the service launcher's startup graph and packages it as an embedded asset. New diagnostic suppressions in bin.ts and vite.config.ts require human review.
No code changes detected at
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).9c7369f. Prior analysis still applies.