refactor: deduplicate clampInt utility across convex modules#1533
refactor: deduplicate clampInt utility across convex modules#1533goulonghui wants to merge 1 commit intoopenclaw:mainfrom
Conversation
Extract the clampInt helper into convex/lib/math.ts and replace 11 duplicate definitions across the codebase. The previous copies used five different rounding strategies (Math.round, Math.trunc, Math.floor, Number.isFinite guard, or none). The canonical version uses Math.trunc with a Number.isFinite guard, matching the most defensive variant from maintenance.ts. Files updated: - convex/souls.ts - convex/commentModeration.ts - convex/leaderboards.ts - convex/users.ts - convex/statsMaintenance.ts - convex/githubBackups.ts - convex/githubBackupsNode.ts - convex/githubSoulBackups.ts - convex/githubSoulBackupsNode.ts - convex/maintenance.ts - convex/skills.ts
|
Someone is attempting to deploy a commit to the 0xBuns Team on Vercel. A member of the Team first needs to authorize it. |
Greptile SummaryThis refactor consolidates 11 duplicate Confidence Score: 4/5Safe to merge if the Math.round → Math.trunc behavior change in skills.ts and souls.ts is intentional. One silent semantic change (Math.round → Math.trunc) affects pagination limits in skills.ts and souls.ts. In practice callers almost certainly pass integer limits, but the Convex API accepts any float and the change is undocumented. convex/skills.ts and convex/souls.ts — confirm the switch from Math.round to Math.trunc is intentional for their pagination limit call sites. Prompt To Fix All With AIThis is a comment left during a code review.
Path: convex/lib/math.ts
Line: 8
Comment:
**Silent `Math.round` → `Math.trunc` behavior change for skills.ts and souls.ts**
The old `clampInt` in `convex/skills.ts` and `convex/souls.ts` used `Math.round`, so a float like `3.9` would produce `4`; `Math.trunc(3.9)` returns `3`. All call sites in those two files are pagination limits (`args.limit`, `args.numItems`) backed by `v.optional(v.number())` validators — meaning any float is a valid input. A caller passing `limit: 5.9` previously received up to 6 results and will now receive 5. Please confirm the switch to `Math.trunc` is intentional for these modules, or restore rounding at the affected call sites.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "refactor: deduplicate clampInt utility a..." | Re-trigger Greptile |
| * falling back to `min`, and clamps the result to the given range. | ||
| */ | ||
| export function clampInt(value: number, min: number, max: number): number { | ||
| const truncated = Math.trunc(value); |
There was a problem hiding this comment.
Silent
Math.round → Math.trunc behavior change for skills.ts and souls.ts
The old clampInt in convex/skills.ts and convex/souls.ts used Math.round, so a float like 3.9 would produce 4; Math.trunc(3.9) returns 3. All call sites in those two files are pagination limits (args.limit, args.numItems) backed by v.optional(v.number()) validators — meaning any float is a valid input. A caller passing limit: 5.9 previously received up to 6 results and will now receive 5. Please confirm the switch to Math.trunc is intentional for these modules, or restore rounding at the affected call sites.
Prompt To Fix With AI
This is a comment left during a code review.
Path: convex/lib/math.ts
Line: 8
Comment:
**Silent `Math.round` → `Math.trunc` behavior change for skills.ts and souls.ts**
The old `clampInt` in `convex/skills.ts` and `convex/souls.ts` used `Math.round`, so a float like `3.9` would produce `4`; `Math.trunc(3.9)` returns `3`. All call sites in those two files are pagination limits (`args.limit`, `args.numItems`) backed by `v.optional(v.number())` validators — meaning any float is a valid input. A caller passing `limit: 5.9` previously received up to 6 results and will now receive 5. Please confirm the switch to `Math.trunc` is intentional for these modules, or restore rounding at the affected call sites.
How can I resolve this? If you propose a fix, please make it concise.
Extract the clampInt helper into convex/lib/math.ts and replace 11 duplicate definitions across the codebase. The previous copies used five different rounding strategies (Math.round, Math.trunc, Math.floor, Number.isFinite guard, or none). The canonical version uses Math.trunc with a Number.isFinite guard, matching the most defensive variant from maintenance.ts.
Files updated: