- Auto-detect browser mode from existing session metadata instead of assuming default; error on explicit mode conflicts
- Make --json work after subcommands (not just before) via argparse SUPPRESS
- Deduplicate utils between main.py and utils.py (lazy portalocker import)
- Extract inline command handlers from main() into standalone functions
- Fix get_available_modes() to match is_mode_available() LOCAL_MODES logic
- Fix setup validation icons for boolean results
- Delete unused protocol.py
The session server had a race condition where concurrent CLI calls could
spawn multiple server processes. The old server would be orphaned when
the new one overwrote the PID file and deleted its socket.
Changes:
- Add flock-based locking using portalocker (already a dependency)
- Server acquires exclusive lock before writing PID file
- CLI checks both is_server_running() AND is_session_locked()
- Add kill_orphaned_server() to clean up servers with PID but no lock
- Increase socket timeout from 0.1s to 0.5s for reliability
- cleanup_session_files() now removes .lock and .meta files
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Use ctypes.OpenProcess on Windows for process existence check
(os.kill raises WinError 87 or SystemError on Windows)
- Use 127.0.0.1 instead of localhost to avoid IPv6 binding issues
- Add reuse_address=True to asyncio.start_server for TCP port reuse
Fixes issues reported in:
- #3912 (os.kill fails on Windows)
- #3918 (WinError 87 in is_server_running)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>