Skip to content

Commit b1ad9d7

Browse files
committed
fix(events): ignore server heartbeat and avoid draining empty queue
Add an ignore list for server events (e.g. "server.heartbeat") so noisy heartbeats don't trigger rendering. Also guard ThrottlingEmitter:_drain to skip calling the process function when there are no items to process, avoiding unnecessary work.
1 parent bce0569 commit b1ad9d7

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lua/opencode/event_manager.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ local log = require('opencode.log')
183183
--- @field state_cwd_listener function|nil Listener for state.current_cwd updates
184184
--- @field is_started boolean Whether the event manager is started
185185
--- @field captured_events table[] List of captured events for debugging
186+
--- @field events_to_ignore string[] List of event types to ignore from server
186187
--- @field throttling_emitter ThrottlingEmitter Throttle instance for batching events
187188
local EventManager = {}
188189
EventManager.__index = EventManager
@@ -198,6 +199,7 @@ function EventManager.new()
198199
is_started = false,
199200
captured_events = {},
200201
_parts_by_id = {},
202+
events_to_ignore = { 'server.heartbeat' },
201203
}, EventManager)
202204

203205
local throttle_ms = config.ui.output.rendering.event_throttle_ms
@@ -553,6 +555,10 @@ function EventManager:_subscribe_to_server_events(server)
553555
local api_client = state.api_client
554556

555557
local emitter = function(event)
558+
if not event or not event.type or vim.tbl_contains(self.events_to_ignore, event.type) then
559+
log.debug('Ignoring event from server: %s', vim.inspect(event))
560+
return
561+
end
556562
self.throttling_emitter:enqueue(event)
557563
end
558564

lua/opencode/throttling_emitter.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ function ThrottlingEmitter:_drain()
4646
local items_to_process = self.queue
4747
self.queue = {}
4848

49-
self.process_fn(items_to_process)
49+
if #items_to_process > 0 then
50+
self.process_fn(items_to_process)
51+
end
5052

5153
-- double check that items weren't added while processing
5254
if #self.queue > 0 and not self.drain_scheduled then

0 commit comments

Comments
 (0)