Skip to content

fix: ssh: a waiting snippet stops typing when its shell is replaced - #2014

Merged
lollipopkit merged 2 commits into
lollipopkit:mainfrom
pwu2775-dev:fix/snippet-toolbar-alive-guard
Dec 1, 2026
Merged

lollipopkit merged 2 commits into
lollipopkit:mainfrom
pwu2775-dev:fix/snippet-toolbar-alive-guard

Conversation

@pwu2775-dev

@pwu2775-dev pwu2775-dev commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

A snippet with a ${sleep N} step can outlive the shell it was written for: the connection reconnects, the user switches to tmux, the foreground shell ends, or the snippet-run dialog hands its session over to a tab. The snippet engine already stops between steps when its alive callback answers false (Step_Sleep in snippet.dart), and the startup snippet path guards every runInTerm with exactly that check (_runStartupInput in init.dart, whose comment states the rule: "what is left must not be typed into the shell that replaced it").

Two snippet entry points passed no alive at all, so their remainder landed in whatever replaced their shell — a freshly reconnected bare shell, or the session the user had switched to:

  • The toolbar / virtual-key snippet picker (_pickSnippet): the terminal object survives its session, so text kept going into it across a reconnect. Now captures the page's _session and passes alive: mounted && identical(_session, shell) — the same identity check init.dart runs under.
  • The snippet run dialog (_SnippetRunViewState._run): now passes alive: mounted && identical(_sess.foreground, shell) — typing stops when the bound foreground shell ends for good (onForegroundDone) or the session is handed over.

Nothing about the engine changes; the two call sites just feed it the check it was built for.

How it was tested

flutter test test/unit/server/snippet_local_test.dart test/widget/snippet_list_test.dart pass (8). flutter analyze on both touched files clean. The behavior fix itself is the two alive closures — exercised end-to-end by the startup path's existing wiring, which this now matches on both remaining entry points.

Windows 11, Flutter 3.50.0. No model / ARB file changed, no crates/ change, no formatter run over untouched code.

Summary by CodeRabbit

  • Bug Fixes
    • Snippet execution now checks that the original terminal shell is still active. If the page closes or the foreground shell changes, the run is recognized as no longer active, helping prevent snippets from continuing in an unintended session. This check applies both when selecting a snippet on the SSH page and when running one from its dedicated view.

@pwu2775-dev

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Both SSH snippet execution paths now pass an alive callback to Snippet.runInTerm. The callbacks check whether the foreground shell is still the shell captured for the run. The SSH page callback also checks whether the page remains mounted.

Changes: SSH snippet shell liveness

Layer / File(s) Summary
Pass shell-liveness callbacks
lib/view/page/ssh/page/page.dart, lib/view/page/ssh/snippet_run.dart
Both paths pass a callback that checks shell identity. The SSH page path also checks that the page remains mounted.

Suggested reviewers: lollipopkit, gt-610

Change: Bug fix

Merge Risk: Minimal · up to a3f22

This change stops a waiting snippet from typing into a replacement shell or session, in both the toolbar picker and the run dialog. No concrete merge-blocking problem was found. The changes are small and easy to revert.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b2c5fdae-e4ec-4a92-99fa-24f7dc392b2a
Commits

Reviewing files that changed from the base of the PR and between d207516 and a3f220d.

Files selected for processing: 2

  • lib/view/page/ssh/page/page.dart
  • lib/view/page/ssh/snippet_run.dart

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Recent review details

Context from checks skipped due to timeout: 5

  • GitHub Check: CodeRabbit
  • GitHub Check: tests (2/3)
  • GitHub Check: tests (1/3)
  • GitHub Check: tests (0/3)
  • GitHub Check: check
Additional context used

Code guidelines: 1

CLAUDE.md — auto-discovered
Path-based instructions: 1

Source excerpt: **In `lib/`, a page is `AppRoute.go`, `AppPageRoute` or `AppPage` (fl_lib), never a bare `MaterialPageRoute` / `MaterialPage`**: a predictive back (Android, and the iOS/macOS edge swipe) pops every route current in its own n...

CodeRabbit inference engine (CLAUDE.md)

Files:

  • lib/view/page/ssh/page/page.dart
  • lib/view/page/ssh/snippet_run.dart
Additional comments: 1

lib/view/page/ssh/page/page.dart: 1

1001-1001: Functional Correctness

The alive checks compare foreground identity. Selecting a tmux pane or window leaves the foreground unchanged, so these checks stay true after a pane switch. The inspected snippet contract and PR objectives stop a waiting snippet when its shell is replaced, not when the user selects another pane in the same tmux session. No inspected source requires that pane selection cancel the snippet. Without that requirement, a remaining snippet that continues into the newly selected pane is not a violation of an established contract. Whether a pane switch should cancel the run is an open product decision.

The startup snippet path (_runStartupInput) guards every runInTerm with
an alive check for exactly this: a snippet can wait through a reconnect
or a tmux switch via a ${sleep N} step, and what is left of it must not
be typed into the shell that replaced it. The two other snippet entry
points had no guard:

- the toolbar / virtual-key picker (_pickSnippet) typed into the
  terminal object, which survives the session it belonged to — the
  remainder landed in the reconnect's new shell, or in whatever session
  the user had switched to;
- the snippet run dialog (_run) kept going after its foreground shell
  ended for good or the session was handed over to a tab.

Both now pass an alive closure in the same shape init.dart already
runs under: the toolbar's compares the page's session by identity, the
dialog's compares the bound foreground shell. Nothing types after the
shell it was written for is gone.

The snippet engine's Step_Sleep already checks alive between steps
(snippet.dart) — this only feeds it, at the two call sites that did not.
@pwu2775-dev
pwu2775-dev force-pushed the fix/snippet-toolbar-alive-guard branch from 5b00404 to b4eb993 Compare December 1, 2026 12:46
@lollipopkit
lollipopkit merged commit bda3fa9 into lollipopkit:main Dec 1, 2026
21 checks passed
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.

2 participants