FoundationAgents/MetaGPT · error · RuntimeError
Environment has not been reset yet
Error message
Environment has not been reset yet
What it means
MinecraftExtEnv._step raises RuntimeError('Environment has not been reset yet') when the has_reset flag is False. The Mineflayer bot and the bridge server are only brought up by reset(), so stepping before the first reset has no bot to execute code against; the flag makes this an explicit failure instead of a cryptic HTTP error.
Source
Thrown at metagpt/environment/minecraft/minecraft_ext_env.py:165
"position": options.get("position", None),
}
self.unpause()
self.mineflayer.stop()
time.sleep(1) # wait for mineflayer to exit
returned_data = self.check_process()
self.has_reset = True
self.connected = True
# All the reset in step will be soft
self.reset_options["reset"] = "soft"
self.pause()
return json.loads(returned_data)
@mark_as_writeable
def _step(self, code: str, programs: str = "") -> dict:
if not self.has_reset:
raise RuntimeError("Environment has not been reset yet")
self.check_process()
self.unpause()
data = {
"code": code,
"programs": programs,
}
res = requests.post(f"{self.server}/step", json=data, timeout=self.request_timeout)
if res.status_code != 200:
raise RuntimeError("Failed to step Minecraft server")
returned_data = res.json()
self.pause()
return json.loads(returned_data)
@mark_as_writeable
def pause(self) -> bool:
if self.mineflayer.is_running and not self.server_paused:
res = requests.post(f"{self.server}/pause")
if res.status_code == 200:View on GitHub (pinned to 11cdf466d0)
Solutions
- Call await env.reset(...) once after construction and before the first step; reset sets has_reset=True and starts the bot.
- If reset() itself failed, fix that first — check the mineflayer process is running (check_process) and the server URL/port are correct.
- In multi-episode loops, call reset at the start of each episode since has_reset persists per instance state.
Example fix
# before
env = MinecraftExtEnv(server="http://127.0.0.1", mc_port=3000, replay_dir="...")
obs = await env.step("bot.chat('hi')") # RuntimeError: Environment has not been reset yet
# after
env = MinecraftExtEnv(server="http://127.0.0.1", mc_port=3000, replay_dir="...")
await env.reset()
obs = await env.step("bot.chat('hi')") Defensive patterns
Strategy: validation
Validate before calling
if not getattr(env, "has_reset", False):
await env.reset() # mandatory before the first step
obs = await env.step(code) Try / catch
try:
obs = await env.step(code)
except RuntimeError as e:
if "not been reset" in str(e):
await env.reset()
obs = await env.step(code) # retry once after establishing the bot
else:
raise Prevention
- Treat reset() as part of construction: call it immediately after creating MinecraftExtEnv, every episode.
- Wrap reset in a hard failure path — if it raises, stop; never continue to step on an unreset env.
- Check env.has_reset (or your own flag) before stepping in loops that may skip their first iteration.
When it happens
Trigger: Creating MinecraftExtEnv(server=..., mc_port=...) and calling await env.step(...) / env.write_to_api('step', ...) before calling await env.reset(...); also in a fresh process resuming a session without re-resetting.
Common situations: Adapting gym-style examples that step immediately after construction; reset() failed earlier (server startup issues) and the exception was swallowed so the code continued to step; multiple episodes where reset happens in a try block that was skipped.
Related errors
- Failed to step Minecraft server
- device-id: {device_id} not found
- create device path: {folder_path} failed
- api_name: {api_name} not found
- {rw_api} not exists
AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14).
Data as JSON: /api/errors/d6e6c822660136d8.
Report an issue: GitHub.