Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] serialization of --windows sometimes yields invalid json #2533

Open
kvndrsslr opened this issue Feb 10, 2025 · 11 comments
Open

[bug] serialization of --windows sometimes yields invalid json #2533

kvndrsslr opened this issue Feb 10, 2025 · 11 comments
Labels
addressed on master; not released Fixed upstream, but not yet released bug Something isn't working

Comments

@kvndrsslr
Copy link

kvndrsslr commented Feb 10, 2025

yabai-v7.1.8

In yesterdays update a bug was introduced where yabai -m query --windows could return an array with a trailing comma, which is invalid and cannot be properly parsed by e.g. jq.

EDIT: After some testing I found that yabai -m query --windows --space 1 was valid, but yabai -m query --windows --space 2 had the trailing comma. I closed all apps that had windows in space 2 and reopened them, after that the problem was fixed.

EDIT2: I have found a way to reproduce the issue. If I close a window of an App that continues to run with 0 windows, the space seems to have this "ghost window" still in its state and that results in the trailing comma. This way, one can get multiple trailing commas too. Re-opening the window by clicking on the App icon resolves the bug. Reproduced in Slack and Teams.

@kvndrsslr kvndrsslr changed the title [bug] serialization of --windows query yields invalid json [bug] serialization of --windows sometimes yields invalid json Feb 10, 2025
@koekeishiya
Copy link
Owner

Hm I can't reproduce this issue using software such as Safari, Orion, Kitty. What do you use to get information about the so called "ghost window" that is still there? The trailing comma would likely be because https://github.com/koekeishiya/yabai/blob/master/src/window_manager.c#L48 window here is null somehow, but that is not really supposed to be possible.

@kvndrsslr
Copy link
Author

I am not familiar with systems programming nor the macOS APIs you use in yabai, therefore I can only speculate and experiment.

So far I was able to reproduce the error with Slack on two separate machines, an Intel iMac and an M2 Macbook.

Here's a short demo:

demo.mp4

I first thought the issue could stem from Electron, but a test with Obsidian did not result in the same error.

Another observation that might be interesting is the following:
Visually, closing the Slack window with CMD + W and reopening it is the same as hiding it with CMD + H and then un-hiding it.
However, for Obsidian there is a noticable delay before it renders the window contents after closing the window with CMD + W but it's as fast as Slack when hiding and un-hiding.

@koekeishiya
Copy link
Owner

koekeishiya commented Feb 10, 2025

If you enable debug output (either through the config file yabai -m config debug_output on, or by running yabai manually in a terminal yabai --verbose; https://github.com/koekeishiya/yabai/wiki/Configuration#debug-output-and-error-reporting), do you see either of these lines for Slack (instead of Safari that I am using as an example here)?

EVENT_HANDLER_APPLICATION_HIDDEN: Safari
EVENT_HANDLER_WINDOW_DESTROYED: Safari 14050

I'd prefer not to have to install Slack or Teams on my private machine, but maybe I'll have to do so.

I do have a way to fix the json output, but I'd like to figure out what is actually the root cause instead of patching something I don't exactly understand.

@kvndrsslr
Copy link
Author

The following is a sequence from the debug output which roughly corresponds to the order of operations shown in the demo above

  • Changing focus to Slack
  • CMD + W
  • Click on Teams to get focus (this is when the query output has the trailing comma and breaks my sketchybar)
  • Clicking the Slack icon in Dock
  • Returning to kitty to get the debug output

I have noticed that some events seem to be logged twice or even three times when in reality there should only be one of them.
For example, I have only ever closed and re-created the Slack Window once during this sequence.

EVENT_HANDLER_MOUSE_UP: 3840.23, 1034.49
EVENT_HANDLER_MOUSE_DOWN: 4161.54, 1006.30
EVENT_HANDLER_MOUSE_DRAGGED: 4161.30, 1006.30
EVENT_HANDLER_MOUSE_UP: 4161.30, 1006.30
EVENT_HANDLER_MOUSE_DOWN: -417.88, 844.52
EVENT_HANDLER_SLS_WINDOW_ORDERED: 73
EVENT_HANDLER_DISPLAY_CHANGED: 1 5
EVENT_HANDLER_APPLICATION_FRONT_SWITCHED: Slack (1361)
EVENT_HANDLER_MOUSE_UP: -417.88, 844.52
EVENT_HANDLER_DAEMON_MESSAGE: query --spaces
EVENT_HANDLER_DAEMON_MESSAGE: query --windows
EVENT_HANDLER_DAEMON_MESSAGE: query --windows --space 3
EVENT_HANDLER_DAEMON_MESSAGE: query --windows --space 2
EVENT_HANDLER_WINDOW_DESTROYED: Slack 73
EVENT_HANDLER_MOUSE_DOWN: -668.31, 935.58
EVENT_HANDLER_SLS_WINDOW_ORDERED: 83
EVENT_HANDLER_APPLICATION_FRONT_SWITCHED: Microsoft Teams (1357)
event_signal_flush: transmitting window_focused to 1 subscriber(s)
EVENT_HANDLER_WINDOW_DESTROYED: Slack 73
EVENT_HANDLER_MOUSE_DOWN: -668.31, 935.58
EVENT_HANDLER_SLS_WINDOW_ORDERED: 83
EVENT_HANDLER_APPLICATION_FRONT_SWITCHED: Microsoft Teams (1357)
EVENT_HANDLER_MOUSE_UP: -668.31, 935.58
EVENT_HANDLER_DAEMON_MESSAGE: query --spaces
EVENT_HANDLER_DAEMON_MESSAGE: query --windows
EVENT_HANDLER_MOUSE_DOWN: -879.75, 1252.98
EVENT_HANDLER_APPLICATION_FRONT_SWITCHED: Slack (1361)
window_manager_create_and_add_window:73 Slack - %REDACTED% (AXWindow:AXStandardWindow:1)
event_signal_flush: transmitting window_created to 1 subscriber(s)
EVENT_HANDLER_MOUSE_DOWN: -879.75, 1252.98
EVENT_HANDLER_APPLICATION_FRONT_SWITCHED: Slack (1361)
window_manager_create_and_add_window:73 Slack - %REDACTED% (AXWindow:AXStandardWindow:1)
EVENT_HANDLER_WINDOW_FOCUSED: Slack 73
event_signal_flush: transmitting window_focused to 1 subscriber(s)
EVENT_HANDLER_MOUSE_DOWN: -879.75, 1252.98
EVENT_HANDLER_APPLICATION_FRONT_SWITCHED: Slack (1361)
window_manager_create_and_add_window:73 Slack - %REDACTED% (AXWindow:AXStandardWindow:1)
EVENT_HANDLER_WINDOW_FOCUSED: Slack 73
EVENT_HANDLER_DAEMON_MESSAGE: query --spaces
EVENT_HANDLER_DAEMON_MESSAGE: query --windows
EVENT_HANDLER_DAEMON_MESSAGE: query --windows --space 3
EVENT_HANDLER_DAEMON_MESSAGE: query --windows --space 2
EVENT_HANDLER_MOUSE_DOWN: 3846.73, 828.29
EVENT_HANDLER_SLS_WINDOW_ORDERED: 65
EVENT_HANDLER_DISPLAY_CHANGED: 3 18
EVENT_HANDLER_APPLICATION_FRONT_SWITCHED: kitty (1355)
event_signal_flush: transmitting window_focused to 1 subscriber(s)
EVENT_HANDLER_MOUSE_DOWN: 3846.73, 828.29
EVENT_HANDLER_SLS_WINDOW_ORDERED: 65
EVENT_HANDLER_DISPLAY_CHANGED: 3 18
EVENT_HANDLER_APPLICATION_FRONT_SWITCHED: kitty (1355)
EVENT_HANDLER_MOUSE_DRAGGED: 3846.73, 828.05
EVENT_HANDLER_MOUSE_DRAGGED: 3846.73, 827.80
EVENT_HANDLER_MOUSE_UP: 3846.73, 827.80
EVENT_HANDLER_DAEMON_MESSAGE: query --spaces
EVENT_HANDLER_DAEMON_MESSAGE: query --windows
EVENT_HANDLER_DAEMON_MESSAGE: query --windows --space 3
EVENT_HANDLER_DAEMON_MESSAGE: query --windows --space 2

@smackesey
Copy link

Just want to add that I have this issue and I've seen both the trailing comma at the end of a list and also a double comma, suggesting that it is indeed null values resolving to empty strings.

@koekeishiya
Copy link
Owner

Can you downgrade to v7.1.6 and do the same exact steps. Instead of getting trailing commas you should instead get window output where has-ax-reference is false. It appears that some applications destroy their window, but create a substitute of some kind, and one of the APIs used by yabai picks up the substitute window.

@koekeishiya koekeishiya added the bug Something isn't working label Feb 11, 2025
@daviehh
Copy link

daviehh commented Feb 11, 2025

ran into this issue, where there are ,, in the list. Downgrading to 7.1.6 shows the one has-ax-reference false window is 1password "Quick Access — 1Password"

yabai -m query --windows | jq -r 'map(select(.["has-ax-reference"] == false))'

Confirmed w/ 7.1.8,

  • no 1password: ok
  • after opening the 1password quickwindow: errors (double ,, in list)

@koekeishiya
Copy link
Owner

Can you post more of the query output information, maybe such as layer/sub-layer and level/sub-level?

@daviehh
Copy link

daviehh commented Feb 11, 2025

full output of yabai -m query --windows | jq -r 'map(select(.["has-ax-reference"] == false))'

[
  {
    "id": 3038,
    "pid": 41263,
    "app": "1Password",
    "title": "Quick Access — 1Password",
    "scratchpad": "",
    "frame": {
      "x": 625.0000,
      "y": 277.0000,
      "w": 550.0000,
      "h": 108.0000
    },
    "role": "",
    "subrole": "",
    "root-window": true,
    "display": 1,
    "space": 1,
    "level": 101,
    "sub-level": 0,
    "layer": "unknown",
    "sub-layer": "normal",
    "opacity": 1.0000,
    "split-type": "none",
    "split-child": "none",
    "stack-index": 0,
    "can-move": false,
    "can-resize": false,
    "has-focus": false,
    "has-shadow": true,
    "has-parent-zoom": false,
    "has-fullscreen-zoom": false,
    "has-ax-reference": false,
    "is-native-fullscreen": false,
    "is-visible": false,
    "is-minimized": false,
    "is-hidden": false,
    "is-floating": false,
    "is-sticky": false,
    "is-grabbed": false
  }
]

no scripting addition/sip enabled

@koekeishiya
Copy link
Owner

Can you try the latest master?

@daviehh
Copy link

daviehh commented Feb 11, 2025

thanks for the quick fix, latest master solved it in my case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed on master; not released Fixed upstream, but not yet released bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants