zellij-org / zellij

A terminal workspace with batteries included
https://zellij.dev
MIT License
21.99k stars 669 forks source link

Sixel support broken since v0.40.0 #3372

Open Zettexe opened 6 months ago

Zettexe commented 6 months ago

Basic information

zellij --version: zellij 0.40.0, zellij 0.40.1

stty size: 76 157

uname -av or ver(Windows): Linux zettnet-desktop 6.1.87 #1-NixOS SMP PREEMPT_DYNAMIC Wed Apr 17 09:18:29 UTC 2024 x86_64 GNU/Linux

zellij.log:

INFO   |zellij_client            | 2024-05-23 14:05:30.463 [main      ] [zellij-client/src/lib.rs:178]: Starting Zellij client! 
INFO   |zellij_server            | 2024-05-23 14:05:30.469 [main      ] [zellij-server/src/lib.rs:281]: Starting Zellij server! 
WARN   |zellij_server::route     | 2024-05-23 14:05:30.472 [server_router] [zellij-server/src/route.rs:1025]: Server not ready, trying to place instruction in retry queue... 
WARN   |zellij_server::route     | 2024-05-23 14:05:30.472 [server_router] [zellij-server/src/route.rs:1126]: Server ready, retrying sending instruction. 
WARN   |zellij_server::route     | 2024-05-23 14:05:30.472 [server_router] [zellij-server/src/route.rs:1025]: Server not ready, trying to place instruction in retry queue... 
WARN   |zellij_server::route     | 2024-05-23 14:05:30.472 [server_router] [zellij-server/src/route.rs:1034]: Server not ready, trying to place instruction in retry queue... 
WARN   |zellij_server::route     | 2024-05-23 14:05:30.472 [server_router] [zellij-server/src/route.rs:1126]: Server ready, retrying sending instruction. 
WARN   |zellij_server::route     | 2024-05-23 14:05:30.472 [server_router] [zellij-server/src/route.rs:1034]: Server not ready, trying to place instruction in retry queue... 
WARN   |zellij_server::route     | 2024-05-23 14:05:30.472 [server_router] [zellij-server/src/route.rs:1045]: Server not ready, trying to place instruction in retry queue... 
WARN   |zellij_server::route     | 2024-05-23 14:05:30.472 [server_router] [zellij-server/src/route.rs:1126]: Server ready, retrying sending instruction. 
WARN   |zellij_server::route     | 2024-05-23 14:05:30.472 [server_router] [zellij-server/src/route.rs:1045]: Server not ready, trying to place instruction in retry queue... 
WARN   |zellij_server::route     | 2024-05-23 14:05:30.472 [server_router] [zellij-server/src/route.rs:1056]: Server not ready, trying to place instruction in retry queue... 
WARN   |zellij_server::route     | 2024-05-23 14:05:30.472 [server_router] [zellij-server/src/route.rs:1126]: Server ready, retrying sending instruction. 
WARN   |zellij_server::route     | 2024-05-23 14:05:30.472 [server_router] [zellij-server/src/route.rs:1056]: Server not ready, trying to place instruction in retry queue... 
WARN   |zellij_server::route     | 2024-05-23 14:05:30.472 [server_router] [zellij-server/src/route.rs:1056]: Server not ready, trying to place instruction in retry queue... 
WARN   |zellij_server::route     | 2024-05-23 14:05:30.472 [server_router] [zellij-server/src/route.rs:1126]: Server ready, retrying sending instruction. 
WARN   |zellij_server::route     | 2024-05-23 14:05:30.472 [server_router] [zellij-server/src/route.rs:1056]: Server not ready, trying to place instruction in retry queue... 
WARN   |zellij_server::route     | 2024-05-23 14:05:30.472 [server_router] [zellij-server/src/route.rs:1056]: Server not ready, trying to place instruction in retry queue... 
INFO   |zellij_server            | 2024-05-23 14:05:30.472 [main      ] [zellij-server/src/lib.rs:1058]: Compiling plugins using Cranelift 
INFO   |zellij_server::plugins   | 2024-05-23 14:05:30.473 [wasm      ] [zellij-server/src/plugins/mod.rs:200]: Wasm main thread starts 
WARN   |zellij_utils::input::layo| 2024-05-23 14:05:30.474 [wasm      ] [zellij-utils/src/input/layout.rs:105]: Overriding plugin alias 
WARN   |zellij_utils::input::layo| 2024-05-23 14:05:30.474 [wasm      ] [zellij-utils/src/input/layout.rs:105]: Overriding plugin alias 
ERROR  |zellij_utils::input::layo| 2024-05-23 14:05:30.474 [screen    ] [zellij-utils/src/input/layout.rs:1089]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
ERROR  |zellij_utils::input::layo| 2024-05-23 14:05:30.479 [screen    ] [zellij-utils/src/input/layout.rs:1089]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
WARN   |zellij_server::route     | 2024-05-23 14:05:30.481 [server_router] [zellij-server/src/route.rs:1126]: Server ready, retrying sending instruction. 
INFO   |zellij_utils::input::plug| 2024-05-23 14:05:30.482 [async-std/runti] [zellij-utils/src/input/plugins.rs:139]: Plugin 'tab-bar.wasm' exists in the 'PLUGIN DIR' at '/home/zettexe/.local/share/zellij/plugins/' but is being ignored 
INFO   |zellij_utils::input::plug| 2024-05-23 14:05:30.482 [async-std/runti] [zellij-utils/src/input/plugins.rs:139]: Plugin 'status-bar.wasm' exists in the 'PLUGIN DIR' at '/home/zettexe/.local/share/zellij/plugins/' but is being ignored 
ERROR  |zellij_utils::input::layo| 2024-05-23 14:05:30.482 [screen    ] [zellij-utils/src/input/layout.rs:1089]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
ERROR  |zellij_utils::input::layo| 2024-05-23 14:05:30.483 [screen    ] [zellij-utils/src/input/layout.rs:1089]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
INFO   |zellij_server::plugins::p| 2024-05-23 14:05:30.492 [async-std/runti] [zellij-server/src/plugins/plugin_loader.rs:518]: Loaded plugin 'tab-bar' from cache folder at '/home/zettexe/.cache/zellij' in 8.545652ms 
INFO   |zellij_server            | 2024-05-23 14:05:30.492 [async-std/runti] [zellij-server/src/lib.rs:1058]: Compiling plugins using Cranelift 
ERROR  |zellij_utils::input::layo| 2024-05-23 14:05:30.504 [screen    ] [zellij-utils/src/input/layout.rs:1089]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
ERROR  |zellij_utils::input::layo| 2024-05-23 14:05:30.504 [screen    ] [zellij-utils/src/input/layout.rs:1089]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
INFO   |zellij_server::plugins::p| 2024-05-23 14:05:30.509 [async-std/runti] [zellij-server/src/plugins/plugin_loader.rs:518]: Loaded plugin 'status-bar' from cache folder at '/home/zettexe/.cache/zellij' in 23.70576ms 
INFO   |zellij_server            | 2024-05-23 14:05:30.509 [async-std/runti] [zellij-server/src/lib.rs:1058]: Compiling plugins using Cranelift 
ERROR  |zellij_utils::input::layo| 2024-05-23 14:05:30.519 [screen    ] [zellij-utils/src/input/layout.rs:1089]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
ERROR  |zellij_utils::input::layo| 2024-05-23 14:05:30.519 [screen    ] [zellij-utils/src/input/layout.rs:1089]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
WARN   |zellij_server::panes::gri| 2024-05-23 14:05:30.570 [screen    ] [zellij-server/src/panes/grid.rs:2436]: Unhandled osc: [[55], [102, 105, 108, 101, 58, 47, 47, 122, 101, 116, 116, 110, 101, 116, 45, 100, 101, 115, 107, 116, 111, 112, 47, 104, 111, 109, 101, 47, 122, 101, 116, 116, 101, 120, 101]] 
WARN   |zellij_server::panes::gri| 2024-05-23 14:05:32.601 [screen    ] [zellij-server/src/panes/grid.rs:3074]: Unhandled esc_dispatch: 92->[] 
INFO   |zellij_server::plugins   | 2024-05-23 14:05:33.522 [wasm      ] [zellij-server/src/plugins/mod.rs:734]: wasm main thread exits 
ERROR  |zellij_utils::input::layo| 2024-05-23 14:05:33.522 [screen    ] [zellij-utils/src/input/layout.rs:1089]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
ERROR  |zellij_utils::input::layo| 2024-05-23 14:05:33.522 [screen    ] [zellij-utils/src/input/layout.rs:1089]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
INFO   |zellij_client            | 2024-05-23 14:05:33.522 [main      ] [zellij-client/src/lib.rs:533]: Bye from Zellij! 
ERROR  |zellij_server::os_input_o| 2024-05-23 14:05:33.522 [screen    ] [zellij-server/src/os_input_output.rs:915]: Failed to apply cached resizes: failed to send message to pty writer 
INFO   |zellij_server::plugins::w| 2024-05-23 14:05:33.522 [wasm      ] [zellij-server/src/plugins/wasm_bridge.rs:282]: Bye from plugin 0 
ERROR  |zellij_server::os_input_o| 2024-05-23 14:05:33.522 [screen    ] [zellij-server/src/os_input_output.rs:904]: Failed to cache resizes: failed to send message to pty writer 
ERROR  |zellij_server::os_input_o| 2024-05-23 14:05:33.522 [screen    ] [zellij-server/src/os_input_output.rs:915]: Failed to apply cached resizes: failed to send message to pty writer 
ERROR  |zellij_utils::errors::not| 2024-05-23 14:05:33.522 [async-std/runti] [zellij-utils/src/errors.rs:652]: Panic occured:
             thread: async-std/runtime
             location: At zellij-server/src/pty.rs:987:30
             message: Program terminates: a fatal error occured

Caused by:
    0: failed to spawn terminals for layout
    1: failed to listen for bytes from PTY
    2: failed to async-send to screen
    3: failed to send message to screen
    4: Originating Thread(s)

    5: failed to send message to channel: PtyBytes(
           0,
           [
               13,
               10,
           ],
       ) 
INFO   |zellij_server::plugins::w| 2024-05-23 14:05:33.522 [wasm      ] [zellij-server/src/plugins/wasm_bridge.rs:282]: Bye from plugin 1 

Issue description

v0.40.0 and v0.40.1 are completely unable to render Sixels even if they report as being capable. This is tested in the foot terminal with confirmed working Sixels.

Other relevant information

Additionally I have looked at every version up until v0.31.0 (The version Sixel support was added) and concluded that in every version 0.31.0 -> 0.39.2 Sixels are rendered with twice the height they should and do not get cleared properly as shown in #3173

manueldeprada commented 4 months ago

I add some things I noticed, in case its helpful:

  1. The issue does not occur the first time zellij is launched. Removing ~/.cache/zellij solves the issue for the next zellij launch.
  2. If you try a few times, even without removing the cache, sometimes it works, randomly. I paste here both a log for when it works and when it doesn't in case it helps. This is zellij 0.40.1.

Working:

INFO   |zellij_client            | 2024-07-08 17:44:48.028 [main      ] [zellij-client/src/lib.rs:178]: Starting Zellij client! 
INFO   |zellij_server            | 2024-07-08 17:44:48.032 [main      ] [zellij-server/src/lib.rs:284]: Starting Zellij server! 
INFO   |zellij_server            | 2024-07-08 17:44:48.086 [main      ] [zellij-server/src/lib.rs:1068]: Compiling plugins using Cranelift 
INFO   |zellij_server::plugins   | 2024-07-08 17:44:48.087 [wasm      ] [zellij-server/src/plugins/mod.rs:203]: Wasm main thread starts 
WARN   |zellij_utils::input::layo| 2024-07-08 17:44:48.088 [wasm      ] [zellij-utils/src/input/layout.rs:105]: Overriding plugin alias 
ERROR  |zellij_utils::input::layo| 2024-07-08 17:44:48.089 [screen    ] [zellij-utils/src/input/layout.rs:1088]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
ERROR  |zellij_utils::input::layo| 2024-07-08 17:44:48.094 [screen    ] [zellij-utils/src/input/layout.rs:1088]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
ERROR  |zellij_utils::input::layo| 2024-07-08 17:44:48.099 [screen    ] [zellij-utils/src/input/layout.rs:1088]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
ERROR  |zellij_utils::input::layo| 2024-07-08 17:44:48.100 [screen    ] [zellij-utils/src/input/layout.rs:1088]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
INFO   |zellij_server::plugins::p| 2024-07-08 17:44:48.110 [async-std/runti] [zellij-server/src/plugins/plugin_loader.rs:533]: Loaded plugin 'compact-bar' from cache folder at '/home/prada/.cache/zellij' in 9.852545ms 
INFO   |zellij_server            | 2024-07-08 17:44:48.110 [async-std/runti] [zellij-server/src/lib.rs:1068]: Compiling plugins using Cranelift 
ERROR  |zellij_utils::input::layo| 2024-07-08 17:44:48.115 [screen    ] [zellij-utils/src/input/layout.rs:1088]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
ERROR  |zellij_utils::input::layo| 2024-07-08 17:44:48.116 [screen    ] [zellij-utils/src/input/layout.rs:1088]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" }

Not working:

INFO   |zellij_client            | 2024-07-08 17:42:22.222 [main      ] [zellij-client/src/lib.rs:178]: Starting Zellij client! 
INFO   |zellij_server            | 2024-07-08 17:42:22.225 [main      ] [zellij-server/src/lib.rs:284]: Starting Zellij server! 
INFO   |zellij_server            | 2024-07-08 17:42:22.279 [main      ] [zellij-server/src/lib.rs:1068]: Compiling plugins using Cranelift 
WARN   |zellij_server::route     | 2024-07-08 17:42:22.280 [server_router] [zellij-server/src/route.rs:1037]: Server not ready, trying to place instruction in retry queue... 
INFO   |zellij_server::plugins   | 2024-07-08 17:42:22.280 [wasm      ] [zellij-server/src/plugins/mod.rs:203]: Wasm main thread starts 
WARN   |zellij_server::route     | 2024-07-08 17:42:22.280 [server_router] [zellij-server/src/route.rs:1138]: Server ready, retrying sending instruction. 
WARN   |zellij_server::route     | 2024-07-08 17:42:22.280 [server_router] [zellij-server/src/route.rs:1037]: Server not ready, trying to place instruction in retry queue... 
WARN   |zellij_server::route     | 2024-07-08 17:42:22.280 [server_router] [zellij-server/src/route.rs:1037]: Server not ready, trying to place instruction in retry queue... 
WARN   |zellij_server::route     | 2024-07-08 17:42:22.280 [server_router] [zellij-server/src/route.rs:1138]: Server ready, retrying sending instruction. 
WARN   |zellij_server::route     | 2024-07-08 17:42:22.280 [server_router] [zellij-server/src/route.rs:1037]: Server not ready, trying to place instruction in retry queue... 
WARN   |zellij_server::route     | 2024-07-08 17:42:22.280 [server_router] [zellij-server/src/route.rs:1046]: Server not ready, trying to place instruction in retry queue... 
WARN   |zellij_server::route     | 2024-07-08 17:42:22.280 [server_router] [zellij-server/src/route.rs:1138]: Server ready, retrying sending instruction. 
WARN   |zellij_utils::input::layo| 2024-07-08 17:42:22.282 [wasm      ] [zellij-utils/src/input/layout.rs:105]: Overriding plugin alias 
ERROR  |zellij_utils::input::layo| 2024-07-08 17:42:22.282 [screen    ] [zellij-utils/src/input/layout.rs:1088]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
ERROR  |zellij_utils::input::layo| 2024-07-08 17:42:22.287 [screen    ] [zellij-utils/src/input/layout.rs:1088]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
ERROR  |zellij_utils::input::layo| 2024-07-08 17:42:22.290 [screen    ] [zellij-utils/src/input/layout.rs:1088]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
ERROR  |zellij_utils::input::layo| 2024-07-08 17:42:22.292 [screen    ] [zellij-utils/src/input/layout.rs:1088]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
INFO   |zellij_server::plugins::p| 2024-07-08 17:42:22.302 [async-std/runti] [zellij-server/src/plugins/plugin_loader.rs:533]: Loaded plugin 'compact-bar' from cache folder at '/home/prada/.cache/zellij' in 8.298075ms 
INFO   |zellij_server            | 2024-07-08 17:42:22.302 [async-std/runti] [zellij-server/src/lib.rs:1068]: Compiling plugins using Cranelift 
ERROR  |zellij_utils::input::layo| 2024-07-08 17:42:22.306 [screen    ] [zellij-utils/src/input/layout.rs:1088]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" } 
ERROR  |zellij_utils::input::layo| 2024-07-08 17:42:22.306 [screen    ] [zellij-utils/src/input/layout.rs:1088]: Failed to read layout dir: Os { code: 2, kind: NotFound, message: "No such file or directory" }

In my case, I use Contour and an Alacritty mod with Sixel support.

lypanov commented 4 months ago

Able to reproduce all mentioned issues, without a cache clear sixels are broken. And they are double height. I'm also using foot.

manueldeprada commented 4 months ago

Let's try to bump this, it should be a simple regression fix. @imsnif seems to be the Sixel God on zellij

lypanov commented 4 months ago

My own release bisect shows this breaks with 0.35.0. Anything >= 35 needs a cache clear. I'll dig into which part of the release it was tomorrow.

lypanov commented 4 months ago

My gut instinct on the patch in 0.35.0 that may have caused this seems to be right, at 5235407 the tree is fine, 3a0e56a broken. So https://github.com/zellij-org/zellij/pull/2173 looks like the PR that causes the regression.

This also means that you only need a rm ~/.cache/zellij/zellij-stdin-cache-* rather than a full cache/zellij delete.

Looks like the addition of the cache is causing a race condition when sending the ScreenInstruction TerminalPixelDimensions. When it's correctly sent via a retry from send_to_screen_or_retry_queue! sixels work, however 9 out of 10 times it's not being sent. 10 times out of 10 only one of the expected TerminalPixelDimensions is sent. This frequently hits the fg/bg color resends also.

Will continue to persevere on this but my knowledge of concurrency in Rust is rudimentary.

lypanov commented 4 months ago

Had a bit more time to look into this and looks like route_thread_main is dropping the ScreenInstructions entirely from the retry queue when the retry queue itself is being replayed rather than placing them back on the retry queue. Making the no-brainer-i-don't-know-what-i'm-doing fix causes zellij to hang entirely on startup. Looks like something is keeping a lock during startup and preventing the retry queue from being executed.

Update: No locking just a race condition between session init and the retry queue. Only when session init has completed first do fg/bg/pixel dims get correctly set in the screen.

lypanov commented 4 months ago

Okay had a bit more time to look into this and figured out the obvious reason for the hang (infinite loop). Quick re-trail led me to a fix. Will clean up the patch, and create a PR.

manueldeprada commented 4 months ago

thanks @lypanov this is great!!

lypanov commented 4 months ago

If anyone has time to test the above PR/branch and confirm the fix locally, please do so!