Skip to content

Commit 42a7c52

Browse files
committed
Return benchmark queue correlation ids
Use the triggered activity ID as the benchmark queue correlation handle so successful trigger responses return a value that is also preserved on queued fanout and outbox work. #787 (comment) Assisted-by: Codex:gpt-5.5
1 parent 968d687 commit 42a7c52

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

docs/manual/benchmarking.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,15 @@ A successful trigger returns `202 Accepted`:
153153
{
154154
"version": 1,
155155
"activityId": "https://example.com/activities/bench-1",
156-
"queueCorrelationId": null,
156+
"queueCorrelationId": "https://example.com/activities/bench-1",
157157
"recipientCount": 1,
158158
"inboxCount": 1
159159
}
160160
~~~~
161161

162+
The `queueCorrelationId` is the activity ID preserved on the queued fanout or
163+
outbox work.
164+
162165

163166
Metrics
164167
-------

packages/fedify/src/federation/bench.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ export async function handleBenchmarkTrigger<TContextData>(
197197
const sender = parseSender(body.sender);
198198
const recipients = await parseRecipients(body.recipients, context);
199199
const activity = await parseActivity(body.activity, context);
200+
if (activity.id == null) {
201+
throw new BenchmarkTriggerError("activity must have an id.");
202+
}
203+
const activityId = activity.id.href;
200204
const inboxes = extractInboxes({ recipients });
201205
const inboxUrls = Object.keys(inboxes);
202206
if (inboxUrls.length < 1) {
@@ -220,8 +224,8 @@ export async function handleBenchmarkTrigger<TContextData>(
220224
return jsonResponse(
221225
{
222226
version: 1,
223-
activityId: activity.id?.href ?? null,
224-
queueCorrelationId: null,
227+
activityId,
228+
queueCorrelationId: activityId,
225229
recipientCount: recipients.length,
226230
inboxCount: inboxUrls.length,
227231
},

packages/fedify/src/federation/middleware.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,17 +677,21 @@ test("benchmarkMode trigger endpoint", async (t) => {
677677
const body = await response.json() as {
678678
version: number;
679679
activityId: string;
680-
queueCorrelationId: string | null;
680+
queueCorrelationId: string;
681681
recipientCount: number;
682682
inboxCount: number;
683683
};
684684
assertEquals(body.version, 1);
685685
assertEquals(body.activityId, "https://example.com/activities/bench-1");
686-
assertEquals(body.queueCorrelationId, null);
686+
assertEquals(
687+
body.queueCorrelationId,
688+
"https://example.com/activities/bench-1",
689+
);
687690
assertEquals(body.recipientCount, 1);
688691
assertEquals(body.inboxCount, 1);
689692
assertEquals(messages.length, 1);
690693
assertEquals(messages[0].type, "outbox");
694+
assertEquals(messages[0].activityId, body.queueCorrelationId);
691695
assertEquals(messages[0].inbox, "https://sink.example/inbox");
692696
});
693697
});

0 commit comments

Comments
 (0)