fix(diagnose): format disk byte counters as sizes, not percentages - #232
fix(diagnose): format disk byte counters as sizes, not percentages#232agent-zhang-beihai[bot] wants to merge 1 commit into
Conversation
`diagnose metrics` appended a percent sign to every non-network metric, so raw byte counters rendered as e.g. `disk_total 8511270912.0%`. Route disk_used/disk_total/disk_database/disk_wal through formatBytes via a BYTE_METRICS set, extend formatBytes past MB to GB/TB so multi-GB volumes read sensibly, and add the four missing METRIC_LABELS entries. Disk Usage stays a percentage. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Greptile SummaryThe PR corrects human-readable diagnostic metric output by formatting four disk counters as byte sizes and assigning descriptive labels, while preserving percentage and network-rate formatting.
Confidence Score: 5/5The PR appears safe to merge with no actionable defects identified. The changed formatter correctly routes the four current disk byte counters through byte-size formatting while retaining the established behavior for percentage and network metrics, and the tests cover the relevant unit boundaries.
|
| Filename | Overview |
|---|---|
| src/commands/diagnose/metrics.ts | Correctly classifies disk byte counters, adds readable labels, and extends the existing formatter through GB and TB without changing JSON output. |
| src/commands/diagnose/metrics.test.ts | Adds targeted regression coverage for all newly classified counters and verifies existing percentage and network-rate behavior. |
Reviews (1): Last reviewed commit: "fix(diagnose): format disk byte counters..." | Re-trigger Greptile
jwfing
left a comment
There was a problem hiding this comment.
Review — fix(diagnose): format disk byte counters as sizes, not percentages
Summary: A tight, well-tested bugfix that routes disk_* byte counters through formatBytes (with GB/TB support) instead of the percent fallback, and adds the four missing table labels — no Critical issues found.
Requirements context
Consulted docs/specs/2026-03-27-diagnose-command-design.md and docs/specs/2026-03-27-diagnose-implementation-plan.md. The design specifies Disk Usage 42.1% and "Network values (bytes/sec) auto-scaled to B/KB/MB" — this fix keeps disk_usage as a percent and network as a rate while correctly treating the raw byte counters as sizes. Extending the ladder to GB/TB is a reasonable enhancement consistent with the intent (multi-GB volumes shouldn't read as 8116.0 MB). Fully in scope for the referenced feedback item.
Findings
Critical
(none)
Suggestion
- Software engineering —
src/commands/diagnose/metrics.test.tsunit-testsformatValuethoroughly (the byte ladder, percent, and network rate cases all check out numerically), but nothing exercises the newMETRIC_LABELSentries or the table wiring inmetrics.ts:166-176. Low blast radius (a plainRecordlookup), so this is optional — a small assertion thatdisk_walrenders underDisk WALwould fully pin the reported behavior.
Information
- Software engineering — There are now three slightly divergent
formatBytesimplementations:src/commands/diagnose/metrics.ts:55-65(1dp, B→TB),src/commands/diagnose/index.ts:386-390(formatBytesCompact, 1dp, B→MB, no space), andsrc/commands/usage/index.ts:10-15(log-based, 2dp,!n → '0 B'guard). Not worth changing in this PR, but a sharedformatBytesutil would prevent future drift. - Functionality — The
--metricsoption help (metrics.ts:125) and the spec still enumerate onlycpu_usage,memory_usage,disk_usage,network_in,network_out; the newdisk_used/total/database/walaren't listed. If those counters are always returned (not user-selectable) this is fine as-is; if they're selectable, the help string could mention them. No behavior impact either way. - Functionality — Verified the fix is complete for its scope: the unified
insforge diagnosesummary view (index.ts:308-318) only rendersdisk_usageas a percent and never surfaces the raw byte counters, so there's no parallel byte-as-percent bug left behind.
Security: No security-relevant changes — pure output formatting, no new user input reaching SQL/shell/HTTP, no secrets logged, --json path untouched.
Performance: No concerns — constant-time formatting on an already-fetched, aggregated result set.
Verdict
approved (informational — no Critical findings; the two Suggestion/Information items are optional). Posted as a COMMENT; explicit GitHub approval remains a separate human action.
What was broken
insforge diagnose metricsformatted every non-network metric as a percentage, so the raw disk byte counters returned by the metrics API were rendered with a percent sign:The affected counters also had no
METRIC_LABELSentry, so they showed up under their raw metric names.What changed
src/commands/diagnose/metrics.ts:BYTE_METRICS = new Set(['disk_used', 'disk_total', 'disk_database', 'disk_wal']), checked informatValuebefore the percent fallback so those metrics route throughformatBytes. Mirrors the existingBYTE_METRICSpattern insrc/commands/usage/index.ts.formatBytespast MB to GB/TB, so multi-GB volumes read as7.9 GBinstead of8116.0 MB.METRIC_LABELSentries: Disk Used / Disk Total / Disk Database / Disk WAL.disk_usageremains a percentage, and network metrics keep their/ssuffix. No flags, command names, or JSON output shapes changed — the--jsonpath already emitted raw numbers and is untouched, so noInsForge/agent-skillsupdate is needed for this fix.How it was verified
src/commands/diagnose/metrics.test.tspins the behavior:formatValue('disk_total', 8511270912)→"7.9 GB", the KB/MB/GB/TB ladder,formatValue('disk_usage', 42.1)→"42.1%", and the network rate cases.npm run lint(full vitest suite + eslint): 784 passed, 13 skipped, no eslint findings.npm run build: clean.Addresses user feedback 1dbfad65-96ad-4f6f-bfb1-88040b7aafab (cli): diagnose metrics formats byte counters as percentages
Summary by cubic
Fixes
insforge diagnose metricsrendering of disk byte counters. Previously, non-network metrics showed a percent sign; nowdisk_*byte counters render as human-readable sizes with proper labels. This improves CLI readability without changing JSON output.disk_used,disk_total,disk_database,disk_walthrough aBYTE_METRICSpath so they useformatBytes.formatBytesto support GB/TB; addsMETRIC_LABELSfor the four disk counters.disk_usageas a percentage andnetwork_*as B/s;--jsonoutput remains raw numbers.Addresses Linear feedback 1dbfad65.
Written for commit 4b68c18. Summary will update on new commits.
Note
Fix disk byte counter formatting in
diagnosemetrics to display as sizesdisk_used,disk_total,disk_database,disk_wal) were previously formatted as percentages; they now render as human-readable byte sizes (e.g.1.2 GB).BYTE_METRICSset in metrics.ts to identify raw byte counters, and updatesformatValueto branch on this set.formatBytesto support GB and TB units in addition to B, KB, and MB.Macroscope summarized 4b68c18.