Skip to content

Parse top CPU idle under decimal-comma locales - #12320

Open
Bartok9 wants to merge 2 commits into
omacom:quattrofrom
Bartok9:bartok9/system-stats-locale-cpu
Open

Bartok9 wants to merge 2 commits into
omacom:quattrofrom
Bartok9:bartok9/system-stats-locale-cpu

Conversation

@Bartok9

@Bartok9 Bartok9 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

omarchy-system-stats (no-arg path) parsed top -bn1 by deleting every comma, then doing 100 - idle. Under LC_NUMERIC=es_ES.UTF-8 (and other decimal-comma locales) top prints 84,3 id. That became 843, then a huge negative CPU% (-743% and similar).

This keeps LC_ALL=C LC_NUMERIC=C for the top call, treats comma as a decimal on the idle field, and matches the id label even when it still has a trailing comma.

--bar-widget is unchanged (it reads /proc/stat).

Closes #12315

@llstrk

llstrk commented Sep 17, 2026

Copy link
Copy Markdown

Automated AI review: locale fix verified

A/B-tested 2bda36b2 against f99d33a8, executing the actual omarchy-system-stats command under C, Spanish, and German UTF-8 locales.

  • Controlled idle input 84,3 changes from -743% on baseline to 16% on the PR. Dot-decimal input remains correct, and idle 100/0 produce 0%/100% in every tested locale.
  • The controlled tests confirm that top receives LC_ALL=C. Real top also produces valid CPU percentages in all three patched runs; baseline produced a negative value under Spanish and an empty CPU field under German.
  • The unchanged --bar-widget path still emits its CPU, memory, and load fields successfully in all three locales.

No blocking issue found. One optional regression-test improvement: stub top and run the actual command rather than a duplicate of its awk parser. Include idle 84.7 and 84,7, expecting 15%, since the current 84.3 case cannot distinguish correct fractional parsing from truncation to 84.

The live samples establish valid output, not exact before/after CPU measurement accuracy. Alternate awk modes, graphical behavior, and the full repository suite were not verified.

@omarchybot omarchybot added bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review labels Sep 27, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks, @Bartok9. The bug is real and forcing the C locale on top is the right fix. I reproduced it on a disposable Omarchy VM with real top (procps-ng 4.0.7) under es_ES.UTF-8: base quattro reported cpu -888% for a 98,8% idle machine, and this branch reports 0–1%.

The VM also showed a shape the parsing missed. top prints a 100.0 without a space after the comma before it: a fully idle CPU comes out as 0.0 ni,100.0 id, (3 of 4 samples on the idle VM), and a CPU stuck on I/O as 0.0 id,100.0 wa,. On this branch the first read as cpu 100% and the second as an empty value. Since top now runs under LC_ALL=C, a comma can only be a separator, so I pushed 7fd1d3a to your branch. It turns each comma into a space before the existing loop, which brings the awk back to what quattro had apart from that one character. It also replaces the test, which grepped the script for its own lines and ran a copy of the awk, so it could not fail whatever the command did. The new test runs bin/omarchy-system-stats against a stub top that prints decimal commas unless started under the C locale. It clears LC_ALL, so an inherited C locale cannot hide a missing override, and covers the busy, fully idle and I/O-wait lines. On the VM it fails on base (-743%), fails on your commit alone (100% for the idle line), and passes on 7fd1d3a.

Tests on the VM at 7fd1d3a: ./test/cli passes. ./test/shell fails ascii-test.sh, branding-about-animation-test.sh and screenshot-sanity-test.sh, and all three fail the same way on base f99d33a8, so this change did not cause them.

Second opinion: Codex Medium reviewed the change in two rounds. The first round found the I/O-wait case and the inherited-LC_ALL gap in the test, and suggested the comma-to-space parse; all three are in 7fd1d3a. The second round, on 7fd1d3a, found nothing further.

Nothing is left for you to do. This is waiting on the maintainer: the shell suite has those unrelated failures on base and the PR has no CI run yet.

@Bartok9

Bartok9 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — 7fd1d3a is the right follow-up. Under LC_ALL=C a comma is only a field separator, so splitting before the idle loop covers the glued 100.0 idle and I/O-wait lines that the original parser missed. Running the real command against a stub top (and clearing inherited LC_ALL) is also better than grepping a copy of the awk.

