Incorrect panel order after API request to /dashboards/db

After submitting a dashboard model through the API (/dashboards/db), the order of panels specified in the request is lost and panels are ordered seemingly randomly.

This is a big issues, because for uncollapsed rows the row/panel relationship is determined purely by the panel order. For example, I send the following model:

panel type=row
panel a
panel b
panel c
panel type=row collapsed=true
     subpanels of the collapsed row

But the resulting dashboard has:

panel type=row
panel a
panel type=row collapsed=true
     subpanels of the collapsed row
panel b
panel c

Meaning that panels b and c are no longer under the first row.

Is it a bug? Is there a way to preserve the order? Or to be able to always include panels as subfield of rows (it does not work for non-collapsed rows)?

Could it be related to gridPos? We don’t specify y, is that an issue? Docs say that all panels automatically gravitate upwards.