Skip to content

session/replaytest: add multi-backend replay consistency framework#2265

Open
Wsp030914 wants to merge 6 commits into
trpc-group:mainfrom
Wsp030914:feat/2001-replay-consistency
Open

session/replaytest: add multi-backend replay consistency framework#2265
Wsp030914 wants to merge 6 commits into
trpc-group:mainfrom
Wsp030914:feat/2001-replay-consistency

Conversation

@Wsp030914

Copy link
Copy Markdown

What changed

  • Add a reusable backend-independent replay consistency framework under
    session/replaytest.
  • Add 10 public replay cases covering events, state, memory, summaries,
    tracks, concurrent writes, and failure recovery.
  • Add the default InMemory and SQLite matrix, with Redis, Postgres, MySQL,
    and ClickHouse integrations enabled through environment variables.
  • Add normalization, field-level comparison, strict allowed-diff handling,
    snapshot invariants, and structured JSON reports.
  • Add fault-injection, race, comparator, normalizer, reporter, backend
    integration tests, and running documentation.

Why

Session and Memory backends can preserve different replay-visible behavior
for the same agent trajectory. This framework detects event ordering, state,
memory, summary, and track inconsistencies before backend migration or release.

Fixes #2001

Testing

  • go test ./session/replaytest -count=1 — 100 tests passed.
  • go test -race ./session/replaytest -count=1 — 100 tests passed.
  • cd test && go test ./replayconsistency -count=1 — 54 tests passed.
  • cd test && go test -race ./replayconsistency -count=1 — 54 tests passed.
  • go vet passed for both packages.
  • gofmt and license-header checks passed for all added Go files.
  • Repository-wide testing is left to project CI.

Notes for reviewers

  • Please focus on normalization boundaries, summary ownership/filter-key
    comparison, concurrent replay ordering, retry idempotency, and allowed-diff
    precision.
  • Optional external backends are environment-gated and skipped when not
    configured.
  • The additional test/go.mod dependencies come from the Redis, Postgres,
    MySQL, ClickHouse, and SQLite adapters.
  • No existing Session or Memory runtime API is changed.

RELEASE NOTES: Added a reusable multi-backend replay consistency test framework
for Session, Memory, Summary, and Track backends.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR adds a reusable Go replay-consistency framework with typed snapshots, ten standard scenarios, normalization, semantic comparison, deterministic reports, backend fixtures, capability probes, integration matrices, and write-boundary fault tests across Session and Memory implementations.

Changes

Replay consistency framework

