carlos / platform Public

console: a saved home link clears its start request in the same step

GET /api/cli/link could answer linked:true together with a pending
start. The background poll saved the link (homeLinkSave), and only after
homeLinkPoll returned did its goroutine clear s.homeLink.start.
TestHomeStartPollStores read that gap under load on CI (#897). The CLI
was unaffected: it checks linked before start.

homeLinkSave now clears the start, if it is still this request, right
after PutHomeLink and under ops, as the save. The poll's own clear then
finds nothing. Lock order is ops then mu, as on every other path;
nothing takes ops while holding mu.

Witness: with a 300 ms delay before the poll's clear, the test failed
with the CI output on every run before this change and passes after.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 76fd1c8035e829484c393e32aacb13a228f40549 parent 9b79292
1 file changed, +9 −0
  • internal/console/homelink.go +9 −0

CI cancelled — superseded by a newer push — run details

diff --git a/internal/console/homelink.go b/internal/console/homelink.go
index 3d00baf1a..5f1edd721 100644
--- a/internal/console/homelink.go
+++ b/internal/console/homelink.go
@@ -353,6 +353,15 @@ func (s *Server) homeLinkSave(seq uint64, base string, ans *linkPollAnswer) stri
log.Printf("console: home link %s: save: %v", ans.LinkID, err)
return copyHomeLinkSaveFailed
}
+ // The request is over the moment the link is saved: clear it here,
+ // under ops as the save, so GET /api/cli/link never answers linked
+ // together with a pending start (#897). The poll's own clear after it
+ // returns then finds nothing. Lock order: ops, then mu, as everywhere.
+ s.homeLink.mu.Lock()
+ if cur := s.homeLink.start; cur != nil && cur.seq == seq {
+ s.homeLink.start = nil
+ }
+ s.homeLink.mu.Unlock()
log.Printf("console: home link %s: linked to %s on %s", ans.LinkID, ans.Account, base)
return ""
}