snarfed / bridgy-fed

🌉 A bridge between decentralized social network protocols
https://fed.brid.gy
Creative Commons Zero v1.0 Universal
705 stars 34 forks source link

Bluesky => AP: post with link got converted to reply #1237

Closed snarfed closed 3 months ago

snarfed commented 3 months ago

This is a weird one, I still don't understand what happened. @mackuba replied (now deleted) to this Bluesky post with a link embed to this Mastodon post. When we converted that reply to AS2, we for some reason set inReplyTo to the linked Mastodon post, which is clearly wrong. I haven't been able to reproduce that bug locally yet.

Bluesky post record:

{
  "$type": "app.bsky.feed.post",
  "createdAt": "2024-08-05T21:38:18.901Z",
  "facets": [
    {
      "$type": "app.bsky.richtext.facet",
      "features": [{
        "$type": "app.bsky.richtext.facet#mention",
        "did": "did:plc:6x3sa4qcuhtc4yky2f6eu2ki"
      }],
      "index": {
        "byteEnd": 18,
        "byteStart": 0
      }
    },
    {
      "$type": "app.bsky.richtext.facet",
      "features": [{
        "$type": "app.bsky.richtext.facet#mention",
        "did": "did:plc:esmiuxk53vmsllayghrq676w"
      }],
      "index": {
        "byteEnd": 40,
        "byteStart": 19
      }
    },
    {
      "features": [{
        "$type": "app.bsky.richtext.facet#link",
        "uri": "https://mkultra.monster/@cmdr_nova/112909755730245873"
      }],
      "index": {
        "byteEnd": 105,
        "byteStart": 74
      }
    }
  ],
  "langs": ["en"],
  "reply": {
    "parent": {
      "cid": "bafyreibbho5r2wj7thdv3insxt234taukpeszhbqd3kukxlpzbonz35mhy",
      "uri": "at://did:plc:6x3sa4qcuhtc4yky2f6eu2ki/app.bsky.feed.post/3kyt3df7obk27"
    },
    "root": {
      "cid": "bafyreibssi2nwd4mwfw5youwqmjtpmayfnpviz6enb7lbhnvuh2qbauekm",
      "uri": "at://did:plc:oio4hkxaop4ao4wz2pp3f4cr/app.bsky.feed.post/3kyme6oeauk2j"
    }
  },
  "text": "@flaky.bsky.social @o.simardcasanova.net check out the last sentence here mkultra.monster/@cmdr_nova/1... \ud83e\udee0"
}

AP inbox delivery log with full AS2 activity:

