You are reading content from Scuttlebutt
@SoapDog (Macbook Air M1) %ttoZPKcaQzXi5S0AGZHNaChGw0NSHkeCgDzYmI1hJMg=.sha256

This is going to be a different kind of post. I'm going to try to document live, how I proceed to debug and fix something on patchfox. The objective behind this is showing my poor debugging skills how approachable patchfox is from a coding point-of-view. Be aware that I'm not even sure I can fix this bug, or how hard it will be to fix it, that is why I think this is valuable. It is not a curated and sterille fixing-the-bug journal that is prepared after the fact and shows an idealised experience that is never reflected in reality, this will be ugly.

So what's the bug?

Basically there is something funky going on with the calendar.

The way it works — much like all other packages — is that calendar provides a specialised Card View to handle the message types it is interested in. The specific file is GatheringCard.svelte which is supposed to handle gathering messages flying by the timeline.

This bug is confusing because once Patchfox finds a gathering to display, it used ssb-gatherings to coalesce the data about it, so the gathering displays correctly even though some of the messages that compose that gathering don't.

To better illustrate this bug, look at the screenshot below:

Patchfox screenshot detailing the bug.

It was taken from the Public Timeline view, it shows a series of three messages related to the same gathering, but the third message is rendered as an unknown message.

What that indicates is that the validator for the message handlers in the Calendar package is wrong.

@SoapDog (Macbook Air M1) %BU9oWd20gX5er5nATO8AeTA5imJjJfvZJcuDoY4U8cQ=.sha256

calendar.js — patchfox 2021-05-24 14-38-01.png

Above there is a screenshot of the Calendar package declaration. I have highlighted the message validator for about messages used by that package, and clearly it is very naive. Not only it doesn't cover all the possible cases of updating a gathering, but also it might claim unrelated messages as it's own.

@SoapDog (Macbook Air M1) %8sRsz/K9oobWy6G9Dkpo401rttGBIdGhzKJD8EVqxaE=.sha256

correction, Patchfox uses scuttle-gathering to get the data not ssb-gathering which I guess doesn't exists.

@SoapDog (Macbook Air M1) %FdgTjSAi2RFY9BTLblyrG+5MovyVpUSpVYgYRS8W7p8=.sha256

I'm going to attempt to use ssb-gathering-schema to build a better validator.

For that I need to install it in the project with npm and import it into the package declaration for Calendar package. I'm mentioning this because this sometimes is where things go wrong. Some NodeJS modules used in our SSB ecosystem will attempt to load data from disk at runtime using NodeJS fs.* and path.* APIs. This is simply not available on a browser context, which means that either I can't use the package, or that I need to kick it until it browserifies correctly. I hope this will not be the case.

@SoapDog (Macbook Air M1) %poLnAJ33iO3keAdvabZzYj+TZAjn3/A6rnRbWhM/+d4=.sha256

So I installed things, hooked them up so that it would use isGatheringUpdate() from ssb-gathering-schema. It became this:

