[Perf] Linux: Grok sessions walk /proc every 25 ms on the server event loop, although the cgroup lease already handles teardown
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- linux, typescript
- 領域
- backend, performance
調査の方向性
packages/provider-acp/src/server/AcpSessionRuntime.tsで、cgroup leaseのセットアップと継続的なownership observerを確認します。teardownの各分岐を調べ、leaseがない場合にのみownership ledgerが使われることを確かめてから、issueに記載されたカウント用controllerのテストを追加または更新します。observerがleaseのもとでrootを一度だけ取得し、アイドル時のポーリングが停止し、セッションを閉じるとleaseが空になることを確認できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
The problem
On Linux, when a Grok session has a cgroup v2 lease (t3-acp-*, the normal case under systemd),
AcpSessionRuntime still runs observePosixOwnershipLedgerContinuously for the whole life of the
session. Every 25 ms it walks the agent's process tree in /proc on the server's main thread. Its
result (the ownership ledger) is read only by terminatePosixProcessTree, which runs only when
there is no lease. Under a lease, teardown is cgroup.kill plus the root identity captured
once at spawn. The walk is unused work on the event loop.
Claude and Codex sessions have no equivalent. They are spawned detached and torn down with one
kill(-pgid) (ClaudeAdapterV2.ts:320, provider-core/src/server/processGroup.ts). Of the
providers in this repo, only provider-grok sets ownDescendantProcessGroups.
Measured impact (T3 v0.1.1, fe27e8e3, headless t3 serve, Ubuntu 26.04, cgroup v2)
Controlled test on one server process. Each Grok session was a task whose only action was
sleep 300. Per session: grok agent --always-approve stdio (46 threads) and
t3 acp-mcp-bridge (11 threads) in their own lease. Main thread measured with
/proc/<pid>/task/<pid>/stat and bpftrace raw_syscalls filtered to the main thread.
| Grok sessions | main thread CPU | main-thread /proc opens/s |
getdents64/s |
kernel time in these calls |
|---|---|---|---|---|
| 0 (Claude and Codex sessions live) | 6.8% of a core | 0 | 0 | — |
| 1, idle | 15.6% | 2,415 | 284 | 5.6% of a core |
| 3, idle | 24.6% | 6,390 | 759 | 12.9% of a core |
| 3, turns finished, sessions still open | 21.0% | 5,858 | 395 | 11.6% of a core |
| 0, after the 30 min idle release | 10.2% | 0 | 0 | 0.03% of a core |
- An idle session runs the walk at the full rate: about 40 passes/s × (one
task/<tid>/children
read per agent thread +statandreadlink exeper process). The cost scales with sessions and
with the agent's thread count. - It lasts beyond the turn. Idle provider sessions are released after
DEFAULT_IDLE_TIMEOUT_MS
(30 min, up to 4 h when pinned;ProviderSessionManager.ts:56-57). The test sessions were
released 30 min after their last activity, and the/proctraffic stopped with them. - Under load the walk runs slower (we saw about 5 passes/s on a busy server), because it shares
the main thread. Then it shows up as event-loop delay instead of CPU.
This is the measurement requested when #19255 was closed.
Root cause
packages/provider-acp/src/server/AcpSessionRuntime.ts @ fe27e8e3:
- Grok enables descendant ownership on Linux:
provider-grok/src/server/acpSupport.ts#L90-L101. - That creates a cgroup v2 lease and joins the agent to it before
exec:
L1402-L1421. - Without checking for the lease, it then forks the continuous observer for the session's
lifetime:
L1493-L1534,
loop at
L739-L758
(25 ms target, insideEffect.sync, so each pass blocks the event loop). - With a lease, graceful teardown
(L1596-L1609)
and forced teardown
(L1624-L1641)
use only the root identity from the initial capture andterminateLinuxCgroupLease. The ledger
is consumed only byterminatePosixProcessTree, reached whenlinuxCgroupLease === undefined.
Proposed fix
Start the continuous observer only when there is no lease. The initial root capture stays, so
signalLinuxCgroupRootTerm still targets the right pid:starttime. Sessions without a lease
(cgroup v1, no delegated cgroup) behave exactly as today.
- yield* observePosixOwnershipLedgerContinuously({
- childQueues: posixOwnershipChildQueues,
- controller: posixController,
- frontier: posixOwnershipFrontier,
- ledger: posixOwnershipLedger,
- root: posixOwnershipRoot,
- rootPid: Number(child.pid),
- }).pipe(Effect.forkIn(runtimeScope));
+ // Under a cgroup lease, teardown is cgroup.kill and reads only the root captured above.
+ if (linuxCgroupLease === undefined) {
+ yield* observePosixOwnershipLedgerContinuously({
+ childQueues: posixOwnershipChildQueues,
+ controller: posixController,
+ frontier: posixOwnershipFrontier,
+ ledger: posixOwnershipLedger,
+ root: posixOwnershipRoot,
+ rootPid: Number(child.pid),
+ }).pipe(Effect.forkIn(runtimeScope));
+ }
Test: with a counting fake posixProcessTreeController and a temp-directory lease, assert that
childPidsOf runs once (the initial capture) over an idle window of 10+ intervals, and that closing
the session still empties the lease. #19255 had this test (8 reads instead of 1 on main).
Expected result
Under a lease: 0 /proc opens from idle Grok sessions, the same as Claude and Codex, and about
5–9% of a core of main-thread time back per open Grok session.
- 主要言語
- TypeScript
- スター
- 24.8k
- フォーク
- 6.4k
- 平均マージ
- 8時間 4分
- マージ済み PR(30日)
- 199
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pingdotgg/t3code のほかの issue
-
[Bug]: Device screenshot fails with 500 on iPhone Duo (Xcode 27.2): serve-sim calls simctl without --display対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
pingdotgg/t3code#24900 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
pingdotgg/t3code#24800 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
[Bug]: Desktop startup briefly warns about Codex provider status before its initial check completesオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
pingdotgg/t3code の issue をすべて見る
似ている issue
-
freshness freshness:observed-only
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
thoroc/context-radar#282 ·
-
bug P2 rust
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
area: web
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
gabe-santana/arkdraw#25 ·
-
bug require-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
expressjs/expressjs.com#2549 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug good first issue hacktoberfest
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
codercops/discord-bot#101 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信