Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 30, 2025

Cards played during the 2-second wait period after a round ends were being cleared by the scheduled timeout from the previous round.

Problem

Race condition: round_ended schedules a setTimeout to clear playedCards after 2s. If a player starts a new round during this window, the stale timeout still fires and clears the new round's cards.

Solution

Added roundClearIdRef to invalidate pending timeouts when a new round starts.

// Capture current ID when scheduling
const clearId = roundClearIdRef.current;
setTimeout(() => {
  if (roundClearIdRef.current === clearId) {
    setPlayedCards({});
  }
}, 2000);

// Increment on new round to invalidate pending timeouts
roundClearIdRef.current += 1;
  • round_started: Increments ref before clearing, invalidating any pending timeout
  • round_ended: Captures ref value; timeout only clears if unchanged
  • game_restarted / next_game_started: Increments ref to handle edge cases
Original prompt

现在在一轮出完牌后的两秒等待时间内出牌会导致这张牌也一起消失。修复一下。


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…round ends

Added roundClearIdRef to track which round a setTimeout belongs to.
When a new round starts, the ref is incremented, causing any pending
timeout from the previous round to skip clearing the cards.

Co-authored-by: Roushelfy <104953631+Roushelfy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix card disappearance issue after dealing Fix cards disappearing when played during round-end wait period Nov 30, 2025
Copilot AI requested a review from Roushelfy November 30, 2025 20:41
@Roushelfy
Copy link
Collaborator

