fix(terminal): bound hidden exec lifecycle so calls always complete - #6
Open
yoruuuchan wants to merge 1 commit into
Open
yoruuuchan wants to merge 1 commit into
yoruuuchan wants to merge 1 commit into
Conversation
Hidden exec calls could wait forever while the shell became ready, while the creation mutex was held, or while a blocked pipe write was joined through cancellation, because the caller deadline did not cover those phases. - Run prepare, queueing, write and read inside the caller deadline and report the phase that expired - Cancel a blocked writer instead of joining it, and destroy the shell that owned it - Retire failed, timed-out or cancelled executors through an idempotent close - Re-resolve the executor key when a queued call finds a retired shell - Destroy processes whose creation raced with cancellation - Cover success, start failure, queueing, cancellation, process exit and disconnect paths with JVM unit tests
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
LocalTerminalProvider.executeHiddenCommandcould stay pending forever. The caller budget was applied withwithTimeout(timeoutMs), but the phases that can block were outside its guarantee, and cancellation had to join non-cancellable IO children:getOrCreateHiddenExecShell()ran before the timeout: shell startup, readiness (a fixed internal 30s wait) and the global creation mutex were not bounded by the caller deadline.withContext(Dispatchers.IO) { writer.write(...); writer.flush() }. When a hidden shell stops draining its pipe, that write blocks a thread; coroutine cancellation only marks the job and still waits for the child to return.awaitHiddenExecReady()used its own fixed internal timeout instead of the caller budget.hiddenExecScope.launch { ... }, so the next call with the sameexecutorKeycould race a half-closed shell while the result read was skipped entirely.Because of (2) and (4) the calling Kotlin tool never returned, so the ToolPkg
Tools.System.terminal.hiddenExecPromise in Operit never settled. QQbot triggers it reliably when it starts its background gateway, but the defect is in the generic hidden executor chain, not in that caller.Fix
executeHiddenCommandnow runs prepare, queueing, write and read inside a singlewithTimeoutOrNull(timeoutMs)budget and reports the phase that expired.closeHiddenExecShellis idempotent (AtomicBoolean+ConcurrentHashMap.remove(key, shell)) and destroys the process before closing the buffered writer, so a blocked writer cannot hold cleanup.disconnect()cancels the scope before closing shells.SSHFileConnectionManager.executeHiddenCommandconsumes the same budget for setup,connect()and draining, and disconnects the channel infinally.TerminalProvider.executeHiddenCommanddocuments thattimeoutMscovers the whole lifecycle.Tests
13 new JVM unit tests in
LocalTerminalProviderTest, green on JDK 21 (./gradlew :terminal:testDebugUnitTestfrom the Operit build):Against the unfixed implementation, the readiness, creation-mutex and blocked-write cases fail with a wall-clock
TimeoutException— the reported permanent pending behavior.