Skip to content

Fix ByteSize unit constructors rejecting exact decimal quantities - #10217

Merged
tim-smart merged 8 commits into
Effect-TS:mainfrom
devangpratap:fix/bytesize-inexact-decimal-quantities
Oct 31, 2026
Merged

tim-smart merged 8 commits into
Effect-TS:mainfrom
devangpratap:fix/bytesize-inexact-decimal-quantities

Conversation

@devangpratap

@devangpratap devangpratap commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

The decimal ByteSize unit constructors now give exact byte counts for decimal quantities. Before, they multiplied in floating point, so some whole-byte quantities threw and others returned the wrong count:

ByteSize.megabytes(2.01)
// before: throws "expected an exact non-negative safe-integer byte result"
// after:  2010000n

ByteSize.petabytes(8.00000000000001)
// before: 8000000000000011n
// after:  8000000000000010n

For SI units (kB–QB), the shortest decimal form of the number (String(quantity), including exponent forms such as 4e-15) is scaled exactly with bigint arithmetic. fromStringUnsafe shares the same helper. Binary units keep the floating-point product, which is exact for powers of 2.

Number inputs are still limited to Number.MAX_SAFE_INTEGER bytes, and quantities that are not a whole number of bytes still throw. Large non-integral quantities that used to round silently, such as kilobytes(563006803248.6641), now throw too.

Closes #10216
Closes EFF-3193

fromQuantity required quantity * factor to be a safe integer, but the
floating-point product is often slightly off, so megabytes(2.01) threw
even though 2.01 MB is 2010000 bytes. Round to the nearest byte and
accept it only when it converts back to the original quantity.
@changeset-bot

changeset-bot Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 526c719

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 33 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-cloudflare Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/ai-typesafe Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/graphql-generator Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-janitor effect-janitor Bot added the 4.0 label Oct 31, 2026
@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 39.41 KB 39.41 KB 0.00 KB (0.00%)
basic.ts 7.23 KB 7.23 KB 0.00 KB (0.00%)
batching.ts 11.08 KB 11.08 KB 0.00 KB (0.00%)
brand.ts 6.87 KB 6.87 KB 0.00 KB (0.00%)
cache.ts 11.54 KB 11.54 KB 0.00 KB (0.00%)
config.ts 22.84 KB 22.84 KB 0.00 KB (0.00%)
differ.ts 22.00 KB 22.00 KB 0.00 KB (0.00%)
http-client.ts 26.95 KB 26.95 KB 0.00 KB (0.00%)
http-router.ts 37.02 KB 36.91 KB +0.11 KB (+0.30%)
logger.ts 12.01 KB 12.01 KB 0.00 KB (0.00%)
metric.ts 9.47 KB 9.47 KB 0.00 KB (0.00%)
optic.ts 7.10 KB 7.10 KB 0.00 KB (0.00%)
pubsub.ts 16.03 KB 16.03 KB 0.00 KB (0.00%)
queue.ts 12.82 KB 12.82 KB 0.00 KB (0.00%)
schedule.ts 11.80 KB 11.80 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 14.14 KB 14.14 KB 0.00 KB (0.00%)
schema-binary.ts 41.26 KB 41.26 KB 0.00 KB (0.00%)
schema-class.ts 21.73 KB 21.73 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 29.60 KB 29.60 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 27.99 KB 27.99 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.35 KB 15.35 KB 0.00 KB (0.00%)
schema-string.ts 12.34 KB 12.34 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.27 KB 16.27 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 38.95 KB 38.95 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 26.15 KB 26.15 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 20.90 KB 20.90 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 21.05 KB 21.05 KB 0.00 KB (0.00%)
schema-toFormatter.ts 21.14 KB 21.14 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 26.17 KB 26.17 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 21.23 KB 21.23 KB 0.00 KB (0.00%)
schema.ts 20.82 KB 20.82 KB 0.00 KB (0.00%)
stm.ts 14.20 KB 14.20 KB 0.00 KB (0.00%)
stream.ts 10.38 KB 10.38 KB 0.00 KB (0.00%)

@fubhy

fubhy commented Oct 31, 2026

Copy link
Copy Markdown
Member

@effect-bot

@effect-bot

Copy link
Copy Markdown
Contributor

Thanks @fubhy. I'm taking this PR over, and the work is tracked internally. I'll push the follow-up changes to this branch.

@tim-smart
tim-smart merged commit 5216684 into Effect-TS:main Oct 31, 2026
14 of 15 checks passed
@effect-bot effect-bot mentioned this pull request Oct 31, 2026
brandhaug added a commit to brandhaug/b2b-saas-starter that referenced this pull request Nov 5, 2026
## pnpm-workspace.yaml (default)

## Dependency Updates

