Skip to content

Handle Linux distros without VERSION_ID#435

Open
botirkhaltaev wants to merge 4 commits into
CodSpeedHQ:mainfrom
botirkhaltaev:handle-linux-os-release-build-id
Open

Handle Linux distros without VERSION_ID#435
botirkhaltaev wants to merge 4 commits into
CodSpeedHQ:mainfrom
botirkhaltaev:handle-linux-os-release-build-id

Conversation

@botirkhaltaev

Copy link
Copy Markdown

Summary

Fix local CLI startup on Linux distributions whose os-release data has no VERSION_ID, such as Arch Linux.

The runner now keeps the existing support policy:

  • Ubuntu and Debian remain first-class supported distributions.
  • Other Linux distributions remain manual-install distributions.
  • OS detection no longer fails before executor support can decide what to do.

Changes

  • Move Linux version lookup into a Linux-specific resolver.
  • Keep macOS using sysinfo OS version as before.
  • For Linux, use sysinfo OS version first, then fall back to VERSION_ID or BUILD_ID from /etc/os-release or /usr/lib/os-release.
  • Add unit tests for VERSION_ID preference, BUILD_ID fallback, quoted values, and missing version fields.

Validation

  • cargo fmt --check
  • CARGO_BUILD_JOBS=1 CARGO_TARGET_DIR=/home/botirk/repos/codspeed-target TMPDIR=/home/botirk/repos/codspeed-tmp cargo check
  • CARGO_BUILD_JOBS=1 CARGO_TARGET_DIR=/home/botirk/repos/codspeed-target TMPDIR=/home/botirk/repos/codspeed-tmp cargo test --lib system::os
  • CARGO_BUILD_JOBS=1 CARGO_TARGET_DIR=/home/botirk/repos/codspeed-target TMPDIR=/home/botirk/repos/codspeed-tmp cargo run -- status

On the Arch Linux host that previously failed with Failed to get OS version, status now reports arch rolling and reaches normal repository/tool status output.

Closes #434

@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a startup crash on Linux distributions (like Arch Linux) that omit VERSION_ID from their /etc/os-release, by layering an OsRelease parser under the existing sysinfo::System::os_version() call rather than failing immediately when sysinfo returns None.

  • Version resolution for Linux now falls back to reading VERSION_ID, then BUILD_ID, from /etc/os-release and /usr/lib/os-release when sysinfo cannot provide a version, leaving macOS unchanged.
  • OsRelease parser handles quoted values (both \" and '), comment lines, and blank lines; five focused unit tests cover the preference ordering, fallback, and edge-case quoting.

Confidence Score: 5/5

Safe to merge — the change is additive, narrowly scoped to Linux version detection, and does not touch any shared API surface or wire format.

The fix correctly layers a lazy file-based fallback under the sysinfo call without touching macOS or any other code path. The OsRelease parser is self-contained and covered by five targeted unit tests. The only noteworthy detail is that the iterator strategy may consult /usr/lib/os-release even when /etc/os-release is present but versionless, which is a minor deviation from the freedesktop spec that won't affect any of CodSpeed's currently supported distributions.

No files require special attention.

Important Files Changed

Filename Overview
src/system/os.rs Adds OsRelease parser as a lazy fallback for Linux version detection when sysinfo returns None; logic and tests are correct with one minor os-release spec deviation in file-priority handling.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[from_os] --> B{os family?}
    B -->|linux| C[System::distribution_id]
    C --> D[System::os_version]
    D -->|Some| E[use sysinfo version]
    D -->|None| F[OsRelease::read]
    F --> G{/etc/os-release readable?}
    G -->|yes| H[parse: seek VERSION_ID or BUILD_ID]
    H -->|found| I[use os-release version]
    H -->|not found| J{/usr/lib/os-release readable?}
    G -->|no| J
    J -->|yes| K[parse: seek VERSION_ID or BUILD_ID]
    K -->|found| I
    K -->|not found| L[Err: Failed to get Linux OS version]
    J -->|no| L
    E --> M[LinuxDistribution::from_id]
    I --> M
    M --> N[SupportedOs::Linux]
    B -->|macos| O[System::os_version]
    O -->|Some| P[SupportedOs::Macos]
    O -->|None| Q[Err: Failed to get OS version]
    B -->|other| R[bail: Unsupported OS]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[from_os] --> B{os family?}
    B -->|linux| C[System::distribution_id]
    C --> D[System::os_version]
    D -->|Some| E[use sysinfo version]
    D -->|None| F[OsRelease::read]
    F --> G{/etc/os-release readable?}
    G -->|yes| H[parse: seek VERSION_ID or BUILD_ID]
    H -->|found| I[use os-release version]
    H -->|not found| J{/usr/lib/os-release readable?}
    G -->|no| J
    J -->|yes| K[parse: seek VERSION_ID or BUILD_ID]
    K -->|found| I
    K -->|not found| L[Err: Failed to get Linux OS version]
    J -->|no| L
    E --> M[LinuxDistribution::from_id]
    I --> M
    M --> N[SupportedOs::Linux]
    B -->|macos| O[System::os_version]
    O -->|Some| P[SupportedOs::Macos]
    O -->|None| Q[Err: Failed to get OS version]
    B -->|other| R[bail: Unsupported OS]
Loading

Reviews (3): Last reviewed commit: "Inline os-release value parsing" | Re-trigger Greptile

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.

CLI fails to detect OS version on Arch Linux

1 participant