Skip to content

Commit 8d8b2cf

Browse files
committed
sessions: 完善回放异常恢复与测试隔离
新增 SQL 与 Mock Redis 写入中途失败测试,覆盖 update_session 和 store_session 在 commit 或 expire 前后发生异常的场景。验证重试后存储快照与 InMemory 一致,且不会产生重复事件、脏 state、错误 Summary 或重复 Memory。 固定假阳性测试的运行环境,清理 REPLAY_LIGHTWEIGHT、REPLAY_SQL_URL 和 REPLAY_REDIS_URL,避免环境变量导致测试空转或外部连接误报。 Fixes #89 RELEASE NOTES: 完善 Session、Memory 和 Summary 多后端回放的异常恢复测试。
1 parent a06779e commit 8d8b2cf

4 files changed

Lines changed: 237 additions & 85 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"id":"07_summary_create_update","allowed_diff":["events[0].summary_metadata.summary_replaces_event_ids[4]","events[0].summary_metadata.summary_replaces_event_ids[5]","events[1].author","events[1].text","events[2].author","events[2].text"],"allowed_diff_reason":"Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed.","operations":[{"op":"append","author":"user","text":"I need help planning a Shenzhen trip"},{"op":"append","author":"agent","text":"What dates and budget do you have"},{"op":"append","author":"user","text":"I will travel next weekend with a small budget"},{"op":"append","author":"agent","text":"Train travel may be suitable"},{"op":"append","author":"user","text":"I prefer a hotel near the station"},{"op":"append","author":"agent","text":"I will remember the station hotel preference"},{"op":"append","author":"user","text":"Please also check weather"},{"op":"append","author":"agent","type":"function_call","name":"weather","args":{"city":"Shenzhen"}},{"op":"append","author":"tool","type":"function_response","name":"weather","response":{"temperature":28,"condition":"sunny"}},{"op":"summary","text":"User is planning a budget Shenzhen trip next weekend, prefers train travel and a station hotel, and requested weather information.","keep_recent":3},{"op":"append","author":"agent","text":"Shenzhen will be sunny and warm"},{"op":"append","author":"user","text":"Give me a final short itinerary"},{"op":"append","author":"agent","text":"Take the train, stay near the station, and pack light clothes"},{"op":"summary","text":"Budget Shenzhen trip: train travel, station hotel, sunny 28 degree weather, and a short itinerary were discussed.","keep_recent":3}]}
1+
{"id":"07_summary_create_update","operations":[{"op":"append","author":"user","text":"I need help planning a Shenzhen trip"},{"op":"append","author":"agent","text":"What dates and budget do you have"},{"op":"append","author":"user","text":"I will travel next weekend with a small budget"},{"op":"append","author":"agent","text":"Train travel may be suitable"},{"op":"append","author":"user","text":"I prefer a hotel near the station"},{"op":"append","author":"agent","text":"I will remember the station hotel preference"},{"op":"append","author":"user","text":"Please also check weather"},{"op":"append","author":"agent","type":"function_call","name":"weather","args":{"city":"Shenzhen"}},{"op":"append","author":"tool","type":"function_response","name":"weather","response":{"temperature":28,"condition":"sunny"}},{"op":"summary","text":"User is planning a budget Shenzhen trip next weekend, prefers train travel and a station hotel, and requested weather information.","keep_recent":3},{"op":"append","author":"agent","text":"Shenzhen will be sunny and warm"},{"op":"append","author":"user","text":"Give me a final short itinerary"},{"op":"append","author":"agent","text":"Take the train, stay near the station, and pack light clothes"},{"op":"summary","text":"Budget Shenzhen trip: train travel, station hotel, sunny 28 degree weather, and a short itinerary were discussed.","keep_recent":3}]}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"id":"08_summary_truncation","allowed_diff":["events[5].author","events[5].text","events[6]","events[7]"],"allowed_diff_reason":"Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed.","operations":[{"op":"append","author":"user","text":"I am learning Python for data analysis"},{"op":"append","author":"agent","text":"Start with Python basics and pandas"},{"op":"append","author":"user","text":"I can study four hours each week"},{"op":"append","author":"agent","text":"Use a small weekly practice schedule"},{"op":"append","author":"user","text":"I prefer practical exercises"},{"op":"append","author":"agent","text":"Practice with CSV analysis projects"},{"op":"append","author":"user","text":"What should I study next"},{"op":"append","author":"agent","text":"Next learn plotting with matplotlib"},{"op":"summary","text":"User is learning Python data analysis, has four hours weekly, and prefers practical pandas and CSV exercises.","keep_recent":3,"store_historical":true},{"op":"append","author":"user","text":"Please add one visualization exercise"},{"op":"append","author":"agent","text":"Create a matplotlib chart from a CSV file"}]}
1+
{"id":"08_summary_truncation","operations":[{"op":"append","author":"user","text":"I am learning Python for data analysis"},{"op":"append","author":"agent","text":"Start with Python basics and pandas"},{"op":"append","author":"user","text":"I can study four hours each week"},{"op":"append","author":"agent","text":"Use a small weekly practice schedule"},{"op":"append","author":"user","text":"I prefer practical exercises"},{"op":"append","author":"agent","text":"Practice with CSV analysis projects"},{"op":"append","author":"user","text":"What should I study next"},{"op":"append","author":"agent","text":"Next learn plotting with matplotlib"},{"op":"summary","text":"User is learning Python data analysis, has four hours weekly, and prefers practical pandas and CSV exercises.","keep_recent":3,"store_historical":true},{"op":"append","author":"user","text":"Please add one visualization exercise"},{"op":"append","author":"agent","text":"Create a matplotlib chart from a CSV file"}]}

