Skip to content

Fix and clarify Cloudflare Workers documentation#669

Merged
dahlia merged 3 commits intofedify-dev:mainfrom
dahlia:docfix
Apr 9, 2026
Merged

Fix and clarify Cloudflare Workers documentation#669
dahlia merged 3 commits intofedify-dev:mainfrom
dahlia:docfix

Conversation

@dahlia
Copy link
Copy Markdown
Member

@dahlia dahlia commented Apr 9, 2026

Summary

This PR fixes a few immediate mismatches in the Cloudflare Workers documentation.

packages/cfworkers/README.md still showed outdated API usage, and docs/manual/deploy.md had a processQueuedTask() example that no longer matched the current signature. While updating those examples, this PR also documents the extra consumer-side step required when WorkersMessageQueue is used with orderingKey.

Changes

  • update packages/cfworkers/README.md to use createFederation(), federation.fetch(), and the current processQueuedTask(contextData, message) signature
  • fix the same processQueuedTask() mismatch in docs/manual/deploy.md
  • fix the broken InProcessMessageQueue anchor in docs/manual/deploy.md
  • document orderingKv and WorkersMessageQueue.processMessage() in docs/manual/mq.md, and link back to that guidance from docs/manual/deploy.md and packages/cfworkers/README.md

Why

These examples are easy to copy into real projects, so small mismatches matter. The old federation.handle() call and the stale processQueuedTask() example can send readers to APIs that no longer exist or no longer accept those arguments. The ordering-key note closes a separate gap between the published docs and the current WorkersMessageQueue implementation.

Verification

This is a docs-only change. I cross-checked the updated examples against the current implementations in packages/fedify/src/federation/federation.ts and packages/cfworkers/src/mod.ts.

dahlia and others added 3 commits April 9, 2026 19:16
Update the Cloudflare Workers README snippet to use the
current federation API. The example now imports
createFederation, calls federation.fetch(), and passes
context data and a Message value to processQueuedTask().

AI-assisted with Codex for drafting and editing the
documentation changes; reviewed in the workspace.

Co-Authored-By: OpenAI Codex <noreply@openai.com>
Correct the Cloudflare Workers deployment example to
match the processQueuedTask() signature and repair the
broken InProcessMessageQueue anchor in the same guide.

AI-assisted with Codex for drafting and editing the
documentation changes; reviewed in the workspace.

Co-Authored-By: OpenAI Codex <noreply@openai.com>
Explain the extra queue consumer step needed for
ordering keys on Cloudflare Workers. The manual,
deployment guide, and package README now point users
to orderingKv and WorkersMessageQueue.processMessage().

AI-assisted with Codex for drafting and editing the
documentation changes; reviewed in the workspace.

Co-Authored-By: OpenAI Codex <noreply@openai.com>
@issues-auto-labeler issues-auto-labeler bot added component/build Build system and packaging component/federation Federation object related component/mq Message queue related labels Apr 9, 2026
@dahlia dahlia self-assigned this Apr 9, 2026
@dahlia dahlia requested a review from Copilot April 9, 2026 10:23
@dahlia dahlia added type/documentation Improvements or additions to documentation runtime/cfworkers Cloudflare Workers runtime related and removed component/federation Federation object related component/build Build system and packaging labels Apr 9, 2026
@dahlia dahlia added this to the Fedify 2.2 milestone Apr 9, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c81e0a34-dd2f-4ae8-9802-44a30600317d

📥 Commits

Reviewing files that changed from the base of the PR and between 4104661 and 85fc4b8.

📒 Files selected for processing (3)
  • docs/manual/deploy.md
  • docs/manual/mq.md
  • packages/cfworkers/README.md

📝 Walkthrough

Walkthrough

Documentation updates for Cloudflare Workers message queue handling, including corrected documentation links, reordered function arguments in examples, and new guidance on using orderingKey with WorkersMessageQueue configuration and processing.

Changes

