fix: session ID collision in cmd_start + delegate issue ref extraction #82

Closed
shoko wants to merge 0 commits from fix/issue-81-session-id-collision into main
Owner

Summary

Fixes two bugs in issue #81:

  1. Session ID collision: When cmd_start detects newly created sessions after forking, it now excludes both base_session_id AND pm_agent_session_id from detection.

  2. Delegate issue ref extraction: cmd_delegate now extracts issue refs from messages and calls cmd_start directly when an issue ref is found.

  3. GITEA_TOKEN pass-through: Passes GITEA_TOKEN environment variable to opencode run.

Changes

  • extract_issue_ref_from_message(): New function to parse issue refs
  • cmd_delegate(): Now calls cmd_start when issue ref is found
  • cmd_start(): Session detection now excludes pm_agent_session_id

Fixes #81

## Summary Fixes two bugs in issue #81: 1. **Session ID collision**: When `cmd_start` detects newly created sessions after forking, it now excludes both `base_session_id` AND `pm_agent_session_id` from detection. 2. **Delegate issue ref extraction**: `cmd_delegate` now extracts issue refs from messages and calls `cmd_start` directly when an issue ref is found. 3. **GITEA_TOKEN pass-through**: Passes `GITEA_TOKEN` environment variable to `opencode run`. ## Changes - `extract_issue_ref_from_message()`: New function to parse issue refs - `cmd_delegate()`: Now calls `cmd_start` when issue ref is found - `cmd_start()`: Session detection now excludes pm_agent_session_id Fixes #81
shoko added 1 commit 2026-04-02 01:04:40 +02:00
- Fix session ID detection in cmd_start to exclude pm_agent_session_id
  (prevents forked sessions from getting same ID as pm-agent)
- Add extract_issue_ref_from_message function for parsing issue refs
  from short format (git.fbrns.co/user/repo#123) or URLs
- Update cmd_delegate to call cmd_start when issue ref is found
- Pass GITEA_TOKEN to opencode run for API access
- Fixes #81
shoko force-pushed fix/issue-81-session-id-collision from 0a2baf99d5 to ae99f86f9d 2026-04-02 01:36:00 +02:00 Compare
shoko added 1 commit 2026-04-02 01:43:19 +02:00
Replace string-based session comparison with array-based approach:

- Store before_sessions in an array instead of pipe-delimited string
- This is more robust against word-splitting issues in bash
- Skip base_session_id and pm_agent_session_id explicitly
- Compare each after-session against the before array

This approach is more reliable when multiple agents fork concurrently
because it properly compares each session ID individually rather than
relying on regex matching in a string.

Fixes #81
shoko added 1 commit 2026-04-02 02:07:21 +02:00
Document findings from database investigation:
- Session table schema with all fields explained
- Session ID format and generation (unique, no duplicates)
- Parent-child relationships for forked sessions
- Session detection logic used by kugetsu
- Permission structure and common issues
- SQL queries for debugging session problems
- Known issues and solutions (from #81, #36)

This document helps future debugging of session-related issues
without having to investigate opencode internals directly.
han approved these changes 2026-04-02 02:12:59 +02:00
han left a comment
First-time contributor

lgtm

lgtm
shoko closed this pull request 2026-04-02 02:14:01 +02:00
shoko deleted branch fix/issue-81-session-id-collision 2026-04-02 02:14:01 +02:00

Pull request closed

Sign in to join this conversation.