@@ -186,6 +186,52 @@ def test_chat_idempotency_keys_reject_different_requests(tmp_path: Path) -> None
186186 )
187187
188188
189+ def test_generated_message_id_skips_transcript_deduplication (
190+ tmp_path : Path ,
191+ monkeypatch : pytest .MonkeyPatch ,
192+ ) -> None :
193+ store = ChatSessionStore (tmp_path )
194+ session_id = str (
195+ store .create_session (
196+ goal_id = "goal-one" ,
197+ agent_id = "codex" ,
198+ executor_endpoint_id = "codex" ,
199+ adapter_kind = "codex_app_server" ,
200+ upstream_thread_id = "thread-one" ,
201+ upstream_mode = "chat" ,
202+ )["session_id" ]
203+ )
204+ expected = store .append_message (
205+ session_id ,
206+ role = "agent" ,
207+ text = "durable completion" ,
208+ message_id = "completion-one" ,
209+ )
210+ assert (
211+ store .append_message (
212+ session_id ,
213+ role = "agent" ,
214+ text = "ignored replay" ,
215+ message_id = "completion-one" ,
216+ )
217+ == expected
218+ )
219+
220+ read_messages = chat_store ._read_jsonl
221+ monkeypatch .setattr (
222+ chat_store ,
223+ "_read_jsonl" ,
224+ lambda _path : pytest .fail ("generated message IDs must not scan the transcript" ),
225+ )
226+ appended = store .append_message (session_id , role = "user" , text = "new message" )
227+
228+ assert appended ["message_id" ] != "completion-one"
229+ assert read_messages (store ._session_dir (session_id ) / "messages.jsonl" ) == [
230+ expected ,
231+ appended ,
232+ ]
233+
234+
189235@pytest .mark .parametrize ("restart" , [False , True ])
190236@pytest .mark .parametrize ("with_image" , [False , True ])
191237def test_managed_replay_compares_durable_attachments (
0 commit comments