Skip to content

fix: wait for SessionStart hook in window picker flow#35

Open
hscheema1979 wants to merge 7 commits intosix-ddc:mainfrom
hscheema1979:fix/session-tracking-and-status-polling
Open

fix: wait for SessionStart hook in window picker flow#35
hscheema1979 wants to merge 7 commits intosix-ddc:mainfrom
hscheema1979:fix/session-tracking-and-status-polling

Conversation

@hscheema1979
Copy link

Summary

Fixes race condition in window picker flow where ccbot binds a new topic to an existing tmux window before the SessionStart hook has written the session_map entry.

Problem

When creating a new Telegram topic and using the window picker to select an existing tmux window:

  1. User selects window from picker
  2. ccbot immediately calls bind_thread()
  3. User sends first message to the new topic
  4. ccbot tries to forward message but gets KeyError: "Session not in session_map"

Root cause: The SessionStart hook runs asynchronously and needs time to write session_map.json. The window picker flow was calling bind_thread() immediately after window selection, without waiting for the hook to complete.

Solution

Added wait_for_session_map_entry() call in the window picker callback handler (bot.py line ~1141):

  • Waits up to 5 seconds for session_map entry to appear
  • Returns early with user-friendly error if timeout occurs
  • Logs warning for troubleshooting
  • Only affects window picker flow (auto-create flow already had this fix)

Changes

  • bot.py: Added wait_for_session_map_entry() call before bind_thread() in CB_WIN_BIND handler
  • docs/TESTING_FIX.md: Added comprehensive testing procedure

Testing

See docs/TESTING_FIX.md for detailed testing procedure.

Success criteria:

  • ✅ Window picker successfully binds to existing windows
  • ✅ No "Session not in session_map" errors
  • ✅ Topic renames to match window name
  • ✅ Pending messages are forwarded correctly
  • ✅ session_map.json contains the new binding

Related

This mirrors the fix already applied to the auto-create flow (line 1033), ensuring consistency across both session creation paths.


🤖 Generated with Claude Code

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants