Closed Bug 1865760 Opened 2 years ago Closed 6 months ago

Revisions created after a landing on phabricator sometimes don't match neither what the patch was before the landing nor what landed

Categories

(Conduit :: Phabricator, defect)

defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: glandium, Assigned: sheehan)

References

(Depends on 1 open bug)

Details

Attachments

(1 external file)

Concrete example: https://phabricator.services.mozilla.com/D188673
Diff id 777519 is what lando operated on. It's what landed.
Diff id 777524 is what was recorded as the landing. It's different from diff id 777519, in that all binary files are empty.
Diff id 789018 is a relanding attempt, presumably identical to diff id 777524, except, well, it's bogus, because by asking a relanding, I was expecting the same thing that landed the first time to land. (and it thankfully visibly broke the build)

Component: General → Phabricator
Duplicate of this bug: 1867510
See Also: → 1709608

I did some investigation around this. Looking at the differential.querydiffs API output response for a revision that hits this bug, you can see differences between the diffs created by moz-phab and the diffs created when a revision lands in the repo. The former has a creationMethod of moz-phab-hg, and the latter has a creationMethod of commit. Then, in the "changes" object that corresponds to the file, you can see that for a moz-phab-hg diff, the metadata object contains some extra information about the binary, including a PHID that points to a file object in Phabricator. For a changes object created by a commit, the metadata object is instead an empty list. I believe this missing metadata is the source of the empty binary files in Phabricator.

Example changes object for a diff created by moz-phab:

{
        "id": "7062701",
        "metadata": {
          "old:binary-phid": null,
          "old:file:size": 0,
          "old:file:mime-type": "",
          "new:binary-phid": "PHID-FILE-kz6liay6wbz3isrm4bgy",
          "new:file:size": 1024,
          "new:file:mime-type": "audio/x-wav",
          "hash.effect": "rV3hKCon1ogp"
        },
        "oldPath": null,
        "currentPath": "dom/media/webaudio/test/waveformatextensible.wav",
        "awayPaths": [],
        "oldProperties": [],
        "newProperties": {
          "unix:filemode": "100644"
        },
        "type": "1",
        "fileType": "3",
        "commitHash": null,
        "addLines": "0",
        "delLines": "0",
        "hunks": []
      },

And a changes object built by a commit:

      {
        "id": "7064830",
        "metadata": [],
        "oldPath": "dom/media/webaudio/test/waveformatextensible.wav",
        "currentPath": "dom/media/webaudio/test/waveformatextensible.wav",
        "awayPaths": [],
        "oldProperties": [],
        "newProperties": {
          "unix:filemode": "100644"
        },
        "type": "1",
        "fileType": "3",
        "commitHash": null,
        "addLines": "0",
        "delLines": "0",
        "hunks": []
      },

You can see this output yourself by going to the differential.querydiffs endpoint and passing [192850] in the revisionIDs field.

Looking into the source code for Phabricator, we can see the DifferentialDiffExtractionEngine.php file is where the commit created diffs originate. This function gathers the raw diff from Phabricator, parses the diff into changes objects with ArcanistDiffParser->parseDiff, then creates a new diff and saves it, which associates it with the revision. Right before saving the diff, there is a TODO about attaching binary files. So it looks like we need to complete this TODO.

After more searching, it looks like there is already an existing PHP function in Arcanist that can do this for us, ArcanistDiffWorkflow::uploadFilesForChanges. This function takes an array of changes objects (which will already exist for us in the ArcanistDiffParser), filters out any non-binary changes, uploads the binary content to Phabricator as files, and attaches all the missing metadata into each changes object it acts upon. It appears this is the missing piece of the puzzle! The only complication here is that the ArcanistDiffWorkflow is intended to be run as a command in arc, not necessarily used as a library within Phabricator. There are a few places that ask for input on the command line when an error is hit, for example, but aside from that it doesn't appear there would be any major issues with using this piece of code explicitly for that function. I think the best path forward is to paper over those command line prompts (with a new argument like no_prompt etc) and add a call to this function right before we save the new diff parsed from the repository.

An alternative option could be to just re-implement the binary file upload with Phabricator APIs like ConduitCall and attach the metadata to the changes objects directly. We could use the moz-phab implementation as a reference. I think using the ArcanistDiffWorkflow::uploadFilesForChanges would be the least error-prone, assuming we can confirm it works after testing on Phab-dev/suite.

:sheehan while the solution is under investigation, is there any way to prevent the rev from being created if there is any binary data detected?
We can manually uplift those changes, but we sometimes don't realize the mismatch until after we see failures in CI.

Flags: needinfo?(sheehan)

I'm unable to test the fix to Phabricator due to bug 1868612 at the moment.

As a stopgap, I'll take a look at making Lando avoid using a diff if there is an empty binary file attached.

Depends on: 1868612
Flags: needinfo?(sheehan)

I've deployed a fix to Lando that avoids this issue for uplift revisions. In short:

  • For each uplifted revision, query differential.querydiffs to get the alternative diff response format.
  • Find the most recent non-commit diff on Phabricator and return that as the diff to use for creating the uplift revision. Diffs with a creationMethod of commit will have empty binary files, but other creationMethod's work as expected.
  • Query Phabricator to get the differential.diff.search response format for the returned diff, since the existing code expects data from that response.
  • Pass the contents of the differential.querydiffs response along to the code that parses the raw diff from differential.getrawdiff. When a binary file change is encountered, re-use the metadata from the differential.querydiffs response. This adds a link between the changes object for the binary file and an existing upload of the file on Phabricator via the file's PHID.

The issue of binary files emptying on a regular mozilla-central revision after backout is still ongoing.

I think I ran into this issue on https://phabricator.services.mozilla.com/D216814 and https://phabricator.services.mozilla.com/D216815. I had a binary file for some unit tests (just a zip file). It looks like the binary data got wiped out after a backout. main--some-collection.zip ended up being empty and had to be recreated. I think my sheriff ended up having to manually fix it for landing.

We should probably apply the logic from comment 5 to regular landings as well.

FYI, we hit this issue again today for a pdf file reset to a 0 size when uplifting Bug 1912500

(In reply to Mathieu Leplatre [:leplatrem] from comment #9)

FWIW I had a patch with a binary attachment (.json.lz4) that was backed out, and I didn't hit this bug :)

https://phabricator.services.mozilla.com/D216338
https://hg.mozilla.org/integration/autoland/rev/173c877bf8da
https://hg.mozilla.org/mozilla-central/rev/173c877bf8da

This is because in each of those cases, you updated the revision with a new diff before re-landing. You probably updated the diff using the existing copy you had in your local clone, which still had the binary file data available. If you had done a moz-phab patch + edit something + moz-phab submit, or just re-landed the patch without any changes because it was backed out due to an irrelevant intermittent, you would have hit this bug. In your revision you can see that diffs which are created by commits to m-c (ie diff 15, 18 and 20) have empty binary content compared to the other diffs.

Assignee: nobody → sheehan

I deployed my PR to Phabricator-dev and ran a reproduction of the bug on D4105:

We will land and deploy the PR tomorrow.

Status: NEW → RESOLVED
Closed: 6 months ago
Resolution: --- → FIXED
Regressions: 2039366
See Also: → 2037822
No longer regressions: 2039366
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: