Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: stamp peer push delivery floor at payload-snapshot time so manual sweep keeps undelivered tombstones (#11772)

[._.]/ Adam Eivy6eecffdf76cf
diff --git a/server/services/sharing/peerSync.test.js b/server/services/sharing/peerSync.test.js
index a91992d2d5..1092a4b16b 100644
--- a/server/services/sharing/peerSync.test.js
+++ b/server/services/sharing/peerSync.test.js
@@ -2148,6 +2148,33 @@ describe('peerSync', () => {
expect(afterFail.lastConfirmedPushedAt).toBe(stamped); // unchanged
});
+ it('stamps lastConfirmedPushedAt at payload-snapshot time, so a live push answered after the delete stays below deletedAt (#11772)', async () => {
+ // A push that read the record while live and whose response lands after
+ // the user deleted it only proves the peer holds the LIVE state. Stamping
+ // the floor at response time would lift it past the tombstone and let
+ // tombstoneGc prune a deletion the peer never received.
+ vi.mocked(getUniverse).mockResolvedValue({ id: 'u1', name: 'Foo' });
+ let releaseFetch;
+ vi.mocked(peerFetch).mockImplementation(() => new Promise((resolve) => {
+ releaseFetch = () => resolve({ ok: true, json: async () => ({ missingAssets: [] }) });
+ }));
+ const sub = await subscribePeer(
+ { peerId: 'peer-a', recordKind: 'universe', recordId: 'u1' },
+ { adoptedFromReverse: true },
+ );
+ const inFlight = pushRecordToPeer(sub);
+ await vi.waitFor(() => expect(releaseFetch).toBeTypeOf('function'));
+ await new Promise((r) => setTimeout(r, 5));
+ const deletedAt = Date.now();
+ await new Promise((r) => setTimeout(r, 5));
+ releaseFetch();
+ expect((await inFlight).pushed).toBe(true);
+ const refreshed = await findPeerSubscription('peer-a', 'universe', 'u1');
+ expect(refreshed.lastConfirmedPushedAt).toBeLessThan(deletedAt);
+ // The human-facing "last pushed" time still reports the response.
+ expect(Date.parse(refreshed.lastPushedAt)).toBeGreaterThan(deletedAt);
+ });
+
it('handles a network-level failure without throwing (returns pushed:false)', async () => {
vi.mocked(getUniverse).mockResolvedValue({ id: 'u1', name: 'Foo' });
vi.mocked(peerFetch).mockRejectedValue(new Error('ECONNREFUSED'));
diff --git a/server/services/sharing/peerSyncPush.js b/server/services/sharing/peerSyncPush.js
index fa24b48ae5..a9dcc6a9e6 100644
--- a/server/services/sharing/peerSyncPush.js
+++ b/server/services/sharing/peerSyncPush.js
@@ -173,6 +173,11 @@ export async function pushRecordToPeer(sub, options = {}) {
return { pushed: false, reason: 'unknown-local-instance' };
}
+ // Delivery evidence is "peer holds state as of this time" (#11772): stamp
+ // BEFORE the record is read, not at response time, so a slow push of a
+ // pre-delete snapshot cannot raise lastConfirmedPushedAt past a tombstone
+ // it never carried and let tombstoneGc prune it.
+ const payloadSnapshotAtMs = Date.now();
const payload = await buildPushPayload(sub, ourInstanceId);
if (!payload) return { pushed: false, reason: 'record-not-found' };
@@ -365,7 +370,7 @@ export async function pushRecordToPeer(sub, options = {}) {
const linkedTrackObligationSatisfied = sub.recordKind === 'musicVideoProject'
&& !trackSyncPending
&& (!trackOwed || Boolean(payload.linkedTrack));
- const recordPushAcceptedAtMs = Date.now();
+ const recordPushAcceptedAtMs = payloadSnapshotAtMs;
const deliveryEvidence = {
recordPushAcceptedAtMs,
linkedTrackObligationSatisfiedAtMs: linkedTrackObligationSatisfied ? recordPushAcceptedAtMs : null,
diff --git a/server/services/sharing/tombstoneGc.test.js b/server/services/sharing/tombstoneGc.test.js
index cfc5c62fa3..df143c3746 100644
--- a/server/services/sharing/tombstoneGc.test.js
+++ b/server/services/sharing/tombstoneGc.test.js
@@ -727,6 +727,31 @@ describe('sweepTombstones — per-record confirmed-push clamp (peer-sync-per-rec
expect(A_DELETED_AT).toBeGreaterThanOrEqual(cutoff); // A NOT pruned
});
+ it('keeps a tombstone whose row was last pushed after the delete but only confirmed a pre-delete snapshot (#11772)', async () => {
+ // peerSyncPush stamps lastConfirmedPushedAt at payload-snapshot time; a
+ // live push answered after the delete leaves lastPushedAt past deletedAt.
+ // GC must read the snapshot floor, not the response time, even on the
+ // manual graceMs:0 sweep with the per-peer ack cursor past deletedAt.
+ const snapshotAt = A_DELETED_AT - 1000;
+ getMinAckAcrossPeers.mockResolvedValue(B_DELETED_AT);
+ getPeers.mockResolvedValue([{ instanceId: 'peer-a', enabled: true }]);
+ mockSubs({
+ universe: [
+ {
+ peerId: 'peer-a', recordId: 'u-A',
+ createdAt: new Date(NOW - 60 * 60 * 1000).toISOString(),
+ lastConfirmedPushedAt: snapshotAt,
+ lastPushedAt: new Date(A_DELETED_AT + 1000).toISOString(),
+ },
+ { peerId: 'peer-a', recordId: 'u-B', createdAt: new Date(NOW - 60 * 60 * 1000).toISOString(), lastConfirmedPushedAt: NOW },
+ ],
+ });
+ await sweepTombstones({ now: NOW, graceMs: 0 });
+ const cutoff = pruneTombstonedUniverses.mock.calls[0][0];
+ expect(cutoff).toBe(snapshotAt + 1);
+ expect(A_DELETED_AT).toBeGreaterThanOrEqual(cutoff); // A NOT pruned
+ });
+
it('prunes record-A tombstone once A push is confirmed past its deletedAt', async () => {
// After A's delete-push finally lands, A's row confirm advances above its
// deletedAt and the clamp no longer holds the line — A is prunable.