Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): prevent a second server from breaking active threads #10360

Closedt3dotgg(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromt3code/fix-broken-threadopened View on GitHub

Opening desktop while the background server is running can start a second server on port 3774 against the same database. The second server marks running threads as lost and cannot resume their Codex sessions because the original server still owns them. Follow-up messages then fail with already has an active writer.

Desktop now refuses startup when its default port is occupied instead of scanning for another port. The error explains how to use the running server or a separate T3 home. Explicit port settings retain their current behavior.

This brings #9003 onto current main after confirming the exact failure in a live thread. Credit to @maxibotstef for the original fix. This covers the automatic desktop fallback path. General server directory locking is separate.

Validation: all 5 focused tests passed, desktop typecheck passed, and targeted lint and format checks passed. No browser or desktop UI was launched.

Created with GPT-6 Astra in Codex.

Closes #6097

    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: Not approved

      Macroscope's review found this PR not approvable — The PR changes the packaged desktop default startup policy from selecting a fallback port to refusing startup when 3773 is occupied. Its host preflight can also reject a usable IPv4 bind because of an IPv6-only listener, so human review is warranted.

      Not approved because:

      • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Note

      🤖 GPT-6 Astra responding on behalf of Theo

      @cursor review

    4. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.5 KiB13.6 KiB+53 B (+0.4%)15.1 KiB✅
      CodexThread snapshot wire7.0 KiB7.0 KiB0 B (0.0%)7.3 KiB✅
      CodexLive turn WebSocket wire6.5 KiB6.6 KiB+53 B (+0.8%)7.8 KiB✅
      CodexLive turn WebSocket decoded57.0 KiB57.1 KiB+88 B (+0.2%)66.4 KiB✅
      CodexLive turn messages810+2 (+25.0%)21✅
      ClaudeTotal thread wire13.6 KiB13.6 KiB+16 B (+0.1%)15.1 KiB✅
      ClaudeThread snapshot wire7.0 KiB7.0 KiB+3 B (+0.0%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.5 KiB6.6 KiB+13 B (+0.2%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded57.8 KiB57.9 KiB+44 B (+0.1%)66.4 KiB✅
      ClaudeLive turn messages910+1 (+11.1%)21✅

      Baseline: 223ff44 · PR result: 4a3bda1 · 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: 113.9 KiB
      • Claude decoded thread snapshot: 114.5 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    5. Note: GPT-6 on behalf of shivam (@shivamhwp).

      Please correct the startup error's recovery guidance. It suggests using a different T3CODE_HOME, but port selection still refuses startup whenever 3773 is occupied and no explicit port is configured, regardless of the data directory. Changing only T3 home therefore repeats the same error. For a separate environment, the guidance needs both a separate home and an explicit free T3CODE_PORT; changing only the port must not be presented as safe for an already-owned home.

    6. Me on behalf of me:

      Please merge this, been hitting this error pretty often, thanks!

    7. juliusmarminge added labelsmacroscope-review

    8. @@ -79,18 +80,6 @@
      7980 }
      8081
      8182 const net = yield* NetService.NetService;
      82- for (let port = DEFAULT_DESKTOP_BACKEND_PORT; port <= MAX_TCP_PORT; port += 1) {
      83- let availableOnEveryHost = true;
      84-
      85- for (const host of DESKTOP_BACKEND_PORT_PROBE_HOSTS) {
      86- if (!(yield* net.canListenOnHost(port, host))) {
      87- availableOnEveryHost = false;
      88- break;
      89- }
      90- }
      91-
      92- if (availableOnEveryHost) {
      93- return {
      94- port,
      95- selectedByScan: true,
      96- } as const;
      83+ const unavailableHosts: string[] = [];
      84+ for (const host of DESKTOP_BACKEND_PORT_PROBE_HOSTS) {
      85+ if (!(yield* net.canListenOnHost(DEFAULT_DESKTOP_BACKEND_PORT, host))) {
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High app/DesktopApp.ts:85

      resolveDesktopBackendPort returns DesktopBackendPortInUseError when an IPv6-only listener occupies [::]:3773, even though the backend binds only to the IPv4 host(s) 127.0.0.1 or 0.0.0.0 and could still start. The loop probes every DESKTOP_BACKEND_PORT_PROBE_HOSTS entry, so probe only the resolved backend bind host(s), or defer this check until exposure settings are resolved.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/desktop/src/app/DesktopApp.ts around line 85:
      
      `resolveDesktopBackendPort` returns `DesktopBackendPortInUseError` when an IPv6-only listener occupies `[::]:3773`, even though the backend binds only to the IPv4 host(s) `127.0.0.1` or `0.0.0.0` and could still start. The loop probes every `DESKTOP_BACKEND_PORT_PROBE_HOSTS` entry, so probe only the resolved backend bind host(s), or defer this check until exposure settings are resolved.
    9. me on behalf of me, this would be really helpful! just ran into this issue and had to have an agent debug it

    10. Note

      Written by gpt-6.1-sol on behalf of Maria

      Superseded by #16102, which prevents two servers from sharing a T3 database regardless of which port they bind. The replacement protects CLI/offline writes and update rollback, and stops desktop/service retries after ownership refusal. It includes real-client reproduction and focused verification. Maria requested closure of superseded PRs; #6097 stays open until the replacement lands.

    11. maria-rcks closed this

    12. maria-rcks reopened this

    13. Note

      Grok responding on behalf of Julius.

      Superseded by #16102, which already landed on main and closes #6097 (exclusive ownership of the T3 home / database so a second server cannot open the same state). Closing this PR as superseded.

    14. juliusmarminge closed this

Sign in to join this conversation.