Task 40390650995723039811
Params: [('obj', 'ahBicmlkZ3ktZmVkZXJhdGVkcmQLEgZPYmplY3QiWGF0Oi8vZGlkOnBsYzpvaW80aGt4YW9wNGFvNHd6MnBwM2Y0Y3IvYXBwLmJza3kuZmVlZC5wb3N0LzNreXl0emhpazYyMjQjYnJpZGd5LWZlZC1jcmVhdGUM'), ('orig_obj', 'ahBicmlkZ3ktZmVkZXJhdGVkckELEgZPYmplY3QiNWh0dHBzOi8vbWt1bHRyYS5tb25zdGVyL0BjbWRyX25vdmEvMTEyOTA5NzU1NzMwMjQ1ODczDA'), ('protocol', 'activitypub'), ('url', 'https://mkultra.monster/users/cmdr_nova/inbox'), ('user', 'ahBicmlkZ3ktZmVkZXJhdGVkci0LEgdBVFByb3RvIiBkaWQ6cGxjOm9pbzRoa3hhb3A0YW80d3oycHAzZjRjcgw')]
Sending activitypub post at://did:plc:oio4hkxaop4ao4wz2pp3f4cr/app.bsky.feed.post/3kyytzhik6224#bridgy-fed-create to https://mkultra.monster/users/cmdr_nova/inbox
Signing with did:plc:oio4hkxaop4ao4wz2pp3f4cr 's key
requests.post https://mkultra.monster/users/cmdr_nova/inbox {
  "id": "https://bsky.brid.gy/convert/ap/at://did:plc:oio4hkxaop4ao4wz2pp3f4cr/app.bsky.feed.post/3kyytzhik6224#bridgy-fed-create",
  "actor": "https://bsky.brid.gy/ap/did:plc:oio4hkxaop4ao4wz2pp3f4cr",
  "published": "2024-08-05T21:38:19.556403+00:00",
  "@context": "https://www.w3.org/ns/activitystreams",
  "type": "Create",
  "object": {
    "id": "https://bsky.brid.gy/convert/ap/at://did:plc:oio4hkxaop4ao4wz2pp3f4cr/app.bsky.feed.post/3kyytzhik6224",
    "url": "https://fed.brid.gy/r/https://bsky.app/profile/did:plc:oio4hkxaop4ao4wz2pp3f4cr/post/3kyytzhik6224",
    "content": "<p><a href=\"https://bsky.brid.gy/ap/did:plc:6x3sa4qcuhtc4yky2f6eu2ki\">@flaky.bsky.social</a> <a href=\"https://bsky.brid.gy/ap/did:plc:esmiuxk53vmsllayghrq676w\">@o.simardcasanova.net</a> check out the last sentence here <a href=\"https://mkultra.monster/@cmdr_nova/112909755730245873\">mkultra.monster/@cmdr_nova/1...</a> \\ud83e\\udee0</p>",
    "published": "2024-08-05T21:38:18.901Z",
    "contentMap": {
      "en": "@flaky.bsky.social @o.simardcasanova.net check out the last sentence here mkultra.monster/@cmdr_nova/1... \\ud83e\\udee0"
    },
    "attributedTo": "https://bsky.brid.gy/ap/did:plc:oio4hkxaop4ao4wz2pp3f4cr",
    "type": "Note",
    "inReplyTo": "https://mkultra.monster/users/cmdr_nova/statuses/112909755730245873",
    "tag": [
      {
        "type": "Mention",
        "name": "@flaky.bsky.social",
        "href": "https://bsky.brid.gy/ap/did:plc:6x3sa4qcuhtc4yky2f6eu2ki"
      },
      {
        "type": "Mention",
        "name": "@o.simardcasanova.net",
        "href": "https://bsky.brid.gy/ap/did:plc:esmiuxk53vmsllayghrq676w"
      },
      {
        "url": "https://mkultra.monster/@cmdr_nova/112909755730245873",
        "type": "Article",
        "name": "mkultra.monster/@cmdr_nova/1..."
      },
      {
        "type": "Mention",
        "href": "https://mkultra.monster/users/cmdr_nova"
      }
    ],
    "cc": [
      "https://mkultra.monster/users/cmdr_nova",
      "https://www.w3.org/ns/activitystreams#Public",
      "https://mkultra.monster/users/cmdr_nova/followers"
    ],
    "content_is_html": true,
    "to": [
      "https://www.w3.org/ns/activitystreams#Public"
    ]
  },
  "to": [
    "https://www.w3.org/ns/activitystreams#Public"
  ]
}
Received 202
snarfed commented 3 months ago

When I test the conversion locally, it doesn't have the bad inReplyTo:

o = Object.get_by_id('at://did:plc:oio4hkxaop4ao4wz2pp3f4cr/app.bsky.feed.post/3kyytzhik6224')
p(ActivityPub.convert(o))

