Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): background service launcher uses 75% less memory #29284

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/29284/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

The 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:

mainThis PR
Launcher memory (PSS)259 MiB66 MiB (-75%)
Launcher time to start the server467 ms29 ms
Launcher CPU at startup590 ms20 ms
acp-mcp-call startup (wall / CPU)288 / 294 ms283 / 293 ms
t3 serve memory420 MiB418 MiB

Guards:

  • build:exe fails if the bootstrap grows past 1 MiB, so the CLI cannot slip back into it.
  • Both executable configs pass --require-module, so NODE_OPTIONS=--no-require-module cannot break the embedded load.
  • The release smoke test now also runs __service-launcher on 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 --help and 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

DelegateRound 1Round 2Round 3
Claude Opus 5.57/108/109/10
Muse Wonder Full7/109/109/10
Codex GPT-6.1 Sol9/109/109/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

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      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 9c7369f. Prior analysis still applies.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded21.5 KiB21.5 KiB0 B (0.0%)24.4 KiB✅
      CodexLive turn messages110 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
      ClaudeLive turn messages110 (0.0%)8✅

      Baseline: 59ec1ba · PR result: 9c7369f · Source CI: success

      Scenario 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.

    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      Important

      Review skipped

      Review was skipped as selected files did not have any reviewable changes.

      Run configuration

      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_status to false in 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.ts
      Executable 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.ts
      The 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.ts
      Tests check CLI loading for normal and service-launcher invocations. The archive smoke check verifies the expected missing-T3CODE_HOME error.

      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
        end

      Possibly 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 review c7810

      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: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title describes the launcher memory reduction, which is the main change.
      Description checkPassedThe description covers the problem, change, and verification. It does not include the required scope and approval information.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck 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

      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.ts
      • apps/server/src/bin.ts
      • apps/server/src/binCli.ts
      • apps/server/src/cliCompileCache.test.ts
      • apps/server/vite.config.ts
      • scripts/lib/linux-arm64-sea.ts

      Limit details: You’ve used all 10 included reviews currently available.

    5. Independent test of this PR on Linux x64 (build:exe at head 61ccc105bc against base 47f2c8d29e, Node 26.12.1, memory measured as PSS). Your numbers hold.

      basethis PR
      Launcher, same binary file as the server215 MB31 MB
      Launcher + server581 MB405 MB
      Launcher, separate binary file from the server248 MB50 MB
      Direct t3 serve400 MB383 MB

      These also behaved correctly:

      • SIGTERM with a live server: launcher exits 0 and the server stops.
      • kill -9 on the server: launcher exits 1, the same as base.
      • Missing home or state: same errors as base.
      • Executable paths containing spaces, #, %20 and é, 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:

      1. 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 install or a fix for #17490.
      2. Small start-up cost on fast paths. About 36 ms (6%): acp-mcp-call went from 557 to 593 ms median, and acp-mcp-bridge from 557 to 589 ms (10 runs each, one batch per build). This looks like a fair trade, though acp-mcp-call pays 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.

    6. t3dotgg(GitHub profile, opens in a new tab) changed the title

Sign in to join this conversation.