| Package | From | To | Type |
| --- | --- | --- | --- |
| `@effect/platform-node` | 4.1.1 | 4.1.2 | patch |
| `@effect/sql-d1` | 4.1.1 | 4.1.2 | patch |
| `@effect/vitest` | 4.1.1 | 4.1.2 | patch |
| `cn` | 0.5.1 | 0.5.2 | patch |
| `effect` | 4.1.1 | 4.1.2 | patch |
| `jose` | 6.2.14 | 6.2.15 | patch |

## Release Notes

<details>
<summary><b>@<!---->effect/platform-node</b> (4.1.1 → 4.1.2)</summary>

### Patch Changes

- [#10237](Effect-TS/effect#10237)
[`ee4f710`](Effect-TS/effect@ee4f710)
Thanks @<!---->Hoishin! - Pin `@effect/platform-node-shared` to the
exact version released with each platform package.

- [#10257](Effect-TS/effect#10257)
[`b0a1cee`](Effect-TS/effect@b0a1cee)
Thanks @<!---->tim-smart! - Update repository dependencies to their
latest compatible releases.
- Updated dependencies
[[`5216684`](Effect-TS/effect@5216684),
[`b707ad1`](Effect-TS/effect@b707ad1),
[`46f48af`](Effect-TS/effect@46f48af),
[`92201bc`](Effect-TS/effect@92201bc),
[`cf329f3`](Effect-TS/effect@cf329f3),
[`1d25d78`](Effect-TS/effect@1d25d78),
[`d190d97`](Effect-TS/effect@d190d97),
[`d7b3b6b`](Effect-TS/effect@d7b3b6b),
[`a478745`](Effect-TS/effect@a478745),
[`69eaa29`](Effect-TS/effect@69eaa29),
[`3711ba6`](Effect-TS/effect@3711ba6),
[`715c5e4`](Effect-TS/effect@715c5e4),
[`b0a1cee`](Effect-TS/effect@b0a1cee),
[`2a10622`](Effect-TS/effect@2a10622),
[`6bccdd5`](Effect-TS/effect@6bccdd54e1bc5d7f

…[full
notes](https://github.com/Effect-TS/effect/releases/tag/%40effect/platform-node%404.1.2)

</details>

<details>
<summary><b>@<!---->effect/sql-d1</b> (4.1.1 → 4.1.2)</summary>

### Patch Changes

- [#10257](Effect-TS/effect#10257)
[`b0a1cee`](Effect-TS/effect@b0a1cee)
Thanks @<!---->tim-smart! - Update repository dependencies to their
latest compatible releases.
- Updated dependencies
[[`5216684`](Effect-TS/effect@5216684),
[`b707ad1`](Effect-TS/effect@b707ad1),
[`46f48af`](Effect-TS/effect@46f48af),
[`92201bc`](Effect-TS/effect@92201bc),
[`cf329f3`](Effect-TS/effect@cf329f3),
[`1d25d78`](Effect-TS/effect@1d25d78),
[`d190d97`](Effect-TS/effect@d190d97),
[`d7b3b6b`](Effect-TS/effect@d7b3b6b),
[`a478745`](Effect-TS/effect@a478745),
[`69eaa29`](Effect-TS/effect@69eaa29),
[`3711ba6`](Effect-TS/effect@3711ba6),
[`715c5e4`](Effect-TS/effect@715c5e4),
[`b0a1cee`](Effect-TS/effect@b0a1cee),
[`2a10622`](Effect-TS/effect@2a10622),
[`6bccdd5`](Effect-TS/effect@6bccdd5),
[`60be011`](Effect-TS/effect@60be011),
[`e1edcdc`](Effect-TS/effect@e1edcdc),
[`ef81e9d`](https://github.com/Effect-TS/effec

…[full
notes](https://github.com/Effect-TS/effect/releases/tag/%40effect/sql-d1%404.1.2)

</details>

<details>
<summary><b>@<!---->effect/vitest</b> (4.1.1 → 4.1.2)</summary>

### Patch Changes

- Updated dependencies
[[`5216684`](Effect-TS/effect@5216684),
[`b707ad1`](Effect-TS/effect@b707ad1),
[`46f48af`](Effect-TS/effect@46f48af),
[`92201bc`](Effect-TS/effect@92201bc),
[`cf329f3`](Effect-TS/effect@cf329f3),
[`1d25d78`](Effect-TS/effect@1d25d78),
[`d190d97`](Effect-TS/effect@d190d97),
[`d7b3b6b`](Effect-TS/effect@d7b3b6b),
[`a478745`](Effect-TS/effect@a478745),
[`69eaa29`](Effect-TS/effect@69eaa29),
[`3711ba6`](Effect-TS/effect@3711ba6),
[`715c5e4`](Effect-TS/effect@715c5e4),
[`b0a1cee`](Effect-TS/effect@b0a1cee),
[`2a10622`](Effect-TS/effect@2a10622),
[`6bccdd5`](Effect-TS/effect@6bccdd5),
[`60be011`](Effect-TS/effect@60be011),
[`e1edcdc`](Effect-TS/effect@e1edcdc),
[`ef81e9d`](Effect-TS/effect@ef81e9d),
[`013fb34`](Effect-TS/effect@013fb34),
[`113dbc7`](Effect-TS/effect@113dbc7

…[full
notes](https://github.com/Effect-TS/effect/releases/tag/%40effect/vitest%404.1.2)

</details>

<details>
<summary><b>cn</b> (0.5.1 → 0.5.2)</summary>

### Patch Changes

- [#162](shadcn-ui/cn#162)
[`b8c5a1b`](shadcn-ui/cn@b8c5a1b)
Thanks [@<!---->nonhana](https://github.com/nonhana)! - Export
`CnFunction`, `Engine`, and `ClassNameValue` from `cn/config`, and those
plus `ClassValue` from `cn/engine`. Exporting an inferred `createCn()`
result (`export const cn = createCn({ ... })`) no longer fails with
TS2742 or TS2883 in projects that emit declarations.

- [#167](shadcn-ui/cn#167)
[`6ebb4ce`](shadcn-ui/cn@6ebb4ce)
Thanks [@<!---->RaphaelFakhri](https://github.com/RaphaelFakhri)! - `cn
build` keeps numeric spacing such as `p-4` when a stylesheet declares
`--spacing` after a `--*: initial` or `--spacing-*: initial` reset, and
keeps `p-px` through the reset, as Tailwind does.

- [#160](shadcn-ui/cn#160)
[`a805c68`](shadcn-ui/cn@a805c68)
Thanks [@<!---->mehimanshupatil](https://github.com/mehimanshupatil)! -
`createCn`, `createTwMerge`, and `extendTailwindMerge` from `cn/config`
accept optional type arguments for custom class-group and theme ids,
like tailwind-merge's `extendTailwindMerge<ClassGroupIds,
ThemeGroupIds>`. With them, unknown group keys and conflict ids are type
errors. Without them, any id is still accepted.

</details>

<details>
<summary><b>effect</b> (4.1.1 → 4.1.2)</summary>

### Patch Changes

- [#10217](Effect-TS/effect#10217)
[`5216684`](Effect-TS/effect@5216684)
Thanks @<!---->devangpratap! - Fix `ByteSize` decimal unit constructors
such as `megabytes(2.01)` throwing or returning the wrong byte count,
and reject fractional-byte quantities instead of rounding them.

- [#10261](Effect-TS/effect#10261)
[`b707ad1`](Effect-TS/effect@b707ad1)
Thanks @<!---->effect-bot! - Fix cluster entity defect restart backoff
being shared by all entities of a type and never resetting.

- [#10249](Effect-TS/effect#10249)
[`46f48af`](Effect-TS/effect@46f48af)
Thanks @<!---->effect-bot! - Prevent an interrupted cluster request that
keeps defecting from stalling message delivery to other entities.

- [#10218](Effect-TS/effect#10218)
[`92201bc`](Effect-TS/effect@92201bc)
Thanks @<!---->sbking! - Defer the runner notification for a discarded
persisted send made inside a `ClusterSchema.WithTransaction` handler
until the transaction commits. The message was invisible to the runner
before the commit, so delivery waited for the next storage poll.

- [#10260](Effect-TS/effect#10260)
[`cf329f3`](Effect-TS/effect@cf329f3)
Thanks @<!---->effect-bot! - Fix `ClusterWorkflowEngine` turning
transient storage failures while saving durable clocks or deferred
completions into workflow defects; they are now retried.

- [#10262](Effect-TS/effect#10262)
[`1d25d78`](Effect-TS/effect@1d25d78)
Thanks @<!---->effect-bot! - Fix `ClusterWorkflowEngine` blocking shard
reacquisition indefinitely after a forced shard release interrupted a

…[full
notes](https://github.com/Effect-TS/effect/releases/tag/effect%404.1.2)

</details>

<details>
<summary><b>jose</b> (6.2.14 → 6.2.15)</summary>

### Fixes

* **jwe:** cancel decompression when output exceeds the limit
([67541aa](panva/jose@67541aa))
* **jwks:** reject negative cache durations
([a3b296f](panva/jose@a3b296f))
* **jwt:** reject negative clockTolerance
([67d6c83](panva/jose@67d6c83))

</details>

---
*This PR was auto-generated by
[catalog-update-action](https://github.com/brandhaug/catalog-update-action).*

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

This branch is waiting to be deployed

1 waiting deployment
fork — 526c719e Waiting Oct 31, 2026 by effect-bot via approval-gate #24434
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ByteSize unit constructors throw for exact decimal quantities like megabytes(2.01)

4 participants