Records Architecture decision

ADR-106

Discover the Neighborhood on the Server

Partially superseded Decided 2026-09-25 Source file

Partially superseded by ADR-128, which serves Neighborhood images through the remote image proxy. Server-side discovery remains current.

Context

FDR-042 kept the server passive. The server stored Neighbor origins, and the browser contacted each advertised server to load its directory, profile, logo, and banner. Each contacted server could see the user's IP address. The Server Directory therefore asked for consent before its first discovery request. The browser also had to schedule and limit a recursive crawl for each page session.

Each registered server already knows the user's IP address. When a registered server contacts other servers for the user, no additional server sees that address.

Decision

Each Chatto server discovers its own Neighborhood in the background and publishes the cached result through the public ServerDiscoveryService.ListNeighborhoodServers RPC. A call to this RPC reads only the cache. It never starts a remote request. A caller cannot supply a URL, so the RPC is not a general proxy.

A discovery pass applies the FDR-042 rules on the server:

  • It starts from the server's own Neighbors and lists each direct Neighbor whose public profile loads.
  • It reads a direct Neighbor's directory. It expands that Neighbor only when the Neighbor advertises the server back.
  • It lists a recommended server when that server advertises the recommending server back. It follows at most two mutual hops.
  • It removes duplicate canonical origins and records every mutual recommender.

One pass permits at most 150 directory requests and 120 profile requests, with six active requests and a ten-second timeout for each request. It reads at most 100 origins from one remote directory and ignores advertised origins longer than 300 bytes. It truncates the stored name, version, and description.

The server uses the link-preview HTTP client for discovery requests. That client checks each resolved address when it connects and rejects loopback, private, and link-local addresses. Discovery rejects redirects. It accepts a logo or banner from any public HTTP or HTTPS host, because a server builds its image URLs from its configured webserver.url and that host can differ from the advertised origin. It resolves a relative image URL against the advertised origin. ADR-128 fetches, processes, and serves the images.

The latest directory is one cache_state.v1.NeighborhoodDirectory value under neighborhood.directory in MEMORY_CACHE. Each image record holds the absolute source URL. ListNeighborhoodServers returns each image as a signed, server-relative remote image path (ADR-128). The client resolves the path against the origin that it called, also when the server does not configure that origin.

Every replica runs one worker that checks the directory every five seconds. A check reads the directory and compares a hash of its Neighbor set with the local Neighbor projection. A pass is due when the directory is missing or one hour old. It is also due after ten minutes when a remote request failed in the previous pass, and after ten seconds when the Neighbor set changed. Every replica sees a Neighbor change through its projection, so no change signal is necessary. After a failed check, the replica waits one minute.

With no Neighbors, the check publishes an empty directory directly. This also clears old results after the last Neighbor is removed. With one or more Neighbors, all replicas enqueue the same JOBS job for the same due directory. Its ID uses the cache revision and broker timestamp. On a cold cache, the first check creates an empty entry so a new cache has its own job identity. Public reads return no directory until the first pass completes. A worker checks the generation before it crawls and updates only that revision. If the writer stops after enqueue, any replica can finish the job. After a failed job attempt, the first retry waits one minute. Each subsequent failure doubles the delay up to thirty minutes. Retries continue until the job succeeds or a newer cache generation supersedes it.

Consequences

  • A client can show the Neighborhood without a consent step and without contacting unregistered servers. Joining a server still contacts that server because the user starts that action.
  • The server now makes outbound requests to its Neighbors and their mutual recommendations. Operators who block outbound traffic get an empty or partial Neighborhood.
  • Discovery rejects servers on private network addresses. A Neighborhood of internal servers is not available through this RPC.
  • A remote server receives requests once per discovery pass from each recommending server, not once per user visit. A worker crash before publication can repeat requests on retry.
  • Results can be up to one hour old. A Neighbor change appears within about fifteen seconds. A server that was unavailable during a pass can return after about ten minutes.
  • A NATS restart removes the memory-backed directory. The next check starts a new pass. Backups exclude ASSET_CACHE and the legacy NEIGHBORHOOD_IMAGES.
  • The bundled Server Directory merges the Neighborhoods of all registered servers and removes its browser crawl and consent prompt. It accepts cached images only from the registered server that supplied them.
  • This supersedes FDR-042 Design Decisions 3 and 12. The Neighbor administration page also reads public profiles from the cached Neighborhood (FDR-042 Design Decision 16).

Shared cache update (2026-10-08)

Resized images and Neighborhood images share ASSET_CACHE to reduce replicated NATS resources. Its TTL is fixed at seven days. The core.assets.cache configuration section and its environment variables are removed. The existing configuration loader still accepts unknown settings, but they have no effect.

New replicas do not create or write NEIGHBORHOOD_IMAGES. Discovery regenerates the images in the shared cache. Missing images during cache rebuilds and mixed version operation are acceptable. The directory protobuf and public image URLs keep their existing content hashes without the storage prefix.

The server does not delete the old bucket. An operator can remove it after all replicas use the new version. Until then, older replicas can still use it and apply their configured TTL to ASSET_CACHE. The fixed TTL takes full effect after the rollout. Both cache buckets remain excluded from backups.

Remote image proxy (2026-11-23)

ADR-128 replaces the image copies of this decision. Discovery no longer keeps content-addressed copies under neighborhood_image.{sha256} or rewrites them, and the /assets/neighborhood/{sha256} route is removed. The remote image proxy fetches, caches, and serves the images when a client shows them. Image fetches now follow redirects; the SSRF-safe client checks every address that a redirect reaches.

Records that name this record

Esc