Skip to content

An out-of-order write's audit entry logs the newer record's @expiresAt deadline as its own #3766

Open

Description

@kriszyp

Problem

When a write older than the stored record (precedesExisting < 0 in Table._writeUpdate) carries no explicit expiresAt, the expiry logged in its audit entry is derived from the merged record. If the newer head set the @expiresAt field, the merged record holds the head's value, so the older write's audit entry carries the head's deadline rather than one of its own.

That audit entry is what a replica applies (event.expiresAt becomes the write's explicit expiresAt) and what crash replay re-applies. A replica that receives the older write before the head, or never receives the head, stores the older write's data with the head's deadline. Once the head arrives, the replica converges, because an older write now keeps the newer head's stored expiry.

The same derivation means a derived expiry (field or table default) is replicated as an absolute deadline, which then overrides the receiver's own field and table default.

This behavior predates the out-of-order expiry fix; that fix keeps the record's expiry correct and leaves the audit value as it was.

A related precedence case: an older write that sets an @expiresAt field the newer record lacked, and also carries an explicit expiresAt, stores its explicit expiry over the newer record's, because an explicit expiry outranks the field. With a past explicit value, a live record is hidden. This matches origin/main.

The mirror case has the same cause: a newer record whose expiry came from an explicit expiresAt, then an older write that sets a past or nearer @expiresAt field and carries no explicit expiry. Delivered in order, the newer explicit expiry wins; delivered out of order, the merge changed the field, so the older write's field decides and the record expires early. Both cases need the stored record to remember whether its expiry came from an explicit option or from the field. Once a record is stored with the older write's expiry, the @expiresAt sweep evicts it on that stored deadline (hasExpired) even while the merged field is live. This also matches origin/main.

Fix direction

Decide what an older write's own expiry is when it carries no explicit one (its own @expiresAt field if it set one, else none), and log that. Changing it changes what replicas apply, so it needs a replication-level test (a relay with a local-only head).

Review-Deferral: 48b59b13c48d1032 severity=minor category=data-integrity
Review-Deferral: ebcc7032fa78bafd severity=minor category=correctness
Review-Deferral: fb657eab6be8572e severity=major 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