From 4dc6235ad8e7bb2a2091e5beb78fd0f8aeb37503 Mon Sep 17 00:00:00 2001 From: "Beau Beauchamp, WebTigers" Date: Fri, 24 Jul 2026 19:44:22 -0400 Subject: [PATCH] test: de-flake AgentModelsTest transcript-order (same-millisecond v7 tie) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit messages_append_and_transcript_reads_oldest_first appended two messages in the same millisecond, so neither created_at (second precision) nor the time-ordered v7 message_id could order them deterministically — transcript()'s message_id-DESC tiebreak fell to the v7 random bits, and the order flipped ~intermittently (green in #65, red in #67's CI run). Real conversation turns are seconds apart; force a created_at gap so the oldest-first assertion is deterministic. Verified stable across repeated runs. No source change — the model's ordering is correct for real use. Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/Integration/Model/AgentModelsTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/Integration/Model/AgentModelsTest.php b/tests/Integration/Model/AgentModelsTest.php index 8382026..5c20fb3 100644 --- a/tests/Integration/Model/AgentModelsTest.php +++ b/tests/Integration/Model/AgentModelsTest.php @@ -72,10 +72,16 @@ public function messages_append_and_transcript_reads_oldest_first(): void $me = Tiger_Uuid::v7(); $cid = $conv->start(Tiger_Uuid::v7(), $me, 'T', 'anthropic', 'claude'); - $msg->append($cid, Tiger_Model_AgentMessage::ROLE_USER, 'hello'); + $userId = $msg->append($cid, Tiger_Model_AgentMessage::ROLE_USER, 'hello'); $runId = Tiger_Uuid::v7(); $asst = $msg->append($cid, Tiger_Model_AgentMessage::ROLE_ASSISTANT, 'hi there', ['actions' => [['type' => 'navigate']]], $runId); + // Both appends land in the same millisecond here, so neither created_at (second precision) nor the + // time-ordered v7 message_id can order them deterministically — real conversation turns are seconds + // apart. Force a gap so the oldest-first transcript ordering is deterministic. + $this->db->update('agent_message', ['created_at' => '2020-01-01 00:00:01'], $this->db->quoteInto('message_id = ?', $userId)); + $this->db->update('agent_message', ['created_at' => '2020-01-01 00:00:02'], $this->db->quoteInto('message_id = ?', $asst)); + $rows = $msg->transcript($cid, 100); $this->assertCount(2, $rows); $this->assertSame('hello', $rows[0]['content'], 'oldest message first');