@@ -4070,6 +4070,58 @@ async def test_canonical_transcript_page_crosses_multiple_compaction_boundaries(
40704070 assert [entry .message_id for entry in forward ] == [entry .message_id for entry in loaded ]
40714071
40724072
4073+ @pytest .mark .asyncio
4074+ async def test_canonical_page_skips_null_legacy_ids_without_hiding_valid_rows (manager ):
4075+ node = await manager .create ("agent:main:webchat:legacy-null-page" )
4076+ await manager ._storage .conn .executemany (
4077+ """
4078+ INSERT INTO compacted_transcript_entries (
4079+ session_id, session_key, compaction_id, compaction_index,
4080+ original_entry_id, message_id, role, content, created_at, archived_at
4081+ ) VALUES (?, ?, ?, ?, ?, ?, 'user', ?, ?, ?)
4082+ """ ,
4083+ [
4084+ (
4085+ node .session_id ,
4086+ node .session_key ,
4087+ "legacy-compaction" ,
4088+ 0 ,
4089+ original_id ,
4090+ f"legacy-{ created_at } " ,
4091+ f"legacy message { created_at } " ,
4092+ created_at ,
4093+ created_at ,
4094+ )
4095+ for created_at , original_id in ((1 , 1 ), (2 , None ), (3 , 3 ))
4096+ ],
4097+ )
4098+ await manager ._storage .conn .commit ()
4099+
4100+ latest = await manager .get_canonical_transcript_page (node .session_key , limit = 1 )
4101+ before = await manager .get_canonical_transcript_page (
4102+ node .session_key ,
4103+ limit = 1 ,
4104+ before = (3 , 3 ),
4105+ )
4106+ after = await manager .get_canonical_transcript_page (
4107+ node .session_key ,
4108+ limit = 1 ,
4109+ after = (1 , 1 ),
4110+ )
4111+ full = await manager .get_canonical_transcript_page (node .session_key , limit = 2 )
4112+
4113+ assert [(entry .created_at , entry .id ) for entry in latest .entries ] == [(3 , 3 )]
4114+ assert latest .has_more is True
4115+ assert latest .canonical_complete is False
4116+ assert [(entry .created_at , entry .id ) for entry in before .entries ] == [(1 , 1 )]
4117+ assert before .has_more is False
4118+ assert [(entry .created_at , entry .id ) for entry in after .entries ] == [(3 , 3 )]
4119+ assert after .has_more is False
4120+ assert [(entry .created_at , entry .id ) for entry in full .entries ] == [(1 , 1 ), (3 , 3 )]
4121+ assert full .has_more is False
4122+ assert full .canonical_complete is False
4123+
4124+
40734125@pytest .mark .asyncio
40744126async def test_canonical_transcript_page_preserves_turn_context (manager ):
40754127 """Paged canonical reads must keep turn_context on active and archived rows."""
0 commit comments