This repository was archived by the owner on Apr 9, 2026. It is now read-only.
Repository navigation
fix(watcher): add debounce to prevent duplicate IPC actions - #78
Merged
Merged
Conversation
added 2 commits
January 12, 2026 23:14
…ations - Change consumption order: read content, clear file, then execute side-effect - Add 3-second debounce window for identical URL/notification content - Use md5 hash for notification content comparison - Fixes issue where OpenCode writes IPC files 7-11 times per action
added 4 commits
January 12, 2026 23:21
Problem: fswatch processes were becoming orphans because: - ocd_start_watcher runs in subshell, returns subshell PID - kill only killed subshell, not fswatch (child process) - Result: 130+ zombie fswatch processes accumulating Solution: - Enable job control (set -m) before spawning watcher - This makes subshell a process group leader - kill -- -$PID now correctly kills entire group - Add pkill fallback for any residual processes - Use process group kill in startup cleanup too
The previous fix used set -m inside ocd_start_watcher, but when called via $() command substitution, it ran in a subshell where set -m had no effect on the main shell's process group handling. Changes: - ocd_start_watcher now sets global _OCD_WATCHER_PID directly - bin/ocd calls ocd_start_watcher without $() wrapper - This ensures set -m runs in main shell, making process group kill work - Added pkill fallback in _ocd_cleanup for extra safety
aaajiao
force-pushed
the
fix/ipc-debounce
branch
from
January 12, 2026 23:03
ac46ea6 to
510a466
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
Fixes duplicate browser windows and notifications when OpenCode writes to IPC files multiple times per action.
Problem
When OpenCode triggers IPC events (e.g., opening WebUI, sending notifications), it writes to IPC files 7-11 times per action due to internal implementation. The OCD watcher had a race condition:
opencommand)This allowed subsequent writes to trigger additional executions before the file was cleared.
Solution
Atomic Consumption
Changed order to: read → clear → execute
This ensures the file is cleared before the slow side-effect runs, preventing race conditions.
Debounce Logic
State stored in
/tmp/.ocd_ipc_state/with timestamp + content tracking.Changes
lib/watcher.sh: Added atomic consumption + debounce toocd_handle_urlandocd_handle_notifytests/bats/watcher.bats: Added 6 new tests for debounce behaviorTesting