TypeScript SDK reuses item IDs across turns on the same thread
Summary
Successive Thread.run() calls on the same TypeScript SDK thread can return different items with the same id. A consumer that keeps the conversation's items in a map keyed by item.id will overwrite earlier items. The README explicitly supports successive calls on one thread, but the item type does not describe the ID's scope.
In a local test the first response was message 0 with ID item_1, and the second was message 1 with the same ID. A separate model-metadata warning occupied item_0 in each invocation. The collision is independent of that warning: the counter is restarted by each codex exec process.
Reproduction
Install the TypeScript SDK and matching CLI. Set CODEX_EXEC_PATH to the CLI executable, CODEX_SDK_URL to the file URL of the installed SDK's dist/index.js, and put this checkout's sdk/python/src and sdk/python/tests on PYTHONPATH. Then run:
import os
import subprocess
import tomllib
from pathlib import Path
from tempfile import TemporaryDirectory
from app_server_harness import AppServerHarness
with TemporaryDirectory(ignore_cleanup_errors=True) as directory:
with AppServerHarness(Path(directory)) as h:
config = tomllib.loads((h.codex_home / "config.toml").read_text(encoding="utf8"))
assert config["model_provider"] == "mock_provider"
assert config["model_providers"]["mock_provider"]["base_url"].startswith(h.responses.url)
h.responses.enqueue_assistant_message("first answer", response_id="one")
h.responses.enqueue_assistant_message("second answer", response_id="two")
env = dict(os.environ, CODEX_HOME=str(h.codex_home),
CODEX_APP_SERVER_DISABLE_MANAGED_CONFIG="1")
script = """
const { Codex } = await import(process.env.CODEX_SDK_URL);
const codex = new Codex({ codexPathOverride: process.env.CODEX_EXEC_PATH });
const thread = codex.startThread({ skipGitRepoCheck: true });
const first = await thread.run("first");
const threadId = thread.id;
const second = await thread.run("second");
const a = first.items.find(item => item.type === "agent_message");
const b = second.items.find(item => item.type === "agent_message");
console.log(JSON.stringify({
sameThread: threadId === thread.id,
first: a, second: b,
mapSize: new Map([[a.id, a], [b.id, b]]).size
}));
"""
result = subprocess.run(
["node", "--input-type=module", "-e", script],
cwd=h.workspace, env=env, capture_output=True,
text=True, encoding="utf8", timeout=30, check=True,
)
print(result.stdout)
Observed: sameThread is true, the two answer texts differ, their IDs are equal, and mapSize is 1. The local Responses fixture makes no external inference requests. Reproduced on Windows with matching SDK/CLI 0.167.2 and 0.170.0-alpha.2; source inspected at c0cc9fc820f62e4dbdde68214dd6d792d6c8a7ee.
Expected and suggested fix
Items in a continued thread should have identifiers that distinguish them across turns, or the API should explicitly document that IDs are scoped to each individual invocation. Consider emitting a turn/execution identifier alongside items or preserving unique item IDs across invocations; keep the same ID for updates to the same item within an invocation. Until then, consumers can namespace item IDs with their own per-call identifier.
I reproduced the item-ID collision on Linux with the published @openai/codex-sdk 0.167.1 and matching codex-cli 0.167.1, using a synthetic local Responses fixture. Two run() calls on one SDK Thread returned different agent messages—first synthetic answer and second synthetic answer—but both had id: "item_1". The SDK thread ID remained unchanged, and a Map keyed by those item IDs had size 1. The fixture recorded exactly two loopback Responses requests; no external model requests were made.
This adds a Linux release reproduction to the Windows results above. It does not establish a downstream UI failure or the intended scope of item.id. Could a maintainer clarify whether item IDs are meant to be unique per run or across the whole thread? If they are per-run, documenting that scope and how consumers should namespace them would help. If they are thread-wide, I can share a focused regression test.