Skip to content

Add configurable distribution modes for federation delivery#3044

Open
pfefferle wants to merge 13 commits intotrunkfrom
add/distribution-mode-setting
Open

Add configurable distribution modes for federation delivery#3044
pfefferle wants to merge 13 commits intotrunkfrom
add/distribution-mode-setting

Conversation

@pfefferle
Copy link
Copy Markdown
Member

Fixes #2672

Proposed changes:

  • Add a "Distribution Mode" setting to the Advanced Settings page with four presets: Default (100/batch, 30s pause), Balanced (50/batch, 60s pause), Eco (20/batch, 5min pause), and Custom (manual configuration).
  • Wire the presets into the existing activitypub_dispatcher_batch_size and activitypub_scheduler_async_batch_pause filters so admins can tune federation delivery speed without code.
  • Add ACTIVITYPUB_DISTRIBUTION_MODE constant for wp-config.php override (hides the UI when set).

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

  • Go to Settings > ActivityPub > Advanced.
  • Verify the "Distribution Mode" setting appears as the first field.
  • Select each mode (Default, Balanced, Eco, Custom) and save — verify the page reloads with the correct selection preserved.
  • Select "Custom", enter custom values for batch size and pause, save — verify the values are preserved.
  • Verify the Custom fields toggle visibility when switching between Custom and other modes.
  • Define ACTIVITYPUB_DISTRIBUTION_MODE as 'eco' in wp-config.php — verify the UI field is hidden and Eco mode values are used.

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch

Type

  • Added - for new features

Message

Add a Distribution Mode setting to control how quickly posts are delivered to followers.

Adds a "Distribution Mode" setting to the Advanced Settings page with
four presets (Default, Balanced, Eco, Custom) that control batch size
and pause between batches for federation delivery. Includes a constant
override via ACTIVITYPUB_DISTRIBUTION_MODE in wp-config.php.

Fixes #2672
Copilot AI review requested due to automatic review settings March 17, 2026 09:56
@pfefferle pfefferle added the Enhancement New feature or request label Mar 17, 2026
@pfefferle pfefferle self-assigned this Mar 17, 2026
@pfefferle pfefferle requested a review from a team March 17, 2026 09:56
Copy link
Copy Markdown

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

Adds an admin-configurable “Distribution Mode” that controls federation delivery pacing via existing dispatcher/scheduler filters, with an optional wp-config.php constant override to enforce a mode and hide the UI.

Changes:

  • Adds an Advanced Settings “Distribution Mode” radio field with presets and custom batch/pause inputs.
  • Registers new options and wires delivery pacing into activitypub_dispatcher_batch_size and activitypub_scheduler_async_batch_pause.
  • Adds ACTIVITYPUB_DISTRIBUTION_MODE constant override and a changelog entry.

Reviewed changes

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

File Description
includes/wp-admin/class-advanced-settings-fields.php Adds the Distribution Mode settings UI, including custom input toggling.
includes/constants.php Defines ACTIVITYPUB_DISTRIBUTION_MODE for wp-config.php overrides.
includes/class-options.php Registers new settings and applies distribution mode to existing delivery pacing filters.
.github/changelog/3044-from-description Records the feature in the changelog.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread includes/wp-admin/class-advanced-settings-fields.php Outdated
Comment thread includes/class-options.php
Comment thread includes/class-options.php Outdated
Comment thread includes/class-options.php Outdated
Comment thread includes/class-options.php Outdated
Comment thread includes/wp-admin/class-advanced-settings-fields.php Outdated
@pfefferle pfefferle marked this pull request as draft March 17, 2026 10:21
@pfefferle pfefferle marked this pull request as draft March 17, 2026 10:21
- Fix inconsistent constant check: use `false ===` in both the UI
  visibility check and the option override
- Validate ACTIVITYPUB_DISTRIBUTION_MODE constant against allowed
  modes, falling back to 'default' for invalid values
- Centralize preset definitions in Options::get_distribution_modes()
  and reuse in both admin UI and parameter resolution
- Add static cache in get_distribution_params() to avoid rebuilding
  presets on every filter call during delivery
- Null-guard the custom fields DOM element in inline script
Use `use` statements at the top of files instead of inline
fully-qualified class names like \Activitypub\Options::method().
@github-actions github-actions Bot added the Docs label Mar 30, 2026
- Prevent batch size of 0 with max(1, absint()) sanitization.
- Default mode now passes through the incoming filter value so other
  plugins and constants are not silently overridden.
- Remove static cache from get_distribution_params() since get_option()
  is already cached by WordPress and the static var caused stale values.
- Add tests for presets, custom mode, sanitization, and filter behavior.
…stant

- Cap custom batch size at 500 and pause at 3600s to prevent
  accidental server overload via misconfiguration.
- Reject 'custom' as a valid ACTIVITYPUB_DISTRIBUTION_MODE constant
  value since its parameters are still DB-settable.
- Add tests for upper bound enforcement.
@pfefferle pfefferle marked this pull request as ready for review April 2, 2026 06:53
Default 15s, Balanced 30s, Eco 30s — the differentiation between
modes is now purely batch size (100/50/20). The previous 5min Eco
pause caused unreasonably long delivery times.
- Move the inline distribution-mode toggle script into
  assets/js/activitypub-distribution-mode.js and enqueue it alongside
  the settings field. Inline <script> blocks bypass WordPress asset
  management and break under strict CSP.
- Extract the constant-reading body of
  pre_option_activitypub_distribution_mode() into a new
  resolve_distribution_mode() helper so the wp-config lock path can be
  tested without redefining ACTIVITYPUB_DISTRIBUTION_MODE.
- Add three tests covering the resolver: valid presets are returned
  verbatim, 'custom' and bogus values fall back to 'default', and an
  unset constant leaves the pre-get value untouched.
- _doing_it_wrong() when ACTIVITYPUB_DISTRIBUTION_MODE is set to 'custom'
  or an unknown value. Silent fall-through to 'default' was hard for
  operators to diagnose in a misconfigured wp-config.php.
- Collapse the two get_option() calls inside filter_dispatcher_batch_size
  and filter_scheduler_batch_pause into one by returning 'mode' from
  get_distribution_params().
- Wrap the three register_setting() descriptions in __() so REST
  consumers and translators pick them up.
- Split the invalid-constant test to add setExpectedIncorrectUsage()
  around the two paths that now trigger the _doing_it_wrong() notice.
Custom mode fell back to batch_size=100, pause=30 when the custom
options had never been saved, even though the default preset uses
pause=15. Switching to custom now starts from the same numbers the
default preset advertises. Values come from
Options::get_distribution_modes()['default'] so there is one source of
truth going forward.

Existing sites that already saved a custom pause of 30 are unaffected —
the saved value still wins over the fallback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add configurable distribution modes for federation delivery

3 participants