Skip to content

fix: enumerate foreground process groups without CONFIG_PROC_CHILDREN - #2269

Open
knowsuchagency wants to merge 2 commits into
herdrdev:masterfrom
knowsuchagency:fix/proc-children-fallback
Open

fix: enumerate foreground process groups without CONFIG_PROC_CHILDREN#2269
knowsuchagency wants to merge 2 commits into
herdrdev:masterfrom
knowsuchagency:fix/proc-children-fallback

Conversation

@knowsuchagency

Copy link
Copy Markdown

Current behavior

On Linux kernels built without CONFIG_PROC_CHILDREN, an agent started through a wrapper is never identified. Running claude directly works, because the shell puts it in the foreground process group and it is the group leader. Running it through a task runner (mise run <task> -> claude) does not: the pane shows agent_status: "unknown", never appears in the agents sidebar or herdr agent list, and herdr pane process-info lists only the wrapper.

CONFIG_PROC_CHILDREN is optional and off in some container/Kubernetes node kernels, so this is not exotic hardware; on those hosts every wrapper-launched agent is invisible.

Cause

foreground_process_group_members walks /proc/<pid>/task/<tid>/children to find the pane's process subtree. Those files only exist when the kernel was built with CONFIG_PROC_CHILDREN. When they are missing, every read comes back empty, so process_tree_pids returns only the roots it was seeded with and the real agent process is never inspected. child_groups_foreground_process_group reads the same files and has the same blind spot.

Fix

Probe the interface once (cached in a OnceLock) by stat'ing our own /proc/<pid>/task/<pid>/children, and only when it is absent fall back to enumerating /proc. The existing live_process_group_member filter is unchanged and still decides membership, so the fallback widens the candidate set without loosening what counts as a member. child_groups_foreground_process_group gets the equivalent fallback via a ppid scan.

On kernels that do expose the children files — the overwhelming majority — nothing changes: the probe short-circuits and /proc is never enumerated. I deliberately kept the scan behind the probe rather than making it unconditional, since the pane-scoped walk exists precisely to avoid full /proc sweeps (#1390), and the fallback is additionally gated by the existing should_probe_foreground_job throttle rather than running every poll.

Verification

Reproduced live in two containers on kernel 6.18.35 (no CONFIG_PROC_CHILDREN). Before: with mise run norm launching claude in a pane, herdr pane process-info reported only mise run norm while ps showed claude in the same pgid, and the pane never appeared in herdr agent list. After: both processes are enumerated and the pane is detected and listed.

just ci passes on this branch apart from workspace::git::status::tests::git_status_recomputes_ahead_behind_when_head_moves, which fails identically on a clean origin/master checkout here and is unrelated to this change. All 42 platform:: tests pass.

Tests

New unit tests cover both directions of the probe for each function (fallback used when children files are absent, scan not called when they are present), the empty-group case, and /proc/<pid>/stat ppid parsing including a comm containing ). The support probe itself is only asserted to be stable across calls, since its answer depends on the host kernel; the behavior it gates is covered by the injected-flag tests.

No docs change needed — this restores intended behavior on affected kernels rather than changing any documented behavior.

https://claude.ai/code/session_013DSUQrZfBkKtumyVZQxeT3

Kernels built without CONFIG_PROC_CHILDREN (some container hosts) expose
no /proc/<pid>/task/<tid>/children files, so the foreground job walk only
ever returned its own roots and wrapper-launched agents (mise run ->
claude) were never identified or shown in the agents sidebar. Probe the
interface once at startup and fall back to scanning /proc, reusing the
existing process-group membership filter; child-group inference gets the
same fallback via a ppid scan.

Claude-Session: https://claude.ai/code/session_013DSUQrZfBkKtumyVZQxeT3
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 746911c4-eb77-4f50-a81d-5b0e52f8a382

📥 Commits

Reviewing files that changed from the base of the PR and between e1097cf and bcacaa0.

📒 Files selected for processing (1)
  • src/platform/linux.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/platform/linux.rs

📝 Walkthrough

Walkthrough

Linux process-group discovery now detects /proc child-file support and falls back to bounded /proc scans when unavailable. Child-group and foreground-member enumeration deduplicate candidates, filter invalid groups, and reuse shared PID and parent-PID helpers.

Changes

Linux process-group discovery

Layer / File(s) Summary
/proc capability and PID helpers
src/platform/linux.rs
Adds cached child-file support detection, shared numeric PID enumeration, parent-PID parsing, session-process reuse of the shared helper, and related tests.
Child-group fallback discovery
src/platform/linux.rs
Extends child-group discovery with /proc fallback scanning, candidate deduplication, scan limits, shell-group filtering, and validation tests.
Foreground-member fallback enumeration
src/platform/linux.rs
Extends foreground-member discovery with /proc fallback enumeration and process-group filtering. Tests cover supported and unsupported child files, empty groups, degradation, and updated helper arguments.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Discovery as Linux process-group discovery
  participant ProcChildren as /proc child files
  participant ProcScan as all_process_pids
  participant GroupLookup as process-group lookup
  Caller->>Discovery: enumerate child groups or foreground members
  Discovery->>ProcChildren: read task-derived children
  alt child files unsupported
    Discovery->>ProcScan: enumerate visible /proc PIDs
    ProcScan-->>Discovery: fallback candidate PIDs
  end
  Discovery->>GroupLookup: filter candidates by process group
  GroupLookup-->>Discovery: matching process groups or members
Loading

Possibly related PRs

Suggested labels: coderabbit-review

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: restoring foreground process-group enumeration without CONFIG_PROC_CHILDREN.
Description check ✅ Passed The description explains the CONFIG_PROC_CHILDREN issue, the /proc fallback, affected behavior, and verification results.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@kangal-bot kangal-bot added the ai-review Trigger automated AI reviews for pull requests admitted by the PR gate label Aug 4, 2026
@greptile-apps

greptile-apps Bot commented Aug 4, 2026

Copy link
Copy Markdown

Greptile Summary

The PR restores Linux foreground-agent detection on kernels without CONFIG_PROC_CHILDREN.

  • Caches a probe for /proc/<pid>/task/<tid>/children support.
  • Falls back to process-group and parent-PID scans through /proc when that interface is unavailable.
  • Adds focused tests for fallback selection, scan limits, empty groups, and /proc/<pid>/stat parsing.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/platform/linux.rs Adds guarded /proc scanning fallbacks for foreground process-group discovery while retaining existing membership filtering and scan limits.

Reviews (2): Last reviewed commit: "fix(linux): bound the child-group /proc ..." | Re-trigger Greptile

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f86a2fda-3cf8-4458-a0fd-fba0c35226dd

📥 Commits

Reviewing files that changed from the base of the PR and between adb50cb and e1097cf.

📒 Files selected for processing (1)
  • src/platform/linux.rs

Comment thread src/platform/linux.rs Outdated
The fallback ppid scan read every visible pid before
CHILD_GROUPS_SCAN_LIMIT could apply, so an unexpectedly wide parent did
unbounded work on the way to failing closed. Stream /proc instead of
materializing every pid and stop one past the limit, which is all the
caller needs to return None.

Claude-Session: https://claude.ai/code/session_013DSUQrZfBkKtumyVZQxeT3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Trigger automated AI reviews for pull requests admitted by the PR gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants