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)
Tracking
(Not tracked)
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)
| Assignee | ||
Comment 2•2 years ago
|
||
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.
Comment 3•2 years ago
|
||
: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.
| Assignee | ||
Comment 4•2 years ago
|
||
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.
| Assignee | ||
Comment 5•2 years ago
|
||
I've deployed a fix to Lando that avoids this issue for uplift revisions. In short:
- For each uplifted revision, query
differential.querydiffsto get the alternative diff response format. - Find the most recent non-
commitdiff on Phabricator and return that as the diff to use for creating the uplift revision. Diffs with acreationMethodofcommitwill have empty binary files, but othercreationMethod's work as expected. - Query Phabricator to get the
differential.diff.searchresponse format for the returned diff, since the existing code expects data from that response. - Pass the contents of the
differential.querydiffsresponse along to the code that parses the raw diff fromdifferential.getrawdiff. When a binary file change is encountered, re-use the metadata from thedifferential.querydiffsresponse. This adds a link between thechangesobject 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.
Comment 6•2 years ago
|
||
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.
| Assignee | ||
Comment 7•2 years ago
|
||
We should probably apply the logic from comment 5 to regular landings as well.
Comment 8•2 years ago
|
||
FYI, we hit this issue again today for a pdf file reset to a 0 size when uplifting Bug 1912500
Comment 9•1 year ago
|
||
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
| Assignee | ||
Comment 10•1 year ago
|
||
(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 | ||
Updated•6 months ago
|
Comment 11•6 months ago
|
||
| Assignee | ||
Comment 12•6 months ago
|
||
I deployed my PR to Phabricator-dev and ran a reproduction of the bug on D4105:
- Initial diff contains the binary content as expected.
- Commit created by initial landing contains the binary content as expected.
- Diff created while processing initial landing contains the binary content as expected.
- Commit is backed out, the revision is re-opened.
- Commit is re-landed without any changes, the binary/image content is non-empty in the subsequent landing.
- Diff created by second landing also contains the expected binary content.
We will land and deploy the PR tomorrow.
Comment 13•6 months ago
|
||
Authored by https://github.com/cgsheeh
https://github.com/mozilla-conduit/phabricator/commit/9192587da78cd36a16e0767be3d0ae78af78dde2
[master] Bug 1865760: upload binary files to commit diffs (#87)
Description
•