openai/codex · error · RuntimeError

thread {state.thread_id!r} already has an active goal operat

Error message

thread {state.thread_id!r} already has an active goal operation

What it means

Error "thread {state.thread_id!r} already has an active goal operation" thrown in openai/codex.

Source

Thrown at sdk/python/src/openai_codex/_message_router.py:134

        item = turn_queue.get()
        if isinstance(item, BaseException):
            raise item
        return item

    def register_goal(self, thread_id: str) -> _GoalOperationState:
        """Register one thread-scoped logical goal operation before it starts."""
        state = _GoalOperationState(thread_id=thread_id)
        state.activate_turn_routing()
        return self._register_goal(state)

    def reserve_goal(self, thread_id: str) -> _GoalOperationState:
        """Reserve a thread route without accepting physical turns yet."""
        return self._register_goal(_GoalOperationState(thread_id=thread_id))

    def _register_goal(self, state: _GoalOperationState) -> _GoalOperationState:
        with self._lock:
            if state.thread_id in self._goal_operations:
                raise RuntimeError(
                    f"thread {state.thread_id!r} already has an active goal operation"
                )
            self._goal_operations[state.thread_id] = state
        return state

    def unregister_goal(self, state: _GoalOperationState) -> None:
        """Stop routing notifications to a completed logical goal operation."""
        with self._lock:
            if self._goal_operations.get(state.thread_id) is state:
                self._goal_operations.pop(state.thread_id)

    def has_goal(self, thread_id: str) -> bool:
        """Return whether a logical goal operation owns this thread route."""
        with self._lock:
            return thread_id in self._goal_operations

    def route_response(self, msg: dict[str, JsonValue]) -> None:
        """Deliver a JSON-RPC response or error to its request waiter."""

View on GitHub (pinned to 339751715c)

Solutions

  1. Wait for the active goal operation on the thread to finish before starting another goal.

When it happens

Trigger: Thrown at sdk/python/src/openai_codex/_message_router.py:134 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/9413dbef1080e2de. Report an issue: GitHub.