fix(terminal): always complete hiddenExec on timeout/error/cancel (Fixes #1180) - #1201
Draft
yoruuuchan wants to merge 1 commit into
Draft
yoruuuchan wants to merge 1 commit into
yoruuuchan wants to merge 1 commit into
Conversation
AAswordman#1180) Hidden exec could stay pending forever while the terminal submodule waited for shell readiness, for the executor creation mutex, or for a blocked pipe write: the caller timeout only covered the output read loop, and cancellation had to join non-cancellable IO children. - Point the terminal submodule at the bounded lifecycle implementation - Document that timeoutMs covers the whole hidden execution lifecycle and that a timed-out or failed executor is retired - Log request and completion with executorKey, state and exitCode for diagnosis - Run :terminal:testDebugUnitTest in the Android tests and PR check workflows
yoruuuchan
force-pushed
the
fix/hidden-exec-lifecycle
branch
from
September 16, 2026 08:48
2a2724b to
95e8fda
Compare
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.
Fixes #1180
Where it actually hangs
Tools.System.terminal.hiddenExeccreates a JS Promise that only settles when the Kotlin tool callback returns. That callback ends inLocalTerminalProvider.executeHiddenCommandinside theterminalsubmodule. Two phases there were not bounded by the caller deadline, and one cleanup could not be cancelled:getOrCreateHiddenExecShell()ran beforewithTimeout(timeoutMs): shell startup, readiness (fixed internal 30s) and the global creation mutex were not covered by the caller budget.withContext(Dispatchers.IO). When a hidden shell stops draining its pipe, that write blocks a thread, and coroutine cancellation still has to join the child before the call can return.executorKeycould wait on a half-closed shell.When a hidden shell stops draining its pipe, (2) leaves the call pending forever — no timeout, no error: the returned Promise never resolves or rejects. QQbot reproduces this reliably when it starts its background gateway, but the defect is in the generic hidden executor chain (also used by
code_runnerandlinux_ssh), not in that caller.Fix
terminalsubmodule (see dependent PR fix(terminal): bound hidden exec lifecycle so calls always complete OperitTerminalCore#6): prepare/queue/write/read all run inside one caller deadline; the blocked write is cancellable instead of joined; failed/timed-out/cancelled executors are retired through an idempotent close that destroys the process before closing the writer; a queued call re-resolvesexecutorKeywhen the previous owner retired the shell; processes whose creation raced with cancellation are destroyed.StandardTerminalCommandExecutor: logs request and completion withexecutorKey, state andexitCode, so timeout / error / cancellation is diagnosable.SystemToolPromptsInternalandexamples/types/*.d.ts:timeout_msdocumented as the whole hidden execution lifecycle (initialization + queueing + execution), and a timed-out or failed active executor is retired instead of reused.:terminal:testDebugUnitTestnow runs inandroid-tests.ymlandpr-check.yml.No QQbot-specific workaround.
code_runnerandlinux_sshkeep the same API and the same result shape ({ output, exitCode, executorKey, timedOut }).Verification
./gradlew :terminal:testDebugUnitTest— 13 hidden-exec lifecycle tests pass on JDK 21 (verified on JDK 17 as well).devimplementation: readiness, creation-mutex and blocked-write cases fail with a wall-clockTimeoutException, reproducing [Bug] ToolPkg hiddenExec 调用永久挂起:qqbot「开启监听」卡死(Operit 1.12.1) #1180's permanent wait../gradlew :app:compileDebugKotlinpasses with the updated submodule pointer (JDK 21).:app:testDebugUnitTestcannot compile ondeveither (pre-existingDeepseekProviderMediaRoleTest/XaiProviderReasoningTesterrors — reproduced on a cleandevtree), and a fullassembleDebugneeds a hostnmakefor MNN FlatBuffers that this machine does not have.Dependency
The submodule PR AAswordman/OperitTerminalCore#6 must be merged first: this branch points
terminalat the fix commit, which currently only exists in the fork PR. CI submodule checkout will fail until it is merged.