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
- Regression — all tests pass.
- Documentation generation — central constants file shows all defaults at a glance.
- Search: grep for
Math\.|\d_\d|\d \* \d should find no remaining magic numbers.
Acceptance criteria
Size / Priority
Affected files
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:
60000, another says60_000, another1 * 60 * 1000).Target code
Central constants file:
Per-site usage:
Integration / risk
Test plan
Math\.|\d_\d|\d \* \dshould find no remaining magic numbers.Acceptance criteria
src/util/Constants.ts(or domain-specific)".