Skip to content

Cache key generation should disambiguate input types to avoid collisions #73

@bbopen

Description

@bbopen

Summary

globalCache.generateKey hashes raw string values and JSON.stringify for non-strings. This can produce collisions between different types (e.g., string "1" vs number 1, string "null" vs null).

Failure mode

  • generateKey('x', '1') and generateKey('x', 1) hash the same input sequence.
  • generateKey('x', 'null') and generateKey('x', null) collide.
  • Collisions can return cached results for the wrong inputs.

Evidence

  • src/utils/cache.ts generateKey uses hash.update(input) for strings and hash.update(JSON.stringify(input)) for other primitives, with null/undefined also mapped to 'null'.

Proposed fix

  • Prefix each input with a type tag (e.g., str:, num:, bool:, null:) before hashing.
  • Alternatively, use a stable JSON encoder that preserves types for primitives.

Acceptance criteria

  • Distinct primitive inputs (string vs number vs null) produce distinct keys.
  • Add tests verifying no collisions for 1, "1", true, "true", null, "null".

Metadata

Metadata

Assignees

Labels

area:toolingArea: tooling and CLIbugSomething isn't workingpriority:p2Priority P2 (medium)

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions