{"record":{"id":"1a2a4c7fd655318c","repo":"tinyhumansai/openhuman","slug":"proc-metrics-sample-self-supports-linux-and-macos","errorCode":null,"errorMessage":"proc_metrics::sample_self supports Linux and macOS (this is a {} build)","messagePattern":"proc_metrics::sample_self supports Linux and macOS \\(this is a (.+?) build\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/openhuman/platform/proc_metrics/mod.rs","lineNumber":284,"sourceCode":"    Ok(ProcSample {\n        rss_kib: usage.ri_resident_size / 1024,\n        pss_kib: 0,\n        private_clean_kib: 0,\n        private_dirty_kib: 0,\n        vm_hwm_kib,\n        threads,\n        binary_size_bytes,\n        // `ri_user_time` / `ri_system_time` are nanoseconds on Darwin.\n        cpu_user_ms: usage.ri_user_time / 1_000_000,\n        cpu_system_ms: usage.ri_system_time / 1_000_000,\n        open_fds,\n    })\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_self() -> anyhow::Result<ProcSample> {\n    anyhow::bail!(\n        \"proc_metrics::sample_self supports Linux and macOS (this is a {} build)\",\n        std::env::consts::OS\n    )\n}\n\n/// Median of a slice of `u64`, averaging the two middle values for even counts.\n/// Empty input yields zero.\nfn median_u64(values: &[u64]) -> u64 {\n    if values.is_empty() {\n        return 0;\n    }\n    let mut sorted = values.to_vec();\n    sorted.sort_unstable();\n    let mid = sorted.len() / 2;\n    if sorted.len() % 2 == 1 {\n        sorted[mid]\n    } else {\n        // Average without overflow.","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/749120085864ce16e0f273c7b86fac7740b39c5b/src/openhuman/platform/proc_metrics/mod.rs#L266-L302","documentation":"proc_metrics::sample_self builds a ProcSample from /proc on Linux and rusage on macOS; every other target compiles a stub that bails loudly with the build's OS name rather than fabricating a reading (the source comment says exactly that). Because the desktop product also ships Windows, Windows builds take this stub — the failure is intentional honesty, not an accident.","triggerScenarios":"Calling proc_metrics::sample_self() in a build targeting windows — or any non-linux/macos target such as freebsd, android, or wasm — e.g. a Windows desktop build wiring the health/proc-metrics panel, or cross-target integration tests.","commonSituations":"Windows desktop builds surfacing health dashboards; CI matrices iterating all three desktop OSes; ports to non-supported platforms.","solutions":["Gate the caller: skip the metric on unsupported platforms (cfg or a runtime OS check) — observability must not be load-bearing there.","If the metric matters on Windows, contribute a platform implementation upstream rather than faking a value.","Fall back to coarse std APIs where an approximation is acceptable."],"exampleFix":"// before\nlet sample = proc_metrics::sample_self()?;\n\n// after — degrade to \"no sample\" on unsupported platforms\nlet sample = match proc_metrics::sample_self() {\n    Ok(s) => Some(s),\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 sample = proc_metrics::sample_self()?;\n    // ...\n}","typeGuard":"fn can_sample_self() -> bool {\n    matches!(std::env::consts::OS, \"linux\" | \"macos\")\n}","tryCatchPattern":"Match the 'supports Linux and macOS' message and treat it as a known-unsupported condition (skip the sample); propagate genuine read failures on supported platforms — those indicate a real problem.","preventionTips":["cfg-gate metric wiring per target so unsupported builds never call sample_self.","Keep dashboards tolerant of absent proc metrics.","Do not route product decisions through sample_self on Windows."],"tags":["proc-metrics","platform-support","windows","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"}