From 0d1c87e25f5a4d9dcc6bc0a9adaf492901f5dca3 Mon Sep 17 00:00:00 2001 From: willbot Date: Fri, 20 Nov 2026 08:47:39 +1100 Subject: [PATCH 1/4] docs(agents): never make a value lossy for convenience, and have the review bot flag it A contributor made Prisma.Decimal's < and > work by routing them through a JavaScript number, which silently compares decimals that differ beyond about 15 digits as equal. Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- .coderabbit.yml | 11 +++++++++++ AGENTS.md | 1 + 2 files changed, 12 insertions(+) diff --git a/.coderabbit.yml b/.coderabbit.yml index 6d25d08b8942..c340c8dd5b05 100644 --- a/.coderabbit.yml +++ b/.coderabbit.yml @@ -16,3 +16,14 @@ reviews: # avoiding. base_branches: - 'v7' + path_instructions: + - path: '**/*.{ts,tsx,mts,cts,js,mjs,cjs}' + instructions: >- + Flag any change that turns a value into a lossy JavaScript form to make something convenient: + calling Number() or parseFloat() on a Decimal, a bigint or a 64-bit integer value, or overriding + valueOf or Symbol.toPrimitive on a value class (Prisma.Decimal included) so that <, >, == or + arithmetic compute through a JavaScript number. Such a change loses precision silently (two decimals + that differ beyond about 15 significant digits compare as equal) and is the wrong approach whatever + it fixes. JavaScript has no operator overloading, so no change can make these operators exact; ask + for the type's own exact methods instead, such as a.lt(b), a.cmp(b) or bigint arithmetic. Also flag a + subclass or patch that changes a third-party library's documented behaviour; that belongs upstream. diff --git a/AGENTS.md b/AGENTS.md index ac5a6034743c..09a84282046a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -147,6 +147,7 @@ - Do write documentation comments, and mainly do so for exported items (although intra-module documentation may sometimes be useful as well). - The correct and official abbreviation of WebAssembly is "Wasm", not "WASM". There are instances of "WASM" in the codebase, but they are wrong and you should not repeat them. Fix the capitalization whenever you incidentally touch the corresponding lines or surrounding code for other reasons. - Prefer native JavaScript private properties and methods (`#field`) over the `private` keyword in TypeScript. + - **Never make a value lossy for convenience.** Do not call `Number()` or `parseFloat()` on a `Decimal`, a `bigint` or a 64-bit integer, and do not override `valueOf` or `Symbol.toPrimitive` on a value class (`Prisma.Decimal` included) so that `<`, `>` or arithmetic compute through a JavaScript number: decimals that differ beyond about 15 significant digits then compare as equal. JavaScript has no operator overloading, so no change can make these operators exact; point users at the type's own methods (`a.lt(b)`, `a.cmp(b)`). A third-party library's documented behaviour is changed upstream, not by subclassing or patching it here. Reviewers flag any pull request that does either. - **Workflow reminders**: - Respect existing structure: modifications often require updating both command implementation and tests/fixtures. From b19f4791ddf86eb1c27885ef3044712429f59dff Mon Sep 17 00:00:00 2001 From: willbot Date: Fri, 20 Nov 2026 13:20:28 +1100 Subject: [PATCH 2/4] docs(agents): native bigint operators are exact, and a proven-safe Number() is fine Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- .coderabbit.yml | 17 +++++++++-------- AGENTS.md | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.coderabbit.yml b/.coderabbit.yml index c340c8dd5b05..7c2f83ba2755 100644 --- a/.coderabbit.yml +++ b/.coderabbit.yml @@ -19,11 +19,12 @@ reviews: path_instructions: - path: '**/*.{ts,tsx,mts,cts,js,mjs,cjs}' instructions: >- - Flag any change that turns a value into a lossy JavaScript form to make something convenient: - calling Number() or parseFloat() on a Decimal, a bigint or a 64-bit integer value, or overriding - valueOf or Symbol.toPrimitive on a value class (Prisma.Decimal included) so that <, >, == or - arithmetic compute through a JavaScript number. Such a change loses precision silently (two decimals - that differ beyond about 15 significant digits compare as equal) and is the wrong approach whatever - it fixes. JavaScript has no operator overloading, so no change can make these operators exact; ask - for the type's own exact methods instead, such as a.lt(b), a.cmp(b) or bigint arithmetic. Also flag a - subclass or patch that changes a third-party library's documented behaviour; that belongs upstream. + Decimal, bigint and 64-bit integer types exist to hold values a JavaScript number would round, so flag + a change that routes such a value through a number for convenience: Number() or parseFloat() on it + without a check that proves the value fits exactly (a range check before the conversion is fine), or + an override of valueOf or Symbol.toPrimitive on a value class (Prisma.Decimal included) meant to make + <, >, == or arithmetic work. A string-returning override is wrong too, because < then compares "10" + and "2" as text. Native bigint operators are already exact. Decimal has no exact operators, since + JavaScript has no operator overloading, so ask for its own methods instead, such as a.lt(b) or + a.cmp(b). Also flag a subclass or patch that changes a third-party library's documented behaviour; + that belongs upstream. diff --git a/AGENTS.md b/AGENTS.md index 09a84282046a..45de8de5c8eb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -147,7 +147,7 @@ - Do write documentation comments, and mainly do so for exported items (although intra-module documentation may sometimes be useful as well). - The correct and official abbreviation of WebAssembly is "Wasm", not "WASM". There are instances of "WASM" in the codebase, but they are wrong and you should not repeat them. Fix the capitalization whenever you incidentally touch the corresponding lines or surrounding code for other reasons. - Prefer native JavaScript private properties and methods (`#field`) over the `private` keyword in TypeScript. - - **Never make a value lossy for convenience.** Do not call `Number()` or `parseFloat()` on a `Decimal`, a `bigint` or a 64-bit integer, and do not override `valueOf` or `Symbol.toPrimitive` on a value class (`Prisma.Decimal` included) so that `<`, `>` or arithmetic compute through a JavaScript number: decimals that differ beyond about 15 significant digits then compare as equal. JavaScript has no operator overloading, so no change can make these operators exact; point users at the type's own methods (`a.lt(b)`, `a.cmp(b)`). A third-party library's documented behaviour is changed upstream, not by subclassing or patching it here. Reviewers flag any pull request that does either. + - **Never make a value lossy for convenience.** `Decimal`, `bigint` and 64-bit integer values exist to hold numbers a JavaScript number would round, so do not convert one with `Number()` or `parseFloat()` unless the code first proves the value fits exactly (a range check before the conversion is fine), and do not override `valueOf` or `Symbol.toPrimitive` on a value class (`Prisma.Decimal` included) to make `<`, `>` or arithmetic work: a number-returning override rounds, so decimals that differ beyond about 15 significant digits compare as equal, and a string-returning one compares `"10"` and `"2"` as text. Native `bigint` operators are already exact. `Decimal` has no exact operators, since JavaScript has no operator overloading, so point users at its own methods (`a.lt(b)`, `a.cmp(b)`). A third-party library's documented behaviour is changed upstream, not by subclassing or patching it here. Reviewers flag any pull request that does either. - **Workflow reminders**: - Respect existing structure: modifications often require updating both command implementation and tests/fixtures. From bb7db0d855cf685c1ceaa7c61b72f4e3b6bcd092 Mon Sep 17 00:00:00 2001 From: willbot Date: Fri, 20 Nov 2026 13:24:48 +1100 Subject: [PATCH 3/4] docs(agents): a range check proves exactness for integers only, not for Decimal Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- .coderabbit.yml | 3 ++- AGENTS.md | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.coderabbit.yml b/.coderabbit.yml index 7c2f83ba2755..961206f77b50 100644 --- a/.coderabbit.yml +++ b/.coderabbit.yml @@ -21,7 +21,8 @@ reviews: instructions: >- Decimal, bigint and 64-bit integer types exist to hold values a JavaScript number would round, so flag a change that routes such a value through a number for convenience: Number() or parseFloat() on it - without a check that proves the value fits exactly (a range check before the conversion is fine), or + without a check that proves the conversion is exact (a safe-integer range check is enough for a bigint or + 64-bit integer, but not for a Decimal, since 1.0000000000000001 passes a range check and becomes 1), or an override of valueOf or Symbol.toPrimitive on a value class (Prisma.Decimal included) meant to make <, >, == or arithmetic work. A string-returning override is wrong too, because < then compares "10" and "2" as text. Native bigint operators are already exact. Decimal has no exact operators, since diff --git a/AGENTS.md b/AGENTS.md index 45de8de5c8eb..13ac101dda88 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -147,7 +147,7 @@ - Do write documentation comments, and mainly do so for exported items (although intra-module documentation may sometimes be useful as well). - The correct and official abbreviation of WebAssembly is "Wasm", not "WASM". There are instances of "WASM" in the codebase, but they are wrong and you should not repeat them. Fix the capitalization whenever you incidentally touch the corresponding lines or surrounding code for other reasons. - Prefer native JavaScript private properties and methods (`#field`) over the `private` keyword in TypeScript. - - **Never make a value lossy for convenience.** `Decimal`, `bigint` and 64-bit integer values exist to hold numbers a JavaScript number would round, so do not convert one with `Number()` or `parseFloat()` unless the code first proves the value fits exactly (a range check before the conversion is fine), and do not override `valueOf` or `Symbol.toPrimitive` on a value class (`Prisma.Decimal` included) to make `<`, `>` or arithmetic work: a number-returning override rounds, so decimals that differ beyond about 15 significant digits compare as equal, and a string-returning one compares `"10"` and `"2"` as text. Native `bigint` operators are already exact. `Decimal` has no exact operators, since JavaScript has no operator overloading, so point users at its own methods (`a.lt(b)`, `a.cmp(b)`). A third-party library's documented behaviour is changed upstream, not by subclassing or patching it here. Reviewers flag any pull request that does either. + - **Never make a value lossy for convenience.** `Decimal`, `bigint` and 64-bit integer values exist to hold numbers a JavaScript number would round, so do not convert one with `Number()` or `parseFloat()` unless the code first proves the conversion is exact (for a `bigint` or 64-bit integer, a check that it is within `Number.MAX_SAFE_INTEGER`; a range check does not make a `Decimal` exact, since `1.0000000000000001` is within any range around 1 and still becomes `1`), and do not override `valueOf` or `Symbol.toPrimitive` on a value class (`Prisma.Decimal` included) to make `<`, `>` or arithmetic work: a number-returning override rounds, so decimals that differ beyond about 15 significant digits compare as equal, and a string-returning one compares `"10"` and `"2"` as text. Native `bigint` operators are already exact. `Decimal` has no exact operators, since JavaScript has no operator overloading, so point users at its own methods (`a.lt(b)`, `a.cmp(b)`). A third-party library's documented behaviour is changed upstream, not by subclassing or patching it here. Reviewers flag any pull request that does either. - **Workflow reminders**: - Respect existing structure: modifications often require updating both command implementation and tests/fixtures. From e5d359d46dd72442c879d2e8930e3fb2074b4fe4 Mon Sep 17 00:00:00 2001 From: willbot Date: Fri, 20 Nov 2026 13:26:12 +1100 Subject: [PATCH 4/4] docs(agents): bigint division drops the fraction, so name the exact bigint operations Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- .coderabbit.yml | 2 +- AGENTS.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.coderabbit.yml b/.coderabbit.yml index 961206f77b50..b33c1e4b8b8e 100644 --- a/.coderabbit.yml +++ b/.coderabbit.yml @@ -25,7 +25,7 @@ reviews: 64-bit integer, but not for a Decimal, since 1.0000000000000001 passes a range check and becomes 1), or an override of valueOf or Symbol.toPrimitive on a value class (Prisma.Decimal included) meant to make <, >, == or arithmetic work. A string-returning override is wrong too, because < then compares "10" - and "2" as text. Native bigint operators are already exact. Decimal has no exact operators, since + and "2" as text. Native bigint comparison, addition, subtraction and multiplication are already exact (division drops the fraction). Decimal has no exact operators, since JavaScript has no operator overloading, so ask for its own methods instead, such as a.lt(b) or a.cmp(b). Also flag a subclass or patch that changes a third-party library's documented behaviour; that belongs upstream. diff --git a/AGENTS.md b/AGENTS.md index 13ac101dda88..370a46e18146 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -147,7 +147,7 @@ - Do write documentation comments, and mainly do so for exported items (although intra-module documentation may sometimes be useful as well). - The correct and official abbreviation of WebAssembly is "Wasm", not "WASM". There are instances of "WASM" in the codebase, but they are wrong and you should not repeat them. Fix the capitalization whenever you incidentally touch the corresponding lines or surrounding code for other reasons. - Prefer native JavaScript private properties and methods (`#field`) over the `private` keyword in TypeScript. - - **Never make a value lossy for convenience.** `Decimal`, `bigint` and 64-bit integer values exist to hold numbers a JavaScript number would round, so do not convert one with `Number()` or `parseFloat()` unless the code first proves the conversion is exact (for a `bigint` or 64-bit integer, a check that it is within `Number.MAX_SAFE_INTEGER`; a range check does not make a `Decimal` exact, since `1.0000000000000001` is within any range around 1 and still becomes `1`), and do not override `valueOf` or `Symbol.toPrimitive` on a value class (`Prisma.Decimal` included) to make `<`, `>` or arithmetic work: a number-returning override rounds, so decimals that differ beyond about 15 significant digits compare as equal, and a string-returning one compares `"10"` and `"2"` as text. Native `bigint` operators are already exact. `Decimal` has no exact operators, since JavaScript has no operator overloading, so point users at its own methods (`a.lt(b)`, `a.cmp(b)`). A third-party library's documented behaviour is changed upstream, not by subclassing or patching it here. Reviewers flag any pull request that does either. + - **Never make a value lossy for convenience.** `Decimal`, `bigint` and 64-bit integer values exist to hold numbers a JavaScript number would round, so do not convert one with `Number()` or `parseFloat()` unless the code first proves the conversion is exact (for a `bigint` or 64-bit integer, a check that it is within `Number.MAX_SAFE_INTEGER`; a range check does not make a `Decimal` exact, since `1.0000000000000001` is within any range around 1 and still becomes `1`), and do not override `valueOf` or `Symbol.toPrimitive` on a value class (`Prisma.Decimal` included) to make `<`, `>` or arithmetic work: a number-returning override rounds, so decimals that differ beyond about 15 significant digits compare as equal, and a string-returning one compares `"10"` and `"2"` as text. Native `bigint` comparison, addition, subtraction and multiplication are already exact (division drops the fraction: `5n / 2n` is `2n`). `Decimal` has no exact operators, since JavaScript has no operator overloading, so point users at its own methods (`a.lt(b)`, `a.cmp(b)`). A third-party library's documented behaviour is changed upstream, not by subclassing or patching it here. Reviewers flag any pull request that does either. - **Workflow reminders**: - Respect existing structure: modifications often require updating both command implementation and tests/fixtures.