Skip to content

libsimlin: add deterministic patch race regressions - #314

Merged
bpowers merged 1 commit into
mainfrom
libsimlin-deterministic-patch-race-regressions
Feb 24, 2026
Merged

bpowers merged 1 commit into
mainfrom
libsimlin-deterministic-patch-race-regressions

Conversation

@bpowers

@bpowers bpowers commented Feb 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

Test plan

  • cargo test -p simlin passes all new concurrency tests
  • Existing tests unaffected (hooks are #[cfg(test)] only)

Add explicit regression coverage for issues #296, #297, and #298 in the libsimlin patch path. The new tests use test-only hook points in apply_project_patch_internal to force the critical interleavings deterministically, rather than relying on timing-sensitive stress loops.

The hooks are cfg(test)-only and keep production behavior unchanged. They allow us to verify that snapshot reads remain atomic under the project lock, sync_state is never transiently cleared during staging, and sim_new cannot observe staged dry-run state before patch decisions are finalized.
@claude

claude Bot commented Feb 24, 2026

Copy link
Copy Markdown

Code Review: libsimlin deterministic patch race regressions

Summary

This PR adds test-only hook infrastructure to the patch pipeline and three regression tests for concurrency issues (#296, #297, #298). I reviewed the hook infrastructure in patch.rs and all three tests in tests_concurrency.rs, cross-referencing with apply_project_patch_internal, simlin_sim_new, and simlin_project_get_model to verify lock-ordering assumptions.

Findings

No bugs found. The implementation is sound:

Verdict

Correct. Existing code and tests will not break. The patch is free of bugs and blocking issues.

@codecov

codecov Bot commented Feb 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.18%. Comparing base (7963fde) to head (e56d228).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #314   +/-   ##
=======================================
  Coverage   79.18%   79.18%           
=======================================
  Files         121      121           
  Lines       30375    30384    +9     
=======================================
+ Hits        24053    24061    +8     
- Misses       6322     6323    +1     

☔ View full report in Codecov by Sentry.
📢 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.

@bpowers

bpowers commented Feb 24, 2026

Copy link
Copy Markdown
Owner Author

Code Review

I reviewed the full diff across both files (src/libsimlin/src/patch.rs and src/libsimlin/src/tests_concurrency.rs).

Summary

This PR adds a test hook mechanism to the patch system and three regression tests for concurrency issues (#296, #297, #298). The approach is sound:

  • The hook infrastructure uses #[cfg(test)] throughout, ensuring zero production overhead.
  • invoke_patch_test_hook correctly clones the Arc before dropping the PATCH_TEST_HOOK mutex, avoiding holding two locks simultaneously and preventing deadlock when the hook is invoked inside a project or db lock scope.
  • The PatchTestHookGuard + PATCH_TEST_HOOK_LOCK pattern ensures test-level serialization so concurrent test execution does not interfere.
  • Reference counting is correct in all three tests (each thread that calls unref has a corresponding ref call, plus the main thread's final unref).

Per-test analysis

Findings

No bugs found. The patch is clean and the tests correctly validate the intended concurrency invariants.

Verdict: Correct. Existing code and tests will not break, and the patch is free of bugs.

@bpowers

bpowers commented Feb 24, 2026

Copy link
Copy Markdown
Owner Author

Review Summary

This PR was reviewed by both Codex (gpt-5.3-codex) and Claude (opus) in a single iteration. Neither reviewer found actionable issues.

Both reviewers confirmed the test-only #[cfg(test)] hook infrastructure is correctly scoped to avoid deadlocks (the hook mutex is dropped before invoking the closure), the test serialization lock prevents interference between concurrent test runs, and reference counting is properly balanced across threads. The three regression tests exercise the intended concurrency scenarios deterministically.

@bpowers
bpowers merged commit 0352c18 into main Feb 24, 2026
12 checks passed
@bpowers
bpowers deleted the libsimlin-deterministic-patch-race-regressions branch February 24, 2026 04:24
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.

1 participant