Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): refuse to share a T3 home with an older background service #19715

Mergedarun279(GitHub profile, opens in a new tab)merged 10 commits intomain fromrefs/pull/19715/headmerged by juliusmarminge View on GitHub

An older background service can keep running after another pre-lock server overwrites and removes its runtime record. A newer server then sees no owner and can open the same T3 home.

Startup now checks the installed launchd or systemd user service when its configured userdata directory resolves to the same directory. If that service is active or enabled and its recorded version is before stable 0.1.0, startup exits 78 with recovery guidance. A loaded service with a deferred update is also refused, because the recorded version may already name a replacement that has not started. No service is stopped.

The own-service bypass requires both launcher context and an IPC connection, so a command in a T3 terminal cannot bypass the guard by inheriting its environment. This uses the recorded version rather than executing the installed runtime. It covers older npm runtime layouts and allows lock-aware stable releases that shipped before this PR. Windows has no native boot-service probe here; WSL follows Linux. Desktop and WSL conflict messages explain updating or uninstalling and reinstalling an older service from a current CLI.

Thanks @arun279 for the diagnosis and original implementation in #19715, following #16102. The takeover preserves the contributor commits and merges main. It removes the new preflight protocol and runtime probe after independent reviews found that those missed npm-installed services and falsely rejected lock-aware stable services.

Verification on head e06d57dc4a:

  • 84 tests passed on this head across serverRuntimeState, cloud/servicePreflight, cloud/serviceLauncherClient, serviceLauncher, and cloud/bootService. The earlier five-suite run including cloud/selfUpdate also passed (91 tests). The original refusal regressions fail against main; focused tests also reproduced both review findings before their fix. The ownership/preflight suites contain 20 tests, with all 14 baseline tests preserved. Original 6 added tests became 6 focused behavior tests after adding the missing npm-layout regression; scenarios reduced from 17 to 16.
  • Scoped lint and formatting, plus server and desktop typechecks, passed.
  • Process proof with temporary homes, production ProcessRunner, and an external service-manager stand-in: the full serve command exits 78 for old standalone and npm layouts with no runtime record, for a loaded service awaiting restart into 0.1.0, and when a command inherits launcher context without IPC. Production ownership acquisition accepts a stopped-but-enabled 0.1.0 service and a stopped, disabled old service. Only read-only manager probes run; no installed runtime is invoked or runtime record published. No live T3 home or installed service was touched.
  • Three independent full-diff review rounds on Claude Opus 5.5 and GPT-6-Sol. Round 1 found the npm-layout miss and stable-service false refusal; round 2 identified inherited launcher context without IPC. All three issues have behavioral regressions and fixes. Round 3 found no blockers on this head.

This is nonvisual startup behavior; focused tests and process output provide proof. Native launchd/systemd managers, real installed older runtimes, desktop/WSL dialogs, real SSH startup, macOS, Windows, iOS, and Android were not exercised on this head.

The legacy guard remains best effort: missing/unreadable configuration or an unavailable service manager allows startup. Lock-aware prereleases below 0.1.0 may be conservatively refused. Service layouts without service-state.json, invisible legacy foreground processes, and old services starting after the check remain outside this fix. The original revision's native verification is not claimed for this rebuilt implementation.

