Skip to content

tests: add Session/Memory/Summary multi-backend replay consistency testing framework#152

Open
DNKYr wants to merge 7 commits into
trpc-group:mainfrom
DNKYr:replay-consistency-python
Open

tests: add Session/Memory/Summary multi-backend replay consistency testing framework#152
DNKYr wants to merge 7 commits into
trpc-group:mainfrom
DNKYr:replay-consistency-python

Conversation

@DNKYr

@DNKYr DNKYr commented Jul 9, 2026

Copy link
Copy Markdown

Related Issues

Resolved #89

Summary

Build a replay consistency harness that validates InMemory, SQL, and Redis
backends produce equivalent results when driven by identical operation sequences.
Drives the same trajectory through multiple backends and generates a structured
diff report with field-level precision.

Changes

Design notes

  • docs/replay_harness/DESIGN.md (English) and DESIGN.zh_CN.md (Chinese)
  • Covers normalization strategy, summary comparison, allowed differences, and
    backend integration.

Replay cases (10 JSON trajectory files)

  • tests/sessions/replay_cases/_base.pyReplayOp/ReplayCase data models
    with JSON loader.
  • 10 standardized replay case files covering:
    • 01 single-turn chat
    • 02 multi-turn conversation
    • 03 tool call (function_call + function_response)
    • 04 state update (write and overwrite)
    • 05 memory store and search
    • 06 summary generation and retrieval
    • 07 summary with event truncation
    • 08 error recovery (duplicate append)
    • 09 injected anomaly (extra event detection)
    • 10 injected anomaly (state corruption detection)

Replay harness (3 modules + unit tests, 75 tests)

  • Normalizer (_normalizer.py + 24 tests)
    Strips auto-generated fields (timestamps, UUIDs, invocation IDs) and replaces
    timestamps with sequential indices for deterministic comparison.

  • Comparator (_comparator.py + 30 tests)
    Pairwise field-level diff across events, state, memory, and summaries. Detects
    summary loss, overwrite errors, and wrong-session-affiliation. Supports
    AllowedDiff rules for known-acceptable backend differences.

  • Report (_report.py + 22 tests)
    Generates session_memory_summary_diff_report.json with run metadata, per-case
    results, aggregate statistics, and false-positive rate (excluding anomaly cases).

E2E tests (11 tests)

  • Runs all 10 replay cases through InMemory vs SQL (sqlite :memory:) backend pair.
  • Anomaly cases (09-10) verify 100% detection.
  • Generates the full diff report.

Results

Metric Value
Normal cases (01-08) 0 diffs, 0% false positive rate
Anomaly cases (09-10) 100% detection
Total unit + E2E tests 87 passing
External dependencies None (SQL uses sqlite :memory:)
Redis support Opt-in via TRPC_REDIS_URL env var

Backward Compatibility

No API changes. All new code lives under tests/sessions/. No effect on the
production SDK.

DNKYr and others added 7 commits July 9, 2026 18:45
Add DESIGN.md (English) and DESIGN.zh_CN.md (Chinese) for the
Session/Memory/Summary multi-backend replay consistency testing
framework. Covers normalization strategy, summary comparison
approach, allowed difference rules, backend integration, and
harness self-testing strategy.

Updates trpc-group#89

RELEASE NOTES: NONE
Add ReplayOp / ReplayCase Pydantic models and 10 standardized
replay trajectory files covering:

- 01 single-turn chat
- 02 multi-turn conversation
- 03 tool call (function_call + function_response)
- 04 state update (write and overwrite)
- 05 memory store and search
- 06 summary generation and retrieval
- 07 summary with event truncation
- 08 error recovery (duplicate append)
- 09 injected anomaly (extra event detection)
- 10 injected anomaly (state corruption detection)

Updates trpc-group#89

RELEASE NOTES: NONE
Implement normalization utilities that strip auto-generated and
backend-dependent fields (timestamps, UUIDs, invocation IDs) from
events, state, summaries, and memory entries before comparison.

24 unit tests cover: event field stripping, timestamp-to-index
replacement, function_call/response extraction, state deep-sort
determinism, summary timestamp removal, memory entry normalization,
and the full normalize_backend_result orchestrator.

Updates trpc-group#89

RELEASE NOTES: NONE
Implement pairwise comparison of normalized backend results with
field-level precision. Covers events (author, text, function calls,
responses, state deltas), state (deep recursive diff), summaries
(loss, overwrite, wrong-session-affiliation detection), and memory.
Includes AllowedDiff rules to suppress known-acceptable backend
differences via pattern matching.

30 unit tests verify: identical detection, count mismatches, field-
level diffs, event-index precision, nested state diff paths, summary
loss / overwrite / mis-affiliation, memory diffs, and allow-rule
suppression with backend-pair scoping.

Updates trpc-group#89

RELEASE NOTES: NONE
Implement DiffReport generation with run metadata, per-case results,
and aggregate summary statistics including false-positive rate
calculation. Supports JSON serialization and file output via
write_report.

21 unit tests cover: ReportMetadata defaults, CaseResult fields,
ReportSummary, false-positive rate computation (edge cases for
no-passing, all-pass-no-diffs, mixed, failing-only), generate_report
with empty/all-pass/all-fail/mixed scenarios, report_to_dict JSON
round-trip, and write_report file creation.

Updates trpc-group#89

RELEASE NOTES: NONE
Implement ReplayEngine that executes replay cases against session
and memory backends, with support for:
- Building Events from replay ops (text, function calls, responses)
- Summary injection into SummarizerSessionManager cache
- Memory store/search integration
- Duplicate append error recovery simulation
- Anomaly injection for detection verification

Add test_replay_consistency.py with 11 E2E tests:
- 10 parametrized tests running all replay cases through
  InMemory vs SQL (sqlite) backend pair
- 1 test generating the session_memory_summary_diff_report.json

All 87 tests pass (24 normalizer + 30 comparator + 22 report + 11 E2E).
Diff report shows 0% false positive rate on normal cases and 100%
detection on injected anomaly cases.

Fix false-positive-rate calculation to exclude anomaly cases where
diffs are expected.

Updates trpc-group#89

RELEASE NOTES: NONE
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@DNKYr

DNKYr commented Jul 9, 2026

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

Rook1ex added a commit to trpc-group/cla-database that referenced this pull request Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

构建 Session / Memory 多后端回放一致性测试框架

1 participant