Repository navigation
fix(coordinator): snapshot AttestationResult on store (fix -race data race) - #336
Conversation
…ta race persistProviderNow asynchronously json.Marshal(p.AttestationResult) under p.mu, while the provider-registration path mutates a single local result struct (Valid/Error/...) across several validation checks and hands its pointer to the registry via SetAttestationResult. Storing the caller's pointer aliased that mutable struct, so the unsynchronized field writes raced the async marshal — caught intermittently by the -race detector in coordinator/api (TestProviderRegistrationRejectsInvalidConfiguredBinaryHash and others; the async persist goroutine outlives the test that spawned it). SetAttestationResult now stores a shallow copy. VerificationResult is all value-typed fields, so the copy is a complete, immutable, Provider-owned snapshot; the caller can keep mutating its local result without touching it. Regression: a deterministic snapshot test (mutation after store doesn't leak) plus a -race test (concurrent marshal vs caller mutate+restore).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This PR fixes a data race in Trust boundaries touched
Threat analysisT-034 — Provider runs modified code while advertising a trusted identity ✅ Strengthens mitigation (marginally) The race being fixed is between:
Before this change, The fix — This does not change the logic of attestation verification or the CodeAttested gate, so it doesn't directly affect whether a modified binary passes. It does ensure the stored attestation snapshot faithfully represents what was verified, removing a window where a race could produce an inconsistent persisted state that might be audited or re-evaluated later. New attack surface introducedNone. This change narrows behaviour (removes aliasing); it introduces no new API surface, no new goroutines, and no new trust decisions. Open findings resolvedNone explicitly. The PR doesn't reference any SEC-* finding, and no existing finding directly describes this race. The related test file Minor notes for the reviewer
🔐 Threat model: |
|
@codex review this |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
ethenotethan
left a comment
There was a problem hiding this comment.
Automated Code Review — Layr-Labs/d-inference#
Verdict: REQUEST_CHANGES
Security — ✅ No issues found
Performance — 1 finding(s) (1 blocking)
- 🟡 [MEDIUM]
coordinator/registry/attestation_result_race_test.go:60-65— Redundant json.Marshal calls in tight loop without using result- Suggestion: Consider reducing iteration count or adding minimal work between marshals to better simulate real usage patterns
Type_diligence — ✅ No issues found
Additive_complexity — ✅ No issues found
1 finding(s) total, 1 blocking. Verdict: REQUEST_CHANGES.
🤖 Automated review by Centaur · DAR-186
| defer wg.Done() | ||
| for i := 0; i < 5000; i++ { | ||
| if got := p.GetAttestationResult(); got != nil { | ||
| _, _ = json.Marshal(got) | ||
| } | ||
| } |
There was a problem hiding this comment.
🟡 [MEDIUM] ⚡ Redundant json.Marshal calls in tight loop without using result
💡 Suggestion: Consider reducing iteration count or adding minimal work between marshals to better simulate real usage patterns
📊 Score: 2×4 = 8 · Category: Repeated work
ethenotethan
left a comment
There was a problem hiding this comment.
Automated Code Review — Layr-Labs/d-inference#
Verdict: REQUEST_CHANGES
Security — ✅ No issues found
Performance — 1 finding(s) (1 blocking)
- 🟡 [MEDIUM]
coordinator/registry/attestation_result_race_test.go:60-65— Redundant json.Marshal calls in tight loop without using result- Suggestion: Consider reducing iteration count or adding small delay between marshals to avoid unnecessary CPU usage in test
Type_diligence — ✅ No issues found
Additive_complexity — 1 finding(s)
- 🔵 [INFO]
coordinator/registry/attestation_result_race_test.go:51-75— Race test uses arbitrary high iteration count (5000) without justification- Suggestion: Use a smaller iteration count (100-500) or make it configurable via build tags for CI vs local testing
2 finding(s) total, 1 blocking. Verdict: REQUEST_CHANGES.
🤖 Automated review by Centaur · DAR-186
| defer wg.Done() | ||
| for i := 0; i < 5000; i++ { | ||
| if got := p.GetAttestationResult(); got != nil { | ||
| _, _ = json.Marshal(got) | ||
| } | ||
| } |
There was a problem hiding this comment.
🟡 [MEDIUM] ⚡ Redundant json.Marshal calls in tight loop without using result
💡 Suggestion: Consider reducing iteration count or adding small delay between marshals to avoid unnecessary CPU usage in test
📊 Score: 2×4 = 8 · Category: Repeated work
| // races on the shared struct's fields without it. | ||
| func TestSetAttestationResultNoRaceWithConcurrentMarshal(t *testing.T) { | ||
| p := &Provider{} | ||
| r := &attestation.VerificationResult{Valid: true, Error: "orig"} | ||
| p.SetAttestationResult(r) | ||
|
|
||
| var wg sync.WaitGroup | ||
| wg.Add(2) | ||
| go func() { // reader: persistProviderNow-style marshal of the stored snapshot | ||
| defer wg.Done() | ||
| for i := 0; i < 5000; i++ { | ||
| if got := p.GetAttestationResult(); got != nil { | ||
| _, _ = json.Marshal(got) | ||
| } | ||
| } | ||
| }() | ||
| go func() { // writer: registration-style mutate-then-restore of the local result | ||
| defer wg.Done() | ||
| for i := 0; i < 5000; i++ { | ||
| r.Valid = !r.Valid | ||
| r.Error = "x" | ||
| p.SetAttestationResult(r) | ||
| } | ||
| }() | ||
| wg.Wait() |
There was a problem hiding this comment.
🔵 [INFO] 🧩 Race test uses arbitrary high iteration count (5000) without justification
💡 Suggestion: Use a smaller iteration count (100-500) or make it configurable via build tags for CI vs local testing
📊 Score: 2×3 = 6 · Category: over-configuration
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed width (#1555) * perf(flint): pin SDK speedups, chain constrained decode, serve at paged width Pins mlx-swift-lm claude/flint-perf (0349802): larger decode command buffers, fewer paged decode dispatches and host uploads, a fused MoE FP32 expert combine, batched sliding-window prefill attention, final-layer KV-only evaluation chunks, and constrained decode chaining with cached device masks. Every SDK change is byte-identical to the previous path. FlintNativeProtocolConstraint and FlintAnswerStopConstraint opt into chained decode and key their cached masks by constraint state, since the allowed set depends only on the state while output budget remains. RecursiveSI/flint-int4 joins the automatic paged list, so it serves at the legacy paged width (8) on M5 Pro, Max and Ultra. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(flint): pin mlx-swift-lm 758c25bc (fork.yaml and formatting only) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(flint): pin mlx-swift-lm cbaf4cc9 (zero-filled decode merge scratch) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(flint): pin merged mlx-swift-lm main 993f7060 (#336) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* perf(flint): pin SDK speedups, chain constrained decode, serve at paged width Pins mlx-swift-lm claude/flint-perf (0349802): larger decode command buffers, fewer paged decode dispatches and host uploads, a fused MoE FP32 expert combine, batched sliding-window prefill attention, final-layer KV-only evaluation chunks, and constrained decode chaining with cached device masks. Every SDK change is byte-identical to the previous path. FlintNativeProtocolConstraint and FlintAnswerStopConstraint opt into chained decode and key their cached masks by constraint state, since the allowed set depends only on the state while output budget remains. RecursiveSI/flint-int4 joins the automatic paged list, so it serves at the legacy paged width (8) on M5 Pro, Max and Ultra. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(flint): pin mlx-swift-lm 758c25bc (fork.yaml and formatting only) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(flint): pin mlx-swift-lm cbaf4cc9 (zero-filled decode merge scratch) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(flint): pin exact decode fusions (mlx-swift-lm 3676bff1) Fused q/k/v and gate/up projections, fused routed gate/up banks, one MoE combine-and-residual kernel and compiled router steps: the batch-1 decode graph drops from 2,042 to 1,233 GPU primitives per token with byte-identical logits, K/V and tokens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(flint): describe the decode fusions; pin mlx-swift-lm 9b7f5b07 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(flint): pin merged mlx-swift-lm main 993f7060 (#336) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Fixes a data race (caught intermittently by the
-racedetector incoordinator/api, e.g.TestProviderRegistrationRejectsInvalidConfiguredBinaryHash) betweenregistry.persistProviderNow's async marshal and the provider-registration path.Root cause
persistProviderNowspawns a detached goroutine thatjson.Marshalsp.AttestationResultunderp.mu. The registration path (coordinator/api/provider.go) builds a single localresult(*attestation.VerificationResult), mutates its fields across several validation checks (result.Valid,result.Error, …), and hands the pointer to the registry viaSetAttestationResult(&result). Storing the caller's pointer madep.AttestationResultalias that still-mutable struct, so the unsynchronized field writes raced the async marshal.It's nondeterministic because the persist goroutine outlives the test that spawned it and only collides with another test's registration under the wrong interleaving — so the test passes in isolation but trips occasionally on a full-package
-racerun.This is pre-existing on
master(bothpersistProviderNowand the pointer-storingSetAttestationResultare unchanged there); it is not specific to any feature branch.Fix
SetAttestationResultnow stores a shallow copy underp.mu:attestation.VerificationResultis all value-typed fields (bools / strings /time.Time), so the copy is a complete, immutable, Provider-owned snapshot — the caller can keep mutating its localresultwithout ever touching what the registry marshals.nilis preserved.Test plan
go test -race ./coordinator/registry/and./coordinator/api/— pass. New regression tests incoordinator/registry/attestation_result_race_test.go:TestSetAttestationResultSnapshotsCallerStruct— deterministic: mutating the caller's struct afterSetAttestationResultmust not change the stored value.TestSetAttestationResultNoRaceWithConcurrentMarshal— a marshal loop concurrent with caller mutate-then-restore, clean under-race.TestSetAttestationResultNilClears— nil clears the stored result.Verified the tests fail without the fix: reverting
SetAttestationResultto the pointer-store makes the snapshot test fail deterministically (stored result was not snapshotted: Valid=false Error="mutated") and the concurrency test reportDATA RACE. The originally-flakyTestProviderRegistrationRejectsInvalidConfiguredBinaryHashran 15× clean under-racewith the fix.Context
Surfaced as a flaky CI failure on an unrelated PR (#335). Fixed here on
masterso all branches inherit it.Follow-up (not in this PR)
Review flagged a separate, pre-existing low-severity item, untouched by this change:
cmd/coordinator/main.go:352,360readsp.AttestationResultwithoutp.muin theSetOnMDAcallback (the siblingSetOnLateSecurityInfocallback locks correctly). This snapshot fix reduces its danger — the stored struct is now immutable — but the pointer read should go throughGetAttestationResult(). Worth a small standalone fix.Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.