Bug: Forked sessions show same session ID as pm-agent + delegate without args shows wrong error #81
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?
Bug Description
Two bugs observed when running
kugetsu delegatefor a new issue:Bug 1: Forked session shows same session ID as pm-agent
Steps to reproduce:
Expected: Forked session should have its own unique session ID (e.g.,
ses_zzz).Actual: Forked session shows
ses_yyywhich is the pm-agent's session ID. This means both the pm-agent and the forked issue appear to share the same session.Likely cause: In
cmd_start(), the session ID detection loop finds the pm-agent's session first (or the pm-agent session shares the same ID after fork):The pm-agent was forked from the base session, so it appears in
after_sessionsbut not inbefore_set. The condition[[ "$sess" != "$base_session_id" ]]is true for the pm-agent, so it gets assigned as the new session ID.Bug 2:
kugetsu delegatewithout arguments shows opencode help instead of errorSteps to reproduce:
Expected: Error message like "Error: message is required" or "Usage: kugetsu delegate "
Actual: Prints opencode CLI help text (opencode's own help, not kugetsu's).
Likely cause: When
kugetsu delegateis called without arguments, thecmd_delegatefunction callskugetsu delegatewith no message, but the shell appears to route it toopencode runwhich prints its help.Actually looking at the code more carefully:
When called as
kugetsu delegatewith no message at all (positional args),messagewould be empty and should print the error. But the actual output was opencode help. This might be a shell parsing issue where$1isn't being passed correctly when the command is run without subshell.Environment
Severity
Medium — the session ID bug means forked issue sessions are not properly isolated from the pm-agent. The delegate command still "works" in that it creates worktrees and triggers opencode, but session tracking is broken.
Files affected
~/.local/bin/kugetsu— the main scriptcmd_start()function — session detection after forkcmd_delegate()function — argument handlingClarifying Questions
I reviewed this issue and have some questions:
Bug 1 (session ID collision):
I see that
cmd_delegate(lines 509-529) sends a message to the existing PM agent viaopencode run --continue --session "$pm_session"- it does NOT create a new forked session. A new session is only created bycmd_start.But the output you showed indicates
Session started for "owner/repo#2": ses_yyywhich comes fromcmd_start, notcmd_delegate.Can you clarify: is the bug happening when you call
kugetsu startdirectly, or is there a code path wherecmd_delegatecallscmd_start?Bug 2 (delegate without args):
The current code already has this check:
Has this been fixed already, or are you seeing different behavior?
Additional context:
The issue title mentions "forked sessions show same session ID as pm-agent" - can you confirm if:
kugetsu listshows the same ID for both?Replies
Bug 1 (session ID collision):
cmd_delegateDOES callcmd_startwhen an issue ref is found in the message. My message was:This matches the short ref pattern and
cmd_startwas called. The sequence was:kugetsu delegate "git.fbrns.co/shoko/jigaido#2 - ..."cmd_delegateextracted issue refgit.fbrns.co/shoko/jigaido#2cmd_startwas calledcmd_startforked from base session (ses_2b7b405...)ses_2b7a817(the pm-agent's session) was returnedThe root cause you identified is likely correct — the pm-agent was forked from base earlier and appears in
after_sessionsbut not inbefore_set, so it gets picked up as "new."To confirm:
kugetsu listshowed the forked issue AND pm-agent sharing the same session ID (ses_2b7a817daffeaQGNzKDT5q1F3t).Bug 2 (delegate without args):
The code has the check but when I ran
kugetsu delegate(without any arguments), it printed opencode help instead of the error. I did NOT pass$1— I literally rankugetsu delegatewith no arguments at all. The checkif [ -z "$message" ]wheremessage="${1:-}"should have caught this, but it seems like the shell is routing toopencode runwith no message argument which then shows its own help.So both issues are confirmed. The session ID bug makes delegation unusable for new issues. The delegate-without-args bug is a minor UX issue.
Summary:
kugetsu listkugetsu delegatewith no args shows opencode help instead of kugetsu error