Skip to content

fix: document Evaluator thread-safety contract#33

Merged
kyle-elliott-tob merged 2 commits into
masterfrom
fix/evaluator-thread-safety-cluster
May 5, 2026
Merged

fix: document Evaluator thread-safety contract#33
kyle-elliott-tob merged 2 commits into
masterfrom
fix/evaluator-thread-safety-cluster

Conversation

@kyle-elliott-tob

Copy link
Copy Markdown
Collaborator

Summary

Closes the evaluator-thread-safety cluster (3 findings) from the 2026-05-04 audit. 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 was implicit and hostile to future contributors.

Findings closed:

  • lifting-passes-34 — Evaluator copy constructor: no thread-safety documentation
  • lifting-passes-41 — Evaluator::Remap function-path closure captures mutable buffer
  • decomposition-engine-7 — BuildRemainderEvaluator closure captures mutable workspaces (Informational)

Changes

  • Added a class-level Thread-safety contract doc block on Evaluator spelling out (1) the function-path closure mutable buffer, (2) the compiled-path EvaluatorWorkspace ownership rule, and (3) the BuildRemainderEvaluator closure capture.
  • Annotated the Remap function-path closure construction with a pointer-back to the contract.
  • Annotated 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_local or per-thread copies deliberately rather than discovering the constraint from a heisenbug.

Test plan

  • Full unit suite (1171 tests, dataset/diagnostic suites excluded) passes (no behavioral change)

🤖 Generated with Claude Code

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
@kyle-elliott-tob kyle-elliott-tob merged commit 489d17f into master May 5, 2026
9 checks passed
@kyle-elliott-tob kyle-elliott-tob deleted the fix/evaluator-thread-safety-cluster branch May 5, 2026 18:37
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