fix(daemon): sync workspaces from API before failing on empty runtime list

When the CLI config has no watched workspaces (e.g. fresh desktop app
install), loadWatchedWorkspaces returns successfully but registers zero
runtimes. The runtime check immediately after fails with "no runtimes
registered" before workspaceSyncLoop gets a chance to discover
workspaces from the API.

Run one sync cycle inline when the watched list is empty so the daemon
can bootstrap itself without a pre-configured workspace list.
This commit is contained in:
Jiang Bohan
2026-04-14 19:52:16 +08:00
parent cbb2cf0c6c
commit eaefd1927a

View File

@@ -86,6 +86,17 @@ func (d *Daemon) Run(ctx context.Context) error {
return err
}
// If no runtimes yet (empty watched list), run one sync cycle to discover
// workspaces from the API before giving up. workspaceSyncLoop normally
// handles this, but the runtime check below would fail before it runs.
if len(d.allRuntimeIDs()) == 0 {
d.syncWorkspacesFromAPI(ctx)
// syncWorkspacesFromAPI writes to config; reload and register.
if err := d.loadWatchedWorkspaces(ctx); err != nil {
return err
}
}
runtimeIDs := d.allRuntimeIDs()
if len(runtimeIDs) == 0 {
return fmt.Errorf("no runtimes registered")