{"record":{"id":"872e0913d8922b39","repo":"tinyhumansai/openhuman","slug":"proc-metrics-sample-tree-supports-linux-and-macos","errorCode":null,"errorMessage":"proc_metrics::sample_tree supports Linux and macOS (this is a {} build)","messagePattern":"proc_metrics::sample_tree supports Linux and macOS \\(this is a (.+?) build\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/openhuman/platform/proc_metrics/tree.rs","lineNumber":202,"sourceCode":"                pid,\n                name: macos::proc_name(pid),\n                rss_kib,\n            }),\n            None => {\n                eprintln!(\n                    \"[proc_metrics] tree: skipping child pid={pid}: proc_pid_rusage unavailable (exited or permission denied)\"\n                );\n            }\n        }\n    }\n\n    Ok(TreeSample::assemble(self_sample, children))\n}\n\n/// Unsupported-platform stub — fails loudly rather than fabricating a reading.\n#[cfg(not(any(target_os = \"linux\", target_os = \"macos\")))]\npub fn sample_tree() -> anyhow::Result<TreeSample> {\n    anyhow::bail!(\n        \"proc_metrics::sample_tree supports Linux and macOS (this is a {} build)\",\n        std::env::consts::OS\n    )\n}\n\n#[cfg(target_os = \"macos\")]\nmod macos {\n    use std::collections::HashSet;\n    use std::mem::{size_of, MaybeUninit};\n\n    /// Direct children of `ppid` via `proc_listchildpids`. Empty on any error.\n    ///\n    /// Note the Darwin ABI quirk: `proc_listchildpids` returns the **number of\n    /// pids** written (not a byte count, unlike `proc_listpids`), and fills the\n    /// buffer with that many `pid_t`. It also doesn't reliably support the NULL\n    /// size-probe form, so we allocate a real buffer up front and grow it if the\n    /// kernel filled it completely (the list may have been truncated).\n    fn child_pids(ppid: i32) -> Vec<i32> {","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/749120085864ce16e0f273c7b86fac7740b39c5b/src/openhuman/platform/proc_metrics/tree.rs#L184-L220","documentation":"proc_metrics::sample_tree samples the process plus its children (children via /proc on Linux and proc_listchildpids on macOS, skipping children whose rusage call fails) and assembles a TreeSample; every platform other than Linux and macOS compiles a stub that bails with the build's OS name instead of fabricating readings. Same intentional-honesty design as sample_self, one level up the process tree.","triggerScenarios":"Calling proc_metrics::sample_tree() in a windows (or otherwise non-linux/macos) build — e.g. a health monitor that includes child-process CPU/memory on the Windows desktop target.","commonSituations":"Windows desktop builds with tree-aware health panels; cross-platform test matrices; ports to BSD/Android.","solutions":["Gate the caller: skip tree metrics on unsupported platforms.","Contribute a Windows implementation of the child-enumeration path upstream if needed.","Design dashboards to tolerate an absent tree sample rather than erroring."],"exampleFix":"// before\nlet tree = proc_metrics::sample_tree()?;\n\n// after — degrade to \"no tree sample\" on unsupported platforms\nlet tree = match proc_metrics::sample_tree() {\n    Ok(t) => Some(t),\n    Err(e) if e.to_string().contains(\"supports Linux and macOS\") => None,\n    Err(e) => return Err(e),\n};","handlingStrategy":"fallback","validationCode":"fn proc_metrics_supported() -> bool {\n    matches!(std::env::consts::OS, \"linux\" | \"macos\")\n}\n\nif proc_metrics_supported() {\n    let tree = proc_metrics::sample_tree()?;\n    // ...\n}","typeGuard":"fn can_sample_tree() -> bool {\n    matches!(std::env::consts::OS, \"linux\" | \"macos\")\n}","tryCatchPattern":"Match the 'supports Linux and macOS' message and degrade to a self-only or absent tree sample; distinguish it from per-child skip warnings (proc_pid_rusage unavailable), which the Linux/macOS path already tolerates.","preventionTips":["cfg-gate tree-metric wiring per target.","Design health panels to render without child-process data.","Contribute platform implementations rather than stubbing silently."],"tags":["proc-metrics","platform-support","windows","process-tree","unsupported-os"],"backgroundTag":"unsupported-platform","analyzedSha":"749120085864ce16e0f273c7b86fac7740b39c5b","analyzedAt":"2026-08-17T21:21:45.363Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}