Models: GPT-6-Astra (tests), GPT-6.1-Sol (implementation), Claude Opus 5.5 and GPT-6-Sol (reviews). Harnesses: Codex and Claude Code through T3 Code.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This change adds cross-platform service detection and an automatic startup refusal path, rather than only adjusting copy or fixing an isolated internal defect. Because it changes production server-startup behavior and gates whether the existing workflow proceeds, the runtime impact warrants human review.

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

      Warning

      Review limit reached

      Only developers with an assigned seat can use this organization's usage-based review budget, and seats here are assigned manually. Ask an admin to assign a seat, or change the review continuation mode in Billing.

      Next included review available in 17 minutes.

      Check out review usage here.

      View limit details

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

      Learn how review limits work.

      Review configuration:

      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 3cf1ab0e-8f25-4a06-8b17-033873e0ac46
      📥 Commits

      Reviewing files that changed from the base of the PR and between 0d0ee61f0837f774ac937bf4c63d3f7054db0f75 and ff1c9d63503e88f29e8471d5e042c7ea61457424.

      📒 Files selected for processing: 5
      • apps/desktop/src/backend/DesktopBackendPool.ts
      • apps/desktop/src/wsl/DesktopWslBackend.ts
      • apps/server/src/cloud/bootService.ts
      • apps/server/src/serverOwnership.ts
      • apps/server/src/serverRuntimeState.test.ts

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: dc6f4180-988a-4485-86e8-e74b721616c1
      📥 Commits

      Reviewing files that changed from the base of the PR and between ec1313c8f8333292506f05a355bb72d308a455d8 and 0d0ee61f0837f774ac937bf4c63d3f7054db0f75.

      📒 Files selected for processing: 7
      • apps/desktop/src/backend/DesktopBackendPool.ts
      • apps/desktop/src/wsl/DesktopWslBackend.ts
      • apps/server/src/cloud/bootService.ts
      • apps/server/src/cloud/servicePreflight.test.ts
      • apps/server/src/cloud/servicePreflight.ts
      • apps/server/src/serverOwnership.ts
      • apps/server/src/serverRuntimeState.test.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

      📝 Walkthrough

      Server startup now checks whether an older macOS or Linux boot service may share its state directory. It blocks startup when it detects a matching service without the ownership protocol. Desktop conflict messages also include commands to update an older service.

      Changes: Boot-Service Ownership

      Layer / File(s)Summary
      Define service compatibility signals
      apps/server/src/cloud/servicePreflight.ts, apps/server/src/cloud/servicePreflight.test.ts, apps/server/src/cloud/bootService.ts
      Service preflight results now include ownershipProtocol: 1, and the decoder preserves the marker only when its value is exactly 1. The boot-service filename, label, and plist constants are exported.
      Detect and block older boot services
      apps/server/src/serverOwnership.ts, apps/desktop/src/backend/DesktopBackendPool.ts, apps/desktop/src/wsl/DesktopWslBackend.ts
      Startup checks installed services for matching state-directory ownership and service status. A detected older service blocks startup with OlderBootServiceError. Desktop conflict messages now include t3 update and npx t3 update instructions.
      Test ownership compatibility cases
      apps/server/src/serverRuntimeState.test.ts
      Tests cover service state, state-directory matches, launcher protocol versions, pending restarts, launcher contexts, and unavailable or failed probes.

      Priority: ➖ Normal

      Estimated code review effort: 3 (Moderate) | ~25 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Sequence Diagram(s)

      sequenceDiagram
        participant Startup as Server startup
        participant Config as Boot-service configuration
        participant Release as Active service release
        Startup->>Config: Check state directory and service status
        alt Loaded service has pending restart
          Config-->>Startup: Report pending restart
        else Service is loaded or scheduled
          Startup->>Release: Run service preflight
          Release-->>Startup: Return ownership protocol marker
        end

      Suggested reviewers: maria-rcks, juliusmarminge

      Merge Risk: ⚪ Minimal · up to 0d0ee

      No identified issue prevents merging after normal checks.

      Security architecture risk: 🔵 Low · up to 0d0ee

      The change reduces the chance that incompatible servers share the same data directory. It preserves the existing ownership lock and refuses startup without stopping another server. Detection remains best effort, so unreadable configuration, unsuccessful probes, and some concurrent legacy-service starts can still escape detection.

      Retained concerns No architecture-level concerns identified.

      Security review details

      Security Blast Radius

      • observed — The checked resource is the current startup's state directory. A service is considered only when its configured home's userdata directory resolves to that same real path. The probe receives that directory's statev2.sqlite path; a different home's service is skipped.

      Trust Boundaries and Controls

      • observed — The new execution path trusts the installed local service configuration and runtime: it reads the unit or plist, reads activeVersion from service-state.json, and invokes runtime/versions/version/t3. Exact SemVer validation prevents activeVersion from supplying path traversal. Canonical-home matching scopes the invocation, but neither it nor the self-reported ownership marker authenticates the executable.
      • observed — The compatibility check is intentionally bypassed when the launcher-context environment variable is present. The launcher supplies that variable to its child. This is a process-context convention, not an authorization credential; the SQLite ownership lock and existing runtime-record check still run before this bypass.

      Resilience and Maintainability Implications

      • observed — Manager commands have five-second timeouts and the runtime probe has a fifteen-second timeout. Probe failures, nonzero exits, unreadable state, and unrecognized decoded responses allow startup. This contains startup disruption but leaves compatibility unproven in those cases. Supplied tests simulate legacy ready and blocked responses, pending restarts, launcher-context bypass, and probe failure; they do not independently establish every released runtime's behavior.
      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Linked Issues checkPassedNo active directly linked issue remains. Issue #6097 is closed and supplies historical context only. Therefore, no linked-issue coding requirements apply to this pull request.
      Out of Scope Changes checkPassedThe reported changes match the current pull request scope: older background-service detection, ownership preflight signaling, exit-78 handling, user messages, and focused tests. Exported service const…
      Title checkPassedThe title is concise, specific, and accurately describes the main change: preventing a T3 home from being shared with an older background service.
      Description checkPassedThe description clearly explains the problem, implementation, scope, verification results, limitations, and review history. It does not provide explicit maintainer approval evidence in the required fo…
      Full details: Out of Scope Changes check

      Explanation

      The reported changes match the current pull request scope: older background-service detection, ownership preflight signaling, exit-78 handling, user messages, and focused tests. Exported service constants support the new test coverage. No unrelated change is demonstrated.

      Full details: Description check

      Explanation

      The description clearly explains the problem, implementation, scope, verification results, limitations, and review history. It does not provide explicit maintainer approval evidence in the required format, but the overall description is complete and relevant.

      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Comment `@coderabbitai help` to get the list of available commands.
    4. juliusmarminge assignedjuliusmarminge

    5. Taking over this one as maintainer. I will trim the tests, rebuild the implementation against current main, and run independent reviews before adding commits to this branch. Thanks @arun279 for identifying and reproducing the older-service ownership gap.

    6. juliusmarminge merged this353d8c5

    7. juliusmarminge closed this

Sign in to join this conversation.