feat(relay): defer binary release with 30s grace window (#21)#23
Merged
Conversation
Swap the /v1/server disconnect-cleanup defer from the immediate Registry.ReleaseServer to ScheduleReleaseServer, threading a grace duration through ServerHandler's constructor. Production wires 30*time.Second per protocol spec § Authentication → Binary → relay; tests use short durations to exercise the scheduled-release path without slowing the suite. A reconnect within the grace window now lands in the same server-id slot atomically (registry-side reclaim from #20). On expiry, orphan phones for that server-id are closed by the registry's expiry handler. Adds TestServerEndpoint_PeerClose_SchedulesGraceRelease asserting the binary entry persists for grace/4 after close (proves scheduled, not immediate) and is gone within grace + slack (proves the timer fires). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
Author
Code Review: #21Decision: PASS FindingsNone. SummaryClean call-site swap that lands exactly the spec laid out. Verified:
Local Security goggles (ticket carries
|
Update server-endpoint feature doc, PROJECT-MEMORY, lessons, and INDEX to reflect the constructor-parameter grace duration, the ScheduleReleaseServer swap on disconnect, and the sharpened defer-after-claim invariant.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Swaps the
/v1/serverdisconnect-cleanupdeferfrom the immediateRegistry.ReleaseServertoRegistry.ScheduleReleaseServer, threading agraceduration throughServerHandler's constructor. Production wires30*time.Secondper protocol spec § Authentication → Binary → relay. After this change, a binary that disconnects (clean close, network error, ping timeout) holds its server-id slot for the grace window; a reconnect within that window lands back in the same slot atomically (registry-side reclaim from #20).The
wsconn.Close()andserver_releasedlog line are unchanged. Thedeferregistration position is unchanged (still after the successfulClaimServer, perdocs/lessons.md:21-23).Issue
Closes #21. Spec:
docs/specs/architecture/21-defer-binary-release-grace-window.md. Builds on #20 (Registry.ScheduleReleaseServer).Testing
startServertest helper now takesgrace time.Duration; all existing call sites pass100*time.Millisecond(none of them rely on the disconnect timing).TestServerEndpoint_PeerClose_ReleasesSlotcontinues to pass — the existing 2-second wait window comfortably covers the 100 ms grace.TestServerEndpoint_PeerClose_SchedulesGraceRelease(grace = 200 ms): asserts the binary entry persists forgrace/4after the peer close (proves scheduled, not immediate) and is gone within2*grace + 500 ms(proves the timer fires). Inspects registry state directly viaBinaryFor, sinceScheduleReleaseServerexposes no return value.go test -race ./...andgo vet ./...clean.Architecture compliance
grace: trusted from the wiring site (compile-time literal inmain.go); the registry tolerates degenerate values safely (relay: registry — schedule deferred binary release with grace-period reclaim #20 contract).connIDgeneration, or theCloseReadhold-open block.Schedule → Close → Logmirrors the oldRelease → Close → Logorder.🤖 Generated with Claude Code