Skip to content

fix(panel-terminal): keep a re-keyed spawn's in-flight flag in step with its owner (#1384) - #1388

Merged
devsuitup merged 3 commits into
mainfrom
fix/1384-panel-rekey-in-flight
Nov 29, 2026
Merged

devsuitup merged 3 commits into
mainfrom
fix/1384-panel-rekey-in-flight

Conversation

@devsuitup

Copy link
Copy Markdown
Owner

Summary

Fixes #1384. The Shell button could stop opening a panel shell for a session until the window reloaded. This happened when the shell was closed during start-up and the owner session was re-keyed (for example a fork re-key through rekeySessionTab) before openTerminal settled.

Root cause

rekeyPanelTerminalState moved the owner id in panelSpawnsInFlight to the new id unconditionally. It updated state.ownerSessionId only while the state was still in panelTerminals, and the close had already removed it. The finally in openPanelTerminal then deleted state.ownerSessionId, which was still the old id, so the new id stayed in flight forever. After that, openPanelTerminal returned early and each Shell click only flipped panelReopenAfterSpawn.

Fix

panelSpawnsInFlight is now a Map from owner id to the state of its pending spawn. When a re-key moves the in-flight entry, it also sets that state's ownerSessionId to the new id, whether or not the state is still registered. The finally therefore clears the id the flag now sits under. These spawn-race branches are unchanged and keep using the current owner id:

  • a shell closed while spawning is stopped on ok;
  • its entry is destroyed on ok:false;
  • the reopen happens only while the panel still shows that owner;
  • reattaching is still avoided.

Tests

New in test/panel-terminal.test.js (one test for each settle outcome): open, then close while the spawn is pending, then re-key owner to new, then resolve or reject openTerminal. The test checks that panelSpawnsInFlight is empty and that a Shell click for new spawns a shell.

RED at 62134ed (base, before the fix), node --test --test-concurrency=1 --test-name-pattern=1384 test/panel-terminal.test.js under Node 22:

not ok 1 - a spawn closed then re-keyed before it resolves lets the new id open a shell again (#1384)
  expected: 0
  actual: 1
    test/panel-terminal.test.js:683:14
not ok 2 - a spawn closed then re-keyed before it rejects lets the new id open a shell again (#1384)
  expected: 0
  actual: 1
    test/panel-terminal.test.js:683:14

Mutation check: with the fix applied but the spawning.ownerSessionId = newId line removed, both tests fail on the same assertion. With the line back, both pass.

test/bg-rekey-renderer-639.test.js seeds the in-flight table directly. It now uses .set('old', shell639) instead of .add('old'), because the table is a Map.

GREEN under Node 22, one file at a time:

  • test/panel-terminal.test.js: 51/51
  • test/build-projects-panel-shell.test.js: 7/7
  • test/panel-terminal-target.test.js: 6/6
  • test/bg-rekey-renderer-639.test.js: 11/11
  • test/session-rekey-renderer.test.js: 27/27
  • test/send-to-background-renderer.test.js: 39/39

Other checks:

  • eslint on the touched files: 0 errors.
  • scripts/check-docs.js --validate and scripts/check-doc-refs.js: exit 0, 0 failures.
  • git diff --check: clean.

Docs

  • .ai/contexts/panel-terminal.md "Spawn races": the known-limitation paragraph replaced by the fixed behaviour. No user docs: the panel shell has no user doc covering this race.
  • CHANGELOG.md: one entry under Unreleased / Fixed.

Not verified

  • Not reproduced in the running app (no Electron, no e2e run); covered by the jsdom renderer tests only.
  • Full task check and the whole test suite were not run, only the files listed above.
  • The PR-only docs job will need the panel-terminal.md body change from the merge of main before it can pass.

…ith its owner (#1384)

A shell closed while its spawn was pending and then re-keyed left the new owner id in panelSpawnsInFlight for good: the re-key moved the flag but could not reach the unregistered state, so the settle cleared the old id. The in-flight table now maps each owner to its spawn's state, and the re-key moves that owner along with the flag.
@devsuitup
devsuitup merged commit 6e4b551 into main Nov 29, 2026
10 checks passed
@devsuitup
devsuitup deleted the fix/1384-panel-rekey-in-flight branch November 29, 2026 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(panel-terminal): a re-key during a closed spawn leaves the new id in flight forever

1 participant