Skip to content

Conversation

@guemidiborhane
Copy link
Contributor

@guemidiborhane guemidiborhane commented Sep 20, 2025

Fixes #1083

Summary by CodeRabbit

  • Bug Fixes
    • Improved process launching on Linux and other non-Windows platforms: external commands now start in their own session and detach from the terminal. This prevents the app from hanging, suppresses unintended console output, and keeps the app responsive after opening files, links, or external tools. Windows and macOS behavior remains unchanged.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@lazysegtree lazysegtree added pr-needs-testing This PR needs some thorough testing before we can merge bug fixes labels Sep 20, 2025
@lazysegtree
Copy link
Collaborator

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 20, 2025

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 20, 2025

Walkthrough

Non-Windows process spawning in executeOpenCommand is updated to start child processes in a new session (Setsid: true) with detached stdio (stdin/stdout/stderr nil) using SysProcAttr. Imports now include syscall. Windows and Darwin code paths are unchanged.

Changes

Cohort / File(s) Summary
Process spawning and detachment
src/internal/handle_panel_movement.go
Added syscall import. For non-Windows platforms in executeOpenCommand, set Cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true} and nil out stdin/stdout/stderr to detach child processes from the terminal. Windows/Darwin logic remains as before.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Superfile
  participant OS
  participant ChildProc

  User->>Superfile: Trigger open (executeOpenCommand)
  Superfile->>OS: Build command for file opener
  alt Windows or Darwin
    OS->>ChildProc: Start process (default session/stdio)
  else Other platforms (Linux, etc.)
    note over Superfile,OS: Configure SysProcAttr{ Setsid: true }<br/>stdin=stdout=stderr=nil
    OS->>ChildProc: Start process detached (new session)
  end
  Superfile-->>User: Return control to TUI
  note over ChildProc: Continues independently of terminal
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I tap my paws, process hops away,
No string attached to terminal’s sway.
In a new session, free and bright,
mpv dances into the night.
Thump-thump—detached delight,
A bunny ships the fix just right. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "fix: fix child process spawning attached" accurately describes the primary intent of the changeset — preventing child processes from remaining attached to the terminal — and directly relates to the modifications in src/internal/handle_panel_movement.go. The code changes implement process detachment (SysProcAttr.Setsid = true and stdio redirection) for non-Windows platforms, which matches the title's focus. The title is slightly redundant with the repeated word "fix" but remains clear and relevant for a quick scan.
Linked Issues Check ✅ Passed For linked issue #1083 (child processes closing when the terminal running superfile is closed), the PR implements detachment by setting SysProcAttr.Setsid = true and assigning nil to Stdin/Stdout/Stderr for spawned processes on non-Windows platforms, which prevents them from inheriting the terminal session and addresses the core objective. The change is narrowly targeted to executeOpenCommand and therefore meets the coding-related requirement to avoid child processes being tied to the terminal on Unix-like systems. Note that Windows and Darwin code paths are left unchanged, so if the issue needs coverage on macOS or Windows those platforms may require additional platform-specific handling or verification.
Out of Scope Changes Check ✅ Passed The raw summary shows a single-file change (src/internal/handle_panel_movement.go) limited to importing syscall and adjusting how child processes are spawned; there are no modifications to unrelated files, public API signatures, or other unrelated functionality. These edits are directly related to the linked issue's objective and therefore there is no evidence of out-of-scope changes in this PR.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/internal/handle_panel_movement.go (1)

108-111: Reap the child to avoid zombies; start a non‑blocking Wait goroutine.

We don’t intend to wait synchronously, but never calling Wait can leave defunct processes until superfile exits. Start a goroutine to reap quickly. Do the same in the Windows branch below.

Apply:

-err := cmd.Start()
-if err != nil {
+err := cmd.Start()
+if err != nil {
   slog.Error("Error while open file with", "error", err)
-}
+  return
+}
+go func() { _ = cmd.Wait() }()

And in the Windows block above:

-err := cmd.Start()
+err := cmd.Start()
 if err != nil {
   slog.Error("Error while open file with", "error", err)
+} else {
+  go func() { _ = cmd.Wait() }()
 }
♻️ Duplicate comments (2)
src/internal/handle_panel_movement.go (2)

101-101: Use constants for GOOS comparisons consistently.

If you keep any GOOS string comparisons elsewhere in this file, replace "windows" with utils.OsWindows to satisfy goconst and match existing style.


101-107: Replace inline GOOS check + SysProcAttr with portable helper; remove redundant stdio lines; also avoid bare "windows" string.

  • The runtime check doesn’t help the Windows compiler; use the helper above.
  • The Stdin/Stdout/Stderr assignments to nil are redundant; nil already maps to os.DevNull per os/exec docs.
  • If any GOOS string checks remain, prefer utils.OsWindows (goconst). This was flagged previously; same guidance applies here.

Apply:

 cmd := exec.Command(openCommand, panel.element[panel.cursor].location)
-if runtime.GOOS != "windows" {
-  cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
-  // Optionally, redirect stdio to avoid terminal hangups
-  cmd.Stdin = nil
-  cmd.Stdout = nil
-  cmd.Stderr = nil
-}
+detachFromTerminal(cmd)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd79f4d and f72d1c4.

📒 Files selected for processing (1)
  • src/internal/handle_panel_movement.go (2 hunks)
🧰 Additional context used
🪛 GitHub Check: Build and Test (windows-latest)
src/internal/handle_panel_movement.go

[failure] 102-102:
unknown field Setsid in struct literal of type syscall.SysProcAttr

🪛 GitHub Actions: Go CI
src/internal/handle_panel_movement.go

[error] 102-102: Build failed: unknown field Setsid in struct literal of type syscall.SysProcAttr

codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@lazysegtree lazysegtree requested a review from yorukot September 20, 2025 07:27
Copy link
Collaborator

@lazysegtree lazysegtree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Although I am not entire sure of the bug.

@lazysegtree lazysegtree added awaiting pr review and removed pr-needs-testing This PR needs some thorough testing before we can merge labels Sep 20, 2025
@yorukot yorukot merged commit d953ece into yorukot:main Sep 20, 2025
7 checks passed
@yorukot
Copy link
Owner

yorukot commented Sep 20, 2025

LGTM, although I do not fully understand why this can help the app detach from superfile.

@guemidiborhane
Copy link
Contributor Author

By using setsid to true, we essentially tell the OS to make the child process (eg: document viewer) a child of PID 1, which prevents terminal closing from sending SIGHUP to the child process and closing it.

tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Oct 15, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [yorukot/superfile](https://github.com/yorukot/superfile) | minor | `v1.3.3` -> `v1.4.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>yorukot/superfile (yorukot/superfile)</summary>

### [`v1.4.0`](https://github.com/yorukot/superfile/releases/tag/v1.4.0)

[Compare Source](yorukot/superfile@v1.3.3...v1.4.0)

Hey folks. Releasing v1.4.0 with many new features, improvements, and bug fixes.

We have an async file preview now, a zoxide panel, and various new features improving UX.

#### Install:

[**Click me to know how to install**](https://github.com/yorukot/superfile?tab=readme-ov-file#installation)

#### Highlights

- We have the Zoxide Panel now. Ensure zoxide is installed on your system, set `zoxide_support` to `true` in the config, and press `z` to use zoxide. <img width="645" height="295" alt="Image" src="https://github.com/user-attachments/assets/238f6549-5318-49d1-a3a0-14cf8a686955" />

- File previewing is now async, meaning reduced lag while scrolling through images, or on slow systems.

- Many bug fixes. See 'Detailed Change Summary'

##### Internal Updates

- Most file operations are now truly async with the usage of the recommended `tea.Cmd` pattern.
- Enabled many new linters to improve code quality.
- Moved golangci-lint to v2. Now developers don't need to keep the old v1 in their systems.
- Refactored file preview in its own package for better maintainability and readability.
- Fixed flaky unit tests.

#### Detailed Change Summary

<details><summary>Details</summary>
<p>

##### Update
- feat: File operation via tea cmd [#&#8203;963](yorukot/superfile#963) by @&#8203;lazysegtree
- feat: processbar improvements, package separation, better channel management [#&#8203;973](yorukot/superfile#973) by @&#8203;lazysegtree
- feat: enable lll and recvcheck linter, fix tests, more refactors [#&#8203;977](yorukot/superfile#977) by @&#8203;lazysegtree
- feat: Remove channel for notification models [#&#8203;979](yorukot/superfile#979) by @&#8203;lazysegtree
- feat: enable cyclop, funlen, gocognit, gocyclo linters, and refactor large functions [#&#8203;984](yorukot/superfile#984) by @&#8203;lazysegtree
- feat: Add a new hotkey to handle cd-on-quit whenever needed [#&#8203;924](yorukot/superfile#924) by @&#8203;ahmed-habbachi
- feat: added option to permanently delete files [#&#8203;987](yorukot/superfile#987) by @&#8203;hupender
- feat: Preview panel separation [#&#8203;1021](yorukot/superfile#1021) by @&#8203;lazysegtree
- feat: Add search functionality to help menu [#&#8203;1011](yorukot/superfile#1011) by @&#8203;iZarrios
- feat: Use zoxide lib [#&#8203;1036](yorukot/superfile#1036) by @&#8203;lazysegtree
- feat: Add zoxide directory tracking on navigation [#&#8203;1041](yorukot/superfile#1041) by @&#8203;lazysegtree
- feat: Zoxide integration [#&#8203;1039](yorukot/superfile#1039) by @&#8203;lazysegtree
- feat: Select mode with better feedback [#&#8203;1074](yorukot/superfile#1074) by @&#8203;lazysegtree
- feat: owner/group in the metadata [#&#8203;1093](yorukot/superfile#1093) by @&#8203;xelavopelk
- feat: Async zoxide [#&#8203;1104](yorukot/superfile#1104) by @&#8203;lazysegtree

##### Bug Fix
- fix: sorting in searchbar [#&#8203;985](yorukot/superfile#985) by @&#8203;hupender
- fix: Async rendering, Include clipboard check in paste items, and update linter configs [#&#8203;997](yorukot/superfile#997) by @&#8203;lazysegtree
- fix: Move utility functions to utils package [#&#8203;1012](yorukot/superfile#1012) by @&#8203;lazysegtree
- fix: Refactoring and separation of preview panel and searchbar in help menu [#&#8203;1013](yorukot/superfile#1013) by @&#8203;lazysegtree
- fix(filePanel): allow focusType to be set correctly [#&#8203;1033](yorukot/superfile#1033) by @&#8203;faisal-990
- fix(ci): Update gomod2nix.toml, allow pre release in version output, release 1.4.0-rc1, bug fixes, and improvements [#&#8203;1054](yorukot/superfile#1054) by @&#8203;lazysegtree
- fix(nix): resolve build failures in the nix flake [#&#8203;1068](yorukot/superfile#1068) by @&#8203;Frost-Phoenix
- fix: Retry the file deletion to prevent flakies (#&#8203;938) [#&#8203;1076](yorukot/superfile#1076) by @&#8203;lazysegtree
- fix(issue-1066): Fixed issue where enter was not searchable [#&#8203;1078](yorukot/superfile#1078) by @&#8203;Simpaqt
- fix(#&#8203;1073): Tech debt fix [#&#8203;1077](yorukot/superfile#1077) by @&#8203;Simpaqt
- fix: fix deleted directory not able to remove from pins (#&#8203;1067) [#&#8203;1081](yorukot/superfile#1081) by @&#8203;yorukot
- fix: fix child process spawning attached [#&#8203;1084](yorukot/superfile#1084) by @&#8203;guemidiborhane
- fix: always clear images when showing a FullScreenStyle [#&#8203;1094](yorukot/superfile#1094) by @&#8203;snikoletopoulos
- fix: Allow j and k keys in zoxide [#&#8203;1102](yorukot/superfile#1102) by @&#8203;lazysegtree
- fix: Zoxide improvements and 1.4.0-rc2 [#&#8203;1105](yorukot/superfile#1105) by @&#8203;lazysegtree
- fix: rename cursor beginning on wrong character because of multiple dots in name (#&#8203;813) [#&#8203;1112](yorukot/superfile#1112) by @&#8203;SyedAsadK
- fix: check and fix file panel scroll position on height changes [#&#8203;1095](yorukot/superfile#1095) by @&#8203;snikoletopoulos

##### Optimization
- perf(website): optimize font loading and asset organization [#&#8203;1089](yorukot/superfile#1089) by @&#8203;yorukot

##### Documentation
- docs: fix incorrect zoxide plugin config name [#&#8203;1049](yorukot/superfile#1049) by @&#8203;shree-xvi
- docs(hotkeys): Fix typo in vimHotkeys.toml comments [#&#8203;1080](yorukot/superfile#1080) by @&#8203;wleoncio
- docs: add section for core maintainers in README.md [#&#8203;1088](yorukot/superfile#1088) by @&#8203;yorukot
- chore: add winget install instruction to readme and website [#&#8203;943](yorukot/superfile#943) by @&#8203;claykom

##### Dependencies
- chore(deps): update dependency go to v1.25.0, golangci-lint to v2, golangci-lint actions to v8 [#&#8203;750](yorukot/superfile#750) by @&#8203;renovate[bot]
- chore(deps): update amannn/action-semantic-pull-request action to v6 [#&#8203;1006](yorukot/superfile#1006) by @&#8203;renovate[bot]
- chore(deps): update actions/first-interaction action to v3 [#&#8203;1005](yorukot/superfile#1005) by @&#8203;renovate[bot]
- chore(deps): update actions/checkout action to v5 [#&#8203;1004](yorukot/superfile#1004) by @&#8203;renovate[bot]
- chore(deps): bump astro from 5.10.1 to 5.12.8 [#&#8203;982](yorukot/superfile#982) by @&#8203;dependabot[bot]
- fix(deps): update module golang.org/x/mod to v0.27.0 [#&#8203;989](yorukot/superfile#989) by @&#8203;renovate[bot]
- fix(deps): update dependency @&#8203;expressive-code/plugin-collapsible-sections to v0.41.3 [#&#8203;990](yorukot/superfile#990) by @&#8203;renovate[bot]
- fix(deps): update dependency sharp to v0.34.3 [#&#8203;992](yorukot/superfile#992) by @&#8203;renovate[bot]
- fix(deps): update dependency @&#8203;expressive-code/plugin-line-numbers to v0.41.3 [#&#8203;991](yorukot/superfile#991) by @&#8203;renovate[bot]
- chore(deps): update dependency go to v1.25.0 [#&#8203;994](yorukot/superfile#994) by @&#8203;renovate[bot]
- fix(deps): update astro monorepo [#&#8203;995](yorukot/superfile#995) by @&#8203;renovate[bot]
- fix(deps): update dependency @&#8203;astrojs/starlight to ^0.35.0 [#&#8203;1000](yorukot/superfile#1000) by @&#8203;renovate[bot]
- fix(deps): update module github.com/urfave/cli/v3 to v3.4.1 [#&#8203;1001](yorukot/superfile#1001) by @&#8203;renovate[bot]
- fix(deps): update module golang.org/x/text to v0.28.0 [#&#8203;1003](yorukot/superfile#1003) by @&#8203;renovate[bot]

##### Misc
- chore: migrate from superfile.netlify.app to superfile.dev [#&#8203;1087](yorukot/superfile#1087) by @&#8203;yorukot
- refactor(filepanel): replace filePanelFocusType with isFocused boolean [#&#8203;1040](yorukot/superfile#1040) by @&#8203;faisal-990
- refactor(ansi): Migrate from github.com/charmbracelet/x/exp/term/ansi to github.com/charmbracelet/x/ansi [#&#8203;1044](yorukot/superfile#1044) by @&#8203;faisal-990
- refactor: common operation on pinned directory file using PinnedManager [#&#8203;1085](yorukot/superfile#1085) by @&#8203;Manaswa-S
- test: unit tests for pinned manager [#&#8203;1090](yorukot/superfile#1090) by @&#8203;Manaswa-S

</p>
</details> 

#### New Contributors
* @&#8203;hupender made their first contribution in yorukot/superfile#985
* @&#8203;ahmed-habbachi made their first contribution in yorukot/superfile#924
* @&#8203;iZarrios made their first contribution in yorukot/superfile#1011
* @&#8203;faisal-990 made their first contribution in yorukot/superfile#1033
* @&#8203;shree-xvi made their first contribution in yorukot/superfile#1049
* @&#8203;Simpaqt made their first contribution in yorukot/superfile#1078
* @&#8203;wleoncio made their first contribution in yorukot/superfile#1080
* @&#8203;guemidiborhane made their first contribution in yorukot/superfile#1084
* @&#8203;Manaswa-S made their first contribution in yorukot/superfile#1085
* @&#8203;xelavopelk made their first contribution in yorukot/superfile#1093
* @&#8203;snikoletopoulos made their first contribution in yorukot/superfile#1094
* @&#8203;SyedAsadK made their first contribution in yorukot/superfile#1112

**Full Changelog**: <yorukot/superfile@v1.3.3...v1.4.0>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xNDYuMCIsInVwZGF0ZWRJblZlciI6IjQxLjE0Ni4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Child process (eg: mpv, viewnior, ...) would close with the terminal window unexpectedly

3 participants