Skip to content

Conversation

@vishwesh007
Copy link
Contributor

@vishwesh007 vishwesh007 commented Dec 14, 2025

This pull request enhances how terminal sessions are managed when launching a terminal with a pending command. It introduces logic to handle session reuse and termination more robustly, ensuring that commands requesting a fresh session can terminate any previous session with the same ID before starting a new one. This improves reliability and predictability for users launching terminals with specific commands.

Session management improvements:

  • When a pending command is present, the code now checks if the command requests termination of any previous session with the same ID, and if so, terminates it before creating or reusing the session. (Terminal.kt, TerminalScreen.kt) [1] [2]
  • The logic for session creation now prioritizes the command's session ID, falling back to the previous behavior (using the present working directory) only if no pending command is provided. (Terminal.kt)
  • After creating or retrieving the session, the terminal client is updated and the current session reference is set accordingly, ensuring correct session focus. (Terminal.kt, TerminalScreen.kt) [1] [2]

Copilot AI review requested due to automatic review settings December 14, 2025 13:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes terminal command handling by properly using pendingCommand in the onNewIntent method and implementing support for the terminatePreviousSession flag. The changes ensure that when launching internal terminal commands, existing sessions can be terminated before creating new ones, and the session ID is consistently used from the pending command.

Key Changes:

  • Added logic to check and terminate previous sessions when terminatePreviousSession is true
  • Extracted pendingCommand to a local variable to avoid repeated null checks
  • Updated onNewIntent in Terminal.kt to handle pending commands with fallback to original pwd-based behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
core/main/src/main/java/com/rk/terminal/TerminalScreen.kt Implements terminatePreviousSession logic and extracts pendingCommand to a local variable for consistent sessionId usage in the factory block
core/main/src/main/java/com/rk/activities/terminal/Terminal.kt Adds pendingCommand handling in onNewIntent with terminatePreviousSession support and maintains backward compatibility with pwd-based session creation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +279 to +281
terminalActivity.sessionBinder?.get()!!.getSession(sessionId) != null) {
terminalActivity.sessionBinder?.get()!!.terminateSession(sessionId)
}
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

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

Multiple null assertion operators (!!) on sessionBinder?.get() create potential for NullPointerException. Consider extracting sessionBinder?.get() to a local variable once at the beginning of the block, similar to how pendingCommand is handled. This would improve both safety and readability by reducing repeated null assertions.

Copilot uses AI. Check for mistakes.
Comment on lines 274 to +285
terminalActivity.sessionBinder?.get()!!.getService().currentSession.value =
pendingCommand!!.id
terminalActivity.sessionBinder?.get()!!.getSession(pendingCommand!!.id)
sessionId
terminalActivity.sessionBinder?.get()!!.getSession(sessionId)
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

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

Additional calls to sessionBinder?.get()!! with null assertions. Extract sessionBinder?.get() to a local variable to avoid repeated null assertions and potential crashes.

Copilot uses AI. Check for mistakes.
this@Terminal.changeSession(info.id)

// Check if there's a pending command from launchInternalTerminal
val command = com.rk.exec.pendingCommand
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

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

Reading pendingCommand without synchronization could lead to race conditions if the command is modified from another thread. Since pendingCommand is a mutable global variable, consider using proper synchronization or thread-safe mechanisms to access it, especially since this code runs in a coroutine context.

Copilot uses AI. Check for mistakes.
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