From c312e7186441d8aa9c33cd62cbd578b8be38cf3a Mon Sep 17 00:00:00 2001 From: Young Joon Lee Date: Tue, 10 Nov 2026 04:28:19 +0900 Subject: [PATCH 1/4] fix(sync): reload the scheduler unit on resume `dot sync resume` rewrote a unit installed before #394 to `--store`, but neither service manager reads a rewritten unit file until it is told to. launchd keeps running the command line it cached when `load` finds the job already loaded (which a failing job usually is), and systemd keeps the ExecStart it read until `daemon-reload`. So the migration alone healed nothing, and the `pause && resume` recovery hint that `dot sync status` prints for a spawn-failed job did not work on either platform. ResumeKind now unloads the plist before loading it on macOS, ignoring the unload error the way InstallKind does, and runs a user-scoped `daemon-reload` before starting the timer on Linux. The lifecycle test helper pins the two-step resume, so a resume that skips the reload fails the tests that record service-manager argv. `dot sync target` no longer says a local target is recorded in the global user state for future workspaces: since #409 the target is written only to this workspace's store, and a workspace without one uses the detected cloud folder. Part of #394. --- docs/commands/dot_sync_target.md | 5 ++-- internal/cli/sync_target_cmd.go | 5 ++-- internal/syncer/scheduler_darwin.go | 7 +++++ internal/syncer/scheduler_other.go | 9 +++++- .../syncer/sync_scheduler_lifecycle_test.go | 30 ++++++++++++------- 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/docs/commands/dot_sync_target.md b/docs/commands/dot_sync_target.md index 6fc2e0a5..80e8499a 100644 --- a/docs/commands/dot_sync_target.md +++ b/docs/commands/dot_sync_target.md @@ -14,8 +14,9 @@ Accepted forms: ssh:user@host:~/work rsync over SSH ~/Dropbox/work bare path — shorthand for local: -Local targets are also recorded in the global user state so future -workspaces inherit them. +The target belongs to this workspace: it is written only to that store's +config.yaml, and another workspace keeps its own. A workspace with no +target of its own syncs to the detected cloud folder. ``` dot sync target [spec] [flags] diff --git a/internal/cli/sync_target_cmd.go b/internal/cli/sync_target_cmd.go index e178a4ff..6adcc870 100644 --- a/internal/cli/sync_target_cmd.go +++ b/internal/cli/sync_target_cmd.go @@ -31,8 +31,9 @@ Accepted forms: ssh:user@host:~/work rsync over SSH ~/Dropbox/work bare path — shorthand for local: -Local targets are also recorded in the global user state so future -workspaces inherit them.`, +The target belongs to this workspace: it is written only to that store's +config.yaml, and another workspace keeps its own. A workspace with no +target of its own syncs to the detected cloud folder.`, Args: cobra.MaximumNArgs(1), RunE: runSyncTarget, SilenceUsage: true, diff --git a/internal/syncer/scheduler_darwin.go b/internal/syncer/scheduler_darwin.go index 0ea44761..b5807eda 100644 --- a/internal/syncer/scheduler_darwin.go +++ b/internal/syncer/scheduler_darwin.go @@ -90,6 +90,12 @@ func (s *Scheduler) PauseKind(ctx context.Context, kind SchedulerKind) error { } // ResumeKind re-loads the launchd job from its persisted plist. +// +// The unload comes first because `load` leaves a job launchd already holds +// running the command line it cached: a plist rewritten on disk (the store +// flag migration) or a job stuck in spawn failed would stay broken otherwise. +// A job that is not loaded makes the unload fail, which is ignored the same +// way InstallKind ignores it. func (s *Scheduler) ResumeKind(ctx context.Context, kind SchedulerKind) error { if err := validateSchedulerMutationHome(s.Config.Home); err != nil { return err @@ -101,6 +107,7 @@ func (s *Scheduler) ResumeKind(ctx context.Context, kind SchedulerKind) error { if s.requiresTargetUserServiceDomain() { return &SchedulerTargetUserActionRequiredError{} } + _, _ = s.Runner.Run(ctx, "launchctl", "unload", plist) _, err := s.Runner.Run(ctx, "launchctl", "load", plist) return err } diff --git a/internal/syncer/scheduler_other.go b/internal/syncer/scheduler_other.go index ade0e1c6..843035a6 100644 --- a/internal/syncer/scheduler_other.go +++ b/internal/syncer/scheduler_other.go @@ -105,7 +105,11 @@ func (s *Scheduler) PauseKind(ctx context.Context, kind SchedulerKind) error { return err } -// ResumeKind starts the timer for the kind. +// ResumeKind reloads the units and starts the timer for the kind. +// +// daemon-reload runs first because systemd keeps the ExecStart it read until +// it is told to reload: a service unit rewritten on disk would otherwise start +// with the old command line. func (s *Scheduler) ResumeKind(ctx context.Context, kind SchedulerKind) error { if err := validateSchedulerMutationHome(s.Config.Home); err != nil { return err @@ -117,6 +121,9 @@ func (s *Scheduler) ResumeKind(ctx context.Context, kind SchedulerKind) error { if s.requiresTargetUserServiceDomain() { return &SchedulerTargetUserActionRequiredError{} } + if _, err := s.Runner.Run(ctx, "systemctl", "--user", "daemon-reload"); err != nil { + return fmt.Errorf("daemon-reload: %w", err) + } _, err := s.Runner.Run(ctx, "systemctl", "--user", "start", filepath.Base(timer)) return err } diff --git a/internal/syncer/sync_scheduler_lifecycle_test.go b/internal/syncer/sync_scheduler_lifecycle_test.go index d6a58268..20cbb43d 100644 --- a/internal/syncer/sync_scheduler_lifecycle_test.go +++ b/internal/syncer/sync_scheduler_lifecycle_test.go @@ -173,7 +173,7 @@ func schedulerLifecycleCommands(paths *Paths, push, intake bool, operation strin if !item.installed { continue } - commands = append(commands, schedulerLifecycleCommand(paths, item.kind, operation)) + commands = append(commands, schedulerLifecycleCommand(paths, item.kind, operation)...) if failFirst { break } @@ -188,13 +188,24 @@ func schedulerStateCommand(paths *Paths, kind SchedulerKind) string { return "--user is-active " + filepath.Base(paths.SystemdTimerFor(kind)) } -func schedulerLifecycleCommand(paths *Paths, kind SchedulerKind, operation string) string { +// schedulerLifecycleCommand is the argv a pause or resume makes for the kind. +// Resume is two commands on both platforms because starting a unit the +// service manager already holds is not enough to make it read the unit file +// again: launchd needs the unload, systemd needs the daemon-reload. +func schedulerLifecycleCommand(paths *Paths, kind SchedulerKind, operation string) []string { + reload := operation == "resume" if runtime.GOOS == "darwin" { - command := map[string]string{"pause": "unload", "resume": "load"}[operation] - return command + " " + paths.PlistFor(kind) + plist := paths.PlistFor(kind) + if reload { + return []string{"unload " + plist, "load " + plist} + } + return []string{"unload " + plist} + } + timer := filepath.Base(paths.SystemdTimerFor(kind)) + if reload { + return []string{"--user daemon-reload", "--user start " + timer} } - command := map[string]string{"pause": "stop", "resume": "start"}[operation] - return "--user " + command + " " + filepath.Base(paths.SystemdTimerFor(kind)) + return []string{"--user stop " + timer} } func readSchedulerLifecycleCommands(t *testing.T, record string) []string { @@ -304,12 +315,9 @@ func TestSyncResumeMigratesAUnitInstalledWithTheRetiredStoreFlag(t *testing.T) { t.Fatalf("%s still runs the retired flag:\n%s", unit, body) } // The migration itself talks to no service manager: the only calls are the - // state query and the reload the resume already made. + // state query and the reload that makes the rewritten unit take effect. got := readSchedulerLifecycleCommands(t, record) - want := []string{ - schedulerStateCommand(paths, SchedulerKindPush), - schedulerLifecycleCommand(paths, SchedulerKindPush, "resume"), - } + want := append([]string{schedulerStateCommand(paths, SchedulerKindPush)}, schedulerLifecycleCommand(paths, SchedulerKindPush, "resume")...) if strings.Join(got, "\n") != strings.Join(want, "\n") { t.Fatalf("service-manager argv = %q, want %q", got, want) } From b4ed0dec658636c32e32ff9c53d7437d1362ac76 Mon Sep 17 00:00:00 2001 From: Young Joon Lee Date: Tue, 10 Nov 2026 15:27:28 +0900 Subject: [PATCH 2/4] test(sync): expect only the command that fails in a failed resume The lifecycle row that injects a failure asserted every resume command for the kind. On Linux that is wrong: a failed `daemon-reload` returns before the timer is started, so `start` never runs. macOS differs only because launchd's unload error is ignored, which puts the failure on the load. The expectation now stops at the failing command on the platforms whose resume returns there, which is what the two implementations do. Product code is unchanged; the row is the only thing that was wrong, and only the ubuntu unit job can execute it. --- internal/syncer/sync_scheduler_lifecycle_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/syncer/sync_scheduler_lifecycle_test.go b/internal/syncer/sync_scheduler_lifecycle_test.go index 20cbb43d..a28345b9 100644 --- a/internal/syncer/sync_scheduler_lifecycle_test.go +++ b/internal/syncer/sync_scheduler_lifecycle_test.go @@ -173,7 +173,14 @@ func schedulerLifecycleCommands(paths *Paths, push, intake bool, operation strin if !item.installed { continue } - commands = append(commands, schedulerLifecycleCommand(paths, item.kind, operation)...) + cmds := schedulerLifecycleCommand(paths, item.kind, operation) + if failFirst && runtime.GOOS != "darwin" { + // The failing command is the last one that ran: launchd ignores + // the unload error and the load then fails, while a failed + // daemon-reload returns before the timer is started. + cmds = cmds[:1] + } + commands = append(commands, cmds...) if failFirst { break } From 40db9c9f458868dff01760809b14c4e3f7fee75c Mon Sep 17 00:00:00 2001 From: Young Joon Lee Date: Tue, 10 Nov 2026 16:27:45 +0900 Subject: [PATCH 3/4] test(sync): count daemon-reload as a lifecycle action The installed-kind check treats a row that recorded no lifecycle action as a vacuous fixture. The Linux resume row under an injected failure records `--user daemon-reload` alone, which the counter did not recognise, so the comparison passed and the row still failed on the counter (ubuntu unit CI). The prefix is now counted, and a small table test pins the counter on both platforms so this Mac notices an unrecognised command next time instead of the ubuntu job. --- .../syncer/sync_scheduler_lifecycle_test.go | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/internal/syncer/sync_scheduler_lifecycle_test.go b/internal/syncer/sync_scheduler_lifecycle_test.go index a28345b9..b2a6c65c 100644 --- a/internal/syncer/sync_scheduler_lifecycle_test.go +++ b/internal/syncer/sync_scheduler_lifecycle_test.go @@ -240,13 +240,40 @@ func schedulerStateQueryCount(commands []string) int { func schedulerLifecycleActionCount(commands []string) int { count := 0 for _, command := range commands { - if strings.HasPrefix(command, "unload ") || strings.HasPrefix(command, "load ") || strings.HasPrefix(command, "--user stop ") || strings.HasPrefix(command, "--user start ") { + if strings.HasPrefix(command, "unload ") || strings.HasPrefix(command, "load ") || strings.HasPrefix(command, "--user stop ") || strings.HasPrefix(command, "--user start ") || strings.HasPrefix(command, "--user daemon-reload") { count++ } } return count } +// schedulerLifecycleActionCount is what keeps the installed-kind check from +// passing vacuously, and a command it does not recognise drops out silently: +// the Linux resume row runs `daemon-reload` alone under an injected failure, +// which read as "made no lifecycle action". Pinned here so this platform +// notices a missing prefix instead of the ubuntu unit job. +func TestSchedulerLifecycleActionCount(t *testing.T) { + for _, command := range []string{ + "unload /tmp/com.dotfiles.sync.plist", + "load /tmp/com.dotfiles.sync.plist", + "--user stop dotfiles-sync.timer", + "--user start dotfiles-sync.timer", + "--user daemon-reload", + } { + if got := schedulerLifecycleActionCount([]string{command}); got != 1 { + t.Errorf("schedulerLifecycleActionCount(%q) = %d, want 1", command, got) + } + } + for _, command := range []string{ + "print gui/501/com.dotfiles.sync", + "--user is-active dotfiles-sync.timer", + } { + if got := schedulerLifecycleActionCount([]string{command}); got != 0 { + t.Errorf("schedulerLifecycleActionCount(%q) = %d, want 0: a state query is not an action", command, got) + } + } +} + // `dot sync resume` is the command that re-arms installed units, so it is where // a unit installed before #394 gets its retired `--profile=` rewritten: the // service manager reads the command line at load time, so a rewrite without the From 5cf0885b06d9750b9561a0e0a532a6aa21eac0c4 Mon Sep 17 00:00:00 2001 From: Young Joon Lee Date: Tue, 10 Nov 2026 16:37:04 +0900 Subject: [PATCH 4/4] style(sync): spell recognize the US way in a comment The repo's misspell linter runs with locale US, so the comment I added over TestSchedulerLifecycleActionCount failed `make lint` on one word. Comment text only. --- internal/syncer/sync_scheduler_lifecycle_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/syncer/sync_scheduler_lifecycle_test.go b/internal/syncer/sync_scheduler_lifecycle_test.go index b2a6c65c..b0bb7fe8 100644 --- a/internal/syncer/sync_scheduler_lifecycle_test.go +++ b/internal/syncer/sync_scheduler_lifecycle_test.go @@ -248,7 +248,7 @@ func schedulerLifecycleActionCount(commands []string) int { } // schedulerLifecycleActionCount is what keeps the installed-kind check from -// passing vacuously, and a command it does not recognise drops out silently: +// passing vacuously, and a command it does not recognize drops out silently: // the Linux resume row runs `daemon-reload` alone under an injected failure, // which read as "made no lifecycle action". Pinned here so this platform // notices a missing prefix instead of the ubuntu unit job.