Skip to content

feat(nix): run the T3 server on mbp as a launchd agent - #490

Merged
furedea merged 1 commit into
mainfrom
feat/t3-server-service
Nov 21, 2026
Merged

furedea merged 1 commit into
mainfrom
feat/t3-server-service

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

概要

  • mbp で T3 server を launchd user agent として常駐させる(t3 serve --no-browser,127.0.0.1:3774,state は既存の ~/.t3).
  • mbp の desktop app は Local environment をオフにして client になり,mba と iPhone は Tailscale Serve(HTTPS 8443)で pairing する.
  • 利用者が決めること:下の切り替え手順を,desktop の Local environment をオフにしたあとで実行する.

Refs #489(plan:https://github.com/furedea/dotfiles/issues/489#issuecomment-7066118534)

flowchart LR
    MBPd["mbp:desktop app(Local env オフ)"] -->|loopback + pairing| T3
    MBA["mba:desktop app"] -->|tailnet HTTPS 8443| TS["Tailscale Serve(mbp)"]
    Phone["iPhone"] -->|tailnet HTTPS 8443| TS
    TS --> T3["T3 server(launchd,127.0.0.1:3774,~/.t3)"]
Loading

利用者の切り替え手順(plan の step 3)

注意: darwin-rebuild switch は desktop の Local environment をオフにしたあと,かつ動いている lane がないときにだけ実行する.オンのまま switch すると,常駐 server は ~/.t3 を取れず exit 78 になる(state は壊れないが,60 秒ごとに再試行する).

  1. mbp の desktop app で Settings → Environments → Local environment をオフ(app が再起動し,自前の server が止まる)
  2. この PR を merge し darwin-rebuild switch(常駐 server が起動)
  3. t3 pair --tailscale --tailscale-serve-port 8443 --label <端末> で mbp の desktop app,mba の desktop app(Add environment),iPhone をつなぐ

server の port は 3774 です(desktop 自身の 3773 と別).ログは ~/.t3/userdata/logs/launchd-server.log.

変更

項目 Before After
hosts.<host>.enableT3Service なし mbp true,mba false
T3 server desktop app が起動し,app を閉じると止まる mbp の launchd agent t3-server(RunAtLoad,KeepAlive,ThrottleInterval = 60)
mbp の system sleep 既定 電源接続時 pmset -c sleep 0(battery は変更なし.enableT3Service の host だけ)
ADR なし ADR-0045(proposed.実機確認まで)
  • agent は Nix の t3(t3codePackage.署名済み Codex 入り)を実行し,env は HOME,PATH,T3CODE_HOME=~/.t3,T3CODE_HOST=127.0.0.1,T3CODE_PORT=3774 だけ.credential は plist にも Nix store にも置かない.
  • PATH は Nix の profile(/etc/profiles/per-user/kaito/bin,/run/current-system/sw/bin),provider の store path(t3codePackage.providerPackages),/usr/local/bin(Tailscale app の CLI wrapper),システムの標準 path.
  • ログ用 directory は home-manager の activation(t3LogDirectory)で作る(launchd は親 directory を作らないため).

再起動の設計

KeepAlive = true と ThrottleInterval = 60 の組み合わせにした.

  • server が exit 78(desktop が ~/.t3 を握っている)で終わっても再試行は 1 分に 1 回で,desktop 側をオフにすれば自動で復帰する.
  • KeepAlive = { SuccessfulExit = false } は exit 78 も異常終了なので連打対策にならず,正常終了(server 自身の再起動など)で戻らなくなるだけなので採らない.Hister(ADR-0018)と同じ 60 秒にそろえた.

判断した点(brief との差)

  • 定義場所:Hister は nix-darwin の launchd.user.agents だが,t3codePackage は nix/home/default.nix にあるので,moshi と同じ home-manager の launchd.agents に置いた(darwin への package 受け渡しを避けるため).standalone-home-services-match-host が両者の一致を見張る.
  • LimitLoadToSessionType = "Aqua":provider の認証が login Keychain にあるため.
  • pmset -c sleep 0 は mba のスリープ設定は変えないので enableT3Service で条件付きにした.

検証

  • nix/checks.nix に先に契約を追加し(agent が無い状態で赤),実装後に緑
  • 契約:mbp のみに存在,RunAtLoad,Nix t3 serve --no-browser,loopback,port 3774,~/.t3,HOME,PATH(profile / provider / tailscale),ログ場所,credential らしい env 名がない,pmset が mbp だけ
  • nix flake check:all checks passed(aarch64-darwin).port を 3773 に変えると t3-service-own-port が落ちることを確認
  • nixfmt --check,statix,deadnix,dprint,adr-check,lefthook(commit 時)
  • 実機確認(利用者):plan step 4.既存の thread と project の表示,複数端末の同時操作,desktop を閉じても継続,iPhone の接続,pairing の取り消し手順.ADR を accepted にするのはそのあと

Limits(review で出た注意.修正しない)

  • pmset -c sleep 0 は enableT3Service を外しても自動では戻らない(手で sleep を戻す).
  • launchd-server.log に rotation はない.
  • T3CODE_HOST と T3CODE_PORT を t3 serve が読むことは eval では確認できない(source には存在).実機確認で lsof -iTCP:3774 が 127.0.0.1 だけであることを見る.

Review:claude-review,codex-review ともに inline finding なし(thread 0 件).

