~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/pds.js

An atproto PDS in JavaScript, for Cloudflare Workers and Node

0
0

A space write answers before its notices go out

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/pds.js:spaces/notify-after-answer

What changes

A space write answers before its notices go out.

  • core: ExtensionHost.background(work) runs work after the response and logs any error from it. A platform passes waitUntil to the server to keep itself running until that work ends.
  • cloudflare: waitUntil is the Durable Object's state.waitUntil.
  • spaces:
    • In the account's own space, the notices to the space's syncers go out through background.
    • In another account's space, outbox.deliver saves the notice first. Only its first try goes through background, and a failed try is retried from the alarm as before.
    • Without background, both run before the answer.
  • notify and outbox: each notice gives up after 3 s (NOTICE_TIMEOUT_MS). A notice to another space's owner that times out is retried.

Why

knotless-serve's organization writes waited 1.7 to 2.7 s on each space.applyWrites, measured from its outgoing-call trace in prod. The PDS awaited the notifyWrite to knotless-serve, the space's syncer, before it answered. knotless-serve meanwhile was resolving a DID on plc.directory to check the notice. So one slow syncer made every write into the space as slow as itself, and with no timeout there was no limit on how slow.

How it was checked

  • npm run ci passes: biome, both typechecks, and 3238 tests within the coverage floors.
  • New tests:
    • A write into the account's own space answers before the syncers' notices are sent, and they are sent afterwards.
    • A write into another account's space saves the notice before answering and delivers it after.
    • The host hands background work to the platform, with any error caught and logged, and runs it with no platform hook.
    • The notice fetches carry an abort signal.

Shortcomings

  • If a Durable Object is evicted mid-send, the notice to its own space's syncers is lost. That notice was always best effort, and a syncer catches up on its next walk.
  • manage.js's forwarding of a received notifyWrite to the syncers still runs before its answer. Its caller is another PDS's outbox, not a person waiting.

🤖 Generated with Claude Code

chadtmiller.com added 1 commit
Merged as a8d1361