Cohort / File(s) Summary
Cloudflare Workers Documentation
docs/manual/deploy.md, docs/manual/mq.md
Corrected documentation link for InProcessMessageQueue, added instructions for queue ordering keys requiring orderingKv namespace configuration and explicit WorkersMessageQueue.processMessage() calls, with full TypeScript example of queue handler implementation.
Cloudflare Workers README
packages/cfworkers/README.md
Updated import statements to use createFederation and type Message, changed fetch handler method names, adjusted queue message processing to include env argument and explicit typing, and added documentation note on supporting orderingKey via WorkersMessageQueue configuration.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title clearly and concisely summarizes the main change: fixing and clarifying Cloudflare Workers documentation. It is specific, directly related to the changeset, and avoids vague terms.
Description check ✅ Passed The pull request description is well-structured and directly related to the changeset, providing clear context for the documentation fixes and new content additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

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

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

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 support for best-effort message ordering on Cloudflare Workers by allowing the use of an ordering KV namespace with WorkersMessageQueue. It updates the documentation to explain the new process of calling WorkersMessageQueue.processMessage() before Federation.processQueuedTask(), and includes minor refactors to the Cloudflare Workers example code to improve consistency and correctness. I have no feedback to provide as the changes are well-documented and follow the established patterns.

Copy link
Copy Markdown
Contributor

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 updates Cloudflare Workers-related documentation to match the current Fedify APIs, correcting outdated examples and adding guidance for queue ordering keys when using WorkersMessageQueue.

Changes:

  • Update Cloudflare Workers examples to use createFederation(), federation.fetch(), and the current Federation.processQueuedTask(contextData, message) signature.
  • Fix a broken InProcessMessageQueue anchor in the deployment manual.
  • Add documentation about orderingKv / WorkersMessageQueue.processMessage() for best-effort ordering-key handling, and link to the detailed guidance.

Reviewed changes

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

File Description
packages/cfworkers/README.md Updates Workers example code and adds an ordering-key note for WorkersMessageQueue.
docs/manual/mq.md Documents ordering-key consumption flow with WorkersMessageQueue.processMessage() and orderingKv.
docs/manual/deploy.md Fixes anchor + updates processQueuedTask() usage and adds a link to ordering-key guidance.

