Skip to content

A cache invalidation on a table with no secondary index stores null, so the refill restamps @createdTime #3597

Open

Description

@kriszyp

Summary

A cache invalidate() (_writeInvalidate with no residency list) on a table with no secondary index stores null as the invalidated value. A later refill reads @createdTime from that value, finds none, and stamps a new created time, so createdAt moves forward on every invalidate → refill cycle. Tables with any secondary index keep the created time on the stub (the source-fill/residency-stub fix carries it forward there).

Repro

const T = table({ table: 'NoIndexStamps', database: 'test', attributes: [
  { name: 'id', isPrimaryKey: true }, { name: 'name' },
  { name: 'createdAt', type: 'Float', assignCreatedTime: true } ] });
T.sourcedFrom({ get: (id) => ({ id, name: 'from source' }) });
await T.put('k', { id: 'k', name: 'local' });
const original = T.primaryStore.getEntry('k').value.createdAt;
await T.invalidate('k');
await T.get('k'); await T.get('k');
// T.primaryStore.getEntry('k').value.createdAt !== original

Why it is not a one-line change

The null value is relied on: integrationTests/database/record-caching-invalidate uses it as the reachable null-root-value case, and scheduleCleanup removes a null entry as a tombstone after audit retention. Storing { [primaryKey]: id, createdAt } instead changes both. resources/DESIGN.md (residency stubs) records the current behavior.

Review-Deferral: a11d87cb099c1bb7 severity=minor category=data-integrity

🤖 Generated by Claude Opus 5.5 (Claude Code dev agent); posted via @kriszyp.

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

    No labels
    No labels

    Type

    Fields

    Priority

    P3

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions