Skip to content

Commit c24af4e

Browse files
kriszypclaude
andcommitted
fix(replication): propagate per-event expiresAt to record writes
Two issues prevented replicated records from being evicted: 1. The `options` object passed to `_writeUpdate` for each replicated event did not include `expiresAt`. In a multi-record transaction batch every event after the first uses the first event as `context`, so `context.expiresAt` would silently apply the wrong expiration (or none) to subsequent records. 2. `_writeUpdate` read `expiresAt` only from `context`, so per-event options were ignored. Now: `options?.expiresAt ?? context?.expiresAt ?? fallback`. 3. `scheduleCleanup()` was only armed when `context.expiresAt` was truthy, missing replicated writes that carry expiration via options. Changed to `if (expiresAt >= 0)` to cover both paths. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e24fb0e commit c24af4e

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

resources/Table.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ export function makeTable(options) {
311311
ensureLoaded: false,
312312
nodeId: event.nodeId,
313313
viaNodeId: event.viaNodeId,
314+
// use per-event expiresAt: batched txn context only holds the first event's expiration
315+
expiresAt: event.expiresAt,
314316
async: true,
315317
};
316318
const id = event.id;
@@ -1685,7 +1687,8 @@ export function makeTable(options) {
16851687
const type = fullUpdate ? 'put' : 'patch';
16861688
let residencyId: number | undefined;
16871689
if (options?.residencyId != undefined) residencyId = options.residencyId;
1688-
const expiresAt: number = context?.expiresAt ?? (expirationMs ? expirationMs + Date.now() : -1);
1690+
const expiresAt: number =
1691+
options?.expiresAt ?? context?.expiresAt ?? (expirationMs ? expirationMs + Date.now() : -1);
16891692
const additionalAuditRefs: Array<{ version: number; nodeId: number }> = []; // track additional audit refs to store
16901693

16911694
if (precedesExisting <= 0) {
@@ -1902,7 +1905,7 @@ export function makeTable(options) {
19021905
updateIndices(id, existingRecord, recordToStore, transaction && { transaction });
19031906

19041907
writeCommit(true);
1905-
if (context.expiresAt) scheduleCleanup();
1908+
if (expiresAt >= 0) scheduleCleanup(); // arm for replicated writes too, not just local-context writes
19061909
function writeCommit(storeRecord: boolean) {
19071910
// we need to write the commit. if storeRecord then we need to store the record, otherwise we just need to store the audit record
19081911
updateRecord(

0 commit comments

Comments
 (0)