Layer / File(s) Summary
Replay contracts, cases, and comparison pipeline
session/replaytest/types.go, session/replaytest/operation.go, session/replaytest/cases.go, session/replaytest/normalize.go, session/replaytest/compare.go
Defines replay snapshots and operations, ten standard scenarios, deterministic normalization, scoped tolerances, allowed-diff rules, and semantic locators.
Execution and reporting
session/replaytest/runner.go, session/replaytest/report.go
Runs cases across backends, handles dependencies, failures, capabilities, invariants, deterministic sorting, and JSON report writing.
Framework validation
session/replaytest/*_test.go
Tests contracts, normalization, comparison, reporting, runner behavior, invariants, recovery, and injected-difference detection.
Backend fixtures and adapters
test/replayconsistency/factory.go, test/replayconsistency/fixture.go
Wires InMemory, SQLite, Redis, PostgreSQL, MySQL, and ClickHouse fixtures and converts runtime service data into replay snapshots.
Capability and integration coverage
test/replayconsistency/capability_probe.go, test/replayconsistency/*_test.go, test/go.mod
Adds pagination and TTL probes, lightweight and optional external matrices, state semantics tests, dependency wiring, and an example report.
Write-boundary fault detection
test/replayconsistency/write_fault_test.go
Injects event, state, memory, summary, track, and retry faults and verifies detected differences and locator output.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

Suggested reviewers: sandyskies, winechord, hyprh

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.59% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: a new multi-backend replay consistency framework under session/replaytest.
Description check ✅ Passed The description is directly aligned with the implemented replay framework, cases, backends, tests, and documentation.
Linked Issues check ✅ Passed The PR implements the required multi-backend replay harness, 10 cases, normalization/comparison/reporting, and env-gated backends.
Out of Scope Changes check ✅ Passed The added tests, docs, and go.mod/backend dependency changes support the replay framework and are not unrelated scope.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread session/replaytest/compare.go Outdated
Comment thread test/go.mod
@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.34857% with 144 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.87964%. Comparing base (40ca602) to head (4b2943f).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
session/replaytest/cases.go 87.79715% 47 Missing and 30 partials ⚠️
session/replaytest/normalize.go 90.11299% 24 Missing and 11 partials ⚠️
session/replaytest/runner.go 95.38462% 9 Missing and 6 partials ⚠️
session/replaytest/compare.go 95.43860% 7 Missing and 6 partials ⚠️
session/replaytest/types.go 93.18182% 2 Missing and 1 partial ⚠️
session/replaytest/report.go 98.63014% 1 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##                main       #2265         +/-   ##
===================================================
+ Coverage   89.86515%   89.87964%   +0.01448%     
===================================================
  Files           1148        1157          +9     
  Lines         202302      205299       +2997     
===================================================
+ Hits          181799      184522       +2723     
- Misses         12815       13009        +194     
- Partials        7688        7768         +80     
Flag Coverage Δ
unittests 89.87964% <92.34857%> (+0.01448%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
test/go.mod (1)

8-100: 🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

Bump go.opentelemetry.io/otel/sdk to v1.43.0+
test/go.mod still pulls go.opentelemetry.io/otel/sdk v1.41.0, which falls in GHSA-hfvc-g4fc-pqhx / CVE-2026-39883. The fix is small and removes the BSD/Solaris kenv PATH-hijack risk.

中文

go.opentelemetry.io/otel/sdk 升级到 v1.43.0+
test/go.mod 里仍然引用了 go.opentelemetry.io/otel/sdk v1.41.0,落在 GHSA-hfvc-g4fc-pqhx / CVE-2026-39883 的影响范围内。这个修复很小,可以移除 BSD/Solaris 下 kenv 的 PATH 劫持风险。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/go.mod` around lines 8 - 100, Update the go.opentelemetry.io/otel/sdk
dependency in the test module’s indirect require block from v1.41.0 to v1.43.0
or newer, keeping the dependency declaration otherwise unchanged.
🧹 Nitpick comments (2)
session/replaytest/runner.go (1)

23-35: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Document the Fixture concurrency contract executeParallel invokes fixture.Apply / ApplyWithFault from multiple goroutines, and Fixture is a public interface. Add a doc note that implementations must be safe for concurrent use so downstream backends don’t assume single-threaded access and race on shared state.

中文

Fixture 补充并发契约说明。 executeParallel 会从多个 goroutine 并发调用 fixture.Apply / ApplyWithFault,而 Fixture 是公开接口。建议在注释中明确实现必须支持并发调用,避免下游后端误以为是单线程访问而在共享状态上产生竞态。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@session/replaytest/runner.go` around lines 23 - 35, Update the documentation
comment for the public Fixture interface to state that implementations must be
safe for concurrent use because executeParallel may invoke Apply and
ApplyWithFault from multiple goroutines. Leave the interface methods and
FaultInjector documentation unchanged.
test/replayconsistency/write_fault_test.go (1)

383-420: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Manually-maintained clone whitelist could silently drift from Operation's reference fields.

cloneWriteOperation deep-clones a fixed list of reference-typed fields. If Operation, EventSnapshot, MemorySnapshot, SummarySnapshot, or TrackEventSnapshot gain new map/slice fields later, this helper won't clone them automatically, silently reintroducing the cross-backend aliasing this helper exists to prevent. Worth a short comment here noting the maintenance obligation, or verifying test coverage catches drift when new fields are added.

中文

手动维护的克隆白名单可能与 Operation 的引用类型字段产生偏差。

cloneWriteOperation 对固定的一组引用类型字段做深拷贝。若未来 OperationEventSnapshotMemorySnapshotSummarySnapshotTrackEventSnapshot 新增 map/slice 字段,该辅助函数不会自动克隆它们,会悄然重新引入该函数本应防止的跨后端别名污染问题。建议在此处补充维护提醒注释,或确认新增字段时有测试能捕获遗漏。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/replayconsistency/write_fault_test.go` around lines 383 - 420, Add a
concise maintenance comment to cloneWriteOperation documenting that its explicit
deep-clone list must be updated whenever Operation or its nested snapshot types
gain map or slice fields, preserving the helper’s alias-isolation contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@test/go.mod`:
- Around line 8-100: Update the go.opentelemetry.io/otel/sdk dependency in the
test module’s indirect require block from v1.41.0 to v1.43.0 or newer, keeping
the dependency declaration otherwise unchanged.

---

Nitpick comments:
In `@session/replaytest/runner.go`:
- Around line 23-35: Update the documentation comment for the public Fixture
interface to state that implementations must be safe for concurrent use because
executeParallel may invoke Apply and ApplyWithFault from multiple goroutines.
Leave the interface methods and FaultInjector documentation unchanged.

In `@test/replayconsistency/write_fault_test.go`:
- Around line 383-420: Add a concise maintenance comment to cloneWriteOperation
documenting that its explicit deep-clone list must be updated whenever Operation
or its nested snapshot types gain map or slice fields, preserving the helper’s
alias-isolation contract.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6b4cfcc8-5e33-45b7-a859-a4232fb9d8cc

📥 Commits

Reviewing files that changed from the base of the PR and between 12c70ff and 8d660ab.

⛔ Files ignored due to path filters (1)
  • test/go.sum is excluded by !**/*.sum
