Skip to content

[Feature] Centralize magic-number constants #257

@pathosDev

Description

@pathosDev

Size / Priority

  • Size: Trivial (~30+ sites consolidated)
  • Category: C.2 Simplifications & DRY.
  • Risk: low.

Affected files

  • Across src/cluster/*, src/persistence/*, src/cache/* — magic-numbers scattered as inline literals.

Background

The codebase has ~30+ magic numbers as inline literals:

  • 24 * 60 * 60 * 1000 (tombstone TTL).
  • 5 * 60 * 1000 (default cleanup-tick interval).
  • 1_000 (default gossip interval).
  • 5_000 (default lock TTL, etc.).
  • 30_000 (default ask timeout, etc.).
  • 100 (default batch size).
  • 1024 (frame size class, key-length cap, …).
  • 16 * 1024 * 1024 (default wire-frame cap).

Inline literals:

  • Make intent unclear at the call site.
  • Are hard to search for systematically.
  • Get accidentally divergent (one site says 60000, another says 60_000, another 1 * 60 * 1000).

Target code

Central constants file:

// src/util/Constants.ts (new) — or split by domain into:
// src/cluster/Constants.ts, src/persistence/Constants.ts, etc.

export const TOMBSTONE_TTL_MS = 24 * 60 * 60 * 1000;       // 24h
export const TOMBSTONE_PRUNE_INTERVAL_MS = 5 * 60 * 1000;    // 5min
export const DEFAULT_GOSSIP_INTERVAL_MS = 1_000;
export const DEFAULT_ASK_TIMEOUT_MS = 5_000;
export const DEFAULT_BATCH_SIZE = 100;
export const MAX_FRAME_BYTES = 16 * 1024 * 1024;             // 16 MB
export const MAX_PERSISTENCE_ID_LENGTH = 256;
// ... etc, organised by domain ...

Per-site usage:

// Before:
this.tombstoneTtlMs = settings.tombstoneTtlMs ?? 24 * 60 * 60 * 1_000;

// After:
this.tombstoneTtlMs = settings.tombstoneTtlMs ?? TOMBSTONE_TTL_MS;

Integration / risk

  • No behavioural change.
  • Cleaner code; easier to discover defaults.
  • Allows future fork to override defaults centrally.

Test plan

  1. Regression — all tests pass.
  2. Documentation generation — central constants file shows all defaults at a glance.
  3. Search: grep for Math\.|\d_\d|\d \* \d should find no remaining magic numbers.

Acceptance criteria

  • Constants file(s) created.
  • All identified sites migrated.
  • Constants documented (JSDoc on each).
  • Test suite passes.
  • CHANGELOG entry: "All default constants now in src/util/Constants.ts (or domain-specific)".

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority: lowNice-to-have / niche / demand-driven

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions