fix(pane_tree): prevent nil pane access in symmetric layouts#127
Open
tdragon wants to merge 1 commit into
Open
fix(pane_tree): prevent nil pane access in symmetric layouts#127tdragon wants to merge 1 commit into
tdragon wants to merge 1 commit into
Conversation
Add guard clause to skip panes that have already been processed by another branch in symmetric layouts (e.g., perfect cross layout). This prevents nil pane access errors when a pane appears in both right and bottom branches. Fixes MLFlexer#98
6679791 to
ec66651
Compare
micimize
added a commit
to micimize/resurrect.wezterm
that referenced
this pull request
Mar 5, 2026
Addresses a crash loop caused by periodic auto-save capturing ghost SSH domain tabs (stuck in "Connecting..." with empty cwd and zero dimensions) into workspace JSON. On restore, these spawn broken tabs that cascade into UI crashes. Save-side safeguards: - Add is_pane_healthy() to filter panes with nil/empty cwd, zero cell dimensions, or non-spawnable domains before tree construction - Skip tabs with no healthy panes in window state serialization - Skip windows with no valid tabs in workspace save - Skip periodic save entirely when workspace is degraded - Create .bak backup before overwriting state files Restore-side safeguards: - Add validate_pane_tree() to check cwd and domain validity, with recursive pruning of invalid subtrees - Validate each tab before restoring, skip invalid ones - Track restored_count independently from loop index for correct first-tab reuse logic - Wrap per-window restore in pcall with state reset on failure - Guard against empty tabs[1] access when spawning windows - Fall back to .bak file when primary state file is invalid - Nil guard on active_tab:activate() (latent upstream bug) Upstream fixes incorporated: - PR MLFlexer#127: nil pane guard in insert_panes() for symmetric layouts - PR MLFlexer#123: use direct require("resurrect.state_manager") to fix circular module dependency in save actions - PR MLFlexer#118: set active workspace after restore_workspace() Wrap io.lines() in pcall in load_json() to handle missing files gracefully instead of throwing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
micimize
added a commit
to micimize/resurrect.wezterm
that referenced
this pull request
Mar 5, 2026
Tests cover: - is_pane_healthy: 10 cases (nil pane, nil/empty cwd, zero dims, domains) - create_pane_tree: 6 cases (filtering, empty list, sorting) - validate_pane_tree: 13 cases (nil/empty cwd, domains, subtree pruning) - geometry helpers: 7 cases (is_right, is_bottom, sorting, spatial layouts) - file_io: 7 cases (backup-before-overwrite, load_json error handling) - sanitize_json: 4 cases (control chars, null bytes, tabs, newlines) - state_manager: 4 cases (load_state backup fallback) - PR MLFlexer#127 nil guard: 1 case (2x2 symmetric grid) All 52 tests pass under lua5.4. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
5 tasks
YedPool
added a commit
to YedPool/Wezurrect
that referenced
this pull request
May 10, 2026
`cmd /c mkdir <path>` and `mkdir -p <path>` already create intermediate directories automatically, so the per-component walk in `ensure_folder_exists` was pure overhead — and it was the root cause of the cmd.exe window flashes reported in MLFlexer#125. The walk called `dir_is_accessible(ancestor)` on each path component. `dir_is_accessible` is a probe-write check: it returns false for a directory that **exists but isn't writable to the current user** (e.g. `C:\Users` on a non-admin Windows account). For each such ancestor, `shell_mkdir` then ran `os.execute('cmd /c mkdir ...')`, which on Windows spawns a visible `cmd.exe` console window — the "flickering pop-up" users described. Because `change_state_save_dir` calls `ensure_folder_exists` 4× per init (workspace/window/tab/instances) and `setup_claude_session_hooks` adds a 5th, and `init()` runs on every WezTerm launch and every config reload, affected users saw 4–N flashes per launch / per reload. The previous fix (MLFlexer#127-style probe-write replacing `os.rename`) only fixed one false-negative; it left the read-only-ancestor false-negative intact. This PR removes the walk entirely: - Drop `parse_root` and `mkdir_if_missing` (dead after the walk goes). - Keep a small drive-relative normaliser (C:foo → C:\foo) so the documented behaviour is preserved. - Trust `cmd /c mkdir` and `mkdir -p` to create intermediates. After the change: 0 shell_mkdir calls per launch in steady state. First install still creates the leaf state dirs (1 call per missing leaf, ≤5 total) and is then quiet forever. Verified locally on wezterm 20240203-110809-5046fc22 / Win 11 by instrumenting shell_mkdir and counting invocations across 3 consecutive `wezterm show-keys` runs (which exercises the same config-load path as a real launch and a Ctrl+Shift+R reload): - Launch 1 (fresh): 2 calls (state/instances + .claude/pane-sessions) - Launch 2: 0 calls - Launch 3: 0 calls Closes MLFlexer#125 Co-authored-by: YedPool <181616070+YedPool@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #98 - Resolves nil pane access error that occurs during workspace switching with symmetric pane layouts
Problem
When saving workspace state with symmetric pane layouts (e.g., 2x2 grid or perfect cross layout), the following error occurs:
attempt to index a nil value (field 'pane')
at pane_tree.lua:85 in root.pane:get_domain_name()
Root Cause
In the recursive
insert_panes()function, symmetric pane layouts can cause the same pane node to be encountered multiple times through different branches:root.paneis set tonil(line 122) to avoid memory leaksroot.pane:get_domain_name()on the already-nil pane causes the crashThis happens because in symmetric layouts, a pane can satisfy both
is_right()andis_bottom()conditions from the same parent node, causing it to appear in both branch collections.