Disambiguating sidecar records

Continuing from Extending Lexicons: sidecar records patterns and typed extensions and Connecting records, web pages and apps - #13 by essentialrandom.bsky.social, one need emerged: how can we create “sidecar records” that disambiguate between different collections they refer to?

For example, the new proposed lexicon community.lexicon.meta.links can be used as a standalone sidecar record to point to URLs that are associated with a record:

  • app.bsky.feed.post/3mzf6i2ckhc24 ⇒ bluesky post
  • community.lexicon.meta.links/3mzf6i2ckhc24 ⇒ web-wide URLs associated with the bluesky post record

Two issues:

  1. Given community.lexicon.meta.links/3mzf6i2ckhc24 there’s no way to know which record it refers to (is it a Bluesky post? A standard site record?)
  2. Two records with the same rkey cannot have different community.lexicon.meta.links

These have the same rootcause: rkeys are only unique within a collection, and nothing says anything more about their subject.

Same rkey, different record (#2)

@snarfed.org and I were trying to figure out how common #2 is as a case (outside of records like self), so I got some data on lexicons that would fall into this. If you’re curious why this is needed, open up:

Examples of non-self/non-tid records include...
  • org.tangled.repo.declaration ⇒ repo name
  • place.wisp.domain ⇒ domain of the wisp site
  • app.bsky.feed.generator ⇒ name of the feed
  • at.marque.domain ⇒ bought domain
  • fund.at.dependency ⇒ dependency to fund

These rkey can all easily be the same but have different URLs to point to. For example, someone’s tangled repo could have the same name as a feed they run, which could have the same name as a wisp site they own.

Other found:

  • org.tangled.graph.follow (DID)
  • com.bsky38.influential.vote (DID)
  • Various that use dates (e.g. health tracking app, daily logs, annual surveys) or even numbers (e.g. advent calendar)
  • Wallets addresses

Even with just self (shoutout to someone who has 86 different records with a self rkey), those records are often profiles with their own URL, and it’s possible to add others that would point at those records. For example, my site could have different “about me” pages for e.g. my streamer profiles, or atmosphere conference profile, etc. Without a way to differentiate these records, there’s no way to express that.

Proposal: Unambiguous Sidecar Record Key

We should decide on an algorithm for sidecar lexicons that includes NSID, so it’s possible for a sidecar record to refer to a specific item.

Proposal:

  1. We take the NSID + rkey of the record you want to sidecar, e.g. app.bsky.feed.post/3mzf6i2ckhc24
  2. We replace / with :, in this case app.bsky.feed.post:3mzf6i2ckhc24
  3. That key indicates a sidecar record of app.bsky.feed.post/3mzf6i2ckhc24

Since NSIDs cannot contain :, the first : in an rkey shaped like this always delineates the end of the NSID portion (e.g. com.example.test:record_key:with_a_twist, has NSID com.example.test and record key record_key:with_a_twist).

The only issue would be a NSID + record key that grows past 512 characters (the current limit). If we want to support that case, we could hash the result like sha256:[hash of collection:rkey] to maintain uniqueness. This is rare: even with a maximum-length NSID (317) the subject’s rkey would need to be around 195 characters, and TID-keyed records are 13 chars at most.

See:

Complementary option:

  • Retaining a backward sidecar record ⇒ original record ref, so we can always disambiguate (but that creates a “first come, first linked” situation, where a sidecar lexicon not setup for multiple entries will only be able to target one).

TL;Dr:

If we agree on how to calculate a sidecar record rkey, anyone can then getRecord a record’s sidecar directly without indexing, a backlink service, scanning the whole repo, or knowing that the record they’re looking at is meant to be a sidecar of a specific record. This avoids ambiguity and makes it easier for sidecar mechanisms to be discovered in the wild.

1 Like