Skip to content

fix(server): synchronize relay completion with run admission - #2638

Merged
jbeda merged 1 commit into
mainfrom
fix/server-relay-run-identity
Nov 1, 2026
Merged

jbeda merged 1 commit into
mainfrom
fix/server-relay-run-identity

Conversation

@jbeda

@jbeda jbeda commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Synchronize completeRelay's exact-run comparison with admission promotion using Service.mu.
  • Recheck registry/run identity after acquiring persistMu, before inspecting session state or persisting. A delayed relay cannot save an old snapshot after its registry entry is replaced or removed.
  • Retain shutdown snapshot preservation, terminal persistence, and the existing persistMu → Service.mu lock order. Keep storage I/O outside the global registry mutex.

The historical TestHeadlessAutoApproveUsesExactOwnership failure is a production race, not just test timing: Converse's deferred second finish can encounter a provisional exact-plan successor while promoteRunAdmission publishes its run pointer.

Refs #2327 (server ownership-race watch-list item only; umbrella remains open).

Regression coverage

  • Deterministic persistence barriers for deregistered/replaced runs; restoring the original implementation makes both cases fail by saving the stale completed snapshot.
  • Successor-promotion ordering and concurrent admission through the real promotion method. Moving only the initial identity comparison outside the mutex reproduces the exact data race, independently of the second identity guard.
  • Matching completed/cancelled/failed snapshots still save; nonterminal and shutdown-preserved snapshots do not.
  • A bounded registry-lock probe verifies registry identity and availability during blocked Store.Save, with release-before-join cleanup.

Verification

  • Historical reproducer: original code reproduced the exact completeRelay read versus promoteRunAdmission write race; fixed code passed 10,000 repetitions under -race with GOMAXPROCS=2.
  • All TestCompleteRelay* tests: 100 race repetitions passed after final follow-ups.
  • Neighboring exact-plan, transport-parity, shutdown-preservation, and relay-disconnect tests: 10 race repetitions passed.
  • task test: passed.
  • task lint: passed.
  • task test:race: passed.
  • Offline go run ./cmd/mecademo: passed, including tool calls/results, permission ask/approval, and terminal result.
  • git diff --check: passed.
  • Independent Spec, Standards, Test adequacy, Architecture, Security, Reuse, and Duplication reviews completed; two test-review findings were addressed and confirmed resolved. No outstanding findings.

API compatibility

Restores the existing exact-run cleanup guarantee. Existing conforming clients require no changes. No API-major or feature-identifier changes, no public Go API changes, and no stored-data changes; no upgrade implications.

Guard exact run identity with the admission mutex and revalidate after the persistence barrier before accessing session state. Cover stale persistence, concurrent promotion, terminal saves, and shutdown preservation.

Refs #2327

Co-authored-by: Mecatl <[email protected]>
@jbeda
jbeda merged commit c3adf8f into main Nov 1, 2026
42 checks passed
@jbeda
jbeda deleted the fix/server-relay-run-identity branch November 1, 2026 16:21
@jbeda jbeda mentioned this pull request Nov 1, 2026
10 of 14 tasks
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Nov 18, 2026
2 tasks
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