fix(kugetsu): queue daemon improvements - locking, error handling, cmd_delegate enqueue #164

Merged
shoko merged 5 commits from fix/issue-156-queue-fixes into main 2026-04-06 02:06:36 +02:00
Owner

Summary

Comprehensive fixes for the queue daemon and cmd_delegate workflow:

cmd_delegate changes (issue #158):

  • cmd_delegate now enqueues tasks instead of directly calling cmd_start
  • Tasks are processed by the daemon via cmd_start/cmd_continue

Queue daemon fixes:

  1. Locking: Added acquire_lock/release_lock to prevent conflicts between daemon and manual operations
  2. Proper state updates: Only update state to 'notified' after cmd_start/cmd_continue succeeds
  3. Error handling: Set state to 'error' if command fails, release lock on completion
  4. Session tracking: Get actual session_id from session file after cmd_start completes
  5. GITEA_TOKEN: Use load_agent_env 'pm-agent' for proper token loading

Additional fixes:

  • Moved update_queue_item_state and kugetsu_add_notification to kugetsu-index.sh for daemon access
  • Added required module sourcing to kugetsu-session.sh for daemon use

Issues Fixed

  • #158: cmd_delegate bypassing queue
  • #156: Queue daemon crashes with unbound GITEA_TOKEN
  • Critical race conditions and failure handling

Separate Issues to Address Later

  • Issue #5: origin/main..HEAD hardcoded (needs configurable base branch)
  • Issue #6: Timeout handling for long-running tasks
## Summary Comprehensive fixes for the queue daemon and cmd_delegate workflow: ### cmd_delegate changes (issue #158): - cmd_delegate now enqueues tasks instead of directly calling cmd_start - Tasks are processed by the daemon via cmd_start/cmd_continue ### Queue daemon fixes: 1. **Locking**: Added acquire_lock/release_lock to prevent conflicts between daemon and manual operations 2. **Proper state updates**: Only update state to 'notified' after cmd_start/cmd_continue succeeds 3. **Error handling**: Set state to 'error' if command fails, release lock on completion 4. **Session tracking**: Get actual session_id from session file after cmd_start completes 5. **GITEA_TOKEN**: Use load_agent_env 'pm-agent' for proper token loading ### Additional fixes: - Moved update_queue_item_state and kugetsu_add_notification to kugetsu-index.sh for daemon access - Added required module sourcing to kugetsu-session.sh for daemon use ## Issues Fixed - #158: cmd_delegate bypassing queue - #156: Queue daemon crashes with unbound GITEA_TOKEN - Critical race conditions and failure handling ## Separate Issues to Address Later - Issue #5: origin/main..HEAD hardcoded (needs configurable base branch) - Issue #6: Timeout handling for long-running tasks
shoko added 5 commits 2026-04-06 02:03:24 +02:00
When cmd_delegate detects an issue ref with number (e.g. git.fbrns.co/shoko/kugetsu#158),
it was calling cmd_start directly which tries to create worktree and clone.
This breaks the queue-based workflow where daemon should handle task execution.

Now cmd_delegate calls enqueue_task to add to queue, and daemon processes
tasks by calling cmd_start/cmd_continue as appropriate.
The daemon (kugetsu-queue-daemon.sh) sources kugetsu-index.sh but not the main kugetsu script.
Move update_queue_item_state and kugetsu_add_notification to kugetsu-index.sh
so the daemon can use these functions when processing tasks.
When daemon sources kugetsu-session.sh to call cmd_start/cmd_continue,
it needs access to functions from kugetsu-config.sh, kugetsu-index.sh,
kugetsu-worktree.sh, and kugetsu-log.sh. Add sourcing at top of
kugetsu-session.sh.
- Add acquire_lock/release_lock to prevent daemon vs manual conflicts
- Check cmd_start/cmd_continue success before updating state to 'notified'
- Set state to 'error' if command fails
- Track actual session_id from session file after cmd_start completes
- Release lock when task completes (success or error)
- Use load_agent_env 'pm-agent' for GITEA_TOKEN

Fixes critical race conditions and failure handling in queue processing
han approved these changes 2026-04-06 02:06:12 +02:00
han left a comment
First-time contributor

lgtm

lgtm
shoko merged commit 84c59a3b64 into main 2026-04-06 02:06:36 +02:00
Sign in to join this conversation.