Skip to content

[High priority] retentionPeriod loses precision past ~104 days (nanoseconds as JS number) #60

Description

@jstirnaman

Summary

retentionPeriod is accepted as a JSON number of nanoseconds across the database tools (create_database, update_database) for all product types. JavaScript numbers are IEEE-754 doubles, so integers are exact only up to Number.MAX_SAFE_INTEGER (2^53 − 1 ≈ 9.007e15). Nanosecond retention values exceed that range at roughly 104 days, so longer retention periods can lose precision.

Details

  • 1 day = 86_400 * 1e9 = 8.64e13 ns
  • Number.MAX_SAFE_INTEGER / 8.64e13104 days
  • Example: 1 year = 3.1536e16 ns ≈ 3.5 × MAX_SAFE_INTEGER — not exactly representable.

Affected (all take retentionPeriod as ns-number):

  • src/tools/categories/database.tools.tsinputSchema/zodSchema type number
  • src/services/database-management.service.ts — Cloud Dedicated/Clustered (payload.retentionPeriod), Cloud Serverless (everySeconds from ns), Core/Enterprise (formatRetentionPeriod ns → duration string)

Practical impact: a retention longer than ~104 days may be off by a small amount. For Core/Enterprise specifically, formatRetentionPeriod's hours % 24 === 0 check can fail on an already-imprecise large value and fall back to ${Math.floor(hours)}h, dropping up to an hour.

Suggested fix

Change the retentionPeriod contract to avoid ns-as-number. Options, in rough order of preference:

  1. Accept a humantime duration string (e.g. "1y", "90d") — matches the InfluxDB CLI/API and removes the precision problem entirely.
  2. Accept seconds instead of nanoseconds (pushes the safe boundary out ~285 years).
  3. Accept the ns value as a string and parse server-side.

This is a cross-cutting change to the tool parameter contract for all product types, so it was intentionally left out of #59 (which adds Core/Enterprise retention support).

Context

Found while reviewing #56 / #59. The new unit tests deliberately use periods under the 104-day safe boundary (7d, 60d) to avoid the imprecision.

Priority: high — silent precision loss on a data-retention setting.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions