Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): attribute ProcessLauncher-spawned children to their process groups on Linux #48269

Opensaphid(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/48269/headopened View on GitHub

Problem

On Linux with OTLP metrics export enabled, ProcessGroupMetrics walks each process's ppid chain until current.ppid === serverPid, so launcher-spawned children recognized by the existing name matcher (PROVIDER_GROUPS / OTHER_GROUPS: codex, claude, cursor, opencode, grok, antigravity|gemini, chrom, shells)—along with their child subtrees—are lumped into the other group whenever they are spawned through ProcessLauncher's helper process. (Any pre-existing name-classification gap, such as a native agy binary not matched by PROVIDER_GROUPS, is independent of this ancestry bug and intentionally out of scope.)

End-to-end path to collector payload (source-derived projection, not an observed HTTP export): On Linux, a provider session such as Codex is spawned via ProcessLauncher.layerServer (apps/server/src/server.ts) as a direct child of the long-lived launcher helper (ppid === launcherPid, where launcher.ppid === serverPid). Every minute, ProcessGroupMetrics.layer calls ResourceTelemetry.refresh (native resource-monitor sidecar), groups the process table with groupProcesses, and updates the Effect gauges t3_process_group_resident_bytes, t3_process_group_cpu_percent, and t3_process_group_count keyed by metricAttributes({ group }). When config.otlpMetricsUrl is set, OtlpMetrics.layer (apps/server/src/observability/Observability.ts:93) periodically snapshots the Effect metric registry, serializes each gauge's latest values with their group attributes into separate OTLP data points, and POSTs them to config.otlpMetricsUrl. Projecting the 5-row layer fixture below through OtlpMetrics.layer, base (a75e74eb48d6bb7b758401bc85a8d24d9c690bfa) would serialize an inflated group="other" data point (count=4) with no group="claude" or group="codex" points, whereas head (fa0684543279d8edd3cfcfd00dec78dc65c0ac7f) serializes separated group="claude" (count=2), group="codex" (count=1), and group="other" (count=1) points.

Deterministic repro on origin/main (a75e74eb48d6bb7b758401bc85a8d24d9c690bfa): Because origin/main does not contain the new regression cases, apply only the head test file (git checkout fa0684543279d8edd3cfcfd00dec78dc65c0ac7f -- apps/server/src/resourceTelemetry/ProcessGroupMetrics.test.ts) onto a75e74eb48d6bb7b758401bc85a8d24d9c690bfa without the production fix, then run vp test run apps/server/src/resourceTelemetry/ProcessGroupMetrics.test.ts. The test file exercises two distinct fixtures:

  1. 6-row unit fixture (groupProcesses): server (pid=100, ppid=1), ProcessLauncher helper (pid=101, ppid=100, node -e proxy), claude (pid=102, ppid=101) with child git (pid=103, ppid=102), codex (pid=104, ppid=101), and chrome-headless (pid=105, ppid=101, exercising classification for Chromium processes that are direct children of the launcher; Playwright's normal chromium.launch in apps/server/src/preview/ServerBrowserContexts.ts:188 does not use ProcessLauncher).
    • Observed on origin/main: { server: { count: 1, ... }, other: { count: 5, cpuPercent: 515, residentBytes: 515000 } }.
    • Expected: server (count: 1), other (count: 1), claude (count: 2), codex (count: 1), browser (count: 1).
  2. 5-row layer fixture (ProcessGroupMetrics.layer): Same rows without chrome-headless, asserting against the Effect Metric.snapshot registry (not an HTTP export).
    • Observed on origin/main: t3_process_group_count{group="claude"} is undefined.
    • Expected: t3_process_group_count{group="claude"} is 2 (resident_bytes=205000, cpu_percent=205), codex is 1, and other is 1.

Change

Added an optional launcherPid?: number parameter to groupProcesses in apps/server/src/resourceTelemetry/ProcessGroupMetrics.ts, guarding against PID reuse by verifying byPid.get(launcherPid)?.ppid === serverPid, keeping the launcher helper itself in other, and treating direct children of the verified launcher PID alongside direct children of serverPid. Updated ProcessGroupMetrics.layer to read ProcessLauncher.ProcessLauncher (a Context.Reference already provided in apps/server/src/server.ts via ProcessLauncher.layerServer) and pass yield* processLauncher.currentPid into groupProcesses on each sample. Other resource telemetry modules (Model.ts, ResourceTelemetry.ts) only walk for tree inclusion under serverPid and do not classify direct children into provider groups, so no other files needed changes.

Scope

Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.

Verification

  • Base (a75e74eb48d6bb7b758401bc85a8d24d9c690bfa + head test file only): vp test run apps/server/src/resourceTelemetry/ProcessGroupMetrics.test.ts failed 2/6 tests (6-row unit fixture returned other.count = 5; 5-row layer fixture returned undefined for t3_process_group_count{group="claude"}).
  • Head (fa0684543279d8edd3cfcfd00dec78dc65c0ac7f): vp test run apps/server/src/resourceTelemetry/ProcessGroupMetrics.test.ts passed 6/6 tests, including PID-reuse protection and ProcessGroupMetrics.layer Metric.snapshot verification.
  • vp run check:changed (fa0684543279d8edd3cfcfd00dec78dc65c0ac7f): exited 0 (format, lint, knip, graphql, typecheck across 3 packages, and test across 2 affected files / 8 tests).
  • Before/after + check:changed summary transcript: https://gist.github.com/saphid/3d72d6624fbd11cd1eefe6b44085d733 (unit/layer verification transcript plus the check:changed summary tied to fa0684543279d8edd3cfcfd00dec78dc65c0ac7f; not a standalone scenarios:prove recipe).
  • Not shown: Live OTLP HTTP POST to a running collector (the OtlpMetrics.layer collector payload above is a source-derived projection from apps/server/src/observability/Observability.ts:93), live Linux native resource-monitor sidecar sampling, Playwright browser launches (which do not go through ProcessLauncher), and pre-existing name-matcher gaps (e.g. agy).

Authored by Gemini 4 Neon (Antigravity); reviewed by GPT-6.2 Sol (Codex).

Not shown

  • apps/server/src/resourceTelemetry/ProcessGroupMetrics.test.ts:182 — The deterministic regression stops at the metric registry and is not a standalone scenarios:prove recipe; optional follow-up: run a Linux server against a loopback OTLP collector and assert the posted group counts on base and head.
    1. tanstack-source added labelsbug

    2. Approvability

      Verdict: Approved at 017562f

      Macroscope's review found this PR approvable — This corrects Linux resource-metric attribution for processes spawned through the launcher helper. It preserves existing sampling and export controls without changing process execution or product defaults.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      Process metrics now include direct children of a validated launcher PID in provider-group classification. The sampler passes the current launcher PID to groupProcesses. Tests cover launcher attribution, reused PIDs, and metric gauges.

      Changes: Process attribution

      Layer / File(s)Summary
      Launcher child grouping
      apps/server/src/resourceTelemetry/ProcessGroupMetrics.ts, apps/server/src/resourceTelemetry/ProcessGroupMetrics.test.ts
      groupProcesses accepts an optional launcher PID and uses it when the launcher is present and its parent is the server. Tests cover provider attribution and a reused launcher PID whose parent is not the server.
      Metrics sampler integration
      apps/server/src/resourceTelemetry/ProcessGroupMetrics.ts, apps/server/src/resourceTelemetry/ProcessGroupMetrics.test.ts
      The sampler passes the current launcher PID to groupProcesses. A layer test checks the resulting Claude, Codex, and other metric gauges.

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

      Change: Bug fix

      Sequence Diagram(s)

      sequenceDiagram
        participant MetricsSampler
        participant ProcessLauncher
        participant groupProcesses
        participant MetricGauges
        MetricsSampler->>ProcessLauncher: Read current launcher PID
        MetricsSampler->>groupProcesses: Pass refreshed process snapshot and launcher PID
        groupProcesses->>MetricGauges: Return grouped process metrics
      Merge Risk: Minimal · up to 01756

      This change attributes processes spawned through the launcher to their provider groups in process metrics. It only affects telemetry classification, and tests cover the new behavior and the PID-reuse guard. No merge-blocking risk was found.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title names the main change: ProcessLauncher-spawned children are attributed to their process groups on Linux. It matches the raw summary, which describes launcher-PID-based grouping in groupProce…
      Description checkPassedThe description covers the required template sections: Problem, Change, Scope, and Verification. The Problem section explains the bug and the ppid-chain cause on Linux. The Change section describes th…
      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.
      Full details: Title check

      Explanation

      The title names the main change: ProcessLauncher-spawned children are attributed to their process groups on Linux. It matches the raw summary, which describes launcher-PID-based grouping in groupProcesses. The title is a conventional commit with a clear scope and is concise.

      Full details: Description check

      Explanation

      The description covers the required template sections: Problem, Change, Scope, and Verification. The Problem section explains the bug and the ppid-chain cause on Linux. The Change section describes the optional launcherPid parameter and the PID-reuse guard. Scope explains why no issue is linked, and Verification gives focused test runs with observed results. The author also lists what was not checked. The description does not include a before/after screenshot, but this is a server-side change, so the UI requirement does not apply. The template's agent-model line is present: it names the model and harness that did the work. The description is long and detailed, but it meets the template's requirements.

      Finishing Touches

      Generate unit tests (beta)

      • 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 7ca670595c71ff636d84563145f5ce90e7e9e374 and 017562f99c0e3d08362a785dfb86494752833aa7.

      Files selected for processing: 2

      • apps/server/src/resourceTelemetry/ProcessGroupMetrics.test.ts
      • apps/server/src/resourceTelemetry/ProcessGroupMetrics.ts

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

Sign in to join this conversation.