Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lua/opencode/services/session_runtime.lua
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,10 @@ end

---@param opts? SendMessageOpts
M.cancel = Promise.async(function()
if state.active_session and state.jobs.is_running() then
vim.g.opencode_abort_count = (vim.g.opencode_abort_count or 0) + 1
if state.active_session then
if state.jobs.is_running() then
vim.g.opencode_abort_count = (vim.g.opencode_abort_count or 0) + 1
end

local permissions = state.pending_permissions or {}
if #permissions > 0 and state.api_client then
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/services_session_runtime_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,38 @@ describe('opencode.services.session_runtime', function()

abort_stub:revert()
end)

it('aborts when the model is processing on the server but no client request is in flight', function()
state.session.set_active({ id = 'sess1' })
store.set('job_count', 0)

local abort_stub = stub(state.api_client, 'abort_session').invokes(function()
return Promise.new():resolve(true)
end)

session_runtime.cancel():wait()

assert.stub(abort_stub).was_called()

abort_stub:revert()
end)

it('does not count cancel toward the server-restart threshold when no client request is in flight', function()
state.session.set_active({ id = 'sess1' })
store.set('job_count', 0)
vim.g.opencode_abort_count = 0

for _ = 1, 5 do
session_runtime.cancel():wait()
end

assert.is_equal(0, vim.g.opencode_abort_count)

store.set('job_count', 1)
vim.g.opencode_abort_count = 0
session_runtime.cancel():wait()
assert.is_equal(1, vim.g.opencode_abort_count)
end)
end)

describe('opencode_ok (version checks)', function()
Expand Down
Loading