Skip to content

Support fixed-path actor dispatchers#753

Open
dahlia wants to merge 3 commits intofedify-dev:mainfrom
dahlia:feature/fixed-path-actor-dispatchers
Open

Support fixed-path actor dispatchers#753
dahlia wants to merge 3 commits intofedify-dev:mainfrom
dahlia:feature/fixed-path-actor-dispatchers

Conversation

@dahlia
Copy link
Copy Markdown
Member

@dahlia dahlia commented May 2, 2026

This PR adds mapActorAlias() to ActorCallbackSetters. An actor dispatcher can now map a fixed path, such as /actor or /bot, to an internal sentinel identifier.

Some applications expose a single instance-level actor at a fixed path. Before this change, they had to use a sentinel identifier such as __instance__, and that identifier became part of the actor URI.

mapActorAlias() keeps the sentinel internal. Incoming actor requests resolve through the alias map. Context.getActorUri() uses the same map when building outbound actor URIs.

Implementation details:

  • Aliases register a router route named actorAlias:{identifier}.
  • Alias paths must be fixed. Paths containing route variables are rejected.
  • Context.getActorUri() tries the actorAlias:{identifier} route first, then falls back to the standard actor route.
  • Context.parseUri() and fetch() routing now recognize actorAlias: route names and read the identifier from the route name instead of route values.

Resolves #752.

@dahlia dahlia added this to the Fedify 2.3 milestone May 2, 2026
@dahlia dahlia self-assigned this May 2, 2026
@dahlia dahlia added type/enhancement Improvements to existing features component/federation Federation object related component/actor Actor dispatcher related labels May 2, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 2, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a fixed-path actor alias mechanism: ActorCallbackSetters.mapActorAlias(path, identifier) registers a fixed URL (e.g., /bot) as an alias for a sentinel actor identifier, and wires routing, URI generation, parsing, and WebFinger to resolve and dispatch via that alias.

Changes

Fixed-Path Actor Alias Feature

Layer / File(s) Summary
Interface Definition
packages/fedify/src/federation/federation.ts
Adds public mapActorAlias(path: string, identifier: string) to ActorCallbackSetters<TContextData> with JSDoc and @since 2.3.0.
Builder Implementation & Route Registration
packages/fedify/src/federation/builder.ts, packages/fedify/src/federation/builder.test.ts
Replaces mapAlias(mapper) with mapActorAlias(path, identifier) on setActorDispatcher(...); introduces ACTOR_ALIAS_PREFIX, validates alias path contains no variables, rejects duplicate alias names, and registers route actorAlias:${identifier}. Tests updated to assert path-variable and duplicate-alias errors and that "/actor" route is registered as actorAlias:instance.
Request Routing & Context / URI Handling
packages/fedify/src/federation/middleware.ts, packages/fedify/src/federation/middleware.test.ts
Adds actorAlias route case in JSON-LD handler that extracts identifier from route.name when prefixed with actorAlias:, creates context with invokedFromActorDispatcher, and forwards to handleActor. ContextImpl.getActorUri() prefers actorAlias:${identifier} when present; ContextImpl.parseUri() recognizes actorAlias:* as actor routes and derives identifier accordingly. Tests verify GET /bot, dispatcher invocation, WebFinger self link and aliases, and URI parsing.
Documentation & Changelog
docs/manual/actor.md, CHANGES.md
Docs add "Fixed-path actor URIs" section with TypeScript examples and availability note; CHANGES.md documents mapActorAlias() under Version 2.3.0 with issue references [#752]/[#753].

Sequence Diagram

sequenceDiagram
    participant Client as Client
    participant Router as Router
    participant Handler as Handler
    participant Context as Context
    participant Dispatcher as Dispatcher

    Client->>Router: GET /bot
    Router->>Router: Match route "actorAlias:bot"
    Router->>Handler: Invoke handler for actorAlias route
    Handler->>Handler: Extract identifier "bot" from route name
    Handler->>Context: Create context with invokedFromActorDispatcher
    Context->>Dispatcher: Call actor dispatcher with "bot"
    Dispatcher->>Client: Return actor JSON (id: https://example.com/bot)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

  • #752 — Implements the alias-to-sentinel approach described in the issue (adds mapActorAlias() and wiring for fixed-path actors).
  • #646 — Related discussion about supporting fixed-path or multi-pattern actor dispatchers; this PR implements the aliasing alternative referenced there.

Suggested labels

type/documentation

Suggested reviewers

  • 2chanhaeng
  • sij411
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Support fixed-path actor dispatchers' directly and clearly describes the main change—adding the mapActorAlias() method to enable fixed-path actor routing.
Description check ✅ Passed The description thoroughly explains the feature (mapActorAlias() method, fixed-path mapping), its benefits (no sentinel leakage), and implementation details (alias route naming, path validation, URI generation integration).
Linked Issues check ✅ Passed The PR successfully implements the alias-based approach from issue #752 by adding mapActorAlias() to map fixed paths to sentinel identifiers, integrating the mechanism into URI generation and routing.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the fixed-path actor aliasing feature: method signatures, routing logic, URI generation, and comprehensive test coverage. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: Turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get your free trial and get 200 agent minutes per Slack user (a $50 value).


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@issues-auto-labeler issues-auto-labeler Bot added the activitypub/interop Interoperability issues label May 2, 2026
@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented May 2, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/fedify/src/federation/builder.test.ts`:
- Around line 28-39: Add a new test that asserts mapActorAlias rejects duplicate
alias registrations once the duplication guard is implemented: use
createFederationBuilder<T>(), call setActorDispatcher("/users/{identifier}",
actorDispatcher) and then call mapActorAlias twice with different paths but the
same alias identifier to verify an error is thrown via assertThrows expecting
RouterError; reference the same pattern used in the existing test
(createFederationBuilder, setActorDispatcher, mapActorAlias, assertThrows,
RouterError) so the test ensures duplicate alias registration fails.

In `@packages/fedify/src/federation/builder.ts`:
- Around line 525-534: The mapActorAlias setter is missing the
duplicate-registration guard used elsewhere; before calling
this.router.add(path, `actorAlias:${identifier}`) check
this.router.has(`actorAlias:${identifier}`) and if true throw the same
RouterError used by other setters (e.g. in setActorDispatcher) to prevent silent
overwrites; keep the existing variable-check with new Router() and only perform
this.router.add(...) when the has-check passes so behavior is consistent with
other methods in the class.

In `@packages/fedify/src/federation/federation.ts`:
- Around line 1111-1123: Add a JSDoc `@throws` entry to the public method
mapActorAlias to document that it can throw a RouterError when route input is
invalid; update the comment block above mapActorAlias (the method returning
ActorCallbackSetters<TContextData>) to include a line like "@throws
{RouterError} If the provided path or identifier is invalid or fails runtime
validation" so the public API docs accurately describe the runtime validation
failure mode.

In `@packages/fedify/src/federation/middleware.ts`:
- Around line 1950-1953: The code computes identifier from
route.values.identifier which can be undefined for fixed-path routes; tighten
runtime checks in the branch that handles actor/actorAlias routes (the code
using route, route.name, and identifier) by asserting or providing a safe
fallback: when route.name startsWith("actorAlias:") keep substring logic, but
when using route.values.identifier add a runtime guard (e.g., if route.name ===
"actor" then require route.values.identifier exists, otherwise throw a clear
error or assert) so the returned { type: "actor", identifier } cannot contain
undefined; update the logic around the identifier assignment and the subsequent
if (route.name === "actor" || route.name.startsWith("actorAlias:")) branch to
enforce this invariant at runtime.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 262c4b63-e59c-4267-b259-96554cde3f2e

📥 Commits

Reviewing files that changed from the base of the PR and between 4aa6a88 and 56c1e6c.

📒 Files selected for processing (8)
  • CHANGES.md
  • docs/manual/actor.md
  • packages/fedify/src/federation/builder.test.ts
  • packages/fedify/src/federation/builder.ts
  • packages/fedify/src/federation/federation.ts
  • packages/fedify/src/federation/middleware.test.ts
  • packages/fedify/src/federation/middleware.ts
  • pr-description.md

Comment thread packages/fedify/src/federation/builder.test.ts
Comment thread packages/fedify/src/federation/builder.ts
Comment thread packages/fedify/src/federation/federation.ts
Comment thread packages/fedify/src/federation/middleware.ts Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the mapActorAlias() method to the ActorCallbackSetters interface, enabling the mapping of fixed paths like /actor or /bot to internal sentinel identifiers for instance-level actors. The implementation includes path validation, router updates, and logic in getActorUri and parseUri to handle these aliases, supported by new documentation and tests. A review comment suggests replacing the repeated magic string "actorAlias:" with a constant to improve maintainability and prevent typos across the codebase.

Comment thread packages/fedify/src/federation/middleware.ts Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

Files with missing lines Coverage Δ
packages/fedify/src/federation/builder.ts 55.59% <100.00%> (+0.62%) ⬆️
packages/fedify/src/federation/middleware.ts 95.82% <100.00%> (+0.01%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dahlia dahlia force-pushed the feature/fixed-path-actor-dispatchers branch from 56c1e6c to ca15ae2 Compare May 2, 2026 17:24
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/fedify/src/federation/middleware.test.ts (1)

303-334: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Add a test asserting that mapActorAlias rejects paths with route variables.

The PR description states "alias paths must be fixed; paths containing route variables are rejected." Every other path-registering method in this file has a corresponding "wrong variables in path" step (inbox listeners: line 1479, inbox dispatcher: line 2840). mapActorAlias is missing this coverage, so the validation could be accidentally removed with no test failure.

✅ Suggested test addition (inside the `Federation.createContext()` "`Context`" step, or as its own step)
assertThrows(
  () =>
    createFederation<number>({ kv })
      .setActorDispatcher("/users/{identifier}", () => new vocab.Person({}))
      .mapActorAlias("/users/{identifier}" as `/${string}`, "alias"),
  RouterError,
  "actor alias path must not contain route variables",
);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/fedify/src/federation/middleware.test.ts` around lines 303 - 334,
Add a test that verifies mapActorAlias rejects alias paths containing route
variables: call createFederation(...).setActorDispatcher("/users/{identifier}",
...) and then invoke mapActorAlias("/users/{identifier}" as `/${string}`,
"alias") inside an assertThrows expecting RouterError with message like "actor
alias path must not contain route variables"; place this assertion in the
existing Context step (or as its own step) alongside other path-validation tests
so removal of the validation will fail the tests.
♻️ Duplicate comments (1)
packages/fedify/src/federation/federation.ts (1)

1111-1123: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add @throws to the mapActorAlias() JSDoc (still unaddressed).

The @throws {RouterError} contract is missing. The method performs runtime path validation and throws, but nothing in the public API docs signals this to callers.

📝 Proposed doc update
   * `@param` path The fixed path to map to the identifier.
   * `@param` identifier The sentinel identifier to map the path to.
   * `@returns` The setters object so that settings can be chained.
+  * `@throws` {RouterError} Thrown if `path` contains route variables.
   * `@since` 2.3.0
   */

As per coding guidelines (packages/fedify/src/**/*.{ts,tsx}): "Include JSDoc comments for public APIs."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/fedify/src/federation/federation.ts` around lines 1111 - 1123, The
JSDoc for the public method mapActorAlias is missing a `@throws` annotation for
runtime path validation errors; update the mapActorAlias JSDoc block to add a
`@throws` {RouterError} entry (mentioning when/why it is thrown — e.g., invalid
path format or duplicate mapping) so callers see the contract and align with the
RouterError thrown by the method at runtime.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/fedify/src/federation/middleware.test.ts`:
- Around line 1217-1222: The test assumes body.aliases exists before calling
.includes; add a null-guard for body.aliases (e.g., assertExists(body.aliases)
or an Array.isArray/body.aliases != null check) before the includes assertion so
a missing aliases field yields a clear assertion failure instead of a TypeError;
update the assertion block around the existing selfLink checks (referencing
body.aliases and selfLink) to validate aliases is present and an array before
calling .includes("https://example.com/bot").

In `@pr-description.md`:
- Line 1: Add a setext H1 title to the start of pr-description.md by inserting a
one-line title (e.g., "PR Description") as the first line and immediately
following it with an underline of = characters matching the title length to
satisfy MD041 and the project's markdown guideline; ensure the original body
text is moved below this new two-line setext heading so the document begins with
the required H1.

---

Outside diff comments:
In `@packages/fedify/src/federation/middleware.test.ts`:
- Around line 303-334: Add a test that verifies mapActorAlias rejects alias
paths containing route variables: call
createFederation(...).setActorDispatcher("/users/{identifier}", ...) and then
invoke mapActorAlias("/users/{identifier}" as `/${string}`, "alias") inside an
assertThrows expecting RouterError with message like "actor alias path must not
contain route variables"; place this assertion in the existing Context step (or
as its own step) alongside other path-validation tests so removal of the
validation will fail the tests.

---

Duplicate comments:
In `@packages/fedify/src/federation/federation.ts`:
- Around line 1111-1123: The JSDoc for the public method mapActorAlias is
missing a `@throws` annotation for runtime path validation errors; update the
mapActorAlias JSDoc block to add a `@throws` {RouterError} entry (mentioning
when/why it is thrown — e.g., invalid path format or duplicate mapping) so
callers see the contract and align with the RouterError thrown by the method at
runtime.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9d4122c4-f118-43b9-84f2-7d91a5560be3

📥 Commits

Reviewing files that changed from the base of the PR and between 56c1e6c and ca15ae2.

📒 Files selected for processing (8)
  • CHANGES.md
  • docs/manual/actor.md
  • packages/fedify/src/federation/builder.test.ts
  • packages/fedify/src/federation/builder.ts
  • packages/fedify/src/federation/federation.ts
  • packages/fedify/src/federation/middleware.test.ts
  • packages/fedify/src/federation/middleware.ts
  • pr-description.md

Comment thread packages/fedify/src/federation/middleware.test.ts
Comment thread pr-description.md Outdated
dahlia added a commit to dahlia/fedify-fork that referenced this pull request May 2, 2026
Harden `mapActorAlias()` by adding a duplicate registration guard and
using a constant for the alias prefix.  Updated JSDoc to include the
`RouterError` contract.

Improved test coverage with a duplicate alias registration test and
added a null-guard for WebFinger aliases in the middleware test.
Also added a title to `pr-description.md`.

fedify-dev#753 (comment)
fedify-dev#753 (comment)
fedify-dev#753 (comment)
fedify-dev#753 (comment)
fedify-dev#753 (comment)
fedify-dev#753 (comment)

Assisted-by: Gemini CLI:gemini-3-flash-preview
Assisted-by: Codex:gpt-5.5
dahlia added 2 commits May 3, 2026 03:13
Added `mapActorAlias()` method to `ActorCallbackSetters` interface to
support mapping fixed paths to sentinel identifiers for the actor
dispatcher. This enables exposing a single, instance-level actor at a
fixed path (like `/actor` for a relay or `/bot` for a bot) without
leaking the sentinel identifier into the actor's URI.

When an alias is mapped, the router will use it for resolving inbound
requests and `Context.getActorUri()` will use it for constructing
outbound actor URIs.  WebFinger responses for the actor will also use
the aliased URI.

Fixes fedify-dev#752

Assisted-by: Gemini CLI:gemini-3.1-pro-preview
Assisted-by: Gemini CLI:gemini-3-flash-preview
Assisted-by: Codex:gpt-5.5
Harden `mapActorAlias()` by adding a duplicate registration guard and
using a constant for the alias prefix.  Updated JSDoc to include the
`RouterError` contract.

Improved test coverage with a duplicate alias registration test and
added a null-guard for WebFinger aliases in the middleware test.

fedify-dev#753 (comment)
fedify-dev#753 (comment)
fedify-dev#753 (comment)
fedify-dev#753 (comment)
fedify-dev#753 (comment)
fedify-dev#753 (comment)

Assisted-by: Gemini CLI:gemini-3-flash-preview
Assisted-by: Codex:gpt-5.5
@dahlia dahlia force-pushed the feature/fixed-path-actor-dispatchers branch from f4126bc to 82658ee Compare May 2, 2026 18:14
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/fedify/src/federation/builder.ts`:
- Around line 527-540: mapActorAlias currently only checks identifier collisions
but allows registering an alias path that already resolves to an existing route;
update mapActorAlias to call this.router.route(path) and, if it returns a match
(i.e., path already resolves), throw a RouterError rejecting the alias, instead
of proceeding to add; keep the existing identifier collision and variable
checks, then only call this.router.add(path,
`${ACTOR_ALIAS_PREFIX}${identifier}`) when route(path) is null/undefined, and
add a regression test exercising two different identifiers with the same fixed
path to assert the second call throws.

In `@packages/fedify/src/federation/middleware.test.ts`:
- Around line 1217-1219: The test accesses body.links as an array without
validation, which can throw a TypeError; update the test around the selfLink
assignment to first guard that body.links exists and is an array (e.g., use
Array.isArray(body.links) or an assertion) and only then call .find() to locate
the link; reference the selfLink variable and body.links in your change and if
the guard fails make the test assert a clear failure message instead of letting
.find() throw.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c81b26f3-0ea3-4ddb-834e-30f99ee95349

📥 Commits

Reviewing files that changed from the base of the PR and between ca15ae2 and f4126bc.

📒 Files selected for processing (6)
  • packages/fedify/src/federation/builder.test.ts
  • packages/fedify/src/federation/builder.ts
  • packages/fedify/src/federation/federation.ts
  • packages/fedify/src/federation/middleware.test.ts
  • packages/fedify/src/federation/middleware.ts
  • pr-description.md

Comment thread packages/fedify/src/federation/builder.ts
Comment thread packages/fedify/src/federation/middleware.test.ts
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
packages/fedify/src/federation/middleware.test.ts (1)

1217-1223: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Guard body.links before calling .find().

body.links is still assumed to exist here, so a missing or malformed WebFinger payload will throw a TypeError instead of failing the test cleanly.

🛡️ Proposed fix
     assertEquals(response.status, 200);
     const body = await response.json() as Record<string, unknown>;
     assertEquals(body.subject, "acct:bot@example.com");
-    const selfLink = (body.links as Record<string, unknown>[]).find((l) =>
+    assertExists(body.links, "WebFinger response must include a links array");
+    assert(Array.isArray(body.links), "WebFinger links must be an array");
+    const selfLink = (body.links as Record<string, unknown>[]).find((l) =>
       l.rel === "self"
     );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/fedify/src/federation/middleware.test.ts` around lines 1217 - 1223,
The test assumes body.links exists and calls .find which can throw; before using
.find validate and guard body.links (e.g., assertExists(body.links) and/or
assert(Array.isArray(body.links))) so malformed/missing WebFinger payloads fail
the test cleanly; update the block that computes selfLink (the selfLink variable
and subsequent assertions) to first assert that body.links is present and an
array, then call (body.links as Record<string, unknown>[]).find(...), and
proceed to assertExists(selfLink) and other expectations.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/manual/actor.md`:
- Around line 464-489: The example uses "bot" as both the public path and the
internal dispatcher identifier, so change the dispatcher to use a distinct
opaque sentinel (e.g., "__instance__") and then call
ActorCallbackSetters.mapActorAlias("/bot", "__instance__") so the example
demonstrates alias indirection; update the setActorDispatcher callback to check
for the sentinel identifier (identifier === "__instance__") and construct the
actor using ctx.getActorUri("__instance__") while leaving the public path as
"/bot".

---

Duplicate comments:
In `@packages/fedify/src/federation/middleware.test.ts`:
- Around line 1217-1223: The test assumes body.links exists and calls .find
which can throw; before using .find validate and guard body.links (e.g.,
assertExists(body.links) and/or assert(Array.isArray(body.links))) so
malformed/missing WebFinger payloads fail the test cleanly; update the block
that computes selfLink (the selfLink variable and subsequent assertions) to
first assert that body.links is present and an array, then call (body.links as
Record<string, unknown>[]).find(...), and proceed to assertExists(selfLink) and
other expectations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: de436a85-4d0f-42ea-8060-3918020c6c91

📥 Commits

Reviewing files that changed from the base of the PR and between f4126bc and 82658ee.

📒 Files selected for processing (7)
  • CHANGES.md
  • docs/manual/actor.md
  • packages/fedify/src/federation/builder.test.ts
  • packages/fedify/src/federation/builder.ts
  • packages/fedify/src/federation/federation.ts
  • packages/fedify/src/federation/middleware.test.ts
  • packages/fedify/src/federation/middleware.ts

Comment thread docs/manual/actor.md
@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented May 2, 2026

@codex review

@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented May 2, 2026

/gemini review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the mapActorAlias() method to the ActorCallbackSetters interface, allowing developers to map fixed paths (e.g., /bot or /actor) to specific actor identifiers. This feature is particularly useful for instance-level actors where a sentinel identifier in the URI is undesirable. The implementation includes validation to ensure alias paths do not contain variables and prevents duplicate alias registrations. Corresponding updates were made to the routing logic, URI generation, and WebFinger support to ensure aliases are correctly resolved and advertised. Comprehensive tests and documentation have also been added. I have no feedback to provide as there were no review comments to assess.

Verified that `mapActorAlias()` rejects paths containing route
variables in `middleware.test.ts`, matching the behavior tested in
`builder.test.ts`.

Assisted-by: Gemini CLI:gemini-3-flash-preview
Assisted-by: Codex:gpt-5.5
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
packages/fedify/src/federation/middleware.test.ts (1)

1227-1233: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Guard body.links before calling .find()

At Line 1227, body.links is assumed to be an array. If the field is missing/malformed, the test throws a TypeError instead of failing with a clear assertion. Also worth asserting aliases is an array before .includes().

Suggested patch
     assertEquals(response.status, 200);
     const body = await response.json() as Record<string, unknown>;
     assertEquals(body.subject, "acct:bot@example.com");
+    assertExists(body.links, "WebFinger response must include a links array");
+    assert(Array.isArray(body.links), "WebFinger links must be an array");
     const selfLink = (body.links as Record<string, unknown>[]).find((l) =>
       l.rel === "self"
     );
     assertExists(selfLink);
     assertEquals(selfLink.href, "https://example.com/bot");
     assertExists(body.aliases);
+    assert(Array.isArray(body.aliases), "WebFinger aliases must be an array");
     assert((body.aliases as string[]).includes("https://example.com/bot"));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/fedify/src/federation/middleware.test.ts` around lines 1227 - 1233,
Guard against missing/malformed arrays before using .find() and .includes():
assert that body.links is an array (e.g., use Array.isArray(body.links) with
assertExists or assert) before calling (body.links as Record<string,
unknown>[]).find(...) to avoid TypeError, then proceed to locate selfLink;
likewise assert that body.aliases is an array before using (body.aliases as
string[]).includes(...). Update the test around the symbols selfLink,
body.links, and body.aliases to perform these array checks and keep the existing
assertions for href and alias membership.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@packages/fedify/src/federation/middleware.test.ts`:
- Around line 1227-1233: Guard against missing/malformed arrays before using
.find() and .includes(): assert that body.links is an array (e.g., use
Array.isArray(body.links) with assertExists or assert) before calling
(body.links as Record<string, unknown>[]).find(...) to avoid TypeError, then
proceed to locate selfLink; likewise assert that body.aliases is an array before
using (body.aliases as string[]).includes(...). Update the test around the
symbols selfLink, body.links, and body.aliases to perform these array checks and
keep the existing assertions for href and alias membership.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 15bad549-ad28-4004-93bd-f225fd8c6133

📥 Commits

Reviewing files that changed from the base of the PR and between 82658ee and 80322f0.

📒 Files selected for processing (1)
  • packages/fedify/src/federation/middleware.test.ts

@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented May 2, 2026

@codex review

@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented May 2, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the mapActorAlias() method to the ActorCallbackSetters interface, allowing developers to map fixed paths to specific actor identifiers. This feature enables instance-level actors, such as relays or bots, to have clean URIs (e.g., /actor) without exposing internal sentinel identifiers. The implementation includes path validation, duplicate alias prevention, and updates to URI parsing and generation logic. Comprehensive documentation and tests for routing and WebFinger integration are also provided. I have no feedback to provide.

@dahlia dahlia requested a review from 2chanhaeng May 2, 2026 23:55
@dahlia dahlia requested a review from sij411 May 2, 2026 23:55
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

activitypub/interop Interoperability issues component/actor Actor dispatcher related component/federation Federation object related type/enhancement Improvements to existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support fixed-path actor dispatchers

2 participants