openai/codex · error · anyhow::Error

conversation item was referenced before it was created

Error message

conversation item {item_id} was referenced before it was created

What it means

The reducer tried to update a conversation item by id, but that id is not in rollout.conversation_items — an internal invariant break where a sighting references an item before its creation was recorded.

Solutions

  1. Verify item creation is always applied before sighting updates
  2. Create the item on demand if it is missing
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at codex-rs/rollout-trace/src/reducer/conversation.rs:439 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/89918062cf3036c0. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/rollout-trace/src/reducer/conversation.rs:439

                channel: item.channel,
                kind: item.kind,
                agent_message: item.agent_message,
                body: item.body,
                call_id: item.call_id,
                produced_by,
            },
        );
        item_id
    }

    fn update_conversation_item_from_sighting(
        &mut self,
        item_id: &str,
        normalized: &NormalizedConversationItem,
        produced_by: &[ProducerRef],
    ) -> Result<()> {
        let Some(item) = self.rollout.conversation_items.get_mut(item_id) else {
            bail!("conversation item {item_id} was referenced before it was created");
        };

        if item.kind == ConversationItemKind::Reasoning {
            merge_reasoning_body(&mut item.body, &normalized.body)?;
        }
        for producer in produced_by {
            if !item.produced_by.contains(producer) {
                item.produced_by.push(producer.clone());
            }
        }
        Ok(())
    }

    fn append_thread_conversation_items(
        &mut self,
        thread_id: &str,
        item_ids: &[String],
    ) -> Result<()> {

View on GitHub (pinned to 339751715c)