Feature: kugetsu delegate should be fire-and-forget #41

Closed
opened 2026-03-31 07:32:33 +02:00 by shoko · 2 comments
Owner

Problem

Currently kugetsu delegate is blocking - user waits for PM to respond.

Expected: Fire-and-Forget

kugetsu delegate "work on #5"  # Returns immediately
kugetsu delegate "review #12"  # Can queue multiple tasks
kugetsu notify list            # Check results

Testing (VERIFIED WORKING - 2026-03-31)

cd /tmp
nohup opencode run --continue --session ses_xxx "echo test" > /tmp/delegate-test.log 2>&1 & disown
echo "Delegated"
# Returns immediately, log shows command executed successfully

Result: Background execution works, output captured, immediate return.

Implementation

cmd_delegate() {
    local message="${1:-}"
    if [ -z "$message" ]; then
        echo "Error: message is required" >&2
        exit 1
    fi
    
    local pm_session=$(get_pm_agent_session_id)
    if [ -z "$pm_session" ] || [ "$pm_session" = "null" ]; then
        echo "Error: PM agent session not found. Run 'kugetsu init' first." >&2
        exit 1
    fi
    
    mkdir -p "$KUGETSU_DIR/logs"
    local log_file="$KUGETSU_DIR/logs/delegate-$(date +%s).log"
    nohup opencode run --continue --session "$pm_session" "$message" > "$log_file" 2>&1 &
    disown
    echo "Delegated to PM agent (logged to $(basename "$log_file"))"
}

Notes

  1. Log rotation needed - periodically clean $KUGETSU_DIR/logs/
  2. If PM session dead, command fails silently in background
  3. PM should write to notifications.json on completion (already in PM skill)
  • Issue #38 - fixed session checking
  • This completes the fix by making delegation async

Status

  • Tested: 2026-03-31
  • Implementation: pending
## Problem Currently `kugetsu delegate` is blocking - user waits for PM to respond. ## Expected: Fire-and-Forget ```bash kugetsu delegate "work on #5" # Returns immediately kugetsu delegate "review #12" # Can queue multiple tasks kugetsu notify list # Check results ``` ## Testing (VERIFIED WORKING - 2026-03-31) ```bash cd /tmp nohup opencode run --continue --session ses_xxx "echo test" > /tmp/delegate-test.log 2>&1 & disown echo "Delegated" # Returns immediately, log shows command executed successfully ``` Result: Background execution works, output captured, immediate return. ## Implementation ```bash cmd_delegate() { local message="${1:-}" if [ -z "$message" ]; then echo "Error: message is required" >&2 exit 1 fi local pm_session=$(get_pm_agent_session_id) if [ -z "$pm_session" ] || [ "$pm_session" = "null" ]; then echo "Error: PM agent session not found. Run 'kugetsu init' first." >&2 exit 1 fi mkdir -p "$KUGETSU_DIR/logs" local log_file="$KUGETSU_DIR/logs/delegate-$(date +%s).log" nohup opencode run --continue --session "$pm_session" "$message" > "$log_file" 2>&1 & disown echo "Delegated to PM agent (logged to $(basename "$log_file"))" } ``` ## Notes 1. Log rotation needed - periodically clean $KUGETSU_DIR/logs/ 2. If PM session dead, command fails silently in background 3. PM should write to notifications.json on completion (already in PM skill) ## Related - Issue #38 - fixed session checking - This completes the fix by making delegation async ## Status - Tested: 2026-03-31 - Implementation: pending

if PM session dead, and command fails silently in background, it will just confusing. what are the options to handle this? should we have log or something somewhere so all the delegation can pick it up. or even the kugetsu delegate command can pick it up before delgating to see if oh previous command fails because the PM session is dead, or something. what do you think? what are the simplest way to periodically clean KUGETSU_DIR/logs/ ? should we clean it up during init?

if PM session dead, and command fails silently in background, it will just confusing. what are the options to handle this? should we have log or something somewhere so all the delegation can pick it up. or even the kugetsu delegate command can pick it up before delgating to see if oh previous command fails because the PM session is dead, or something. what do you think? what are the simplest way to periodically clean KUGETSU_DIR/logs/ ? should we clean it up during init?
Author
Owner

Tradeoffs for Dead PM Session Handling

Option 1: Pre-check before delegating

  • Adds 2s latency to every delegate call
  • Actually wait... timeout on a live session still waits for agent response
  • So this does NOT work - opencode run always waits for agent
  • Rejected

Option 2: Marker file (PM removes on success)

  • Requires PM to modify behavior (remove marker after each task)
  • Adds complexity to PM agent
  • If PM crashes mid-task, marker remains - confusing
  • Rejected - too complex

Option 3: Log-based feedback (Simplest)

  • Keep current approach - logs capture everything
  • No additional complexity
  • User checks logs if something seems wrong
  • Accepted

Simplest Log Rotation

# In kugetsu init or a new kugetsu prune-logs command:
find "$KUGETSU_DIR/logs/" -type f -mtime +7 -delete  # Delete logs > 7 days
  1. Keep fire-and-forget as proposed (nohup + disown)
  2. Add kugetsu logs command to view recent delegation logs
  3. Add log rotation to kugetsu init or separate kugetsu prune-logs
  4. Do NOT add dead-session detection - if PM is dead, user will notice when notify list doesnt update

Dont over-engineer it - logs capture everything, user can check if something seems wrong.

## Tradeoffs for Dead PM Session Handling **Option 1: Pre-check before delegating** - Adds 2s latency to every delegate call - Actually wait... timeout on a live session still waits for agent response - So this does NOT work - opencode run always waits for agent - **Rejected** **Option 2: Marker file (PM removes on success)** - Requires PM to modify behavior (remove marker after each task) - Adds complexity to PM agent - If PM crashes mid-task, marker remains - confusing - **Rejected** - too complex **Option 3: Log-based feedback (Simplest)** - Keep current approach - logs capture everything - No additional complexity - User checks logs if something seems wrong - **Accepted** ## Simplest Log Rotation ```bash # In kugetsu init or a new kugetsu prune-logs command: find "$KUGETSU_DIR/logs/" -type f -mtime +7 -delete # Delete logs > 7 days ``` ## Recommended Approach 1. Keep fire-and-forget as proposed (nohup + disown) 2. Add `kugetsu logs` command to view recent delegation logs 3. Add log rotation to `kugetsu init` or separate `kugetsu prune-logs` 4. Do NOT add dead-session detection - if PM is dead, user will notice when notify list doesnt update **Dont over-engineer it** - logs capture everything, user can check if something seems wrong.
shoko closed this issue 2026-03-31 11:23:26 +02:00
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shoko/kugetsu#41