fix(cancel): always call abort_session - #433
Merged
Merged
Conversation
Problem: `M.cancel` was gated on `state.active_session and state.jobs.is_running()`. `state.jobs.is_running()` is true only while the client has an in-flight HTTP request; once the request returns, the counter is back to zero. So attaching to a session whose model is already processing, or toggling off/on with `persist_state`, leaves cancel with nothing to do. The counter that drives the 3-strike server restart must keep gating on `state.jobs.is_running()` — its purpose is to detect the user is trying to abort an in-flight request and the server is not responding, not to count cancel attempts on an idle session. Solution: Move the `state.jobs.is_running()` gate to wrap only the counter increment. The cancel itself always runs. `abort_session` is a no-op on the server for an idle session, so calling it is harmless. Tests: - `aborts running session even when ui is not visible` (existing) covers the in-flight path. - `aborts when the model is processing on the server but no client request is in flight` reproduces the bug and asserts abort is called even with no in-flight request. - `does not count cancel toward the server-restart threshold when no client request is in flight` confirms the counter gate is preserved, so a stuck-idle path does not trigger a spurious server restart.
Contributor
Author
llm analysis from git blame. Not sure if this is the designed purpose. |
Owner
|
This was actually a real issue. The fix is right. No need to gate check. The abort intent is usually something you want to happen immediately. Thanks for the fix |
disrupted
pushed a commit
to disrupted/opencode-native.nvim
that referenced
this pull request
Jul 23, 2026
Problem: `M.cancel` was gated on `state.active_session and state.jobs.is_running()`. `state.jobs.is_running()` is true only while the client has an in-flight HTTP request; once the request returns, the counter is back to zero. So attaching to a session whose model is already processing, or toggling off/on with `persist_state`, leaves cancel with nothing to do. The counter that drives the 3-strike server restart must keep gating on `state.jobs.is_running()` — its purpose is to detect the user is trying to abort an in-flight request and the server is not responding, not to count cancel attempts on an idle session. Solution: Move the `state.jobs.is_running()` gate to wrap only the counter increment. The cancel itself always runs. `abort_session` is a no-op on the server for an idle session, so calling it is harmless. Tests: - `aborts running session even when ui is not visible` (existing) covers the in-flight path. - `aborts when the model is processing on the server but no client request is in flight` reproduces the bug and asserts abort is called even with no in-flight request. - `does not count cancel toward the server-restart threshold when no client request is in flight` confirms the counter gate is preserved, so a stuck-idle path does not trigger a spurious server restart.
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.
Problem:
M.cancelwas gated onstate.active_session and state.jobs.is_running().state.jobs.is_running()is true only whilethe client has an in-flight HTTP request; once the request returns, the
counter is back to zero. So attaching to a session whose model is
already processing, or toggling off/on with
persist_state, leavescancel with nothing to do.
The counter that drives the 3-strike server restart must keep gating on
state.jobs.is_running()— its purpose is to detect the user is tryingto abort an in-flight request and the server is not responding, not to
count cancel attempts on an idle session.
Solution:
Move the
state.jobs.is_running()gate to wrap only the counterincrement. The cancel itself always runs.
abort_sessionis a no-op onthe server for an idle session, so calling it is harmless.