Skip to content

(janitor/dedupe): consolidate duplicated formatBytes helpers - #7405

Merged
kilo-code-bot[bot] merged 1 commit into
mainfrom
janitor/dedupe-format-bytes
Oct 16, 2026
Merged

kilo-code-bot[bot] merged 1 commit into
mainfrom
janitor/dedupe-format-bytes

Conversation

@kilo-code-bot

@kilo-code-bot kilo-code-bot Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Two near-identical decimal byte-size formatters had drifted apart in apps/web:

  • apps/web/src/lib/kiloclaw/instance-display.ts — B/KB/MB/GB units, no guard.
  • apps/web/src/app/admin/data-exports/data-export-format.ts — B/KB/MB/GB/TB units plus a null/NaN/negative guard.

The data-export copy is a strict functional superset of the kiloclaw copy (same log-1024 algorithm, adds the TB unit and input guard). This PR moves that superset implementation into @/lib/utils and re-exports it from both call sites, so the algorithm has a single owner and future changes (new units, rounding fixes) apply everywhere.

Why this is safe

  • No caller behavior changes: the kiloclaw callers (formatVolumeUsage, KiloclawInstanceDetail, DataExportsClient) pass non-negative finite numbers, and the data-export callers keep identical null/NaN handling and the TB unit.
  • Both existing test suites (InstanceTab.test.ts, data-export-components.test.ts) assert outputs that the unified implementation produces unchanged.
  • Same runtime (Next.js apps/web); the canonical home @/lib/utils already holds sibling helpers like formatLargeNumber.

Intentionally left alone

Other formatBytes/byte formatters are not consolidated because their differences are intentional:

  • SessionContainerTelemetry.tsx uses IEC KiB/MiB/GiB/TiB units.
  • CodeIndexing/ClusterStatusCard.tsx uses fixed 2-decimal GB/MB/KB output.

Verification

  • oxfmt and oxlint pass on the changed files.
  • tsgo --noEmit typecheck passes for apps/web (exit 0).
  • Jest suites for the two touched call sites require a PostgreSQL connection (global workerSetup.ts cleanupDbForTest), which is unavailable in this environment; their formatBytes assertions were verified against the unified implementation via a standalone run of the same vectors (all match).

Two near-identical decimal byte-size formatters had drifted apart:
- apps/web/src/lib/kiloclaw/instance-display.ts (B/KB/MB/GB)
- apps/web/src/app/admin/data-exports/data-export-format.ts (B/KB/MB/GB/TB + null/NaN guard)

Move the superset implementation into @/lib/utils and re-export it from
both sites so the algorithm has a single owner. No caller behavior change:
kiloclaw callers pass non-negative numbers, and data-export callers keep
the same null handling and TB unit.
@kilo-code-bot kilo-code-bot Bot added the janitor Automated dead-code/duplication cleanup label Oct 12, 2026
@kilo-code-bot
kilo-code-bot Bot enabled auto-merge (squash) October 12, 2026 07:21
@kilo-code-bot

kilo-code-bot Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • apps/web/src/lib/utils.ts
  • apps/web/src/lib/kiloclaw/instance-display.ts
  • apps/web/src/app/admin/data-exports/data-export-format.ts

Reviewed by deepseek-v4.1-flash · Input: 48.9K · Output: 10.6K · Cached: 341.4K

Review guidance: REVIEW.md from base branch main

@kilo-code-bot

kilo-code-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

Meta Janitor: Safety review passed; requesting approval.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meta-janitor safety approval for 896759c. Signal: #7405 (comment). GitHub auto-merge remains responsible for merging.

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

Labels

janitor Automated dead-code/duplication cleanup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants