fix(kugetsu): queue daemon runs PM agent in correct worktree with proper token #157

Merged
shoko merged 2 commits from fix/issue-156 into main 2026-04-05 23:39:35 +02:00
Owner

Summary

The queue daemon was running the PM agent with --continue --session $pm_session which caused the agent to operate in the wrong directory (daemon process CWD ~/.kugetsu/ instead of the target worktree). This resulted in zero commits after 6+ hours of processing.

Changes

  • Load GITEA_TOKEN from ~/.kugetsu/env/default.env at daemon startup
  • Use --fork --session --dir instead of --continue to run in correct worktree directory
  • Create worktree if it does not exist for the issue before delegating
  • Track forked session ID (not parent pm_session) for completion detection
  • Forked session ends when task completes, parent pm_session continues

Root Cause

# OLD (buggy):
nohup env GITEA_TOKEN="***" sh -c "opencode run ... --continue --session $pm_session" ...

# NEW (fixed):
(cd "$worktree_path" && nohup bash -c "export GITEA_TOKEN=$GITEA_TOKEN opencode run ... --fork --session $pm_session --dir $worktree_path" ...)

Without --dir, opencode uses the daemon process CWD (~/.kugetsu/), not the session directory. Without --fork, the shared session has no per-task isolation.

Fixes #156

## Summary The queue daemon was running the PM agent with `--continue --session $pm_session` which caused the agent to operate in the **wrong directory** (daemon process CWD ~/.kugetsu/ instead of the target worktree). This resulted in zero commits after 6+ hours of processing. ## Changes - **Load GITEA_TOKEN from ~/.kugetsu/env/default.env** at daemon startup - **Use --fork --session --dir** instead of --continue to run in correct worktree directory - **Create worktree if it does not exist** for the issue before delegating - **Track forked session ID** (not parent pm_session) for completion detection - Forked session ends when task completes, parent pm_session continues ## Root Cause ``` # OLD (buggy): nohup env GITEA_TOKEN="***" sh -c "opencode run ... --continue --session $pm_session" ... # NEW (fixed): (cd "$worktree_path" && nohup bash -c "export GITEA_TOKEN=$GITEA_TOKEN opencode run ... --fork --session $pm_session --dir $worktree_path" ...) ``` Without --dir, opencode uses the daemon process CWD (~/.kugetsu/), not the session directory. Without --fork, the shared session has no per-task isolation. Fixes #156
shoko added 1 commit 2026-04-05 22:58:43 +02:00
- Load GITEA_TOKEN from ~/.kugetsu/env/default.env at daemon startup
- Use --fork --session --dir instead of --continue to run in correct directory
- Create worktree if it doesn't exist for the issue
- Track forked session ID (not parent pm_session) for completion detection
- Forked session ends when task completes, parent pm_session continues

Fixes #156
shoko added 1 commit 2026-04-05 23:29:42 +02:00
- Move issue_ref_to_filename and filename_to_issue_ref to kugetsu-index.sh
  (where they logically belong, instead of in main kugetsu script)
- Refactor queue daemon to use cmd_start/cmd_continue for session management
- Daemon now checks if worktree/session exists → cmd_continue, else → cmd_start
- Removes ~40 lines of direct opencode session forking logic from daemon
- cmd_start/cmd_continue handle worktree creation, session forking, and tracking

This simplifies the daemon significantly and centralizes session management
in kugetsu-session.sh where it belongs.
han approved these changes 2026-04-05 23:39:09 +02:00
han left a comment
First-time contributor

lgtm

lgtm
shoko merged commit deb18f1e32 into main 2026-04-05 23:39:35 +02:00
Sign in to join this conversation.