Skip to content

Commit 859b455

Browse files
sakurachanclaude
andcommitted
Fix hash extraction to handle hash-only instance identifiers
The target_hash extraction logic previously only handled the "ProjectName@hash" format, causing it to fail when instance_id was a plain hash (fallback format). This resulted in read_status_file returning the most recent instance instead of the specific instance, breaking per-instance routing during reconnection. Changes: - Update hash extraction to handle both "ProjectName@hash" and hash-only formats - When instance_id contains '@', extract the part after '@' as before - When instance_id has no '@', treat the entire string as the hash - Applied to both Server/ and MCPForUnity/ versions Addresses CodeRabbit feedback: - #360 (comment) - #360 (comment) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 5780adb commit 859b455

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

MCPForUnity/UnityMcpServer~/src/unity_connection.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,14 @@ def read_status_file(target_hash: str | None = None) -> dict | None:
263263

264264
# Extract hash suffix from instance id (e.g., Project@hash)
265265
target_hash: str | None = None
266-
if self.instance_id and '@' in self.instance_id:
267-
maybe_hash = self.instance_id.split('@', 1)[1].strip()
268-
if maybe_hash:
269-
target_hash = maybe_hash
266+
if self.instance_id:
267+
if '@' in self.instance_id:
268+
maybe_hash = self.instance_id.split('@', 1)[1].strip()
269+
if maybe_hash:
270+
target_hash = maybe_hash
271+
else:
272+
# instance_id is just the hash (fallback format)
273+
target_hash = self.instance_id.strip()
270274

271275
# Preflight: if Unity reports reloading, return a structured hint so clients can retry politely
272276
try:

Server/unity_connection.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,14 @@ def read_status_file(target_hash: str | None = None) -> dict | None:
263263

264264
# Extract hash suffix from instance id (e.g., Project@hash)
265265
target_hash: str | None = None
266-
if self.instance_id and '@' in self.instance_id:
267-
maybe_hash = self.instance_id.split('@', 1)[1].strip()
268-
if maybe_hash:
269-
target_hash = maybe_hash
266+
if self.instance_id:
267+
if '@' in self.instance_id:
268+
maybe_hash = self.instance_id.split('@', 1)[1].strip()
269+
if maybe_hash:
270+
target_hash = maybe_hash
271+
else:
272+
# instance_id is just the hash (fallback format)
273+
target_hash = self.instance_id.strip()
270274

271275
# Preflight: if Unity reports reloading, return a structured hint so clients can retry politely
272276
try:

0 commit comments

Comments
 (0)