Skip to content

Conversation

@dahlia
Copy link
Member

@dahlia dahlia commented Jan 27, 2026

Summary

This PR exposes the orderingKey capability through the sendActivity() API, allowing applications to ensure ordered delivery of related activities and prevent race conditions like “zombie posts” (where Delete arrives before Create).

Closes #536.

Changes

  • Add orderingKey option to SendActivityOptions interface
  • Pass orderingKey through fanout and outbox message queues
  • Transform orderingKey to ${orderingKey}\n${inboxOrigin} at outbox stage for per-server ordering while maintaining cross-server parallelism
  • Add documentation for the new feature
  • Add unit tests for orderingKey behavior

Usage

await ctx.sendActivity(
  { identifier: "alice" },
  recipients,
  create,
  { orderingKey: post.id }
);

// Later, the Delete will be delivered after Create
await ctx.sendActivity(
  { identifier: "alice" },
  recipients,
  delete_,
  { orderingKey: post.id }
);

This change exposes the orderingKey capability (added in PR fedify-dev#540) through
the sendActivity() API, allowing applications to ensure ordered delivery
of related activities.

fedify-dev#536

Co-Authored-By: Claude <[email protected]>
@dahlia dahlia added this to the Fedify 2.0 milestone Jan 27, 2026
@dahlia dahlia requested a review from Copilot January 27, 2026 06:44
@dahlia dahlia added the component/federation Federation object related label Jan 27, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @dahlia, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the sendActivity() API by adding an orderingKey option. This allows applications to ensure that related activities are delivered in the correct order, preventing race conditions. The changes include modifications to the SendActivityOptions interface, message queue handling, and documentation, along with new unit tests to verify the behavior of the orderingKey feature.

Highlights

  • Ordering Key Option: Introduces the orderingKey option to SendActivityOptions for ensuring ordered delivery of related activities.
  • Fanout and Outbox Message Queues: Passes the orderingKey through fanout and outbox message queues to maintain order.
  • Per-Server Ordering: Transforms orderingKey to ${orderingKey}\n${inboxOrigin} at the outbox stage for per-server ordering while maintaining cross-server parallelism.
  • Documentation and Unit Tests: Adds documentation and unit tests for the new orderingKey feature.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
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 orderingKey option to SendActivityOptions, enabling ordered delivery of related activities to prevent race conditions. The changes include updating the SendActivityOptions interface, modifying message queue structures (FanoutMessage, OutboxMessage), and implementing the ordering logic within FederationImpl and InProcessMessageQueue. Comprehensive unit tests have been added to validate the new orderingKey behavior across different fanout scenarios. The documentation has also been updated to reflect this new capability and its usage. The implementation correctly handles the transformation of orderingKey for per-server ordering and gracefully falls back to individual enqueues when enqueueMany does not support per-message ordering keys, ensuring robust and correct behavior.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR threads an orderingKey through the sendActivity() pipeline so that related activities can be processed sequentially per recipient server, reducing race conditions like “zombie posts”, and documents/tests this behavior.

Changes:

  • Extend FanoutMessage, OutboxMessage, and SendActivityOptions to include an optional orderingKey, and propagate it through fanout and outbox queues.
  • In the outbox path, derive a per-recipient-server key (${orderingKey}\n${inboxOrigin}) to maintain ordering per remote origin while allowing cross-server parallelism.
  • Add documentation and tests that describe and verify orderingKey behavior and update the changelog to announce the new option.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/fedify/src/federation/queue.ts Adds an optional orderingKey field to FanoutMessage and OutboxMessage so queued messages can carry ordering metadata end-to-end.
packages/fedify/src/federation/middleware.ts Wires orderingKey through fanout and outbox processing, implements per-recipient-server ordering keys, and adjusts the internal options passed into FederationImpl.sendActivity().
packages/fedify/src/federation/middleware.test.ts Extends ContextImpl.sendActivity() tests to assert the orderingKey is preserved for fanout messages, transformed for outbox messages, and omitted when not specified.
packages/fedify/src/federation/context.ts Exposes SendActivityOptions.orderingKey (with docs) and marks several existing options as readonly.
docs/manual/send.md Documents how to use SendActivityOptions.orderingKey, including typical use cases and the per-server transformation behavior.
CHANGES.md Notes the new SendActivityOptions.orderingKey option in the unreleased changes and links it to the relevant issues/PRs.

@codecov
Copy link

codecov bot commented Jan 27, 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/middleware.ts 95.31% <100.00%> (+0.07%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

dahlia and others added 2 commits January 27, 2026 17:04
Mirror the Promise.allSettled + aggregated logging approach used in
the enqueueMany == null branch, so that all enqueue failures are
reported with the same level of detail regardless of whether
enqueueMany is used.

fedify-dev#544 (comment)

Co-Authored-By: Claude <[email protected]>
@dahlia dahlia requested a review from Copilot January 27, 2026 08:13
@dahlia
Copy link
Member Author

dahlia commented Jan 27, 2026

/gemini review

Copy link
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 orderingKey option to the SendActivityOptions interface, enabling ordered delivery of related activities. The changes include modifications to CHANGES.md, docs/manual/send.md, packages/fedify/src/federation/context.ts, packages/fedify/src/federation/middleware.test.ts, packages/fedify/src/federation/middleware.ts, and packages/fedify/src/federation/queue.ts. The code review identified a potential high-severity issue related to error handling in packages/fedify/src/federation/middleware.ts where the orderingKey is specified, and enqueueMany is not supported. This comment is retained as it does not conflict with the provided rules.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Since orderingKey is now available on ForwardActivityOptions via the
Omit<SendActivityOptions, "fanout"> alias, forwardActivityInternal()
should also support it to maintain consistency with sendActivity().

fedify-dev#544 (comment)

Co-Authored-By: Claude <[email protected]>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@dahlia dahlia merged commit ce1bdc2 into fedify-dev:main Jan 27, 2026
36 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/federation Federation object related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Activities can be delivered out of order, causing federation issues

1 participant