cmd_delegate: race condition causes msg file to be deleted before opencode reads it #210

Closed
opened 2026-04-07 11:51:31 +02:00 by shoko · 0 comments
Owner

Problem

cmd_delegate deletes the message file immediately after spawning the background process, causing a race condition where opencode run may not have read the file yet.

Error

Error: File not found: /home/shoko/.kugetsu/logs/msg-ses_298b8ad7fffep3yh1QQDuyi6tz.txt

Root Cause

In cmd_delegate (kugetsu-session.sh:231):

printf %s "$message" > "$msg_file"
nohup sh -c "opencode run @ --session " >> "$log_file" 2>&1 &
rm -f "$msg_file" # Runs immediately after nohup, before opencode reads file!

The rm -f $msg_file executes right after nohup spawns the background process, but opencode run has not necessarily read the file yet.

Fix

Remove rm -f $msg_file from cmd_delegate, consistent with how cmd_start and cmd_continue handle message files (they write to $worktree_path/.kugetsu-msg.txt and never delete it).

Orphaned msg files in $LOGS_DIR/ are harmless and get cleaned up by log rotation in cmd_logs.

## Problem cmd_delegate deletes the message file immediately after spawning the background process, causing a race condition where opencode run may not have read the file yet. ## Error Error: File not found: /home/shoko/.kugetsu/logs/msg-ses_298b8ad7fffep3yh1QQDuyi6tz.txt ## Root Cause In cmd_delegate (kugetsu-session.sh:231): printf %s "$message" > "$msg_file" nohup sh -c "opencode run @ --session " >> "$log_file" 2>&1 & rm -f "$msg_file" # Runs immediately after nohup, before opencode reads file! The rm -f $msg_file executes right after nohup spawns the background process, but opencode run has not necessarily read the file yet. ## Fix Remove rm -f $msg_file from cmd_delegate, consistent with how cmd_start and cmd_continue handle message files (they write to $worktree_path/.kugetsu-msg.txt and never delete it). Orphaned msg files in $LOGS_DIR/ are harmless and get cleaned up by log rotation in cmd_logs.
shoko closed this issue 2026-04-07 11:54:24 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shoko/kugetsu#210