openai/codex · error · Error

Failed to parse item

Error message

Failed to parse item: ${item}

What it means

A raw item yielded by the exec event stream failed parsing into a typed ThreadItem (the JSON-stringified item is included). The runtime emitted an item shape the SDK's schemas do not recognize — usually a newer protocol item than this SDK version knows.

Solutions

  1. Check the stream item against the current schema and update the SDK if the runtime item format changed.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at sdk/typescript/src/thread.ts:103 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


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

Appendix: source

Thrown at sdk/typescript/src/thread.ts:103

      sandboxMode: options?.sandboxMode,
      workingDirectory: options?.workingDirectory,
      skipGitRepoCheck: options?.skipGitRepoCheck,
      outputSchemaFile: schemaPath,
      modelReasoningEffort: options?.modelReasoningEffort,
      signal: turnOptions.signal,
      networkAccessEnabled: options?.networkAccessEnabled,
      webSearchMode: options?.webSearchMode,
      webSearchEnabled: options?.webSearchEnabled,
      approvalPolicy: options?.approvalPolicy,
      additionalDirectories: options?.additionalDirectories,
    });
    try {
      for await (const item of generator) {
        let parsed: ThreadEvent;
        try {
          parsed = JSON.parse(item) as ThreadEvent;
        } catch (error) {
          throw new Error(`Failed to parse item: ${item}`, { cause: error });
        }
        if (parsed.type === "thread.started") {
          this._id = parsed.thread_id;
        } else if (parsed.type === "turn.completed") {
          parsed.usage.cache_write_input_tokens ??= 0;
        }
        yield parsed;
      }
    } finally {
      await cleanup();
    }
  }

  /** Provides the input to the agent and returns the completed turn. */
  async run(input: Input, turnOptions: TurnOptions = {}): Promise<Turn> {
    const generator = this.runStreamedInternal(input, turnOptions);
    const items: ThreadItem[] = [];
    let finalResponse: string = "";

View on GitHub (pinned to 339751715c)