@copilot bot有时候还是会出错: [2025-11-30T20:36:07.255Z] [INFO] Bot AI Bot 2 当前手牌数: 22 [2025-11-30T20:36:07.327Z] [ERROR] Bot响应超时,强制结束进程 [2025-11-30T20:36:08.756Z] [INFO] 开始调用BotService.getBotAction... [2025-11-30T20:36:08.756Z] [INFO] ========== WhoDesigned Bot 决策开始 ========== [2025-11-30T20:36:08.756Z] [INFO] 玩家ID: de5b5749-77a2-487a-b4c1-f6b432963360, 玩家索引: 2, 阶段: play [2025-11-30T20:36:08.756Z] [INFO] 手牌数量: 22, deliver牌数量: 0 [2025-11-30T20:36:08.756Z] [INFO] 历史记录: requests=4, responses=4 [2025-11-30T20:36:08.756Z] [INFO] 构建history: previousRoundCards长度=4, currentRoundCards长度=2, previousLeader=0, currentLeader=0 [2025-11-30T20:36:08.756Z] [INFO] [构建request] 当前阶段request: {"stage":"play","deliver":[],"global":{"first_round":true,"level":"10","banking":{"called":-1,"snatched":-1,"major":"s","banker":2},"total_score":0},"history":[[[48],[70],[24],[62]],[[98],[82]],0,0]} [2025-11-30T20:36:08.757Z] [INFO] [Bot输入] requests数量: 5, responses数量: 4 [2025-11-30T20:36:08.757Z] [INFO] 调用Bot脚本: /app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py [2025-11-30T20:36:08.795Z] [WARN] Bot stderr: Traceback (most recent call last): File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py", line 64, in [2025-11-30T20:36:08.796Z] [WARN] Bot stderr: setMajor(major, level) File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/myutils.py", line 15, in setMajor pointorder.remove(level) ValueError: list.remove(x): x not in list [2025-11-30T20:36:08.801Z] [INFO] Bot进程退出,代码: 1 [2025-11-30T20:36:08.801Z] [ERROR] Bot进程退出,代码: 1, 错误: Traceback (most recent call last): File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py", line 64, in setMajor(major, level) File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/myutils.py", line 15, in setMajor pointorder.remove(level) ValueError: list.remove(x): x not in list [2025-11-30T20:36:08.801Z] [ERROR] [Bot决策失败] 阶段: play, 错误: Bot进程退出,代码: 1, 错误: Traceback (most recent call last): File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py", line 64, in setMajor(major, level) File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/myutils.py", line 15, in setMajor pointorder.remove(level) ValueError: list.remove(x): x not in list [2025-11-30T20:36:08.801Z] [ERROR] [Bot决策失败] 错误堆栈: Error: Bot进程退出,代码: 1, 错误: Traceback (most recent call last): File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py", line 64, in setMajor(major, level) File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/myutils.py", line 15, in setMajor pointorder.remove(level) ValueError: list.remove(x): x not in list at ChildProcess. (file:///app/tractor-game-simulator/server/src/services/WhoDesignedBotService.js:475:18) at ChildProcess.emit (node:events:517:28) at maybeClose (node:internal/child_process:1098:16) at ChildProcess._handle.onexit (node:internal/child_process:303:5) [2025-11-30T20:36:08.801Z] [INFO] [Fallback] play阶段: 返回空数组(跳过),将由gameHandlers的fallback处理 [2025-11-30T20:36:08.801Z] [INFO] [Fallback] 已将默认响应添加到历史,新responses长度: 5 [2025-11-30T20:36:08.801Z] [INFO] ========== WhoDesigned Bot 决策失败,使用Fallback ========== [2025-11-30T20:36:08.801Z] [INFO] Bot AI Bot 2 决策完成,选择出牌: 0 张,卡牌IDs: [] [2025-11-30T20:36:08.801Z] [INFO] 执行Bot AI Bot 2 出牌操作... [2025-11-30T20:36:08.801Z] [ERROR] Bot AI Bot 2 出牌失败: Error: 请选择要出的牌 at GameEngine.playCardsOrderedMode (file:///app/tractor-game-simulator/server/src/services/GameEngine.js:419:15) at GameEngine.playCards (file:///app/tractor-game-simulator/server/src/services/GameEngine.js:271:17) at triggerBotPlay (file:///app/tractor-game-simulator/server/src/socket/handlers/gameHandlers.js:109:31) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) [2025-11-30T20:36:08.802Z] [ERROR] 错误堆栈: Error: 请选择要出的牌 at GameEngine.playCardsOrderedMode (file:///app/tractor-game-simulator/server/src/services/GameEngine.js:419:15) at GameEngine.playCards (file:///app/tractor-game-simulator/server/src/services/GameEngine.js:271:17) at triggerBotPlay (file:///app/tractor-game-simulator/server/src/socket/handlers/gameHandlers.js:109:31) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) [2025-11-30T20:36:08.802Z] [INFO] 尝试Bot AI Bot 2 fallback策略:出 1 张牌, 类型: single [2025-11-30T20:36:08.802Z] [INFO] 房间 9450 玩家 AI Bot 2 出牌 1 张 [2025-11-30T20:36:08.802Z] [INFO] [调试] 调用 onPlayerPlayed 前: playersPlayedThisRound.size=2, players.length=4 [2025-11-30T20:36:08.802Z] [INFO] [调试] 调用 onPlayerPlayed 后: playersPlayedThisRound.size=3, roundUpdate.type=turn_changed [2025-11-30T20:36:08.802Z] [INFO] Bot AI Bot 2 fallback出牌成功 [2025-11-30T20:36:08.802Z] [INFO] 已更新玩家 de5b5749-77a2-487a-b4c1-f6b432963360 的最后响应为: [32] [2025-11-30T20:36:09.804Z] [INFO] === 检查是否需要触发Bot出牌 === [2025-11-30T20:36:09.804Z] [INFO] 房间ID: 9450, 游戏阶段: playing [2025-11-30T20:36:09.804Z] [INFO] --- 轮到Bot AI Bot 3 出牌 --- [2025-11-30T20:36:09.804Z] [INFO] 触发Bot AI Bot 3 自动出牌 [2025-11-30T20:36:09.804Z] [INFO] Bot AI Bot 3 当前手牌数: 22 [2025-11-30T20:36:09.872Z] [ERROR] Bot响应超时,强制结束进程 [2025-11-30T20:36:11.305Z] [INFO] 手牌数量: 22, deliver牌数量: 0 [2025-11-30T20:36:11.305Z] [INFO] 历史记录: requests=4, responses=4 [2025-11-30T20:36:11.306Z] [INFO] 构建history: previousRoundCards长度=4, currentRoundCards长度=3, previousLeader=0, currentLeader=0 [2025-11-30T20:36:11.306Z] [INFO] [构建request] 当前阶段request: {"stage":"play","deliver":[],"global":{"first_round":true,"level":"10","banking":{"called":-1,"snatched":-1,"major":"s","banker":2},"total_score":0},"history":[[[48],[70],[24],[62]],[[98],[82],[32]],0,0]} [2025-11-30T20:36:11.306Z] [INFO] [Bot输入] requests数量: 5, responses数量: 4 [2025-11-30T20:36:11.306Z] [INFO] 调用Bot脚本: /app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py [2025-11-30T20:36:11.341Z] [WARN] Bot stderr: Traceback (most recent call last): File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py", line 64, in setMajor(major, level) File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/myutils.py", line 15, in setMajor pointorder.remove(level) ValueError: list.remove(x): x not in list [2025-11-30T20:36:11.305Z] [INFO] 开始调用BotService.getBotAction... [2025-11-30T20:36:11.305Z] [INFO] ========== WhoDesigned Bot 决策开始 ========== [2025-11-30T20:36:11.305Z] [INFO] 玩家ID: bb69bb03-fee2-4588-8691-1e538e8d4624, 玩家索引: 3, 阶段: play [2025-11-30T20:36:11.345Z] [INFO] Bot进程退出,代码: 1 [2025-11-30T20:36:11.345Z] [ERROR] Bot进程退出,代码: 1, 错误: Traceback (most recent call last): File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py", line 64, in setMajor(major, level) File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/myutils.py", line 15, in setMajor pointorder.remove(level) ValueError: list.remove(x): x not in list [2025-11-30T20:36:11.345Z] [ERROR] [Bot决策失败] 阶段: play, 错误: Bot进程退出,代码: 1, 错误: Traceback (most recent call last): File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py", line 64, in setMajor(major, level) File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/myutils.py", line 15, in setMajor pointorder.remove(level) ValueError: list.remove(x): x not in list [2025-11-30T20:36:11.345Z] [ERROR] [Bot决策失败] 错误堆栈: Error: Bot进程退出,代码: 1, 错误: Traceback (most recent call last): File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/main.py", line 64, in setMajor(major, level) File "/app/tractor-game-simulator/server/src/bots/WhoDesigned/myutils.py", line 15, in setMajor [2025-11-30T20:36:11.345Z] [INFO] Bot AI Bot 3 决策完成,选择出牌: 0 张,卡牌IDs: [] [2025-11-30T20:36:11.345Z] [INFO] 执行Bot AI Bot 3 出牌操作... [2025-11-30T20:36:11.345Z] [ERROR] Bot AI Bot 3 出牌失败: Error: 请选择要出的牌 at GameEngine.playCardsOrderedMode (file:///app/tractor-game-simulator/server/src/services/GameEngine.js:419:15) at GameEngine.playCards (file:///app/tractor-game-simulator/server/src/services/GameEngine.js:271:17) at triggerBotPlay (file:///app/tractor-game-simulator/server/src/socket/handlers/gameHandlers.js:109:31) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) pointorder.remove(level) ValueError: list.remove(x): x not in list at ChildProcess. (file:///app/tractor-game-simulator/server/src/services/WhoDesignedBotService.js:475:18) at ChildProcess.emit (node:events:517:28) at maybeClose (node:internal/child_process:1098:16) at ChildProcess._handle.onexit (node:internal/child_process:303:5) [2025-11-30T20:36:11.345Z] [INFO] [Fallback] play阶段: 返回空数组(跳过),将由gameHandlers的fallback处理 [2025-11-30T20:36:11.345Z] [INFO] [Fallback] 已将默认响应添加到历史,新responses长度: 5 [2025-11-30T20:36:11.345Z] [INFO] ========== WhoDesigned Bot 决策失败,使用Fallback ========== [2025-11-30T20:36:11.345Z] [ERROR] 错误堆栈: Error: 请选择要出的牌 at GameEngine.playCardsOrderedMode (file:///app/tractor-game-simulator/server/src/services/GameEngine.js:419:15) at GameEngine.playCards (file:///app/tractor-game-simulator/server/src/services/GameEngine.js:271:17) at triggerBotPlay (file:///app/tractor-game-simulator/server/src/socket/handlers/gameHandlers.js:109:31) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Copy link
Contributor Author

Copilot AI commented Nov 30, 2025

@copilot bot有时候还是会出错: [2025-11-30T20:36:07.255Z] [INFO] Bot AI Bot 2 当前手牌数: 22 [2025-11-30T20:36:07.327Z] [ERROR] Bot响应超时,强制结束进程 [2025-11-30T20:36:08....

This bot error is a separate issue from the card disappearing bug that this PR fixes. My changes only affected GameBoard.jsx (client-side React code) and didn't touch any bot-related code.

The error you're seeing is in the WhoDesigned bot's Python script (__main__.py line 64), which appears to be a pre-existing issue or a different bug. The bot timeout and Python traceback are unrelated to the race condition fix I implemented here.

If you'd like me to investigate the bot error, please open a new issue for it so we can track and fix it separately.

@Roushelfy Roushelfy closed this Dec 1, 2025
@Roushelfy Roushelfy deleted the copilot/fix-card-disappearance-issue branch December 1, 2025 04:32
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