console: the link status reads the request before the link
With the save now clearing the request, the status handler's old order (the link, then the request) could answer "not linked, no request" in the middle of a save, which the CLI's wait reports as a lost request. It now reads the request first, then the link, and drops the request from a linked answer. A request found gone means the link is already saved.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+14
−6
internal/console/homelink.go+14 −6
CI passed — run details
diff --git a/internal/console/homelink.go b/internal/console/homelink.go| index 5f1edd721..504201e7c 100644 |
| --- a/internal/console/homelink.go |
| +++ b/internal/console/homelink.go |
| @@ -423,12 +423,11 @@ func (s *Server) handleAPIHomeLinkStatus(w http.ResponseWriter, r *http.Request) |
| if !ok { |
| return |
| } |
| - l, err := reg.HomeLink() |
| - if err != nil { |
| - log.Printf("console: home link: read: %v", err) |
| - jsonError(w, http.StatusServiceUnavailable, copyHomeLinkReadFailed) |
| - return |
| - } |
| + // The request is read before the link. homeLinkSave saves the link, |
| + // then clears the request: read in this order, a request found gone |
| + // means the link is already saved, so the answer is never "not linked, |
| + // no request" in the middle of a save (the CLI's wait would call that |
| + // lost), and a linked answer carries no request. |
| out := homeLinkWire{Apps: []homeLinkAppWire{}} |
| s.homeLink.mu.Lock() |
| start := s.homeLink.start |
| @@ -439,6 +438,15 @@ func (s *Server) handleAPIHomeLinkStatus(w http.ResponseWriter, r *http.Request) |
| } |
| } |
| s.homeLink.mu.Unlock() |
| + l, err := reg.HomeLink() |
| + if err != nil { |
| + log.Printf("console: home link: read: %v", err) |
| + jsonError(w, http.StatusServiceUnavailable, copyHomeLinkReadFailed) |
| + return |
| + } |
| + if l != nil { |
| + out.Start = nil |
| + } |
| if l == nil { |
| writeJSON(w, http.StatusOK, out) |
| return |