const GatheringCard = require("./GatheringCard.svelte")
const GatheringView = require("./GatheringView.svelte")
const TimelineView = require("./TimelineView.svelte");
const ExportView = require("./ExportView.svelte");
const GatheringActionCard = require("./GatheringActionCard.svelte");
const { isGathering, isGatheringUpdate, isAttendee } = require("ssb-gathering-schema") 

    name: "calendar",
    messageTypes: [
            type: "gathering",
            card: GatheringCard
          type: "about",
          card: GatheringActionCard,
          validator: msg => isGatheringUpdate(msg)
    gathering: GatheringView,
    timeline: TimelineView,
    export: ExportView,
    menu: {
        group: "Calendar",
        label: "Gatherings",
        items: [
            label: "Future Events",
            event: "package:go",
            data: {
              pkg: "calendar",
              view: "timeline"

And, of course, it already broke...

Patchfox - Public - 1621837007396 2021-05-24 14-54-26.png

Now it is the tricky part of understanding why this simple thing — something that we all expected to work — didn't work. I've been hurt by these bugs before and it is usually related to filesystem access.

This serves as a cautionary tale why the browser is a different environment than electron.

@SoapDog (Macbook Air M1) %i+TNyh5TRyVuRa7UmbIGzhFmyjypYGTmtGjoWy30Irk=.sha256

So the problem was not filesystem related. What is happening is that the README for that package is wrong. In it we have:

var { isGathering, isGatheringUpdate, isAttendee } = require('ssb-gathering-schema')

// => true

— Source:

Which makes you believe that there is a isGatheringUpdate function. That is not the case as can be seen in the index.js:

module.exports = {
  isGathering: require('./gathering/validator'),
  isUpdate: require('./gathering-update/validator'),
  isAttendee: require('./attendee/validator')

The function is actually called isUpdate() and not isGatheringUpdate(). The documentation is wrong. I'm gonna fix that documentation now.

@SoapDog (Macbook Air M1) %ONqXKjqtCO/BYVmW/XEqBTWDajQvPyHnoQhsMJOSdNM=.sha256

PR sent for documentation fix. Asked a review from @mixmix because that's the user GH suggested but anyone else in SSBC can do it. It is a simple fix for the documentation.

PS: This is part of how developing more clients help fix little bugs that add friction to SSB development

@SoapDog (Macbook Air M1) %pQx+PUzEylw7woUZUvcu16fAm2vabqS+2Sbr1PkiVWc=.sha256

That being said, the gathering message still failing to validate. I've changed the validator to output each call to console. In that view, there are two about messages, one is validating, the other isn't.

Patchfox - Public - 1621837007396 2021-05-24 15-12-22.png

I'm going to try to pinpoint why. I suspect that maybe ssb-gathering-schema will need a patch to validate that, or that maybe the message format is wrong on that specific message. That second case would be very odd as I believe both messages been generated by the same client.

@SoapDog (Macbook Air M1) %y70CIdmf+eVVOWCiCBruNMGCndDw73lI7dZXCv9X2Ds=.sha256

I'm guessing the message is actually wrong. As far as I know, about messages need to have an about field pointing to the message they're abouting. This message doesn't. The id for the message I'm talking about is: %nRjtqXP3znJKydH44OEbJ9AKmH3uPYFlscPR9+PqLDM=.sha256.

@cel-desktop sorry to disturb you over there, but I suspect you might have generated this message by hand and forgot to add an about field. Was that the case? Or, maybe I'm not fully understanding how these about messages work. Maybe you could help me figure out if that is valid message or not. :-)

User has not chosen to be hosted publicly
@SoapDog (Macbook Air M1) %A/ZkgsFKlnkSU9U0E0oszIIhks/vga1UopwWbWS9t58=.sha256

Thanks @tim :-) I always think no one reads these messages rsrsrs. I type them because some day in the future, someone will attempt to pick Patchfox and will stumble on some issue, and search for answers in SSB itself. I want these threads to be there when this future masochist archeologist starts spelunking Patchfox source-code.

User has not chosen to be hosted publicly
@cel %jLq6wPxKBobxr33dsRDRZCr6qBaQvifiPk1a0dPmEWI=.sha256

@SoapDog (Macbook Air)
The message was a mistake - sorry about that. I replied to it in %6Kfujf3... to link to the corrected one. I published directly from the patchfoo draft page instead of patchfoo's new gathering page, which accidentally resulted in publishing the single about message without the gathering first, instead of the gathering message and then the about message. :/

@SoapDog (Macbook Air M1) %UdOnDIonMMCTxbbRcHQDJR7n7v20oq8M4n4LOiPn2dA=.sha256

@cel, sorry, I didn't linked your reply about a mistaken message to the original message I was trying to debug. Patchfox doesn't show the reply relationships visually, so I missed it.

Sorry for pestering you about it when you clearly mentioned it on a reply to the original message :~~~

@SoapDog (Macbook Air M1) %oApDQXiT3O/ilyHH13DcWgdRN+ZmH0V2kWG2Ji1DKQ0=.sha256

End of work

I consider that job of fixing the bug done. In the end of this process, we got:

  • A PR to fix documentation on an upstream dependency.
  • A more robust validator for about messages in the Calendar package.

<3 <3 <3

Join Scuttlebutt now