Comment on lines +41 to +43
await federation.processQueuedTask(
env,
message.body as unknown as Message,
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

WorkersMessageQueue.enqueue() wraps queued bodies in a { __fedify_payload__: ... } envelope (and optionally __fedify_ordering_key__). Passing message.body directly to Federation.processQueuedTask() will therefore hand it the wrapper object (missing type, id, traceContext, etc.) and can fail at runtime. Unwrap first via WorkersMessageQueue.processMessage(message.body) and pass result.message to processQueuedTask() (even when not using ordering keys).

Suggested change
await federation.processQueuedTask(
env,
message.body as unknown as Message,
const result = WorkersMessageQueue.processMessage(message.body);
await federation.processQueuedTask(
env,
result.message,

Copilot uses AI. Check for mistakes.
Comment on lines +111 to +113
> `Federation.processQueuedTask()`. This acquires and releases the best-effort
> ordering lock for that key. You can also customize the lock behavior with
> the `orderingKeyPrefix` and `orderingLockTtl` options.
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

This note says processMessage() “acquires and releases” the ordering lock, but processMessage() only acquires and returns a release callback; callers must invoke result.release?.() (typically in a finally) to actually release the lock. Consider updating the wording to avoid implying the lock is released automatically.

Suggested change
> `Federation.processQueuedTask()`. This acquires and releases the best-effort
> ordering lock for that key. You can also customize the lock behavior with
> the `orderingKeyPrefix` and `orderingLockTtl` options.
> `Federation.processQueuedTask()`. This acquires the best-effort ordering
> lock for that key and returns a `release` callback; call
> `result.release?.()` after processing the message, typically in a `finally`
> block. You can also customize the lock behavior with the
> `orderingKeyPrefix` and `orderingLockTtl` options.

Copilot uses AI. Check for mistakes.
Comment thread docs/manual/mq.md
Comment on lines +612 to +613
> `Federation.processQueuedTask()`. Otherwise, the ordering key is embedded in
> the message, but not enforced when the worker consumes it.
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

This note implies processMessage() will enforce ordering by itself, but it only returns a release callback for the acquired lock; the consumer must call result.release?.() after processing to release it. Consider explicitly mentioning the required release call so readers don’t accidentally leak locks until TTL expiration.

Suggested change
> `Federation.processQueuedTask()`. Otherwise, the ordering key is embedded in
> the message, but not enforced when the worker consumes it.
> `Federation.processQueuedTask()`. `processMessage()` does not enforce
> ordering by itself; it returns a result that includes a `release` callback
> for the acquired ordering lock, and you must call `result.release?.()`
> after processing the message (preferably in a `finally` block). Otherwise,
> the ordering key is embedded in the message, but not enforced correctly
> when the worker consumes it, and the lock may remain held until its TTL
> expires.

Copilot uses AI. Check for mistakes.
Comment thread docs/manual/deploy.md
Comment on lines 291 to 296
for (const message of batch.messages) {
try {
await federation.processQueuedTask(
message.body as unknown as Message,
env,
message.body as unknown as Message,
);
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

The manual queue() example passes message.body directly into Federation.processQueuedTask(), but WorkersMessageQueue wraps outgoing bodies in a { __fedify_payload__: ... } envelope (and possibly __fedify_ordering_key__). Without unwrapping via WorkersMessageQueue.processMessage(message.body), processQueuedTask() will receive the wrapper object and can fail at runtime.

Copilot uses AI. Check for mistakes.
Comment thread docs/manual/deploy.md
Comment on lines +306 to +311
If you use queue ordering keys on Cloudflare Workers, instantiate
`WorkersMessageQueue` with an `orderingKv` namespace and call
`WorkersMessageQueue.processMessage()` before
`Federation.processQueuedTask()`. See the
[*`WorkersMessageQueue`* section](./mq.md#workersmessagequeue-cloudflare-workers-only)
for a complete example and caveats about best-effort ordering.
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

This paragraph suggests WorkersMessageQueue.processMessage() is only needed when using ordering keys, but processMessage() is also what unwraps the { __fedify_payload__: ... } envelope used for queue messages. As written, readers may skip processMessage() and pass the wrapped body to processQueuedTask(), leading to runtime errors. Consider rephrasing to recommend processMessage() for all consumed messages, with orderingKv being the extra requirement to enforce ordering locks.

Copilot uses AI. Check for mistakes.
Comment thread docs/manual/mq.md
Comment on lines +608 to +613
> If you use `~MessageQueueEnqueueOptions.orderingKey` with
> `WorkersMessageQueue`, you also need to provide a KV namespace for ordering
> locks and pass each raw queue message through
> `~WorkersMessageQueue.processMessage()` before calling
> `Federation.processQueuedTask()`. Otherwise, the ordering key is embedded in
> the message, but not enforced when the worker consumes it.
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

This note frames WorkersMessageQueue.processMessage() as only necessary when orderingKey is used, but processMessage() is also what unwraps the { __fedify_payload__: ... } envelope used for queued messages. If readers skip processMessage() for non-ordered messages, they may pass the wrapped body into Federation.processQueuedTask() and hit runtime errors. Update the wording to recommend processMessage() for all consumed messages, and mention orderingKv as the additional requirement to enforce ordering locks.

Suggested change
> If you use `~MessageQueueEnqueueOptions.orderingKey` with
> `WorkersMessageQueue`, you also need to provide a KV namespace for ordering
> locks and pass each raw queue message through
> `~WorkersMessageQueue.processMessage()` before calling
> `Federation.processQueuedTask()`. Otherwise, the ordering key is embedded in
> the message, but not enforced when the worker consumes it.
> When consuming messages from `WorkersMessageQueue`, always pass each raw
> queue message through `~WorkersMessageQueue.processMessage()` before
> calling `Federation.processQueuedTask()`. This unwraps the queued payload
> format and, when present, applies ordering metadata. If you use
> `~MessageQueueEnqueueOptions.orderingKey` with `WorkersMessageQueue`, you
> also need to provide a KV namespace for ordering locks; otherwise, the
> ordering key is embedded in the message, but not enforced when the worker
> consumes it.

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.
see 1 file 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 merged commit c094e49 into fedify-dev:main Apr 9, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/mq Message queue related runtime/cfworkers Cloudflare Workers runtime related type/documentation Improvements or additions to documentation

Development

Successfully merging this pull request may close these issues.

2 participants