Task group 2 of federation-hardening. The narrow inbox (Follow/Undo/Accept/Reject) had no replay protection — only Create(Note) did, via the activities.remote_origin_iri unique constraint. A remote redelivering a signed follow-graph activity would re-run its side effects. - New `federation_processed_activities` table (activity IRI PK, received_at + index). Additive, so drizzle-kit push creates it; no hand-written migration needed. - `federation-replay.server.ts`: `markInboundActivityProcessed` does an insert-or-drop (ON CONFLICT DO NOTHING RETURNING) and reports whether the IRI is fresh; `sweepProcessedActivities` deletes rows > 30 days old (signature date-freshness already rejects older replays). - Each inbox listener drops a duplicate before side effects. The follow-graph handlers are idempotent, so a handler failure whose retry is later dropped as a duplicate can't corrupt state. - `federation-dedup-sweep` job (daily 04:30 UTC) runs the TTL sweep. Verified: db + journal typecheck + lint clean; drizzle-kit push creates the table; replay integration test (fresh-vs-duplicate + 30-day sweep) green against real Postgres; journal unit suite 355 passing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
22 lines
868 B
TypeScript
22 lines
868 B
TypeScript
import { defineJournalJob } from "./payloads.ts";
|
|
import { sweepProcessedActivities } from "../lib/federation-replay.server.ts";
|
|
import { logger } from "../lib/logger.server.ts";
|
|
|
|
/**
|
|
* Daily cleanup of federation_processed_activities rows older than 30
|
|
* days (spec: federation-operations "Inbound replay defense"). Replays of
|
|
* activities that old are already rejected by HTTP-signature date
|
|
* freshness, so the dedup record is no longer needed; this keeps the
|
|
* table bounded.
|
|
*/
|
|
export const federationDedupSweepJob = defineJournalJob({
|
|
name: "federation-dedup-sweep",
|
|
cron: "30 4 * * *", // daily at 04:30 UTC (offset from federation-kv-sweep at 04:15)
|
|
retryLimit: 1,
|
|
expireInSeconds: 60,
|
|
async handler() {
|
|
const purged = await sweepProcessedActivities();
|
|
logger.info({ purged }, "federation-dedup-sweep");
|
|
return { purged };
|
|
},
|
|
});
|