fix: document Evaluator thread-safety contract#33
Merged
Conversation
Evaluator-family closures capture mutable buffers (`original_vals` in Remap's function-path branch; `original_workspace` and `core_stack` in BuildRemainderEvaluator). Concurrent calls on the same instance race on those buffers, but neither the class header nor the call sites flagged the constraint, and `std::function` semantics suggest thread-safety to readers. The orchestrator is single-threaded today, so no live race exists, but the contract is implicit and hostile to future contributors. Closes the evaluator-thread-safety cluster from the 2026-05-04 audit: - lifting-passes-34: Evaluator copy ctor — no thread-safety documentation - lifting-passes-41: Evaluator::Remap function-path mutable-buffer capture - decomposition-engine-7: BuildRemainderEvaluator mutable workspaces (Informational) Adds a class-level "Thread-safety contract" doc on Evaluator spelling out (1) the function-path closure mutable buffer, (2) the compiled-path EvaluatorWorkspace ownership rule, and (3) the BuildRemainderEvaluator closure capture. Annotates the Remap and BuildRemainderEvaluator closure construction sites with pointer-back comments. Documentation only; no behavioral or test changes. The closures still race if used concurrently — this PR makes the contract visible so a future contributor can reach for `thread_local` or per-thread copies deliberately rather than discovering the constraint from a heisenbug.
…d-safety-cluster # Conflicts: # include/cobra/core/Evaluator.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the evaluator-thread-safety cluster (3 findings) from the 2026-05-04 audit.
Evaluator-family closures capture mutable buffers (original_valsinRemap's function-path branch;original_workspaceandcore_stackinBuildRemainderEvaluator). Concurrent calls on the same instance race on those buffers, but neither the class header nor the call sites flagged the constraint, andstd::functionsemantics suggest thread-safety to readers. The orchestrator is single-threaded today, so no live race exists, but the contract was implicit and hostile to future contributors.Findings closed:
lifting-passes-34— Evaluator copy constructor: no thread-safety documentationlifting-passes-41— Evaluator::Remap function-path closure captures mutable bufferdecomposition-engine-7— BuildRemainderEvaluator closure captures mutable workspaces (Informational)Changes
Evaluatorspelling out (1) the function-path closure mutable buffer, (2) the compiled-pathEvaluatorWorkspaceownership rule, and (3) theBuildRemainderEvaluatorclosure capture.Remapfunction-path closure construction with a pointer-back to the contract.BuildRemainderEvaluator's closure construction with the same pointer-back.Scope note
Documentation only; no behavioral or test changes. The closures still race if used concurrently. This PR makes the contract visible so a future contributor reaches for
thread_localor per-thread copies deliberately rather than discovering the constraint from a heisenbug.Test plan
🤖 Generated with Claude Code