fix(pane_tree): prevent nil pane access in symmetric layouts#127
Open
tdragon wants to merge 1 commit intoMLFlexer:mainfrom
Open
fix(pane_tree): prevent nil pane access in symmetric layouts#127tdragon wants to merge 1 commit intoMLFlexer:mainfrom
tdragon wants to merge 1 commit intoMLFlexer:mainfrom
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
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.