666ghj/MiroFish · error · ValueError

启用图谱记忆更新时必须提供 graph_id

Error message

启用图谱记忆更新时必须提供 graph_id

What it means

Raised in SimulationRunner's start path: when enable_graph_memory_update is true, graph_id must be supplied; otherwise ValueError('启用图谱记忆更新时必须提供 graph_id'). The graph memory updater writes agent activity back to a specific Zep graph, and without a target graph id there is nothing valid to write to — the code prefers failing over silently disabling the feature.

Source

Thrown at backend/app/services/simulation_runner.py:443

        # STARTING state makes every concurrent start fail closed.
        with cls._finalization_lock(simulation_id):
            existing = cls.get_run_state(simulation_id)
            active_statuses = {
                RunnerStatus.STARTING,
                RunnerStatus.RUNNING,
                RunnerStatus.PAUSED,
                RunnerStatus.STOPPING,
            }
            if (
                existing and existing.runner_status in active_statuses
            ) or ZepGraphMemoryManager.get_updater(simulation_id) is not None:
                raise ValueError(f"模拟已在运行或结束处理中: {simulation_id}")
            cls._save_run_state(state)
        
        # 如果启用图谱记忆更新,创建更新器
        if enable_graph_memory_update:
            if not graph_id:
                raise ValueError("启用图谱记忆更新时必须提供 graph_id")
            
            try:
                ZepGraphMemoryManager.create_updater(simulation_id, graph_id)
                cls._graph_memory_enabled[simulation_id] = True
                logger.info(f"已启用图谱记忆更新: simulation_id={simulation_id}, graph_id={graph_id}")
            except Exception as e:
                logger.error(f"创建图谱记忆更新器失败: {e}")
                cls._graph_memory_enabled[simulation_id] = False
                state.runner_status = RunnerStatus.FAILED
                state.error = f"Zep图谱更新器初始化失败: {e}"
                with cls._finalization_lock(simulation_id):
                    cls._save_run_state(state)
                    cls._sync_simulation_status(
                        simulation_id,
                        RunnerStatus.FAILED,
                        state.error,
                    )
                raise RuntimeError(state.error) from e

View on GitHub (pinned to b5b53acc57)

Solutions

  1. Pass the project's Zep graph_id whenever enable_graph_memory_update is true.
  2. Or set enable_graph_memory_update=false if you don't need agent activity written back to the graph.
  3. Validate the pairing at the API boundary so the request fails with a 422 before reaching the runner.
  4. In the frontend, auto-fill graph_id from the project when the toggle is enabled and disable start until present.

Example fix

# before
runner.start_simulation(sim_id, enable_graph_memory_update=True)  # graph_id omitted
# after
runner.start_simulation(
    sim_id,
    enable_graph_memory_update=True,
    graph_id=project.graph_id,  # from the project/graph that was built
)
Defensive patterns

Strategy: validation

Validate before calling

if enable_graph_memory_update and not graph_id:
    raise HTTPException(422, 'graph_id is required when enable_graph_memory_update is true')

Prevention

When it happens

Trigger: Calling start with enable_graph_memory_update=True but omitting graph_id (e.g. the route's optional graph_id field left null by the client); passing an empty string graph_id (falsy); frontend not propagating the project's graph_id when the toggle is enabled.

Common situations: New UI toggle for graph memory shipped without wiring the graph_id field; API clients copying an old request body that predates the feature; graph_id passed under a different JSON key than the route expects.

Related errors


AI-assisted analysis of 666ghj/MiroFish@b5b53acc57 (2026-08-14). Data as JSON: /api/errors/258db727475c08c2. Report an issue: GitHub.