📒 Files selected for processing (31)
  • session/replaytest/README.md
  • session/replaytest/cases.go
  • session/replaytest/cases_test.go
  • session/replaytest/compare.go
  • session/replaytest/compare_test.go
  • session/replaytest/detection_test.go
  • session/replaytest/doc.go
  • session/replaytest/normalize.go
  • session/replaytest/normalize_test.go
  • session/replaytest/operation.go
  • session/replaytest/operation_test.go
  • session/replaytest/report.go
  • session/replaytest/report_test.go
  • session/replaytest/runner.go
  • session/replaytest/runner_test.go
  • session/replaytest/types.go
  • session/replaytest/types_test.go
  • test/go.mod
  • test/replayconsistency/README.md
  • test/replayconsistency/capability_probe.go
  • test/replayconsistency/capability_probe_test.go
  • test/replayconsistency/external_matrix_test.go
  • test/replayconsistency/factory.go
  • test/replayconsistency/factory_test.go
  • test/replayconsistency/fixture.go
  • test/replayconsistency/fixture_adapter_test.go
  • test/replayconsistency/integration_test.go
  • test/replayconsistency/replay_test.go
  • test/replayconsistency/state_semantics_test.go
  • test/replayconsistency/testdata/session_memory_summary_track_diff_report.json
  • test/replayconsistency/write_fault_test.go

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown

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

@Wsp030914
Wsp030914 force-pushed the feat/2001-replay-consistency branch from 46c78c2 to 825be4c Compare July 20, 2026 03:05
@Wsp030914

Wsp030914 commented Jul 20, 2026

Copy link
Copy Markdown
Author

Addressed all review feedback in 825be4c.

  • Preserved large-integer precision using json.Decoder.UseNumber() and added regression coverage for values above 2^53.
  • Added local replacements for the ClickHouse, MySQL, and PostgreSQL storage modules.
  • Upgraded the test module to Go 1.25 and OpenTelemetry API/SDK to v1.43.0.
  • Clarified the Fixture/FaultInjector concurrency contract.
  • Documented the deep-clone maintenance requirement.

@Rememorio Rememorio left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the changed lines and left 7 inline comments below. The comments focus on issues worth addressing before merge.

Fresh review found seven high-confidence issues. The main framework can silently produce false passes because nested operation payloads are shared across backends, unused allowed-diff rules are accepted, physical session ownership is overwritten without validation, and memory searches execute against final rather than point-in-time state. The integration probes also need stronger seed assertions and bounded pagination contexts.

中文

我看过这次变更的相关代码,在下面留下 7 条行内评论。评论聚焦在合并前值得处理的问题。

本次审阅发现 7 个高置信度问题。框架可能因操作负载在后端间共享、未命中的 allowed-diff 规则仍被接受、物理 Session 归属未经校验就被覆盖,以及 Memory Search 延迟到最终快照才执行而出现静默误判。集成探针还需要更严格的种子数据断言和有界的分页测试上下文。

Comment thread session/replaytest/compare.go Outdated
Comment thread session/replaytest/runner.go
Comment thread test/replayconsistency/fixture.go Outdated
Comment thread test/replayconsistency/fixture.go
Comment thread test/replayconsistency/capability_probe.go Outdated
Comment thread test/replayconsistency/capability_probe.go
Comment thread test/replayconsistency/integration_test.go Outdated
@Wsp030914

Wsp030914 commented Jul 20, 2026

Copy link
Copy Markdown
Author

I reviewed the changed lines and left 7 inline comments below. The comments focus on issues worth addressing before merge.

Fresh review found seven high-confidence issues. The main framework can silently produce false passes because nested operation payloads are shared across backends, unused allowed-diff rules are accepted, physical session ownership is overwritten without validation, and memory searches execute against final rather than point-in-time state. The integration probes also need stronger seed assertions and bounded pagination contexts.

中文

I reviewed the changed lines and left 7 inline comments below. The comments focus on issues worth addressing before merge.

Fresh review found seven high-confidence issues. The main framework can silently produce false passes because nested operation payloads are shared across backends, unused allowed-diff rules are accepted, physical session ownership is overwritten without validation, and memory searches execute against final rather than point-in-time state. The integration probes also need stronger seed assertions and bounded pagination contexts.

中文

Thanks for the thorough review. All seven issues have been addressed in commit 4446d78:

  • Added strict AllowedDiffRule validation and consumption tracking across the complete replay matrix.
  • Deep-cloned operation payloads before normal, fault-injected, and parallel execution.
  • Executed memory searches at the operation point to preserve point-in-time semantics.
  • Added physical Session scope validation for nil and mismatched backend responses.
  • Strengthened pagination probes with an independent oracle and validation for missing, duplicate, extra, or nil results.
  • Verified TTL session creation and physical scope before waiting for expiration.
  • Added bounded contexts to external pagination probes.
  • Added package documentation, the missing BackendConfig comment, and regression coverage.

Local unit, race, vet, lint, and Redis/PostgreSQL/MySQL/ClickHouse integration checks passed. No workflow or unrelated dependency files were changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants