Cannot force camera to face upwards above horizon

In our application we have a mechanism for sharing the initial view of a map. These parameters are saved and can be used to initialise another map, for example:

 "initialCamera": {
                "west": 133.12335073549156,
                "south": -42.38666970744262,
                "east": 156.35409851747534,
                "north": -31.55857883340345,
                "position": {
                    "x": -4120986.489101264,
                    "y": 2901296.804778211,
                    "z": -5529233.584392741
                },
                "direction": {
                    "x": -0.009963608676945457,
                    "y": 0.01443110436389694,
                    "z": 0.999846223040809
                },
                "up": {
                    "x": -0.8138296757070467,
                    "y": 0.580869360008338,
                    "z": -0.01649380314139365
                }
            },

However, it does not work when you try to share a camera orientation where orientation.direction.x is negative, i.e. where the camera is pointing upwards above the horizon.
Is there a way to make this work given the camera position information we record? I have made a sandcastle demo where this does not work. This is the view that should be set:

But instead we get this:

There might be some assumptions about the coordinate system in which the orientatation is given. I cannot provide “THE solution”, because that depends on which coordinate system you are using for the direction/up information. For example, you might have to transform your direction/up to accomodate for the transforms in directionUpToHeadingPitchRoll.

But the following sandcastle might be a small debug helper here:

When you press "c", then it will print to the console the current camera configuration. You can set the camera configuration that you want, press "c", and then use the printed code to restore that configuration. Maybe you can compute the desired configuration from your saved state.


Edited for completeness: The Camera snapshot functionality was inspired by https://github.com/CesiumGS/cesium/tree/main/Documentation/Contributors/PerformanceTestingGuide#pick-a-fixed-camera-view

Thanks very much for your help,
it turns out we are not reading the camera parameters correctly from Cesium in the rare case that the camera is facing upwards above the horizon. Thanks again!