init script captures wrong session IDs when old sessions exist #172

Closed
opened 2026-04-06 03:06:26 +02:00 by shoko · 0 comments
Owner

Bug: init script grabs stale session IDs instead of newly created ones

Steps to reproduce

  1. Have existing opencode sessions (e.g. from previous kugetsu usage)
  2. Run kugetsu init
  3. Observe: index.json contains wrong/old session IDs

Root cause

kugetsu-session.sh cmd_init_new_session() uses tail -1 to find sessions created before init runs, expecting the new session to be last. But if old stale sessions exist, tail -1 picks one of those instead.

# Line 86 - the problematic code
local session_ids=$(opencode session list 2>/dev/null | grep -E '^ses_' | awk '{print $1}' | tail -1)
local pm_session_ids=$(opencode session list 2>/dev/null | grep -E '^ses_' | grep -v "$session_ids" | tail -1)

This approach is fragile. It should capture the session IDs after creating new sessions and diff, not try to infer which is new from the before-state.

Expected behavior

After clean install and init, kugetsu status should return ok immediately.

Actual behavior

index.json contains mismatched IDs, kugetsu status fails:

error: pm_agent session 'ses_2b4814406ffe3AxcpbrP7FknDr  Clean up stale git branches...' not found in opencode

The pm_agent field also captures the full session title line instead of just the session ID, suggesting the parsing is doing awk '{print $1}' on the wrong column or the session list format changed.

Bug: init script grabs stale session IDs instead of newly created ones ## Steps to reproduce 1. Have existing opencode sessions (e.g. from previous kugetsu usage) 2. Run `kugetsu init` 3. Observe: index.json contains wrong/old session IDs ## Root cause `kugetsu-session.sh` cmd_init_new_session() uses `tail -1` to find sessions created *before* init runs, expecting the new session to be last. But if old stale sessions exist, `tail -1` picks one of those instead. ```bash # Line 86 - the problematic code local session_ids=$(opencode session list 2>/dev/null | grep -E '^ses_' | awk '{print $1}' | tail -1) local pm_session_ids=$(opencode session list 2>/dev/null | grep -E '^ses_' | grep -v "$session_ids" | tail -1) ``` This approach is fragile. It should capture the session IDs *after* creating new sessions and diff, not try to infer which is new from the before-state. ## Expected behavior After clean install and init, `kugetsu status` should return `ok` immediately. ## Actual behavior index.json contains mismatched IDs, `kugetsu status` fails: ``` error: pm_agent session 'ses_2b4814406ffe3AxcpbrP7FknDr Clean up stale git branches...' not found in opencode ``` The pm_agent field also captures the full session title line instead of just the session ID, suggesting the parsing is doing `awk '{print $1}'` on the wrong column or the session list format changed.
shoko closed this issue 2026-04-06 03:09:30 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shoko/kugetsu#172