fix(ui): keep an approved payload size consistent with its own unit - #864
Open
ANIRUDDHA ADAK (aniruddhaadak80) wants to merge 1 commit into
Open
ANIRUDDHA ADAK (aniruddhaadak80) wants to merge 1 commit into
ANIRUDDHA ADAK (aniruddhaadak80) wants to merge 1 commit into
Conversation
ANIRUDDHA ADAK (aniruddhaadak80)
requested review from
Aayam Bansal (aayambansal) and
Ishaan Gangwani (ishaan1124)
as code owners
September 30, 2026 05:44
|
ANIRUDDHA ADAK (@aniruddhaadak80) is attempting to deploy a commit to the InkVell Team on Vercel. A member of the Team first needs to authorize it. |
ANIRUDDHA ADAK (aniruddhaadak80)
force-pushed
the
fix/approval-bytes-boundary
branch
from
September 30, 2026 09:38
0ce07a3 to
308db59
Compare
The branch tested the raw byte count but printed one rounded to a decimal, so from 1048525 bytes a single megabyte was labelled 1024 KB beside an exact count that read as less. The finite check also ran after formatting, so NaN reached the label as text.
ANIRUDDHA ADAK (aniruddhaadak80)
force-pushed
the
fix/approval-bytes-boundary
branch
from
September 30, 2026 10:15
308db59 to
1cb6877
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
formatApprovalBytesinfrontend/ui/src/components/permission-actions.tsbranches on the raw byte count but prints a value rounded to one decimal:Why it matters
This is the exactness surface of a permission card. The function feeds the
Payload exactrow and the egresstotal_bytesrow — the numbers a user reads to decide whether to authorize data leaving the machine.The unit contradicts the count in the same string.
Number("1024.0")is1024, so from 1,048,525 bytes — 51 bytes before the real boundary — the label reads a full megabyte in KB.The finite check runs after the formatting.
exactis computed on line 2 and!Number.isFinite(value)is tested on line 3, so a non-finite value is already formatted by the time it is rejected, producing"NaN bytes"and"∞ bytes". Neither call site validates first:hostedScientific()does checkpayload_bytes, but the egresstotal_bytesreaches the formatter unguarded.Verification
New
permission-actions.test.ts— the module had none;message-part-permission.test.tscovers the component, not the formatter. Two of five cases fail before:switches units at the byte where the rounded value would read 1024pins 1,048,524 →1023.9 KBagainst 1,048,525 →1 MB— the exact byte where the one-decimal KB form first reads 1024. That is the case a hand-picked1023_950-style constant gets wrong, so the guard tests the condition it is guarding rather than a magic number.keeps the exact count and ordinary unit boundariescovers 0 / 1023 / 1024 / 1,048,400 so the change cannot have shifted the normal path.The change
export function formatApprovalBytes(value: number) { - const bytes = Math.max(0, Math.trunc(value)) - const exact = new Intl.NumberFormat("en-US").format(bytes) - if (!Number.isFinite(value) || bytes < 1024) return `${exact} bytes` - if (bytes < 1024 * 1024) return `${Number((bytes / 1024).toFixed(1))} KB (${exact} bytes)` + // The exact count is the point of this label, so a value that cannot be + // counted is named as such instead of being formatted into "NaN bytes". + if (!Number.isFinite(value)) return "unknown size" + const bytes = Math.max(0, Math.trunc(value)) + const exact = new Intl.NumberFormat("en-US").format(bytes) + if (bytes < 1024) return `${exact} bytes` + // A rounded KB value reaches 1024 just below the next unit (from 1,048,525 + // bytes), which contradicted the exact count printed beside it. Promote + // those to MB rather than printing "1024 KB". + if (bytes < 1024 * 1024 && Number((bytes / 1024).toFixed(1)) < 1024) + return `${Number((bytes / 1024).toFixed(1))} KB (${exact} bytes)` return `${Number((bytes / (1024 * 1024)).toFixed(1))} MB (${exact} bytes)` }message-part-permission.test.tsis unaffected: 14 pass / 0 fail across both files.Touched files are Prettier-clean (verified on LF-normalized copies; this Windows checkout's
core.autocrlf=truemakes Prettier flag every file repo-wide).Fixes #863