Skip to content

Cleaned up ActivityPub boot noise when sibling service is offline#28996

Draft
9larsons wants to merge 1 commit into
mainfrom
activitypub-dev-degrade
Draft

Cleaned up ActivityPub boot noise when sibling service is offline#28996
9larsons wants to merge 1 commit into
mainfrom
activitypub-dev-degrade

Conversation

@9larsons

Copy link
Copy Markdown
Contributor

Summary

In the default pnpm dev setup the sibling ActivityPub container isn't running, but Ghost's ActivityPubService.getWebhookSecret() still tries to hit http://localhost:2368/.ghost/activitypub/v1/site/ on boot. The dev Caddy gateway has no ACTIVITYPUB_PROXY_TARGET configured, so the request falls through to Ghost's frontend which returns an HTML 404 with status 200. res.json() then throws a SyntaxError parsing <!DOCTYPE ..., the catch logs ERROR Could not get webhook secret for ActivityPub ..., and initialiseWebhooks() then logs a second ERROR No webhook secret found - cannot initialise. Result: ~4 ERROR lines per nodemon boot for an expected dev-mode condition.

Changes

  • getWebhookSecret() now discriminates on the error type:
    • FetchError (network failure) and SyntaxError (HTML masquerading as JSON) → log a single INFO with actionable wording and return null
    • anything else is rethrown so real production failures still surface
  • The !secret branch in initialiseWebhooks() no longer re-logs — the upstream already covered it
  • activity-pub-service-wrapper.js's configureActivityPub() got a try/catch so rethrown errors are logged at the wrapper level instead of becoming unhandled promise rejections (previously the all-swallowing catch made this safe)

Test plan

  • Unit tests cover all three branches: FetchError silent, SyntaxError silent, unexpected error rethrown
  • Unit test pins the no-double-log contract on the !secret path
  • pnpm lint clean in ghost/core
  • All 9 tests in activity-pub-service.test.ts pass

Caddy-side polish (deferred)

The audit also flagged that Caddy could 503 /.ghost/activitypub/* when ACTIVITYPUB_PROXY_TARGET is unset, preventing the HTML-as-JSON fallthrough at the gateway layer. The Ghost-side fix here makes the noise go away regardless of what Caddy returns, so the gateway change is left for a separate PR.

no ref

- getWebhookSecret() classified an expected dev-mode condition (sibling
  ActivityPub container not running) as ERROR with a confusing FetchError
  / SyntaxError stack trace, then logged a phantom follow-up ERROR from
  the !secret branch in initialiseWebhooks(); ~4 red lines per boot
- now catches FetchError (network failure) and SyntaxError (HTML
  fallthrough from Caddy → Ghost frontend) and logs a single INFO with
  actionable wording; everything else rethrows so production failures
  still surface
- the wrapper's configureActivityPub() previously relied on
  getWebhookSecret swallowing all errors; added a try/catch so rethrown
  errors are logged at the wrapper level instead of becoming unhandled
  rejections
- unit tests cover all three branches (FetchError silent, SyntaxError
  silent, unexpected error rethrown) plus the !secret no-double-log
  contract
@nx-cloud

nx-cloud Bot commented Jun 30, 2026

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit a84512e

Command Status Duration Result
nx run ghost:test:ci:integration ✅ Succeeded 2m 36s View ↗
nx run ghost:test:integration ✅ Succeeded 2m 46s View ↗
nx run-many --target=build --projects=tag:publi... ✅ Succeeded 2s View ↗
nx run ghost:test:legacy ✅ Succeeded 2m 13s View ↗
nx run ghost:test:e2e ✅ Succeeded 2m 25s View ↗
nx run-many -t lint -p ghost ✅ Succeeded 34s View ↗
nx run-many -t test:unit -p ghost ✅ Succeeded 30s View ↗
nx run @tryghost/admin:build ✅ Succeeded 5s View ↗
Additional runs (2) ✅ Succeeded ... View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-30 12:10:12 UTC

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7951f216-2b58-454e-9c10-14566071fc1c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch activitypub-dev-degrade

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

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant