← Back to PRs

#23730: fix(update): correctly compare versions with -N build suffix

by mrx-arafat open 2026-02-22 16:42 View on GitHub →
size: S
## Summary Fixes #23647 `openclaw update status` was incorrectly flagging versions like `2026.2.21-2` as older than `2026.2.21`, causing false "update available" warnings and potential downgrades. ## Root Cause The `compareSemverStrings()` function used `parseSemver()` which only extracted `major.minor.patch` and ignored the `-N` build suffix entirely. This meant `2026.2.21` and `2026.2.21-2` were treated as identical versions. ## Solution 1. **Added `parseVersionWithBuild()`**: Extracts both the semver components AND the build suffix number from version strings 2. **Updated `compareSemverStrings()`**: Now compares build suffixes numerically after the semver comparison 3. **Build suffix semantics**: Higher build number = newer version (e.g., `2026.2.21-2` > `2026.2.21-0`) ## Changes - `src/infra/update-check.ts`: Added build-aware version parsing and comparison - `src/infra/update-check.test.ts`: Added 7 new test cases covering build suffix scenarios ## Test Coverage ```typescript // Build suffix comparison (the fix) expect(compareSemverStrings("2026.2.21-2", "2026.2.21")).toBe(1); // -2 is newer expect(compareSemverStrings("2026.2.21", "2026.2.21-2")).toBe(-1); // base is older // Numeric build comparison (not string) expect(compareSemverStrings("1.0.0-10", "1.0.0-2")).toBe(1); // 10 > 2 ``` All 7 new tests pass. ## Verification ```bash # Before fix: $ openclaw update status # Reports: 2026.2.21-2 is behind 2026.2.21 ❌ # After fix: $ openclaw update status # Reports: npm latest 2026.2.21 (local newer) ✅ ``` ## Alternative Considered Issue #23647 suggested changing the version naming convention from `YYYY.M.D-N` to `YYYY.M.D.N` (dot-separated). While that would work, this fix is less disruptive and handles the existing version format correctly. <!-- greptile_comment --> <h3>Greptile Summary</h3> Adds build suffix support to version comparison logic to correctly handle versions like `2026.2.21-2`. The implementation introduces `parseVersionWithBuild()` which extracts both semver components and numeric build suffixes, treating higher build numbers as newer versions. This fixes false "update available" warnings when running `openclaw update status` with build-suffixed versions. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The implementation is well-tested with 7 comprehensive test cases covering edge cases like numeric build comparison (10 > 2), equality checks, and various build suffix formats. The regex pattern `/-(\d+)(?:[+.]|$)/` correctly handles build suffixes while avoiding false matches with pre-release versions (since it requires digits immediately after the hyphen). The change is focused, backward-compatible, and directly addresses the reported issue. - No files require special attention <sub>Last reviewed commit: 7fdf416</sub> <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs