Queue daemon PM agent context drift — agent operates in wrong directory #156
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
The kugetsu queue daemon uses
opencode run --continue --session $pm_sessionwhich causes the PM agent to operate in the wrong working directory — the daemon process CWD (~/.kugetsu/) instead of the target repository worktree. This results in zero commits after 6+ hours of processing.Replacing
--continuewith--forkalone does not fix this. The fix requires--forkcombined with--dir <worktree_path>.Root Cause
The daemon command at line 65 of
kugetsu-queue-daemon.sh:Problems:
--dirflag — opencode uses the daemon process CWD, not the session directory--forkflag — shared session has no per-task isolationissue_ref_to_worktree_pathis never calledGITEA_TOKEN=***— the token is literally***, agent has no tokenFrom SQLite evidence (
~/.local/share/opencode/opencode.db):Delegation logs confirm the agent operates in
~/.kugetsu/and~/.kugetsu/repositories/kugetsu/, processing kugetsu's own issues instead of target repos.Why
--forkalone does NOT fix itFrom
opencode run --help:When
--fork --session $pm_sessionis used:parent_idsetdirectoryfrom SQLite--dir, the forked session still hasdirectory = /home/shoko/.kugetsu-worktrees— wrongProof from
kugetsu start(which works correctly):--fork+--dir+cdall needed together.Concrete Fix
Before:
nohup bash -c "export GITEA_TOKEN=***; opencode run '$message' --continue --session '$pm_session'" >> '$log_file' 2>&1 &
After:
worktree_path=$(issue_ref_to_worktree_path "$issue_ref" "$HOME/.kugetsu-worktrees")
(cd "$worktree_path" && nohup bash -c "export GITEA_TOKEN=$GITEA_TOKEN; opencode run '$message' --fork --session '$pm_session' --dir '$worktree_path'" >> '$log_file' 2>&1) &
Additional Bugs to Fix
--fork, parentpm_sessionnever ends. Detection must check if forked session ended, not parent.***. Theload_agent_envfunction exists but is not called before task launch.Files Involved
~/.local/bin/kugetsu-queue-daemon.sh(installed daemon, line 68)~/.hermes/skills/kugetsu/scripts/kugetsu-queue-daemon.sh(repository version, line 65)~/.local/bin/kugetsu-worktree.sh— providesissue_ref_to_worktree_pathopencode dbat~/.local/share/opencode/opencode.db