{
  "@context": "https://www.w3.org/ns/activitystreams",
  "type": "Note",
  "id": "https://bsky.brid.gy/convert/ap/at://did:plc:oio4hkxaop4ao4wz2pp3f4cr/app.bsky.feed.post/3kyytzhik6224",
  "url": "https://fed.brid.gy/r/https://bsky.app/profile/did:plc:oio4hkxaop4ao4wz2pp3f4cr/post/3kyytzhik6224",
  "inReplyTo": {
    "id": "https://bsky.brid.gy/convert/ap/at://did:plc:6x3sa4qcuhtc4yky2f6eu2ki/app.bsky.feed.post/3kyt3df7obk27",
    "url": "https://bsky.app/profile/did:plc:6x3sa4qcuhtc4yky2f6eu2ki/post/3kyt3df7obk27"
  },
  "content": "<p><a href=\"https://bsky.brid.gy/ap/did:plc:6x3sa4qcuhtc4yky2f6eu2ki\">@flaky.bsky.social</a> <a href=\"https://bsky.brid.gy/ap/did:plc:esmiuxk53vmsllayghrq676w\">@o.simardcasanova.net</a> check out the last sentence here <a href=\"https://mkultra.monster/@cmdr_nova/112909755730245873\">mkultra.monster/@cmdr_nova/1...</a> \ud83e\udee0</p>",
  "published": "2024-08-05T21:38:18.901Z",
  "attributedTo": "https://bsky.brid.gy/ap/did:plc:oio4hkxaop4ao4wz2pp3f4cr",
  "tag": [{
      "type": "Mention",
      "name": "@flaky.bsky.social",
      "href": "https://bsky.brid.gy/ap/did:plc:6x3sa4qcuhtc4yky2f6eu2ki"
    },{
      "type": "Mention",
      "name": "@o.simardcasanova.net",
      "href": "https://bsky.brid.gy/ap/did:plc:esmiuxk53vmsllayghrq676w"
    },{
      "url": "https://mkultra.monster/@cmdr_nova/112909755730245873",
      "type": "Article",
      "name": "mkultra.monster/@cmdr_nova/1..."
    }
  ],
  "to": ["https://www.w3.org/ns/activitystreams#Public"],
  "content_is_html": true
}
mackuba commented 3 months ago

Reproduced!

1) https://hachyderm.io/@shreyan/112573306835667555 2) https://mastodon.social/@psionides/112916384545607094

In the second case I even got a notification on that Mastodon account 💀

Screen Shot 2024-08-06 at 20 07 34
snarfed commented 3 months ago

wowww. what the hell is even going on here 😠

mackuba commented 3 months ago

:p

mackuba commented 3 months ago

Uh… so… this happened again (nothing sensitive, can stay there), but this time also the whole subthread from Bluesky of people replying to my comment with the link got all sent there to that thread too! :O https://mastodon.social/@fediversecounter/112920443483887367

qazmlp commented 3 months ago

Uh… so… this happened again (nothing sensitive, can stay there), but this time also the whole subthread from Bluesky of people replying to my comment with the link got all sent there to that thread too! :O https://mastodon.social/@fediversecounter/112920443483887367

The latter part is expected after the initial fault, as ActivityPub replies only encode the direct parent.

(More specifically, Mastodon does keep track of threads in its database, but it resolves them on receipt of a reply by walking (fetching) backwards until it finds a post it already has. If that fails then the reply becomes permanently detached in some ways, iirc.)

snarfed commented 3 months ago

Found the problem here, the culprit is orig_obj passed through send tasks to ActivityPub.postprocess_as2. That method is a dark ugly corner of the codebase, especially its orig_obj usage. Trying to incrementally clean it up a bit now.

https://github.com/snarfed/bridgy-fed/blob/39aa16be6258d80ac619ae7c176f76e506a1f3d2/activitypub.py#L696-L700

snarfed commented 3 months ago

OK, fix here should be deployed in ~5m. Thanks and props again to @mackuba for catching and investigating this!

Also, re the root cause here, orig_obj is cursed. Gotta get rid of it. Not sure how, since most fediverse software still doesn't understand multiply-valued inReplyTo or object (eg https://funfedi.dev/support_tables/generated/in_reply_to/) ...but still, orig_obj is cursed. Gotta get rid of it.

mackuba commented 3 months ago

👻