{"record":{"id":"1d7dd0b813f14d45","repo":"FoundationAgents/MetaGPT","slug":"bot-not-spawned","errorCode":null,"errorMessage":"Bot not spawned","messagePattern":"Bot not spawned","errorType":"http","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"metagpt/environment/minecraft/mineflayer/index.js","lineNumber":410,"sourceCode":"                    .split(\"\\n\")\n                    [match_line - 1].trim()} in your code`;\n            }\n            return source + err.message + \"\\n\" + code_source;\n        }\n        return err.message;\n    }\n});\n\napp.post(\"/stop\", (req, res) => {\n    bot.end();\n    res.json({\n        message: \"Bot stopped\",\n    });\n});\n\napp.post(\"/pause\", (req, res) => {\n    if (!bot) {\n        res.status(400).json({ error: \"Bot not spawned\" });\n        return;\n    }\n    bot.chat(\"/pause\");\n    bot.waitForTicks(bot.waitTicks).then(() => {\n        res.json({ message: \"Success\" });\n    });\n});\n\n// Server listening to PORT 3000\n\nconst DEFAULT_PORT = 3000;\nconst PORT = process.argv[2] || DEFAULT_PORT;\napp.listen(PORT, () => {\n    console.log(`Server started on port ${PORT}`);\n});\n","sourceCodeStart":392,"sourceCodeEnd":426,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/environment/minecraft/mineflayer/index.js#L392-L426","documentation":"This is an HTTP 400 error from the mineflayer Express bridge's POST /pause endpoint, returned when the module-level `bot` variable is falsy — i.e. no bot has spawned/connect yet. The pause route must send bot.chat('/pause'), which requires a live bot; endpoints like /pause and /unpause check for the bot first and reject early.","triggerScenarios":"Any client (including MinecraftExtEnv.pause(), which fires on every successful reset/step) calling POST /pause before /start has spawned the bot, or after the bot ended via /stop, or after a bot connection error left bot unset.","commonSituations":"Startup ordering races: the Python side calls reset/step machinery before the bot finished connecting to the Minecraft server; the Minecraft server was down so /start failed and later /pause hits the unspawned bot; calling /stop then /pause in cleanup code.","solutions":["Ensure POST /start (reset) completes and the bot connects before any /pause call — sequence your client to await the spawn.","Do not call /pause after /stop; track lifecycle state client-side.","If the Minecraft server was unavailable at start, restart the bridge and re-run /start.","In your own forks, treat a 400 'Bot not spawned' as a benign no-op during shutdown instead of an error."],"exampleFix":"// before (client)\nawait fetch(`${bridge}/pause`, {method: \"POST\"});  // 400 Bot not spawned\n\n// after (client)\nif (botSpawned) {\n  await fetch(`${bridge}/pause`, {method: \"POST\"});\n}\n// or in the route, make pause idempotent:\napp.post(\"/pause\", (req, res) => {\n  if (!bot) { res.json({ message: \"No bot, nothing to pause\" }); return; }\n  ...\n});","handlingStrategy":"validation","validationCode":"// client-side: only pause when the bot was started in this session\nlet botAlive = false;\nasync function start() {\n  const r = await fetch(`${bridge}/start`, { method: \"POST\" });\n  botAlive = r.ok;\n}\nasync function pause() {\n  if (!botAlive) return; // avoid 400 'Bot not spawned'\n  await fetch(`${bridge}/pause`, { method: \"POST\" });\n}","typeGuard":null,"tryCatchPattern":"// server-side fork: treat pause without a bot as a no-op\napp.post(\"/pause\", (req, res) => {\n  if (!bot) { res.status(200).json({ message: \"No bot spawned; nothing to pause\" }); return; }\n  bot.chat(\"/pause\");\n  bot.waitForTicks(bot.waitTicks).then(() => res.json({ message: \"Success\" }));\n});","preventionTips":["Track lifecycle client-side: /start succeeded => pause/unpause allowed; /stop or failed start => skip pause calls.","Never call /pause during teardown after /stop.","Wait for bot spawn (connect/spawn event) before the Python side's first reset-triggered pause."],"tags":["javascript","minecraft","http-api","lifecycle","express"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}