Skip to content

Batch macOS process discovery - #348

Open
sdairs wants to merge 1 commit into
codex/issue-337-org-autodetectfrom
codex/issue-329-batch-lsof
Open

Batch macOS process discovery#348
sdairs wants to merge 1 commit into
codex/issue-337-org-autodetectfrom
codex/issue-329-batch-lsof

Conversation

@sdairs

@sdairs sdairs commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • resolve all ClickHouse process working directories with one batched lsof call on macOS
  • parse lsof -Fn PID/path records and retain valid records if another process exits during discovery
  • preserve the Linux /proc/<pid>/cwd fast path and add focused parser coverage

Why

Process discovery previously launched one lsof subprocess per process named clickhouse. On agent-heavy machines with many clickhouse-local or chDB processes, that made local commands stall for tens of seconds even when none of those processes belonged to the current project.

Impact

macOS discovery now pays the lsof startup cost once regardless of the number of ClickHouse processes. The CLI surface and Linux behavior are unchanged.

Stack

This PR is stacked on #347 and should be reviewed as the delta from codex/issue-337-org-autodetect.

Closes #329.

Validation

  • cargo fmt --all --check
  • cargo build -p clickhousectl --all-targets
  • cargo test -p clickhousectl (570 tests)
  • cargo clippy -p clickhousectl --all-targets -- -D warnings
  • verified batched two-PID lsof -Fn output on macOS

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves local ClickHouse server discovery performance on macOS by resolving all candidate process working directories in a single lsof invocation, while preserving the Linux /proc/<pid>/cwd fast path. It also adds focused unit coverage for parsing batched lsof -Fn output so discovery remains robust when some PIDs disappear during inspection.

Changes:

  • Batch macOS cwd discovery into one lsof -a -d cwd -Fn -p <pid1,pid2,...> call and parse per-PID records (p<pid> / n<path>).
  • Adjust discovery flow to precompute a PID→cwd map and pass cwd into inspect_process (instead of resolving per-PID inline).
  • Add parser tests for correct attribution and malformed/incomplete record handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sdairs
sdairs force-pushed the codex/issue-329-batch-lsof branch from 22ff6b8 to 75937bb Compare August 3, 2026 18:42
@sdairs
sdairs marked this pull request as ready for review August 3, 2026 19:34
@sdairs
sdairs requested review from iskakaushik and rndD as code owners August 3, 2026 19:34
@sdairs
sdairs force-pushed the codex/issue-329-batch-lsof branch from 75937bb to 577468d Compare August 3, 2026 19:34
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.

Server discovery runs one lsof per clickhouse PID — ~29s command stall on machines with many clickhouse-local/chDB processes

2 participants