範囲と前提
  • 範囲外:Tailscale Serve の設定と pairing,desktop app の設定,mba,agent-config,T3 Connect,T3 version の更新.
  • 脅威モデル:server は利用者の権限で agent を動かす.loopback 以外に bind せず,token を store に置かない.PATH が誤ると provider や tailscale が見つからず,ログに出る.
  • t3 コマンドは --help 以外実行していない.darwin-rebuild も未実行(利用者が switch する).
  • port 3774 は desktop の 3773 を避けた固定値.

🤖 Generated with Claude Code

Add the enableT3Service host flag, a home-manager launchd agent that
runs the Nix t3 on loopback port 3774 with the existing ~/.t3 state,
pmset -c sleep 0 on the flagged host, contract checks, and ADR-0045.

Refs #489

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea

furedea commented Nov 21, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T18:37:27.582997Z b7843db Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

Review summary

I reviewed the launchd t3-server agent, the enableT3Service flag in flake.nix, the log-directory activation, the pmset -c sleep 0 change and the new checks in nix/checks.nix. No blocking findings (no P0 or P1).

What I checked:

  • Flag wiring: enableT3Service reaches the darwin specialArgs and hostHomeSpecialArgs, and hostHomeSpecialArgs is used by both the embedded home-manager and the standalone homeConfigurations. Neither evaluation path is missing the new argument.
  • Log directory: the t3LogDirectory activation is placed after writeBoundary and before setupLaunchAgents, so the directory exists before launchd opens the log file.
  • Credentials and network: the plist's environment only sets HOME, PATH and the T3CODE_* variables, the server binds to loopback, and no credential ends up in the Nix store.
  • PATH: it includes the overridden t3codePackage.providerPackages (the signed Codex), so it matches what the checks expect.

Things to know, not defects:

  • pmset -c sleep 0 is never undone. If enableT3Service is later set to false, mbp stays awake on the charger until sleep is reset by hand.
  • ~/.t3/userdata/logs/launchd-server.log has no rotation.
  • Whether t3 serve actually reads T3CODE_HOST and T3CODE_PORT isn't covered by the eval checks. Confirm it in the real-device step: lsof -iTCP:3774 should show 127.0.0.1 only.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: b7843db0fa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@furedea
furedea merged commit ea94f6b into main Nov 21, 2026
23 checks passed
@furedea
furedea deleted the feat/t3-server-service branch November 21, 2026 19:11
furedea added a commit that referenced this pull request Nov 21, 2026
agent-config を 0.5.1 に上げる.T3 で lane を回す手順の修正(待ち方,transport の優先順位,Start
前の branch 確認)と ADR-0028 の accepted が入る.

| 入力 | 変更前 | 変更後 |
| --- | --- | --- |
| `agent-config` | `7e350e03`(v0.5.0) | `7f39859b`(v0.5.1) |

- [ ] CI
- [ ] 反映後,`delegation` skill の `references/t3.md` が新しい Wait 手順(`show` の
polling,`latestRunId` の確認)になっている

<details>
<summary>内容と出典</summary>

- furedea/agent-config#272:利用者が明示した transport を T3 より先に見る,Start 前に
branch の有無を確かめる,失敗の原因は `server.trace.ndjson` で調べる
- furedea/agent-config#273:Wait 手順の修正(承認待ちは `pendingRequestCount`,終了は
`status`,Prompt 後は `latestRunId` の変化を待つ),ADR-0028 を accepted
- 変更は `flake.lock` のみ.agent-harness は `follows` で変わらない
- 反映は #490(T3 server の常駐)と同じ `darwin-rebuild switch` で行う.その前に mbp の
desktop app で Local environment をオフにする(#489 の plan 手順 3)

</details>

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: furedea <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
furedea added a commit that referenced this pull request Nov 22, 2026
実機確認(2026-11-22)と追加確認の結果を ADR-0045 に記録し,status を `accepted`
にする.決定内容は変えない.

| 項目 | 変更前 | 変更後 |
| --- | --- | --- |
| status | `proposed` | `accepted` |
| iOS の切断リスク | Safari を fallback とし,実機確認まで `proposed` |
報告(pingdotgg/t3code#25405,#24909)は残し,実機確認では起きず iPhone app が数分接続を保ったと記録 |
| pairing 手順 | 記述なし | リポジトリ外の手順を Bad として追記 |
| iOS の通知 | 記述なし | T3 account が必要で未使用のため iPhone は通知なし |

- [x] `dprint check`:問題なし
- [x] `autocorrect --lint`:問題なし
- [x] 追加した行は 100 桁以内(29 行目の既存 101 桁は Decision Outcome のため変更しない)
- [x] CI:`all-green` を含む全 check が pass,claude-review と codex-review
は指摘なし

<details>
<summary>根拠と範囲</summary>

- 根拠:PR #490 適用後の実機確認.mbp desktop を終了してもテスト thread が `completed`
まで動き続けた.mbp desktop,mba desktop,iPhone app の 3 client を pairing 済み.mba
desktop と iPhone app から approval に答えると thread が続いた.iPhone app は
Tailscale 経由で数分接続を保った
- pairing で必要だった手順:`tailscale serve --bg --https=8443
http://127.0.0.1:3774` を手動実行,tailnet ACL で `tcp:8443` を許可,token は一度きりで 5
分で失効,pairing URL と QR は `~/.t3/userdata/logs/launchd-server.log`
に出る,Local environment を切ると古い "T3 Code Desktop" client が残る
- 範囲外:Nix コード,plan comment,T3 の設定(#489 step 5),Moshi
-
plan:#489 (comment)
- 計画からの逸脱:なし

</details>

Refs #489

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: furedea <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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