Skip to content

fix(session): include workDir in platform session key derivation to prevent ID collision #16

@hrygo

Description

@hrygo

Problem

When workDir is changed (e.g., from /tmp/hotplex/workspace to /tmp/hotplex/workspace/hotplex-worker), messaging platform sessions (Feishu DM, Slack DM/thread) reuse the same session ID because DerivePlatformSessionKey does not include workDir in its UUIDv5 hash input.

This causes Claude Code CLI to fail with:

Error: Session ID <id> is already in use.

The gateway correctly terminates the old session and creates a new one with the same ID, but the CLI's local session files (under ~/.claude/projects/<old-workdir>/) still exist, causing a conflict.

Root Cause

  • DeriveSessionKey (WebSocket/web) already includes workDir in the hash
  • DerivePlatformSessionKey (Feishu/Slack) does not include workDir
  • NewBridge replaces empty workDir with DefaultWorkerWorkDir, so the same conversation always maps to the same session ID regardless of actual working directory

Fix

Add WorkDir field to PlatformContext and include it in the DerivePlatformSessionKey UUIDv5 hash. This ensures different working directories produce different session IDs for the same conversation context.

Impact

  • Same DM/thread on different workDir → different session IDs (no collision)
  • Same DM/thread on same workDir → same session ID (deterministic, as before)
  • Empty WorkDir is excluded from hash (backward-compatible for direct callers)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions