Compare commits

..

4 Commits

Author SHA1 Message Date
ffdf5e34c8 Merge pull request 'fix(kugetsu): improve session detection in cmd_start with retry logic and logging' (#107) from fix/start-session-detection into main 2026-04-02 11:41:52 +02:00
shokollm
b3ac73a283 Merge origin/main into fix/start-session-detection
Resolve conflict: use cd approach for worktree, keep retry logic
2026-04-02 09:39:45 +00:00
shokollm
1128b3dfa8 fix(kugetsu): improve session detection in cmd_start with retry logic and logging
- Capture fork output to log file for debugging
- Track fork PID to detect if process exits early
- Retry session detection up to 10 seconds instead of 1 second
- Show fork log output when session creation fails
- Improve error message to indicate timeout
2026-04-02 09:29:30 +00:00
90f46a778a Merge pull request 'fix: use cd + worktree inside parent dir instead of --dir flag (fixes #105)' (#106) from fix/worktree-isolation-via-cd into main 2026-04-02 10:29:32 +02:00

View File

@@ -1243,40 +1243,62 @@ cmd_start() {
exit 1 exit 1
fi fi
local fork_log="$SESSIONS_DIR/$session_file.fork.log"
if [ "$DEBUG_MODE" = true ]; then if [ "$DEBUG_MODE" = true ]; then
(cd "$worktree_path" && opencode run "$message" --fork --session "$base_session_id" 2>&1) | tee "$SESSIONS_DIR/$session_file.debug.log" & (cd "$worktree_path" && opencode run "$message" --fork --session "$base_session_id" 2>&1) | tee "$fork_log" &
else else
(cd "$worktree_path" && opencode run "$message" --fork --session "$base_session_id" 2>&1) & (cd "$worktree_path" && opencode run "$message" --fork --session "$base_session_id" 2>&1) >> "$fork_log" &
fi fi
# Wait briefly for session to be created local fork_pid=$!
sleep 1
local max_attempts=10
# Find the new session by comparing before/after lists local attempt=1
# Skip any session that existed before the fork and skip base/pm-agent
local new_session_id="" local new_session_id=""
while IFS= read -r sess; do
# Skip base and pm-agent while [ $attempt -le $max_attempts ]; do
[ "$sess" = "$base_session_id" ] && continue sleep 1
[ "$sess" = "$pm_agent_session_id" ] && continue
# Check if this session existed before if ! kill -0 $fork_pid 2>/dev/null; then
local existed_before=false if [ -s "$fork_log" ]; then
for before_sess in "${before_sessions[@]}"; do echo "Fork command exited. Log output:" >&2
if [ "$sess" = "$before_sess" ]; then tail -20 "$fork_log" >&2
existed_before=true
break
fi fi
done
if [ "$existed_before" = false ]; then
new_session_id="$sess"
break break
fi fi
done < <(opencode session list 2>/dev/null | grep -oP '^ses_\w+')
while IFS= read -r sess; do
[ "$sess" = "$base_session_id" ] && continue
[ "$sess" = "$pm_agent_session_id" ] && continue
local existed_before=false
for before_sess in "${before_sessions[@]}"; do
if [ "$sess" = "$before_sess" ]; then
existed_before=true
break
fi
done
if [ "$existed_before" = false ]; then
new_session_id="$sess"
break
fi
done < <(opencode session list 2>/dev/null | grep -oP '^ses_\w+')
if [ -n "$new_session_id" ]; then
break
fi
attempt=$((attempt + 1))
done
if [ -z "$new_session_id" ]; then if [ -z "$new_session_id" ]; then
echo "Error: Could not find newly created session" >&2 echo "Error: Could not find newly created session after ${max_attempts}s" >&2
if [ -f "$fork_log" ] && [ -s "$fork_log" ]; then
echo "Fork log:" >&2
tail -30 "$fork_log" >&2
fi
remove_worktree_for_issue "$issue_ref" remove_worktree_for_issue "$issue_ref"
exit 1 exit 1
fi fi