Skip to content

Node.js based forum software built for the modern web

chore(activitypub): remove legacy retry cron and _sendMessage (phase 4)\n\n- Remove ap:retry:send cron job and retryFailedMessages() from jobs.js\n- Remove _sendMessage() from index.js (all sends now go through SendPool)\n- Update APSEND.md with phase 4 findings\n\nAssisted-by: unsloth/Qwen3.6-35B-A3B-GGUF

Julian Lam4bbaea5f90c3
diff --git a/APSEND.md b/APSEND.md
index af84a952af..90e9aa17f0 100644
--- a/APSEND.md
+++ b/APSEND.md
@@ -288,6 +288,10 @@ src/activitypub/
1. Remove `retryFailedMessages()` and its cron registration from `jobs.js`
2. Remove `_sendMessage()` from main process (no longer needed)
+**Post-implementation findings (Phase 4 review):**
+- ~~**`retryFailedMessages` cron job**~~ — **FIXED**: Removed `ap:retry:send` cron registration and the `retryFailedMessages()` function from `jobs.js`.
+- ~~**`_sendMessage()` in main process**~~ — **FIXED**: Removed `_sendMessage()` from `index.js`. All sends now go through the worker pool via `SendPool`.
+
### Phase 5: Testing
1. Unit test `sendWorker.js` (mock fetch, verify signing + HTTP POST + SSRF check)
2. Unit test `SendPool` (fork lifecycle, ready signal, crash recovery, result handling)
diff --git a/src/activitypub/index.js b/src/activitypub/index.js
index 7899ab0e06..ed7ca3506e 100644
--- a/src/activitypub/index.js
+++ b/src/activitypub/index.js
@@ -387,42 +387,6 @@ ActivityPub.get = async (type, id, uri, options) => {
}
};
-ActivityPub._sendMessage = async function (uri, keyData, payload, digest) {
- try {
- const headers = await ActivityPub.sign(keyData, uri, digest);
-
- const { response, body } = await request.post(uri, {
- headers: {
- ...headers,
- 'content-type': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
- },
- body: payload,
- timeout: 10000, // configurable?
- });
-
- if (String(response.statusCode).startsWith('2')) {
- ActivityPub.analytics.send({
- type: payload.type,
- target: uri,
- });
- ActivityPub.helpers.log(`[activitypub/send] Successfully sent ${payload.type} to ${uri}`);
- return true;
- }
- if (typeof body === 'object') {
- throw new Error(JSON.stringify(body));
- }
- throw new Error(String(body));
- } catch (e) {
- ActivityPub.helpers.log(`[activitypub/send] Could not send ${payload.type} to ${uri}; error: ${e.message}`);
- ActivityPub.analytics.sendError({
- payload,
- uri,
- error: e,
- });
- return false;
- }
-};
-
ActivityPub.send = async (type, id, targets, payload) => {
if (!meta.config.activitypubEnabled) {
return ActivityPub.helpers.log('[activitypub/send] Federation not enabled; not sending.');
diff --git a/src/activitypub/jobs.js b/src/activitypub/jobs.js
index e028f947c0..6655ae7746 100644
--- a/src/activitypub/jobs.js
+++ b/src/activitypub/jobs.js
@@ -37,13 +37,6 @@ Jobs.start = async () => {
onTick: async () => await tryCronJob(activitypub.actors.prune),
});
- await cron.addJob({
- name: 'ap:retry:send',
- cronTime: '0 * * * * *',
- runOnInit: false,
- onTick: async () => await tryCronJob(retryFailedMessages),
- });
-
await cron.addJob({
name: 'ap:backfill',
cronTime: '15 * * * *',
@@ -78,58 +71,6 @@ Jobs.start = async () => {
});
};
-async function retryFailedMessages() {
- const queueIds = await db.getSortedSetRangeByScore('ap:retry:queue', 0, 50, '-inf', Date.now());
- const queuedData = (await db.getObjects(queueIds.map(id => `ap:retry:queue:${id}`)));
-
- const retryQueueAdd = [];
- const retryQueuedSet = [];
- const queueIdsToRemove = [];
-
- const oneMinute = 1000 * 60;
- await Promise.all(queuedData.map(async (data, index) => {
- const queueId = queueIds[index];
- if (!data) {
- queueIdsToRemove.push(queueId);
- return;
- }
-
- const { uri, id, type, attempts, payload, digest } = data;
- if (!uri || !id || !type || !payload || attempts > 10) {
- queueIdsToRemove.push(queueId);
- return;
- }
- let payloadObj;
- try {
- payloadObj = JSON.parse(payload);
- } catch (err) {
- queueIdsToRemove.push(queueId);
- return;
- }
- const keyData = await activitypub.getPrivateKey(type, id); // keyData could be moved higher up (optimization)
- const ok = await activitypub._sendMessage(uri, keyData, payloadObj, digest);
- if (ok) {
- queueIdsToRemove.push(queueId);
- } else {
- const nextAttempt = (parseInt(attempts, 10) || 0) + 1;
- const timeout = (2 ** nextAttempt) * oneMinute; // exponential backoff
- const nextTryOn = Date.now() + timeout;
- retryQueueAdd.push(['ap:retry:queue', nextTryOn, queueId]);
- retryQueuedSet.push([`ap:retry:queue:${queueId}`, {
- attempts: nextAttempt,
- timestamp: nextTryOn,
- }]);
- }
- }));
-
- await Promise.all([
- db.sortedSetAddBulk(retryQueueAdd),
- db.setObjectBulk(retryQueuedSet),
- db.sortedSetRemove('ap:retry:queue', queueIdsToRemove),
- db.deleteAll(queueIdsToRemove.map(id => `ap:retry:queue:${id}`)),
- ]);
-}
-
async function backfill() {
const start = 0;
const stop = meta.config.topicsPerPage - 1;