Leaving the unrelated ./test/shell failures and the missing CI run for the maintainer.

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues remain.

Summary

The PR fixes CPU percentages under decimal-comma locales.

  • The power panel reads CPU usage correctly with decimal commas.

Bartok9 explained that the comma fixtures intentionally catch removal of the locale override. Greptile withdrew the previous finding. No new actionable issues were found.

Reviews (2) · Last reviewed commit: "Split top's CPU line on commas, so a 100..." · Reviewed by Greptile

@jandrusk

Copy link
Copy Markdown

Thanks for the locale fix and the glued 100.0 id / id,100.0 wa handling — the negative CPU% bug is real.

Prefer landing #15109 (omarchybot): it runs top under full LC_ALL=C (so a user LC_ALL=es_ES cannot override LC_NUMERIC), and also covers the German %CPU(s) label miss that this branch still leaves. Happy to close this in favour of that once it merges, or rebase the glued-field gsub onto it if anything is still missing.

@Bartok9

Bartok9 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Agreed — #15109 is the one to land. It already runs top under full LC_ALL=C (so a user LC_ALL cannot override LC_NUMERIC), splits on commas instead of deleting them, and matches the translated %CPU(s) label this branch still misses.

Nothing left to rebase onto it from here. I'll close this once #15109 merges so #12315 stays covered until then.

Bartok9 and others added 2 commits October 25, 2026 17:27
top prints 84,3 id when LC_NUMERIC uses a comma. Stripping every comma
turned that into 843 and then 100-843. Keep C locale for top, treat
comma as a decimal, and match the id label even when it still has a
trailing comma.

Closes omacom#12315
top prints a 100.0 without a space after the comma before it, so a fully idle CPU arrives as "0.0 ni,100.0 id," and a CPU stuck on I/O as "0.0 id,100.0 wa,". Stripping the comma from the label and turning it into a decimal point in the value read the first as 100% CPU and found no idle field in the second. With top under LC_ALL=C a comma is only ever a separator, so turning each into a space before splitting handles both, and the loop goes back to what it was on quattro.

The test copied the awk program and grepped the script for its own lines, so it passed whatever the command did. It now runs bin/omarchy-system-stats against a stub top that prints decimal commas unless started under the C locale, with LC_ALL cleared so an inherited C locale cannot hide a missing override, and covers the busy, fully idle and I/O wait shapes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
@Bartok9
Bartok9 force-pushed the bartok9/system-stats-locale-cpu branch from 7fd1d3a to 6839675 Compare October 25, 2026 21:27
@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 26, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

@Bartok9, the maintainer merged #15109 into quattro today. It fixes #12315 the same way this PR does: top runs under LC_ALL=C and commas become spaces. So the bin/omarchy-system-stats change here is already on quattro (the extra LC_NUMERIC=C adds nothing under LC_ALL=C), and that hunk now conflicts with it.

One thing here is not in #15109: the I/O-wait case in test/shell.d/system-stats-locale-test.sh (0.0 id,100.0 wa,, expecting 100%). #15109's test/shell.d/system-stats-test.sh covers the busy, translated-label and fully idle lines but not that one, and it is a different boundary: there the glued value comes after the idle label rather than before it. Your other two cases duplicate #15109's. I read the merged parser against that line and it returns 100%, so quattro handles it, but no test checks it. That is why this PR stays open rather than being closed as covered by #15109.

To land what is left, drop the bin/omarchy-system-stats change, and move the I/O-wait assertion into test/shell.d/system-stats-test.sh instead of adding a second test file. That file's stub only varies the idle value, so the wait field will need a variable of its own. Or close this PR if one assertion isn't worth it to you. Nothing was run on a worker this time, because the fix this PR made is already on quattro and the branch has to change before there is anything new to test.

Second opinion: Codex Medium read both diffs. It agreed this PR is not obsolete for the reason above, and checked that the merged parser returns 100% for the I/O-wait line and 0% for the fully idle one. It found nothing else. Its agreement came after my conclusion had been written down, so it is not guaranteed to be independent.

This is waiting on you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

omarchy-system-stats reports wildly wrong (negative) CPU% under decimal-comma locales (es_ES, etc.)

4 participants