tests/sessions/session_memory_summary_diff_report.json

Lines changed: 46 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -117,139 +117,127 @@
117117
{
118118
"case_id": "07_summary_create_update",
119119
"baseline": "in_memory",
120-
"status": "match",
120+
"status": "different",
121121
"comparisons": [
122122
{
123123
"backend": "sql",
124124
"session_id": "replay-session",
125-
"status": "match",
125+
"status": "different",
126126
"diffs": [
127127
{
128128
"path": "events[0].summary_metadata.summary_replaces_event_ids[4]",
129129
"expected": "event-10",
130130
"actual": null,
131-
"allowed": true,
131+
"allowed": false,
132132
"session_id": "replay-session",
133133
"event_index": 0,
134-
"target": "session",
135-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
134+
"target": "session"
136135
},
137136
{
138137
"path": "events[0].summary_metadata.summary_replaces_event_ids[5]",
139138
"expected": "event-10",
140139
"actual": null,
141-
"allowed": true,
140+
"allowed": false,
142141
"session_id": "replay-session",
143142
"event_index": 0,
144-
"target": "session",
145-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
143+
"target": "session"
146144
},
147145
{
148146
"path": "events[1].author",
149147
"expected": "user",
150148
"actual": "agent",
151-
"allowed": true,
149+
"allowed": false,
152150
"session_id": "replay-session",
153151
"event_index": 1,
154-
"target": "session",
155-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
152+
"target": "session"
156153
},
157154
{
158155
"path": "events[1].text",
159156
"expected": "Give me a final short itinerary",
160157
"actual": "Shenzhen will be sunny and warm",
161-
"allowed": true,
158+
"allowed": false,
162159
"session_id": "replay-session",
163160
"event_index": 1,
164-
"target": "session",
165-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
161+
"target": "session"
166162
},
167163
{
168164
"path": "events[2].author",
169165
"expected": "agent",
170166
"actual": "user",
171-
"allowed": true,
167+
"allowed": false,
172168
"session_id": "replay-session",
173169
"event_index": 2,
174-
"target": "session",
175-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
170+
"target": "session"
176171
},
177172
{
178173
"path": "events[2].text",
179174
"expected": "Take the train, stay near the station, and pack light clothes",
180175
"actual": "Give me a final short itinerary",
181-
"allowed": true,
176+
"allowed": false,
182177
"session_id": "replay-session",
183178
"event_index": 2,
184-
"target": "session",
185-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
179+
"target": "session"
186180
}
187181
]
188182
},
189183
{
190184
"backend": "redis_mock",
191185
"session_id": "replay-session",
192-
"status": "match",
186+
"status": "different",
193187
"diffs": [
194188
{
195189
"path": "events[0].summary_metadata.summary_replaces_event_ids[4]",
196190
"expected": "event-10",
197191
"actual": null,
198-
"allowed": true,
192+
"allowed": false,
199193
"session_id": "replay-session",
200194
"event_index": 0,
201-
"target": "session",
202-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
195+
"target": "session"
203196
},
204197
{
205198
"path": "events[0].summary_metadata.summary_replaces_event_ids[5]",
206199
"expected": "event-10",
207200
"actual": null,
208-
"allowed": true,
201+
"allowed": false,
209202
"session_id": "replay-session",
210203
"event_index": 0,
211-
"target": "session",
212-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
204+
"target": "session"
213205
},
214206
{
215207
"path": "events[1].author",
216208
"expected": "user",
217209
"actual": "agent",
218-
"allowed": true,
210+
"allowed": false,
219211
"session_id": "replay-session",
220212
"event_index": 1,
221-
"target": "session",
222-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
213+
"target": "session"
223214
},
224215
{
225216
"path": "events[1].text",
226217
"expected": "Give me a final short itinerary",
227218
"actual": "Shenzhen will be sunny and warm",
228-
"allowed": true,
219+
"allowed": false,
229220
"session_id": "replay-session",
230221
"event_index": 1,
231-
"target": "session",
232-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
222+
"target": "session"
233223
},
234224
{
235225
"path": "events[2].author",
236226
"expected": "agent",
237227
"actual": "user",
238-
"allowed": true,
228+
"allowed": false,
239229
"session_id": "replay-session",
240230
"event_index": 2,
241-
"target": "session",
242-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
231+
"target": "session"
243232
},
244233
{
245234
"path": "events[2].text",
246235
"expected": "Take the train, stay near the station, and pack light clothes",
247236
"actual": "Give me a final short itinerary",
248-
"allowed": true,
237+
"allowed": false,
249238
"session_id": "replay-session",
250239
"event_index": 2,
251-
"target": "session",
252-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
240+
"target": "session"
253241
}
254242
]
255243
}
@@ -258,32 +246,30 @@
258246
{
259247
"case_id": "08_summary_truncation",
260248
"baseline": "in_memory",
261-
"status": "match",
249+
"status": "different",
262250
"comparisons": [
263251
{
264252
"backend": "sql",
265253
"session_id": "replay-session",
266-
"status": "match",
254+
"status": "different",
267255
"diffs": [
268256
{
269257
"path": "events[5].author",
270258
"expected": "user",
271259
"actual": "agent",
272-
"allowed": true,
260+
"allowed": false,
273261
"session_id": "replay-session",
274262
"event_index": 5,
275-
"target": "session",
276-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
263+
"target": "session"
277264
},
278265
{
279266
"path": "events[5].text",
280267
"expected": "Please add one visualization exercise",
281268
"actual": "Create a matplotlib chart from a CSV file",
282-
"allowed": true,
269+
"allowed": false,
283270
"session_id": "replay-session",
284271
"event_index": 5,
285-
"target": "session",
286-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
272+
"target": "session"
287273
},
288274
{
289275
"path": "events[6]",
@@ -297,11 +283,10 @@
297283
"summary_metadata": {}
298284
},
299285
"actual": null,
300-
"allowed": true,
286+
"allowed": false,
301287
"session_id": "replay-session",
302288
"event_index": 6,
303-
"target": "session",
304-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
289+
"target": "session"
305290
},
306291
{
307292
"path": "events[7]",
@@ -315,38 +300,35 @@
315300
"summary_metadata": {}
316301
},
317302
"actual": null,
318-
"allowed": true,
303+
"allowed": false,
319304
"session_id": "replay-session",
320305
"event_index": 7,
321-
"target": "session",
322-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
306+
"target": "session"
323307
}
324308
]
325309
},
326310
{
327311
"backend": "redis_mock",
328312
"session_id": "replay-session",
329-
"status": "match",
313+
"status": "different",
330314
"diffs": [
331315
{
332316
"path": "events[5].author",
333317
"expected": "user",
334318
"actual": "agent",
335-
"allowed": true,
319+
"allowed": false,
336320
"session_id": "replay-session",
337321
"event_index": 5,
338-
"target": "session",
339-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
322+
"target": "session"
340323
},
341324
{
342325
"path": "events[5].text",
343326
"expected": "Please add one visualization exercise",
344327
"actual": "Create a matplotlib chart from a CSV file",
345-
"allowed": true,
328+
"allowed": false,
346329
"session_id": "replay-session",
347330
"event_index": 5,
348-
"target": "session",
349-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
331+
"target": "session"
350332
},
351333
{
352334
"path": "events[6]",
@@ -360,11 +342,10 @@
360342
"summary_metadata": {}
361343
},
362344
"actual": null,
363-
"allowed": true,
345+
"allowed": false,
364346
"session_id": "replay-session",
365347
"event_index": 6,
366-
"target": "session",
367-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
348+
"target": "session"
368349
},
369350
{
370351
"path": "events[7]",
@@ -378,11 +359,10 @@
378359
"summary_metadata": {}
379360
},
380361
"actual": null,
381-
"allowed": true,
362+
"allowed": false,
382363
"session_id": "replay-session",
383364
"event_index": 7,
384-
"target": "session",
385-
"allowed_reason": "Known InMemory event aliasing after update_session() can duplicate post-summary events until the backend bug is fixed."
365+
"target": "session"
386366
}
387367
]
388368
}

0 commit comments

Comments
 (0)