Skip to content

InMemoryBackend: deep-copy values on Set/Get to fix data race#807

Open
AbirAbbas wants to merge 2 commits into
mainfrom
issue/ce5c9b74-inmemory-deepcopy
Open

InMemoryBackend: deep-copy values on Set/Get to fix data race#807
AbirAbbas wants to merge 2 commits into
mainfrom
issue/ce5c9b74-inmemory-deepcopy

Conversation

@AbirAbbas

Copy link
Copy Markdown
Contributor

Summary

  • Recursive deepCopyAny for map[string]any, []any, and []float64 applied on Set, Get, SetVector, GetVector
  • Callers and the backend never share mutable references, preventing data races
  • Verified with go vet clean and go test -race ./agent/

Changes

  • agent/backend/inmemory/inmemory.go — Added deepCopyAny helper and applied it to Set, Get, SetVector, GetVector
  • agent/backend/inmemory/inmemory_test.go — Added regression tests that mutate originals and returned values, asserting stored state is unchanged; concurrent access test

Test plan

  1. Run go vet ./agent/... — passes clean
  2. Run go test -race ./agent/... — all tests pass with race detector enabled
  3. Regression tests verify that mutating returned values does not affect stored state and vice versa
  4. Concurrent access test verifies no data races under parallel reads/writes

Closes #432

🤖 Built with AgentField SWE-AF
🔌 Powered by AgentField

…d Set/Get and SetVector/GetVector to prevent data races
@AbirAbbas
AbirAbbas requested a review from a team as a code owner July 21, 2026 22:10
@AbirAbbas
AbirAbbas marked this pull request as draft July 21, 2026 22:12
@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Performance

SDK Memory Δ Latency Δ Tests Status
Go 190 B -32% 0.47 µs -53%

✓ No regressions detected

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

📊 Coverage gate

Thresholds from .coverage-gate.toml: per-surface ≥ 84%, aggregate ≥ 85%, max per-surface regression ≤ 1.0 pp, max aggregate regression ≤ 0.50 pp.

Surface Current Baseline Δ
control-plane 86.90% 87.40% ↓ -0.50 pp 🟡
sdk-go 92.50% 92.00% ↑ +0.50 pp 🟢
sdk-python 93.82% 93.73% ↑ +0.09 pp 🟢
sdk-typescript 91.05% 90.42% ↑ +0.63 pp 🟢
web-ui 84.75% 84.79% ↓ -0.04 pp 🟡
aggregate 85.54% 85.75% ↓ -0.21 pp 🟡

✅ Gate passed

No surface regressed past the allowed threshold and the aggregate stayed above the floor.

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

📐 Patch coverage gate

Threshold: 80% on lines this PR touches vs origin/main (from .coverage-gate.toml:thresholds.min_patch).

Surface Touched lines Patch coverage Status
control-plane 0 ➖ no changes
sdk-go 35 100.00%
sdk-python 0 ➖ no changes
sdk-typescript 0 ➖ no changes
web-ui 0 ➖ no changes

✅ Patch gate passed

Every surface whose lines were touched by this PR has patch coverage at or above the threshold.

… paths

Exercises the previously-uncovered branches in deepCopyAny ([]any
recursion, []float64 copying, default passthrough) and
deepCopyFloat64Slice (nil input handling) to satisfy the patch-coverage
gate at 80%. No production code changes.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ AbirAbbas
❌ swe-AF
You have signed the CLA already but the status is still pending? Let us recheck it.

@AbirAbbas
AbirAbbas marked this pull request as ready for review July 22, 2026 13:41
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.

[Go SDK] InMemoryBackend stores caller references without deep copy (data race)

3 participants