Thanks for the report. This was a genuine bug on our side, not something you were doing wrong.
Your code was correct, and so was your expectation: filling a canvas red and then clearing an inset rectangle should leave a red border with the centre cleared out, exactly as you described.
What was happening: ClearRectangle was queued correctly, but internally it was implemented by drawing a fully transparent rectangle over the area. Under normal source-over compositing, drawing a fully transparent shape onto existing pixels is a no-op so the red fill underneath was never actually removed, and you just saw a solid red square.
What changed: ClearRectangle now genuinely erases the rectangular region on the rendering surface. It operates in the same coordinate space as your drawing, so transforms, clipping, and command order are all respected. The area you clear is removed, and what shows through is the canvas background - including the Backdrop image when one is set. On picture surfaces, the cleared area becomes transparent.
The fix will be in the next Studio release: https://feedback.objo.dev/bug/1139