Skip to content

Guard PresenceManager.Start against duplicate sweep goroutines#808

Open
AbirAbbas wants to merge 1 commit into
mainfrom
issue/ab42b0b9-presence-start-guard
Open

Guard PresenceManager.Start against duplicate sweep goroutines#808
AbirAbbas wants to merge 1 commit into
mainfrom
issue/ab42b0b9-presence-start-guard

Conversation

@AbirAbbas

Copy link
Copy Markdown
Contributor

Summary

Changes

  • control-plane/internal/services/presence_manager.go — added startOnce sync.Once field and wrapped Start() body so duplicate calls are no-ops.
  • control-plane/internal/services/presence_manager_test.go — added TestPresenceManager_Start_Idempotent (asserts no extra goroutines across repeated Start() calls) and TestPresenceManager_ExpireCallback_OncePerExpiration (asserts the expire callback fires at most once per expired lease across multiple sweep cycles).

Test plan

  • go vet ./... is clean.
  • All 19 TestPresenceManager* tests pass.
  • Full control-plane/internal/services suite passes under -race with -gcflags=all=-d=checkptr=0 (pre-existing boltdb v1.3.1 checkptr incompatibility with Go 1.25 race detector exists on main and is unrelated to this change).
  • Temporarily reverted the startOnce guard and confirmed TestPresenceManager_Start_Idempotent fails with delta=3 (3 extra goroutines from duplicate Start() calls), proving the regression test catches the bug; restored the guard.

🤖 Built with AgentField SWE-AF
🔌 Powered by AgentField

…cate sweep goroutines

Start() now uses sync.Once (mirroring the existing stopOnce pattern) to
ensure only one sweep loop is ever spawned per PresenceManager instance.

Adds two regression tests:
- TestPresenceManager_Start_Idempotent: counts goroutines before/after
  multiple Start() calls to assert no duplicate sweep loops spawn.
- TestPresenceManager_ExpireCallback_OncePerExpiration: counts callback
  invocations across multiple sweep cycles to assert the callback fires
  at most once per expired node lease.

Verification: temporarily reverted the startOnce guard and confirmed
TestPresenceManager_Start_Idempotent fails with delta=3 (3 extra
goroutines spawned by duplicate Start() calls), proving the regression
test catches the bug. Restored the guard; all presence manager tests
pass and go vet is clean.
@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

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.40% 92.00% ↑ +0.40 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

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 3 100.00%
sdk-go 0 ➖ no changes
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.

@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.

[Control Plane] PresenceManager.Start can spawn duplicate sweep goroutines

1 participant