Skip to content

setCollectionDispatcher() routes return 404 after FederationBuilder.build() #849

Description

@dahlia

Description

A custom collection dispatcher registered with FederationBuilder.setCollectionDispatcher() appears not to work on the built Federation instance. The route is accepted by the builder, but fetching the registered collection URL returns 404 Not Found.

This looks like the collection dispatcher state is not copied from the builder into the built federation instance.

Reproduction

Tested with @fedify/fedify@2.3.1:

import { createFederationBuilder } from "jsr:@fedify/fedify@2.3.1";
import { Collection, Note } from "jsr:@fedify/fedify@2.3.1/vocab";

const builder = createFederationBuilder<void>();

builder.setCollectionDispatcher(
  "test",
  Note,
  "/c/{id}",
  () =>
    new Collection({
      id: new URL("https://example.com/c/x"),
    }),
);

const federation = await builder.build({
  kv: undefined,
  origin: "https://example.com",
});

const request = new Request("https://example.com/c/x", {
  headers: { accept: "application/activity+json" },
});

const response = await federation.fetch(request);

console.log(response.status);
console.log(await response.text());

Actual output:

404
Not Found

Expected behavior

The request to https://example.com/c/x should be handled by the custom collection dispatcher registered with setCollectionDispatcher(), and should return an ActivityPub Collection.

Actual behavior

The built federation returns 404 Not Found.

Suspected cause

FederationBuilder.build() clones/copies several mutable fields into the new FederationImpl, including the router, object callbacks, actor callbacks, inbox/outbox callbacks, and built-in collection callbacks such as followers, following, liked, and featured.

However, it appears not to copy these custom collection dispatcher fields:

  • collectionCallbacks
  • collectionTypeIds

The route itself is added to the builder router, but the corresponding collection callback/type maps are missing on the built federation instance, so the route cannot be dispatched.

Context

I ran into this while implementing a FEP-c0e0 fedibird:emojiReactions collection in Hackers' Pub. Registering the collection with setCollectionDispatcher() produced a 404 after build(). As a workaround, I registered equivalent Collection/CollectionPage object dispatchers instead.

This does not seem to be a URI Template matching issue. For example, /ap/notes/{id} does not match /ap/notes/123/emoji-reactions, and /ap/notes/{id}/emoji-reactions correctly extracts id = "123". The failure appears specific to custom collection dispatchers not being carried over into the built federation.

Metadata

Metadata

Assignees

Labels

Type

Priority

High

Effort

Medium

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions