Skip to content

Commit 0e4ac87

Browse files
committed
fix(core): undoing my change to cancel requests on stop
I think I misunderstood how the code should work. We don't just want to cancel our outstanding requests to the opencode server, we want the opencode server to cancel it's upstream requests.
1 parent bb0f1fe commit 0e4ac87

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

lua/opencode/core.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,14 @@ function M.stop()
176176
if state.windows and state.active_session then
177177
if state.is_running() then
178178
vim.notify('Aborting current request...', vim.log.levels.WARN)
179-
state.api_client:abort_session(state.active_session.id):wait()
180179

181-
-- Forcibly reject any pending requests as it seems like they
182-
-- can sometimes get stuck
183-
server_job.cancel_all_requests()
180+
-- FIXME: I think my understanding / logic was wrong here. We don't
181+
-- just want to cancel our requests to the opencode server, we
182+
-- want the opencode server to cance it's requests. Commenting out
183+
-- this code for now and will do more testing
184+
-- server_job.cancel_all_requests()
185+
186+
state.api_client:abort_session(state.active_session.id):wait()
184187
end
185188
require('opencode.ui.footer').clear()
186189
input_window.set_content('')

lua/opencode/server_job.lua

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,11 @@ end
139139
---Forcibly reject any pending requests (they sometimes get stuck
140140
---after an api abort)
141141
function M.cancel_all_requests()
142-
if vim.deep_equal(M.requests, {}) then
143-
-- If we're canceling again and we've already cleared the requests, set the
144-
-- job_count to 0
145-
state.job_count = 0
146-
else
147-
for _, entry in ipairs(M.requests) do
148-
local promise = entry[2]
149-
if not promise:is_resolved() then
150-
pcall(promise.reject, promise, 'Request cancelled')
151-
end
142+
for _, entry in ipairs(M.requests) do
143+
local promise = entry[2]
144+
if not promise:is_resolved() then
145+
pcall(promise.reject, promise, 'Request cancelled')
152146
end
153-
154-
M.requests = {}
155147
end
156148
end
157149

0 commit comments

Comments
 (0)