schedule: spread every-ticks across the period, per instance
An every-schedule is declared once per app and fanned out to every
instance, and its fire was the epoch-aligned boundary, so every instance
was due in the same second. A tick earns its instance one idle window, so
after each boundary the whole population was resident together: 100
instances on every 1h with a 15m window averaged 27 awake and peaked at
100.
Each instance now fires at its own fixed offset into the period: the
first 8 bytes of sha256(host) modulo the period in seconds. The offset
is in the row's spec text ("every 1h offset 1234s") and Spec.Next adds
it, so the runner's re-arm, HoldsAwake, the idle sweep's guard and a row
carried by a move agree with no second input, and one instance's fires
are exactly one period apart. The schedule name is not hashed: two
schedules with one period share an instance's point, and a 6h fire lands
on one of its 1h fires.
Spread is the default. `carlos schedule set --aligned` (schedules.json
"aligned": true) keeps the boundary; cron and one-shots are never
spread. `carlos schedule ls` marks each every-schedule spread or
aligned. A box that upgrades re-arms each old row at its spread time on
the first converge pass, through the existing changed-spec path.
A hash clumps: 100 hosts over 1h put 33 in the busiest 15 minutes, where
even would be 25. A box that predates the offset grammar cannot parse
the new spec, so upgrade the receiving side of a move first.
Not yet run on a box (100 instances, 15m window).
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
11 files changed,
+669
−33
docs/site/cli.md+20 −0docs/superpowers/specs/2026-08-30-scheduled-ticks-and-hibernation-design.md+50 −0internal/schedule/converge.go+6 −1internal/schedule/converge_test.go+8 −1internal/schedule/declaration.go+31 −1internal/schedule/spread_test.go+291 −0internal/timerspec/spec.go+66 −11internal/timerspec/spread_test.go+141 −0schedule.go+27 −8schedule_test.go+21 −3testdata/clireg-golden.jsonl+8 −8
CI failed — run details
diff --git a/docs/site/cli.md b/docs/site/cli.md| index 0e33fb9f4..e7cbe31d8 100644 |
| --- a/docs/site/cli.md |
| +++ b/docs/site/cli.md |
| @@ -880,6 +880,26 @@ carlos schedule set --app hello --name nightly --every 6h --path /jobs/nightly |
| `--every` takes whole minutes, from `1m` up to `720h`; `--cron` takes a |
| five-field expression instead, and you give one or the other, never both. |
| + |
| +An `--every` schedule is spread. Each instance of the app fires at its own |
| +point in the period, and that point is fixed by the instance's host name: it |
| +is the same after a restart, after a move to another box, and when you |
| +declare the schedule again. One instance's runs are always exactly one period |
| +apart. Across the app the instances land evenly over the whole period, so an |
| +hourly schedule on a hundred instances wakes about one every 36 seconds and |
| +never all hundred at the top of the hour. Your handler does not change. Two |
| +schedules with the same period share an instance's point, and an instance's |
| +6h run falls on one of its 1h runs, so several schedules wake it once. The |
| +spread covers the whole period however long it is: an `--every 24h` schedule |
| +runs once a day on each instance, at any time of day. |
| + |
| +Add `--aligned` to fire every instance together on the period's boundary |
| +(the top of the hour for `1h`, midnight UTC for `24h`), as every schedule did |
| +before spreading. Setting the schedule again without `--aligned` spreads it |
| +again. A `--cron` schedule names a time of day and is never spread; it fires |
| +at that moment on every instance. `carlos schedule ls` marks each `--every` |
| +schedule `spread` or `aligned`, and each instance's `next in` is its own. |
| + |
| `carlos schedule ls` prints the declared schedules alongside what each |
| instance reports it will do next and what it did last. `carlos schedule run |
| --app hello --name nightly` asks for one out-of-band run on top of the normal |
diff --git a/docs/superpowers/specs/2026-08-30-scheduled-ticks-and-hibernation-design.md b/docs/superpowers/specs/2026-08-30-scheduled-ticks-and-hibernation-design.md| index bdd713859..fc8800198 100644 |
| --- a/docs/superpowers/specs/2026-08-30-scheduled-ticks-and-hibernation-design.md |
| +++ b/docs/superpowers/specs/2026-08-30-scheduled-ticks-and-hibernation-design.md |
| @@ -313,3 +313,53 @@ and nowhere else — see §4, this is not a blanket "confirm inert". Two checks: |
| The separate idle-window tightening (15m → 90s) is verified on the *next* |
| branch, against the same apps. |
| + |
| +## 8. Addendum, 2026-11-12: every-schedules are spread per instance |
| + |
| +A declaration is fanned out to every instance of the app, and an `every` |
| +fire was the epoch-aligned boundary, so every instance was due in the same |
| +second. Each tick earns its instance one idle window, so for that window |
| +after each boundary the whole population was resident together. Measured |
| +with 100 instances on `every 1h` and a 15m window: 27 awake on average, |
| +100 at the peak. Hibernation lowered the average and left the peak. |
| + |
| +The change: an `every` row fires at a per-host offset into the period. |
| + |
| +- **The offset.** `timerspec.SpreadOffset(host, every)`: the first 8 bytes |
| + of sha256(host), modulo the period in seconds. It depends on the host |
| + name and the period only, so it survives an agent restart, a move to |
| + another box and declaring the schedule again. The schedule's name is not |
| + an input: two schedules of one instance with the same period share a |
| + phase, and a period that divides another (1h, 6h) fires on one of the |
| + shorter one's ticks, so an instance with several schedules is still |
| + woken once. |
| +- **Where it lives.** In the row's spec text: `every 1h offset 1234s`. |
| + `Spec.Next` is `boundary + offset`, so the runner's re-arm, the duty |
| + advance, `holdsAwake` and a row carried by a move all agree with no |
| + second input, and one row's fires are exactly one period apart. |
| +- **No cap.** The spread covers the whole period at any length. The first |
| + fire after a declaration was already up to one period away. A schedule |
| + that means a time of day is a `cron` line. |
| +- **Default on, `aligned` opts out.** `schedules.json` gains |
| + `"aligned": true` per schedule (`carlos schedule set --aligned`). Absent |
| + means spread, so every existing declaration is spread with no change to |
| + the app or its handler. Nothing in the tree depends on instances being |
| + ticked together. `cron` and one-shots are never spread. |
| +- **Upgrade.** A row written before this carries `every 1h`. The first |
| + converge pass of the new agent (at start) sees a different spec text and |
| + re-arms the row at its spread time, as it does for any changed spec: |
| + new registration, attempts reset. That one interval is between zero and |
| + two periods long. Toggling `aligned` moves rows the same way. |
| +- **§3.2 and §3.3 need nothing.** The idle sweep's guard reads each host's |
| + own `next_at` (`EarliestTimers`), and `HoldsAwake` compares the gap |
| + between two fires with the idle window; the offset changes neither. |
| + |
| +A hash is not a comb: 100 hosts over an hour put about 33 in the busiest |
| +15 minutes, where an even comb would put 25. |
| + |
| +A box that predates the offset grammar cannot parse `every 1h offset |
| +1234s`. If it is handed such a row (a move or an HA wake state from a |
| +newer box) its runner drops the row as a bad spec and its own converger |
| +writes the aligned one back; the wake-state check on such a box |
| +(`internal/registry/ha_departures.go`) refuses the state. Upgrade the |
| +receiving side first. |
diff --git a/internal/schedule/converge.go b/internal/schedule/converge.go| index 5f7f835e4..1f104b081 100644 |
| --- a/internal/schedule/converge.go |
| +++ b/internal/schedule/converge.go |
| @@ -301,7 +301,12 @@ func (c *Converger) convergeHost(ctx context.Context, rt registry.Route, decl De |
| keep := map[string]bool{} |
| changed := false |
| for _, sc := range decl.Schedules { |
| - sp, err := sc.Spec() |
| + // SpecFor, not Spec: a spread every-schedule's row carries this |
| + // host's offset in its spec text. A row written before spread, or |
| + // while the schedule was aligned, has a different text, so the |
| + // comparison below re-arms it at the spread time on this pass. That |
| + // is the whole upgrade path, and the way back too. |
| + sp, err := sc.SpecFor(rt.Host) |
| if err != nil { |
| log.Printf("schedule: %s: schedule %q has an invalid spec (%v) — skipped", rt.Host, sc.Name, err) |
| continue |
diff --git a/internal/schedule/converge_test.go b/internal/schedule/converge_test.go| index 3fc2f4153..8ae320616 100644 |
| --- a/internal/schedule/converge_test.go |
| +++ b/internal/schedule/converge_test.go |
| @@ -9,6 +9,7 @@ import ( |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| + "github.com/carlosframework/platform/internal/timerspec" |
| ) |
| func TestHoldsAwakeWhenTheIntervalIsInsideTheIdleWindow(t *testing.T) { |
| @@ -104,7 +105,13 @@ func TestConvergeMaterialisesDeclarationPerExecInstance(t *testing.T) { |
| if err != nil { |
| t.Fatalf("%s: %v", h, err) |
| } |
| - if tm.Kind != KindSchedule || tm.Spec != "every 6h" || tm.Path != "/jobs/sync" || tm.NextAt != at("2026-08-23T18:00:00Z").Unix() { |
| + // Spread: the row carries this host's own offset into the 6h, and |
| + // its first fire is that point, within one period of now. |
| + sp, err := ParseSpec(tm.Spec) |
| + if err != nil { |
| + t.Fatalf("%s: %v", h, err) |
| + } |
| + if tm.Kind != KindSchedule || sp.Every != 6*time.Hour || sp.Offset != timerspec.SpreadOffset(h, 6*time.Hour) || tm.Path != "/jobs/sync" || tm.NextAt != sp.Next(now).Unix() { |
| t.Fatalf("%s: %+v", h, tm) |
| } |
| } |
diff --git a/internal/schedule/declaration.go b/internal/schedule/declaration.go| index b6023f840..ae735d3fa 100644 |
| --- a/internal/schedule/declaration.go |
| +++ b/internal/schedule/declaration.go |
| @@ -22,6 +22,7 @@ import ( |
| "time" |
| "github.com/carlosframework/platform/internal/release" |
| + "github.com/carlosframework/platform/internal/timerspec" |
| ) |
| const MaxSchedulesPerApp = 20 |
| @@ -69,11 +70,40 @@ type Schedule struct { |
| Every string `json:"every,omitempty"` |
| Cron string `json:"cron,omitempty"` |
| Path string `json:"path"` |
| + // Aligned keeps an every-schedule on the period's epoch-aligned |
| + // boundary on every instance at once. Absent, which is every |
| + // declaration written before the field existed, each instance fires at |
| + // its own offset into the period (SpecFor). Spread is the default |
| + // because a declaration is fanned out to every instance of the app and |
| + // a tick earns each one an idle window: aligned, a box has to hold all |
| + // of them awake together after each boundary. Not valid with cron, |
| + // which names a wall-clock moment and is never spread. |
| + Aligned bool `json:"aligned,omitempty"` |
| } |
| -// Spec is the schedule as the box stores it. Exactly one of every/cron. |
| +// Spread reports whether the schedule's instances fire at their own offsets |
| +// into the period, not together: an every-schedule not declared aligned. |
| +func (s Schedule) Spread() bool { return s.Every != "" && !s.Aligned } |
| + |
| +// SpecFor is the schedule as host's timers row stores it: Spec, with the |
| +// host's own offset into the period when the schedule is spread. |
| +func (s Schedule) SpecFor(host string) (Spec, error) { |
| + sp, err := s.Spec() |
| + if err != nil { |
| + return Spec{}, err |
| + } |
| + if s.Spread() { |
| + sp.Offset = timerspec.SpreadOffset(host, sp.Every) |
| + } |
| + return sp, nil |
| +} |
| + |
| +// Spec is the schedule as declared, with no instance's offset. Exactly one |
| +// of every/cron. |
| func (s Schedule) Spec() (Spec, error) { |
| switch { |
| + case s.Aligned && s.Cron != "": |
| + return Spec{}, errors.New("--aligned goes with --every: a cron schedule already fires at the same moment on every instance") |
| case s.Every != "" && s.Cron != "": |
| return Spec{}, errors.New("give --every or --cron, not both") |
| case s.Every != "": |
diff --git a/internal/schedule/spread_test.go b/internal/schedule/spread_test.go| new file mode 100644 |
| index 000000000..a56d1e57d |
| --- /dev/null |
| +++ b/internal/schedule/spread_test.go |
| @@ -0,0 +1,291 @@ |
| +package schedule |
| + |
| +import ( |
| + "context" |
| + "fmt" |
| + "path/filepath" |
| + "sort" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// spreadFixture is n hibernating instances of bab/app on one box. |
| +func spreadFixture(t *testing.T, n int) (*registry.Registry, *release.DirStore, []string) { |
| + t.Helper() |
| + reg, err := registry.Open(filepath.Join(t.TempDir(), "r.db")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { reg.Close() }) |
| + var hosts []string |
| + for i := 0; i < n; i++ { |
| + host := fmt.Sprintf("t%03d.bab.oncarlos.com", i) |
| + hosts = append(hosts, host) |
| + if err := reg.Upsert(registry.Route{Host: host, Kind: "instance", Account: "bab", App: "app", Status: "ready", Hibernate: true}); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + return reg, release.NewDirStore(t.TempDir()), hosts |
| +} |
| + |
| +func convergeAt(t *testing.T, reg *registry.Registry, st release.Store, now time.Time) { |
| + t.Helper() |
| + c := NewConverger(reg, st, "box1", nil) |
| + c.Now = func() time.Time { return now } |
| + if err := c.Pass(context.Background()); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +func nextAts(t *testing.T, reg *registry.Registry, hosts []string, name string) map[string]registry.Timer { |
| + t.Helper() |
| + rows := map[string]registry.Timer{} |
| + for _, h := range hosts { |
| + tm, err := reg.GetTimer(h, name) |
| + if err != nil { |
| + t.Fatalf("%s/%s: %v", h, name, err) |
| + } |
| + rows[h] = *tm |
| + } |
| + return rows |
| +} |
| + |
| +// The headline: one every-schedule fanned out to N instances gives N fire |
| +// times spread over the period, the same ones after a restart, and each |
| +// instance's next fire exactly one period after its own last. |
| +func TestEveryScheduleIsSpreadAcrossItsInstances(t *testing.T) { |
| + const n = 100 |
| + reg, st, hosts := spreadFixture(t, n) |
| + ctx := context.Background() |
| + now := at("2026-08-23T13:07:00Z") |
| + if _, err := UpsertSchedule(ctx, st, "bab", "app", Schedule{Name: "sweep", Every: "1h", Path: "/jobs/sweep"}, now); err != nil { |
| + t.Fatal(err) |
| + } |
| + convergeAt(t, reg, st, now) |
| + |
| + first := nextAts(t, reg, hosts, "sweep") |
| + var times []int64 |
| + distinct := map[int64]bool{} |
| + for h, tm := range first { |
| + if tm.NextAt <= now.Unix() || tm.NextAt > now.Add(time.Hour).Unix() { |
| + t.Fatalf("%s: next_at %d is not within one period of now", h, tm.NextAt) |
| + } |
| + if tm.DueAt != tm.NextAt { |
| + t.Fatalf("%s: due_at %d, next_at %d", h, tm.DueAt, tm.NextAt) |
| + } |
| + if !strings.HasPrefix(tm.Spec, "every 1h offset ") { |
| + t.Fatalf("%s: spec %q carries no offset", h, tm.Spec) |
| + } |
| + times = append(times, tm.NextAt) |
| + distinct[tm.NextAt] = true |
| + } |
| + if len(distinct) < n*9/10 { |
| + t.Fatalf("%d distinct fire times for %d hosts", len(distinct), n) |
| + } |
| + // Spread: no 15 minutes of the hour holds more than two fifths of them |
| + // (even is a quarter; stacked on the boundary, as before, is all). |
| + sort.Slice(times, func(i, j int) bool { return times[i] < times[j] }) |
| + peak := 0 |
| + for i := range times { |
| + in := 0 |
| + for j := range times { |
| + d := (times[j] - times[i] + 2*3600) % 3600 |
| + if d < 900 { |
| + in++ |
| + } |
| + } |
| + peak = max(peak, in) |
| + } |
| + if peak > n*2/5 { |
| + t.Fatalf("%d of %d instances fire inside one 15m window", peak, n) |
| + } |
| + t.Logf("%d instances on every 1h: at most %d fire inside any 15m", n, peak) |
| + |
| + // A restart: a new converger with no memory, later in the hour and |
| + // before anything fired. Not one row moves or is re-registered. |
| + convergeAt(t, reg, st, now.Add(30*time.Second)) |
| + for h, tm := range nextAts(t, reg, hosts, "sweep") { |
| + if tm.NextAt != first[h].NextAt || tm.Spec != first[h].Spec || tm.Registration != first[h].Registration { |
| + t.Fatalf("%s: restart moved the row: %+v, was %+v", h, tm, first[h]) |
| + } |
| + } |
| + // Declaring the same schedule again changes nothing either. |
| + if _, err := UpsertSchedule(ctx, st, "bab", "app", Schedule{Name: "sweep", Every: "60m", Path: "/jobs/sweep"}, now); err != nil { |
| + t.Fatal(err) |
| + } |
| + convergeAt(t, reg, st, now.Add(40*time.Second)) |
| + for h, tm := range nextAts(t, reg, hosts, "sweep") { |
| + if tm.NextAt != first[h].NextAt || tm.Registration != first[h].Registration { |
| + t.Fatalf("%s: re-declaring moved the row: %+v, was %+v", h, tm, first[h]) |
| + } |
| + } |
| + |
| + // Fire them all through the runner, with the clock on the last one's |
| + // time: every row's next is its own last plus the period, exactly. |
| + d := &fakeDeliverer{status: 204} |
| + clock := &testClock{t: time.Unix(times[len(times)-1], 0)} |
| + r := &Runner{Reg: reg, Deliver: d, Timeout: time.Minute, Box: "box1", Build: "test", Now: clock.now, |
| + Token: func(string) (string, error) { return "tok", nil }} |
| + for i := 0; i < 10 && len(d.firedHosts()) < n; i++ { |
| + r.tick() |
| + } |
| + if got := d.firedHosts(); len(got) != n { |
| + t.Fatalf("delivered to %d hosts, want %d", len(got), n) |
| + } |
| + for h, tm := range nextAts(t, reg, hosts, "sweep") { |
| + if tm.NextAt-first[h].NextAt != 3600 { |
| + t.Fatalf("%s: next fire %ds after its last, want 3600", h, tm.NextAt-first[h].NextAt) |
| + } |
| + if tm.LastStatus != "204" || tm.Attempts != 0 { |
| + t.Fatalf("%s: %+v", h, tm) |
| + } |
| + } |
| + // And a restart after the fires leaves those where they are too. |
| + afterFire := nextAts(t, reg, hosts, "sweep") |
| + convergeAt(t, reg, st, clock.now().Add(time.Minute)) |
| + for h, tm := range nextAts(t, reg, hosts, "sweep") { |
| + if tm.NextAt != afterFire[h].NextAt { |
| + t.Fatalf("%s: restart after a fire moved next_at %d → %d", h, afterFire[h].NextAt, tm.NextAt) |
| + } |
| + } |
| +} |
| + |
| +// A cron schedule names a wall-clock moment and a one-shot names an |
| +// instant: neither is spread. An every-schedule declared aligned is not |
| +// either. |
| +func TestCronOnceAndAlignedAreNotSpread(t *testing.T) { |
| + reg, st, hosts := spreadFixture(t, 20) |
| + ctx := context.Background() |
| + now := at("2026-08-23T13:07:00Z") |
| + for _, sc := range []Schedule{ |
| + {Name: "morning", Cron: "0 9 * * *", Path: "/jobs/morning"}, |
| + {Name: "together", Every: "1h", Aligned: true, Path: "/jobs/together"}, |
| + } { |
| + if _, err := UpsertSchedule(ctx, st, "bab", "app", sc, now); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + // The instance's own one-shot (ScheduleAt, off its control socket). |
| + wake := at("2026-08-23T13:30:00Z") |
| + onceSpec := Spec{Kind: KindOnce, At: wake} |
| + for _, h := range hosts { |
| + if err := reg.UpsertTimer(registry.Timer{Host: h, Name: "wake", Kind: KindOnce, Spec: onceSpec.String(), Path: "/wake", NextAt: wake.Unix(), DueAt: wake.Unix(), CreatedAt: now.Unix()}); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + convergeAt(t, reg, st, now) |
| + |
| + for h, tm := range nextAts(t, reg, hosts, "morning") { |
| + if tm.Spec != "cron 0 9 * * *" || tm.NextAt != at("2026-08-24T09:00:00Z").Unix() { |
| + t.Fatalf("%s: cron row %+v", h, tm) |
| + } |
| + } |
| + for h, tm := range nextAts(t, reg, hosts, "together") { |
| + if tm.Spec != "every 1h" || tm.NextAt != at("2026-08-23T14:00:00Z").Unix() { |
| + t.Fatalf("%s: aligned row %+v", h, tm) |
| + } |
| + } |
| + for h, tm := range nextAts(t, reg, hosts, "wake") { |
| + if tm.Spec != onceSpec.String() || tm.NextAt != wake.Unix() || tm.DueAt != wake.Unix() { |
| + t.Fatalf("%s: once row %+v", h, tm) |
| + } |
| + sp, err := ParseSpec(tm.Spec) |
| + if err != nil || !sp.Next(now).Equal(wake) { |
| + t.Fatalf("%s: once Next = %v, %v", h, sp.Next(now), err) |
| + } |
| + } |
| + |
| + // --aligned is refused where it means nothing. |
| + if err := (Schedule{Name: "x", Cron: "0 9 * * *", Aligned: true, Path: "/p"}).Validate(); err == nil { |
| + t.Fatal("aligned cron accepted") |
| + } |
| +} |
| + |
| +// A box that upgrades holds rows on the old boundary. The first converge |
| +// pass re-arms each at its spread time; declaring the schedule aligned |
| +// puts them back together, and dropping the flag spreads them again at the |
| +// same points. |
| +func TestConvergeMovesBoundaryRowsToTheirSpreadTimesAndBack(t *testing.T) { |
| + reg, st, hosts := spreadFixture(t, 10) |
| + ctx := context.Background() |
| + now := at("2026-08-23T13:07:00Z") |
| + boundary := at("2026-08-23T14:00:00Z").Unix() |
| + for _, h := range hosts { |
| + if err := reg.UpsertTimer(registry.Timer{Host: h, Name: "sweep", Kind: KindSchedule, Spec: "every 1h", Path: "/jobs/sweep", NextAt: boundary, DueAt: boundary, CreatedAt: now.Unix()}); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + UpsertSchedule(ctx, st, "bab", "app", Schedule{Name: "sweep", Every: "1h", Path: "/jobs/sweep"}, now) |
| + convergeAt(t, reg, st, now) |
| + spread := nextAts(t, reg, hosts, "sweep") |
| + for h, tm := range spread { |
| + sp, err := Schedule{Name: "sweep", Every: "1h", Path: "/jobs/sweep"}.SpecFor(h) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if tm.Spec != sp.String() || tm.NextAt != sp.Next(now).Unix() || tm.NextAt > boundary+3600-1 { |
| + t.Fatalf("%s: row %+v, want spec %q next %d", h, tm, sp.String(), sp.Next(now).Unix()) |
| + } |
| + } |
| + |
| + UpsertSchedule(ctx, st, "bab", "app", Schedule{Name: "sweep", Every: "1h", Aligned: true, Path: "/jobs/sweep"}, now) |
| + convergeAt(t, reg, st, now) |
| + for h, tm := range nextAts(t, reg, hosts, "sweep") { |
| + if tm.Spec != "every 1h" || tm.NextAt != boundary { |
| + t.Fatalf("%s: aligned row %+v", h, tm) |
| + } |
| + } |
| + |
| + UpsertSchedule(ctx, st, "bab", "app", Schedule{Name: "sweep", Every: "1h", Path: "/jobs/sweep"}, now) |
| + convergeAt(t, reg, st, now) |
| + for h, tm := range nextAts(t, reg, hosts, "sweep") { |
| + if tm.NextAt != spread[h].NextAt || tm.Spec != spread[h].Spec { |
| + t.Fatalf("%s: spread again at %d, was %d", h, tm.NextAt, spread[h].NextAt) |
| + } |
| + } |
| +} |
| + |
| +// The residency inputs still read true for a spread row: the earliest |
| +// timer per host is its own spread time, and HoldsAwake compares the |
| +// period, not the offset, to the idle window. |
| +func TestSpreadRowsFeedTheResidencyRuleAndHoldsAwake(t *testing.T) { |
| + reg, st, hosts := spreadFixture(t, 5) |
| + ctx := context.Background() |
| + now := at("2026-08-23T13:07:00Z") |
| + UpsertSchedule(ctx, st, "bab", "app", Schedule{Name: "sweep", Every: "1h", Path: "/jobs/sweep"}, now) |
| + UpsertSchedule(ctx, st, "bab", "app", Schedule{Name: "tight", Every: "5m", Path: "/jobs/tight"}, now) |
| + convergeAt(t, reg, st, now) |
| + earliest, err := reg.EarliestTimers() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, h := range hosts { |
| + rows, _ := reg.TimersFor(h) |
| + want := int64(0) |
| + for _, r := range rows { |
| + if want == 0 || r.NextAt < want { |
| + want = r.NextAt |
| + } |
| + } |
| + if earliest[h] != want { |
| + t.Fatalf("%s: EarliestTimers %d, want %d", h, earliest[h], want) |
| + } |
| + rt, _ := reg.Get(h) |
| + status, err := StatusFor(reg, *rt, "box1", now, 15*time.Minute) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, ts := range status.Timers { |
| + if ts.HoldsAwake != (ts.Name == "tight") { |
| + t.Fatalf("%s/%s: HoldsAwake = %v", h, ts.Name, ts.HoldsAwake) |
| + } |
| + if ts.NextAt <= now.Unix() { |
| + t.Fatalf("%s/%s: next_at %d not in the future", h, ts.Name, ts.NextAt) |
| + } |
| + } |
| + } |
| +} |
diff --git a/internal/timerspec/spec.go b/internal/timerspec/spec.go| index f1635b12e..f82ab0f9f 100644 |
| --- a/internal/timerspec/spec.go |
| +++ b/internal/timerspec/spec.go |
| @@ -1,5 +1,6 @@ |
| // This file is the timers.spec column's grammar: parse the three stored |
| -// shapes ("every <duration>", "cron <5 fields>", "at <unix>"), compute each |
| +// shapes ("every <duration>" with an optional " offset <seconds>s", |
| +// "cron <5 fields>", "at <unix>"), compute each |
| // one's next fire from now (spec §6.1's coalescing — always from now, never |
| // from the scheduled time), and render the canonical text back for |
| // Converge and Runner to store and for `carlos schedule ls` to show. |
| @@ -7,6 +8,8 @@ |
| package timerspec |
| import ( |
| + "crypto/sha256" |
| + "encoding/binary" |
| "errors" |
| "fmt" |
| "strconv" |
| @@ -33,25 +36,69 @@ const ( |
| type Spec struct { |
| Kind string |
| Every time.Duration |
| - Cron *CronExpr |
| - At time.Time |
| + // Offset is an every-row's phase: it fires at Offset past each |
| + // epoch-aligned boundary of Every. Zero is the boundary itself. Whole |
| + // seconds, 0 <= Offset < Every. It lives in the row's own spec text, so |
| + // whoever holds the row (the runner, the activator's residency rule, a |
| + // box the instance moved to) computes the same next fire with no other |
| + // input. Converge is what sets it, from SpreadOffset. |
| + Offset time.Duration |
| + Cron *CronExpr |
| + At time.Time |
| } |
| -// ParseSpec reads the canonical column text: "every <duration>", |
| -// "cron <5 fields>", "at <unix>". String is its inverse. |
| +// SpreadOffset is the phase of host within an every-period: a hash of the |
| +// host name alone, reduced to whole seconds in [0, every). The instances of |
| +// one app land uniformly over the period and not all on its boundary, where |
| +// each would be awake for the same idle window. |
| +// |
| +// A function of the host and the period only, so it is the same after an |
| +// agent restart, on another box, and when the schedule is declared again. |
| +// The schedule's name is left out on purpose: two schedules of one instance |
| +// with the same period share a phase, and because one hash is reduced by |
| +// each period, a period that divides another (1h and 6h) fires on one of |
| +// the shorter one's ticks. An instance with several schedules is woken once |
| +// for them, not once each. |
| +func SpreadOffset(host string, every time.Duration) time.Duration { |
| + e := uint64(every / time.Second) |
| + if e == 0 { |
| + return 0 |
| + } |
| + sum := sha256.Sum256([]byte(host)) |
| + return time.Duration(binary.BigEndian.Uint64(sum[:8])%e) * time.Second |
| +} |
| + |
| +// ParseSpec reads the canonical column text: "every <duration>" or |
| +// "every <duration> offset <seconds>s", "cron <5 fields>", "at <unix>". |
| +// String is its inverse. |
| func ParseSpec(s string) (Spec, error) { |
| kind, rest, _ := strings.Cut(strings.TrimSpace(s), " ") |
| rest = strings.TrimSpace(rest) |
| switch kind { |
| case "every": |
| - d, err := time.ParseDuration(rest) |
| + fields := strings.Fields(rest) |
| + if len(fields) != 1 && (len(fields) != 3 || fields[1] != "offset") { |
| + return Spec{}, fmt.Errorf("every: %q: want <duration> or <duration> offset <seconds>s", rest) |
| + } |
| + d, err := time.ParseDuration(fields[0]) |
| if err != nil { |
| return Spec{}, fmt.Errorf("every: %w", err) |
| } |
| if err := ValidEvery(d); err != nil { |
| return Spec{}, err |
| } |
| - return Spec{Kind: KindSchedule, Every: d}, nil |
| + sp := Spec{Kind: KindSchedule, Every: d} |
| + if len(fields) == 3 { |
| + off, err := time.ParseDuration(fields[2]) |
| + if err != nil { |
| + return Spec{}, fmt.Errorf("every: offset: %w", err) |
| + } |
| + if off < 0 || off >= d || off%time.Second != 0 { |
| + return Spec{}, fmt.Errorf("every: offset %s: want whole seconds from 0 to less than %s", fields[2], shortEvery(d)) |
| + } |
| + sp.Offset = off |
| + } |
| + return sp, nil |
| case "cron": |
| c, err := ParseCron(rest) |
| if err != nil { |
| @@ -83,6 +130,8 @@ func ValidEvery(d time.Duration) error { |
| func (s Spec) String() string { |
| switch { |
| + case s.Every > 0 && s.Offset > 0: |
| + return "every " + shortEvery(s.Every) + " offset " + strconv.FormatInt(int64(s.Offset/time.Second), 10) + "s" |
| case s.Every > 0: |
| return "every " + shortEvery(s.Every) |
| case s.Cron != nil: |
| @@ -112,17 +161,23 @@ func shortEvery(d time.Duration) string { |
| } |
| } |
| -// Next is the first fire strictly after now — epoch-aligned for every, |
| -// minute-stepped for cron, the instant itself for a pending once and the |
| +// Next is the first fire strictly after now — epoch-aligned for every and |
| +// then shifted by the row's Offset, so one row's fires are always exactly |
| +// Every apart, minute-stepped for cron, the instant itself for a pending once and the |
| // zero time for a once that has passed. Always from now, never from the |
| // scheduled time: that is what coalesces a missed run into one (spec §6.1). |
| func (s Spec) Next(now time.Time) time.Time { |
| now = now.UTC() |
| switch { |
| case s.Every > 0: |
| - n := now.Unix() |
| e := int64(s.Every / time.Second) |
| - return time.Unix((n/e+1)*e, 0).UTC() |
| + o := int64(s.Offset / time.Second) |
| + n := now.Unix() - o |
| + k := n / e |
| + if n < 0 && n%e != 0 { |
| + k-- // floor, not truncation, for an instant before the first offset |
| + } |
| + return time.Unix((k+1)*e+o, 0).UTC() |
| case s.Cron != nil: |
| return s.Cron.Next(now) |
| default: |
diff --git a/internal/timerspec/spread_test.go b/internal/timerspec/spread_test.go| new file mode 100644 |
| index 000000000..a2528e25b |
| --- /dev/null |
| +++ b/internal/timerspec/spread_test.go |
| @@ -0,0 +1,141 @@ |
| +package timerspec |
| + |
| +import ( |
| + "fmt" |
| + "sort" |
| + "testing" |
| + "time" |
| +) |
| + |
| +// peakInWindow is the most offsets that fall in any window of the given |
| +// width, the period taken as a circle: what a box sees awake at once when |
| +// each tick earns its instance one idle window. |
| +func peakInWindow(offsets []time.Duration, period, window time.Duration) int { |
| + sorted := append([]time.Duration(nil), offsets...) |
| + sort.Slice(sorted, func(i, j int) bool { return sorted[i] < sorted[j] }) |
| + peak := 0 |
| + for i, start := range sorted { |
| + n := 0 |
| + for j := range sorted { |
| + d := sorted[(i+j)%len(sorted)] - start |
| + if d < 0 { |
| + d += period |
| + } |
| + if d < window { |
| + n++ |
| + } |
| + } |
| + if n > peak { |
| + peak = n |
| + } |
| + } |
| + return peak |
| +} |
| + |
| +func TestSpreadOffsetIsUniformAcrossThePeriod(t *testing.T) { |
| + for _, tc := range []struct { |
| + n int |
| + period time.Duration |
| + format string |
| + }{ |
| + {100, time.Hour, "t%03d.jam.oncarlos.com"}, |
| + {100, time.Hour, "customer-%d.example.com"}, |
| + {100, 5 * time.Minute, "t%03d.jam.oncarlos.com"}, |
| + {1000, 24 * time.Hour, "i%d.bab.oncarlos.com"}, |
| + } { |
| + var offsets []time.Duration |
| + for i := 0; i < tc.n; i++ { |
| + host := fmt.Sprintf(tc.format, i) |
| + off := SpreadOffset(host, tc.period) |
| + if off < 0 || off >= tc.period || off%time.Second != 0 { |
| + t.Fatalf("SpreadOffset(%q, %s) = %s, want whole seconds in [0, period)", host, tc.period, off) |
| + } |
| + if again := SpreadOffset(host, tc.period); again != off { |
| + t.Fatalf("SpreadOffset(%q) = %s then %s", host, off, again) |
| + } |
| + offsets = append(offsets, off) |
| + } |
| + peak := peakInWindow(offsets, tc.period, tc.period/4) |
| + t.Logf("%d hosts %q over %s: peak %d in any quarter of the period", tc.n, tc.format, tc.period, peak) |
| + // Even would be a quarter of them. A hash is not a comb, so allow |
| + // its clumping, and refuse anything near the stacked 100%. |
| + if limit := tc.n * 2 / 5; peak > limit { |
| + t.Errorf("%d hosts %q over %s: %d in one quarter of the period, want at most %d", tc.n, tc.format, tc.period, peak, limit) |
| + } |
| + } |
| +} |
| + |
| +func TestSpreadOffsetNestsDividingPeriods(t *testing.T) { |
| + // One hash reduced by each period: an instance's 6h fire is one of its |
| + // 1h fires, so two schedules wake it once. |
| + for _, host := range []string{"a.bab.oncarlos.com", "t042.jam.oncarlos.com"} { |
| + hour, six := SpreadOffset(host, time.Hour), SpreadOffset(host, 6*time.Hour) |
| + if six%time.Hour != hour { |
| + t.Errorf("%s: 6h offset %s is not on the 1h offset %s", host, six, hour) |
| + } |
| + } |
| +} |
| + |
| +func TestOffsetSpecRoundTripsAndRefusesBadOffsets(t *testing.T) { |
| + for _, s := range []string{"every 1h offset 1234s", "every 5m offset 1s", "every 720h offset 2591999s"} { |
| + sp, err := ParseSpec(s) |
| + if err != nil { |
| + t.Fatalf("%q: %v", s, err) |
| + } |
| + if got := sp.String(); got != s { |
| + t.Errorf("%q → %q", s, got) |
| + } |
| + } |
| + // Offset zero is the boundary, and renders as the plain form. |
| + if sp, err := ParseSpec("every 1h offset 0s"); err != nil || sp.String() != "every 1h" { |
| + t.Errorf("offset 0s = %q, %v", sp.String(), err) |
| + } |
| + for _, bad := range []string{ |
| + "every 1h offset", "every 1h offset 3600s", "every 1h offset -1s", "every 1h offset 1500ms", |
| + "every 1h spread 5s", "every 1h offset 5s more", "every 1h offset x", |
| + } { |
| + if _, err := ParseSpec(bad); err == nil { |
| + t.Errorf("ParseSpec(%q) = ok, want error", bad) |
| + } |
| + } |
| +} |
| + |
| +func TestNextWithAnOffsetIsThePeriodsBoundaryShifted(t *testing.T) { |
| + at := func(s string) time.Time { |
| + v, err := time.Parse(time.RFC3339, s) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return v |
| + } |
| + sp := Spec{Kind: KindSchedule, Every: time.Hour, Offset: 20*time.Minute + 34*time.Second} |
| + for now, want := range map[string]string{ |
| + "2026-08-23T13:07:00Z": "2026-08-23T13:20:34Z", // before this hour's point |
| + "2026-08-23T13:20:33Z": "2026-08-23T13:20:34Z", |
| + "2026-08-23T13:20:34Z": "2026-08-23T14:20:34Z", // strictly after now |
| + "2026-08-23T13:59:59Z": "2026-08-23T14:20:34Z", |
| + } { |
| + if got := sp.Next(at(now)); !got.Equal(at(want)) { |
| + t.Errorf("Next(%s) = %s, want %s", now, got.Format(time.RFC3339), want) |
| + } |
| + } |
| + // Fire after fire, the gap is the period exactly. |
| + fire := sp.Next(at("2026-08-23T13:07:00Z")) |
| + for i := 0; i < 5; i++ { |
| + // The runner computes the next from when the delivery started, a |
| + // few seconds after the fire. |
| + next := sp.Next(fire.Add(7 * time.Second)) |
| + if next.Sub(fire) != time.Hour { |
| + t.Fatalf("fire %d: %s after the last, want 1h", i, next.Sub(fire)) |
| + } |
| + fire = next |
| + } |
| + // No offset is the boundary, as before. |
| + if got := (Spec{Kind: KindSchedule, Every: 6 * time.Hour}).Next(at("2026-08-23T13:07:00Z")); !got.Equal(at("2026-08-23T18:00:00Z")) { |
| + t.Errorf("aligned Next = %s", got) |
| + } |
| + // An instant before the first offset still gets a fire after it. |
| + if got := sp.Next(time.Unix(10, 0)); got.Unix() != 1234 { |
| + t.Errorf("Next(epoch+10s) = %d, want 1234", got.Unix()) |
| + } |
| +} |
diff --git a/schedule.go b/schedule.go| index 138e3d6ef..404c64a77 100644 |
| --- a/schedule.go |
| +++ b/schedule.go |
| @@ -31,9 +31,12 @@ const scheduleUsage = `usage: carlos schedule <ls|set|rm|run> [flags] |
| ls --app <a> [flags] |
| this app's declared schedules, plus what each instance |
| reports it will do next and what happened last |
| - set --app <a> --name <n> (--every <dur> | --cron "<5 fields>") --path </p> [flags] |
| + set --app <a> --name <n> (--every <dur> [--aligned] | --cron "<5 fields>") --path </p> [flags] |
| declare a schedule, or replace one already declared under |
| - the same name |
| + the same name. an --every schedule is spread: each |
| + instance fires at its own fixed point in the period, so |
| + the app's instances are not all woken at once. --aligned |
| + fires every instance together on the period's boundary |
| rm --app <a> --name <n> [flags] |
| remove a declared schedule |
| run --app <a> --name <n> [flags] |
| @@ -53,7 +56,7 @@ tick is due (within ~15s of a run, or at the schedule's next occurrence). |
| const scheduleLsUsage = `usage: carlos schedule ls --app <a> [--account <a>] [--account-id <id>] [--console <origin>] |
| ` |
| -const scheduleSetUsage = `usage: carlos schedule set --app <a> --name <n> (--every <dur> | --cron "<5 fields>") --path </p> [--account <a>] [--account-id <id>] [--console <origin>] |
| +const scheduleSetUsage = `usage: carlos schedule set --app <a> --name <n> (--every <dur> [--aligned] | --cron "<5 fields>") --path </p> [--account <a>] [--account-id <id>] [--console <origin>] |
| ` |
| const scheduleRmUsage = `usage: carlos schedule rm --app <a> --name <n> [--account <a>] [--account-id <id>] [--console <origin>] |
| @@ -128,6 +131,7 @@ func runScheduleSet(args []string) { |
| every := fs.String("every", "", "fire every duration, whole minutes only (1m to 720h) — give this or --cron, not both") |
| cron := fs.String("cron", "", `fire on a 5-field cron expression ("min hour dom mon dow") — give this or --every, not both`) |
| path := fs.String("path", "", "absolute path on the app's own instance to POST at each fire") |
| + aligned := fs.Bool("aligned", false, "with --every: fire every instance together on the period's boundary. without it each instance fires at its own fixed point in the period") |
| acctRaw, acctIDRaw, _ := accountFlags(fs) |
| consoleFlag := consoleOption(fs, "console to record through (default: the only logged-in one)") |
| fs.Usage = flagUsage(fs, scheduleSetUsage) |
| @@ -138,6 +142,9 @@ func runScheduleSet(args []string) { |
| Every: strings.TrimSpace(*every), |
| Cron: strings.TrimSpace(*cron), |
| Path: strings.TrimSpace(*path), |
| + // Declarative like the rest of set: leaving --aligned off a schedule |
| + // that had it puts the schedule back to spread. |
| + Aligned: *aligned, |
| } |
| // Client-side gate before the server's, restart's and apps create's |
| // pattern: a request the console is certain to refuse should cost a |
| @@ -160,14 +167,20 @@ func runScheduleSet(args []string) { |
| if err != nil { |
| log.Fatalf("schedule set: %v", err) |
| } |
| - // "first fire" is computed from OUR OWN validated spec, not read back |
| + // The fire time is computed from OUR OWN validated spec, not read back |
| // off the response: the console's answer carries every declared |
| // schedule (scheduleAnswer), not just the one just set, and this value |
| - // is already known client-side the moment Validate() succeeded. |
| - fmt.Fprintf(stdout, "%s %s for %s/%s — %s → POST %s; first fire at %s (UTC); boxes pick it up within "+ |
| + // is already known client-side the moment Validate() succeeded. A spread |
| + // schedule has no one fire time to print: each instance's is its own. |
| + first := "first fire at " + sp.Next(time.Now()).UTC().Format(time.RFC3339) + " (UTC)" |
| + if sc.Spread() { |
| + first = "spread: each instance fires at its own fixed point in every " + strings.TrimPrefix(sp.String(), "every ") + |
| + ", the first time within one period (--aligned fires them all together)" |
| + } |
| + fmt.Fprintf(stdout, "%s %s for %s/%s — %s → POST %s; %s; boxes pick it up within "+ |
| "seconds — `carlos schedule ls --app %s` shows each instance's next run\n", |
| colorFor(stdout).ok("recorded"), sc.Name, res.Account, res.App, sp.String(), sc.Path, |
| - sp.Next(time.Now()).UTC().Format(time.RFC3339), res.App) |
| + first, res.App) |
| } |
| func runScheduleRm(args []string) { |
| @@ -298,8 +311,14 @@ func renderScheduleTable(w io.Writer, scs []schedule.Schedule) { |
| } |
| sp, err := sc.Spec() |
| when := sp.String() |
| - if err != nil { |
| + switch { |
| + case err != nil: |
| when = "(invalid: " + err.Error() + ")" |
| + case sc.Spread(): |
| + // Each instance's own point in the period is its "next" below. |
| + when += ", spread" |
| + case sc.Every != "": |
| + when += ", aligned" |
| } |
| whens[i] = when |
| if n := len(when); n > whenW { |
diff --git a/schedule_test.go b/schedule_test.go| index 0fbac0a45..9eed1cfde 100644 |
| --- a/schedule_test.go |
| +++ b/schedule_test.go |
| @@ -266,9 +266,9 @@ func TestRenderScheduleList(t *testing.T) { |
| renderScheduleList(&buf, res, now) |
| want := "schedules for bab/app (updated 2026-08-23T22:14:09Z)\n" + |
| - " NAME WHEN PATH\n" + |
| - " reminders cron 0 8 * * * /jobs/reminders\n" + |
| - " sync every 6h /jobs/sync\n" + |
| + " NAME WHEN PATH\n" + |
| + " reminders cron 0 8 * * * /jobs/reminders\n" + |
| + " sync every 6h, spread /jobs/sync\n" + |
| "\n" + |
| "instances\n" + |
| " a.bab.oncarlos.com (box carlos-ie-1, reported 12s ago)\n" + |
| @@ -443,3 +443,21 @@ func TestScheduleVerbRefusals(t *testing.T) { |
| t.Fatalf("carlos help does not list schedule after restart:\n%s", out) |
| } |
| } |
| + |
| +// The declaration table says which every-schedules are spread and which |
| +// fire every instance together; a cron line is neither. |
| +func TestRenderScheduleTableMarksSpreadAndAligned(t *testing.T) { |
| + var b strings.Builder |
| + renderScheduleTable(&b, []schedule.Schedule{ |
| + {Name: "digest", Cron: "0 9 * * *", Path: "/jobs/digest"}, |
| + {Name: "sweep", Every: "1h", Path: "/jobs/sweep"}, |
| + {Name: "together", Every: "1h", Aligned: true, Path: "/jobs/together"}, |
| + }) |
| + want := " NAME WHEN PATH\n" + |
| + " digest cron 0 9 * * * /jobs/digest\n" + |
| + " sweep every 1h, spread /jobs/sweep\n" + |
| + " together every 1h, aligned /jobs/together\n" |
| + if got := b.String(); got != want { |
| + t.Fatalf("renderScheduleTable =\n%s\nwant\n%s", got, want) |
| + } |
| +} |
diff --git a/testdata/clireg-golden.jsonl b/testdata/clireg-golden.jsonl| index 2dcfe6e28..faf3038bc 100644 |
| --- a/testdata/clireg-golden.jsonl |
| +++ b/testdata/clireg-golden.jsonl |
| @@ -644,14 +644,14 @@ |
| {"case":"schedule rm | -h","argv":["schedule","rm","-h"],"exit":0,"stdout":"","stderr":"usage: carlos schedule rm --app <a> --name <n> [--account <a>] [--account-id <id>] [--console <origin>]\nflags:\n --account <string> account (sqid or name) the app belongs to (default: your only account, or the configured/chosen one; ops in direct mode)\n --account-id <string> account sqid, matched as a sqid ONLY — supersedes --account; this is the flag an ambiguity error tells you to use\n --app, -a <string> app the schedule belongs to\n --console <string> console to remove through (default: the only logged-in one)\n --destination, -d <name> use the named block from .carlos/config's destinations (default: CARLOS_DESTINATION, else the file's default or only one)\n --name <string> schedule name to remove\n --registry <string> registry database (resolves --account) (default: $DIR/data/registry.db)\n"} |
| {"case":"schedule run | --zz-unknown-flag","argv":["schedule","run","--zz-unknown-flag"],"exit":2,"stdout":"","stderr":"flag provided but not defined: -zz-unknown-flag\nusage: carlos schedule run --app <a> --name <n> [--account <a>] [--account-id <id>] [--console <origin>]\nflags:\n --account <string> account (sqid or name) the app belongs to (default: your only account, or the configured/chosen one; ops in direct mode)\n --account-id <string> account sqid, matched as a sqid ONLY — supersedes --account; this is the flag an ambiguity error tells you to use\n --app, -a <string> app the schedule belongs to\n --console <string> console to run through (default: the only logged-in one)\n --destination, -d <name> use the named block from .carlos/config's destinations (default: CARLOS_DESTINATION, else the file's default or only one)\n --name <string> schedule name to run now\n --registry <string> registry database (resolves --account) (default: $DIR/data/registry.db)\n"} |
| {"case":"schedule run | -h","argv":["schedule","run","-h"],"exit":0,"stdout":"","stderr":"usage: carlos schedule run --app <a> --name <n> [--account <a>] [--account-id <id>] [--console <origin>]\nflags:\n --account <string> account (sqid or name) the app belongs to (default: your only account, or the configured/chosen one; ops in direct mode)\n --account-id <string> account sqid, matched as a sqid ONLY — supersedes --account; this is the flag an ambiguity error tells you to use\n --app, -a <string> app the schedule belongs to\n --console <string> console to run through (default: the only logged-in one)\n --destination, -d <name> use the named block from .carlos/config's destinations (default: CARLOS_DESTINATION, else the file's default or only one)\n --name <string> schedule name to run now\n --registry <string> registry database (resolves --account) (default: $DIR/data/registry.db)\n"} |
| -{"case":"schedule set | --zz-unknown-flag","argv":["schedule","set","--zz-unknown-flag"],"exit":2,"stdout":"","stderr":"flag provided but not defined: -zz-unknown-flag\nusage: carlos schedule set --app <a> --name <n> (--every <dur> | --cron \"<5 fields>\") --path </p> [--account <a>] [--account-id <id>] [--console <origin>]\nflags:\n --account <string> account (sqid or name) the app belongs to (default: your only account, or the configured/chosen one; ops in direct mode)\n --account-id <string> account sqid, matched as a sqid ONLY — supersedes --account; this is the flag an ambiguity error tells you to use\n --app, -a <string> app the schedule belongs to\n --console <string> console to record through (default: the only logged-in one)\n --cron <string> fire on a 5-field cron expression (\"min hour dom mon dow\") — give this or --every, not both\n --destination, -d <name> use the named block from .carlos/config's destinations (default: CARLOS_DESTINATION, else the file's default or only one)\n --every <string> fire every duration, whole minutes only (1m to 720h) — give this or --cron, not both\n --name <string> schedule name — [a-z0-9][a-z0-9-]{0,31}\n --path <string> absolute path on the app's own instance to POST at each fire\n --registry <string> registry database (resolves --account) (default: $DIR/data/registry.db)\n"} |
| -{"case":"schedule set | -h","argv":["schedule","set","-h"],"exit":0,"stdout":"","stderr":"usage: carlos schedule set --app <a> --name <n> (--every <dur> | --cron \"<5 fields>\") --path </p> [--account <a>] [--account-id <id>] [--console <origin>]\nflags:\n --account <string> account (sqid or name) the app belongs to (default: your only account, or the configured/chosen one; ops in direct mode)\n --account-id <string> account sqid, matched as a sqid ONLY — supersedes --account; this is the flag an ambiguity error tells you to use\n --app, -a <string> app the schedule belongs to\n --console <string> console to record through (default: the only logged-in one)\n --cron <string> fire on a 5-field cron expression (\"min hour dom mon dow\") — give this or --every, not both\n --destination, -d <name> use the named block from .carlos/config's destinations (default: CARLOS_DESTINATION, else the file's default or only one)\n --every <string> fire every duration, whole minutes only (1m to 720h) — give this or --cron, not both\n --name <string> schedule name — [a-z0-9][a-z0-9-]{0,31}\n --path <string> absolute path on the app's own instance to POST at each fire\n --registry <string> registry database (resolves --account) (default: $DIR/data/registry.db)\n"} |
| -{"case":"schedule | --help","argv":["schedule","--help"],"exit":1,"stdout":"","stderr":"usage: carlos schedule <ls|set|rm|run> [flags]\n\n ls --app <a> [flags]\n this app's declared schedules, plus what each instance\n reports it will do next and what happened last\n set --app <a> --name <n> (--every <dur> | --cron \"<5 fields>\") --path </p> [flags]\n declare a schedule, or replace one already declared under\n the same name\n rm --app <a> --name <n> [flags]\n remove a declared schedule\n run --app <a> --name <n> [flags]\n request an out-of-band run on every instance now, on top\n of its normal schedule\n\n --account <a> account (sqid or name; default \"ops\")\n --account-id <id> account sqid, matched as a sqid ONLY\n --console <origin> console to act through (default: the only logged-in one)\n\nSigned-in only (carlos auth login): a schedule is a console-authorized write,\nthe same shape as carlos restart — boxes act on it within seconds. The write\nitself wakes nothing; a box's runner wakes a hibernating instance when its\ntick is due (within ~15s of a run, or at the schedule's next occurrence).\n"} |
| -{"case":"schedule | --zz-unknown-flag","argv":["schedule","--zz-unknown-flag"],"exit":1,"stdout":"","stderr":"usage: carlos schedule <ls|set|rm|run> [flags]\n\n ls --app <a> [flags]\n this app's declared schedules, plus what each instance\n reports it will do next and what happened last\n set --app <a> --name <n> (--every <dur> | --cron \"<5 fields>\") --path </p> [flags]\n declare a schedule, or replace one already declared under\n the same name\n rm --app <a> --name <n> [flags]\n remove a declared schedule\n run --app <a> --name <n> [flags]\n request an out-of-band run on every instance now, on top\n of its normal schedule\n\n --account <a> account (sqid or name; default \"ops\")\n --account-id <id> account sqid, matched as a sqid ONLY\n --console <origin> console to act through (default: the only logged-in one)\n\nSigned-in only (carlos auth login): a schedule is a console-authorized write,\nthe same shape as carlos restart — boxes act on it within seconds. The write\nitself wakes nothing; a box's runner wakes a hibernating instance when its\ntick is due (within ~15s of a run, or at the schedule's next occurrence).\n"} |
| -{"case":"schedule | -h","argv":["schedule","-h"],"exit":1,"stdout":"","stderr":"usage: carlos schedule <ls|set|rm|run> [flags]\n\n ls --app <a> [flags]\n this app's declared schedules, plus what each instance\n reports it will do next and what happened last\n set --app <a> --name <n> (--every <dur> | --cron \"<5 fields>\") --path </p> [flags]\n declare a schedule, or replace one already declared under\n the same name\n rm --app <a> --name <n> [flags]\n remove a declared schedule\n run --app <a> --name <n> [flags]\n request an out-of-band run on every instance now, on top\n of its normal schedule\n\n --account <a> account (sqid or name; default \"ops\")\n --account-id <id> account sqid, matched as a sqid ONLY\n --console <origin> console to act through (default: the only logged-in one)\n\nSigned-in only (carlos auth login): a schedule is a console-authorized write,\nthe same shape as carlos restart — boxes act on it within seconds. The write\nitself wakes nothing; a box's runner wakes a hibernating instance when its\ntick is due (within ~15s of a run, or at the schedule's next occurrence).\n"} |
| -{"case":"schedule | bare","argv":["schedule"],"exit":1,"stdout":"","stderr":"usage: carlos schedule <ls|set|rm|run> [flags]\n\n ls --app <a> [flags]\n this app's declared schedules, plus what each instance\n reports it will do next and what happened last\n set --app <a> --name <n> (--every <dur> | --cron \"<5 fields>\") --path </p> [flags]\n declare a schedule, or replace one already declared under\n the same name\n rm --app <a> --name <n> [flags]\n remove a declared schedule\n run --app <a> --name <n> [flags]\n request an out-of-band run on every instance now, on top\n of its normal schedule\n\n --account <a> account (sqid or name; default \"ops\")\n --account-id <id> account sqid, matched as a sqid ONLY\n --console <origin> console to act through (default: the only logged-in one)\n\nSigned-in only (carlos auth login): a schedule is a console-authorized write,\nthe same shape as carlos restart — boxes act on it within seconds. The write\nitself wakes nothing; a box's runner wakes a hibernating instance when its\ntick is due (within ~15s of a run, or at the schedule's next occurrence).\n"} |
| -{"case":"schedule | help","argv":["schedule","help"],"exit":1,"stdout":"","stderr":"usage: carlos schedule <ls|set|rm|run> [flags]\n\n ls --app <a> [flags]\n this app's declared schedules, plus what each instance\n reports it will do next and what happened last\n set --app <a> --name <n> (--every <dur> | --cron \"<5 fields>\") --path </p> [flags]\n declare a schedule, or replace one already declared under\n the same name\n rm --app <a> --name <n> [flags]\n remove a declared schedule\n run --app <a> --name <n> [flags]\n request an out-of-band run on every instance now, on top\n of its normal schedule\n\n --account <a> account (sqid or name; default \"ops\")\n --account-id <id> account sqid, matched as a sqid ONLY\n --console <origin> console to act through (default: the only logged-in one)\n\nSigned-in only (carlos auth login): a schedule is a console-authorized write,\nthe same shape as carlos restart — boxes act on it within seconds. The write\nitself wakes nothing; a box's runner wakes a hibernating instance when its\ntick is due (within ~15s of a run, or at the schedule's next occurrence).\n"} |
| -{"case":"schedule | zz-unknown","argv":["schedule","zz-unknown"],"exit":1,"stdout":"","stderr":"usage: carlos schedule <ls|set|rm|run> [flags]\n\n ls --app <a> [flags]\n this app's declared schedules, plus what each instance\n reports it will do next and what happened last\n set --app <a> --name <n> (--every <dur> | --cron \"<5 fields>\") --path </p> [flags]\n declare a schedule, or replace one already declared under\n the same name\n rm --app <a> --name <n> [flags]\n remove a declared schedule\n run --app <a> --name <n> [flags]\n request an out-of-band run on every instance now, on top\n of its normal schedule\n\n --account <a> account (sqid or name; default \"ops\")\n --account-id <id> account sqid, matched as a sqid ONLY\n --console <origin> console to act through (default: the only logged-in one)\n\nSigned-in only (carlos auth login): a schedule is a console-authorized write,\nthe same shape as carlos restart — boxes act on it within seconds. The write\nitself wakes nothing; a box's runner wakes a hibernating instance when its\ntick is due (within ~15s of a run, or at the schedule's next occurrence).\n"} |
| +{"case":"schedule set | --zz-unknown-flag","argv":["schedule","set","--zz-unknown-flag"],"exit":2,"stdout":"","stderr":"flag provided but not defined: -zz-unknown-flag\nusage: carlos schedule set --app <a> --name <n> (--every <dur> [--aligned] | --cron \"<5 fields>\") --path </p> [--account <a>] [--account-id <id>] [--console <origin>]\nflags:\n --account <string> account (sqid or name) the app belongs to (default: your only account, or the configured/chosen one; ops in direct mode)\n --account-id <string> account sqid, matched as a sqid ONLY — supersedes --account; this is the flag an ambiguity error tells you to use\n --aligned with --every: fire every instance together on the period's boundary. without it each instance fires at its own fixed point in the period\n --app, -a <string> app the schedule belongs to\n --console <string> console to record through (default: the only logged-in one)\n --cron <string> fire on a 5-field cron expression (\"min hour dom mon dow\") — give this or --every, not both\n --destination, -d <name> use the named block from .carlos/config's destinations (default: CARLOS_DESTINATION, else the file's default or only one)\n --every <string> fire every duration, whole minutes only (1m to 720h) — give this or --cron, not both\n --name <string> schedule name — [a-z0-9][a-z0-9-]{0,31}\n --path <string> absolute path on the app's own instance to POST at each fire\n --registry <string> registry database (resolves --account) (default: $DIR/data/registry.db)\n"} |
| +{"case":"schedule set | -h","argv":["schedule","set","-h"],"exit":0,"stdout":"","stderr":"usage: carlos schedule set --app <a> --name <n> (--every <dur> [--aligned] | --cron \"<5 fields>\") --path </p> [--account <a>] [--account-id <id>] [--console <origin>]\nflags:\n --account <string> account (sqid or name) the app belongs to (default: your only account, or the configured/chosen one; ops in direct mode)\n --account-id <string> account sqid, matched as a sqid ONLY — supersedes --account; this is the flag an ambiguity error tells you to use\n --aligned with --every: fire every instance together on the period's boundary. without it each instance fires at its own fixed point in the period\n --app, -a <string> app the schedule belongs to\n --console <string> console to record through (default: the only logged-in one)\n --cron <string> fire on a 5-field cron expression (\"min hour dom mon dow\") — give this or --every, not both\n --destination, -d <name> use the named block from .carlos/config's destinations (default: CARLOS_DESTINATION, else the file's default or only one)\n --every <string> fire every duration, whole minutes only (1m to 720h) — give this or --cron, not both\n --name <string> schedule name — [a-z0-9][a-z0-9-]{0,31}\n --path <string> absolute path on the app's own instance to POST at each fire\n --registry <string> registry database (resolves --account) (default: $DIR/data/registry.db)\n"} |
| +{"case":"schedule | --help","argv":["schedule","--help"],"exit":1,"stdout":"","stderr":"usage: carlos schedule <ls|set|rm|run> [flags]\n\n ls --app <a> [flags]\n this app's declared schedules, plus what each instance\n reports it will do next and what happened last\n set --app <a> --name <n> (--every <dur> [--aligned] | --cron \"<5 fields>\") --path </p> [flags]\n declare a schedule, or replace one already declared under\n the same name. an --every schedule is spread: each\n instance fires at its own fixed point in the period, so\n the app's instances are not all woken at once. --aligned\n fires every instance together on the period's boundary\n rm --app <a> --name <n> [flags]\n remove a declared schedule\n run --app <a> --name <n> [flags]\n request an out-of-band run on every instance now, on top\n of its normal schedule\n\n --account <a> account (sqid or name; default \"ops\")\n --account-id <id> account sqid, matched as a sqid ONLY\n --console <origin> console to act through (default: the only logged-in one)\n\nSigned-in only (carlos auth login): a schedule is a console-authorized write,\nthe same shape as carlos restart — boxes act on it within seconds. The write\nitself wakes nothing; a box's runner wakes a hibernating instance when its\ntick is due (within ~15s of a run, or at the schedule's next occurrence).\n"} |
| +{"case":"schedule | --zz-unknown-flag","argv":["schedule","--zz-unknown-flag"],"exit":1,"stdout":"","stderr":"usage: carlos schedule <ls|set|rm|run> [flags]\n\n ls --app <a> [flags]\n this app's declared schedules, plus what each instance\n reports it will do next and what happened last\n set --app <a> --name <n> (--every <dur> [--aligned] | --cron \"<5 fields>\") --path </p> [flags]\n declare a schedule, or replace one already declared under\n the same name. an --every schedule is spread: each\n instance fires at its own fixed point in the period, so\n the app's instances are not all woken at once. --aligned\n fires every instance together on the period's boundary\n rm --app <a> --name <n> [flags]\n remove a declared schedule\n run --app <a> --name <n> [flags]\n request an out-of-band run on every instance now, on top\n of its normal schedule\n\n --account <a> account (sqid or name; default \"ops\")\n --account-id <id> account sqid, matched as a sqid ONLY\n --console <origin> console to act through (default: the only logged-in one)\n\nSigned-in only (carlos auth login): a schedule is a console-authorized write,\nthe same shape as carlos restart — boxes act on it within seconds. The write\nitself wakes nothing; a box's runner wakes a hibernating instance when its\ntick is due (within ~15s of a run, or at the schedule's next occurrence).\n"} |
| +{"case":"schedule | -h","argv":["schedule","-h"],"exit":1,"stdout":"","stderr":"usage: carlos schedule <ls|set|rm|run> [flags]\n\n ls --app <a> [flags]\n this app's declared schedules, plus what each instance\n reports it will do next and what happened last\n set --app <a> --name <n> (--every <dur> [--aligned] | --cron \"<5 fields>\") --path </p> [flags]\n declare a schedule, or replace one already declared under\n the same name. an --every schedule is spread: each\n instance fires at its own fixed point in the period, so\n the app's instances are not all woken at once. --aligned\n fires every instance together on the period's boundary\n rm --app <a> --name <n> [flags]\n remove a declared schedule\n run --app <a> --name <n> [flags]\n request an out-of-band run on every instance now, on top\n of its normal schedule\n\n --account <a> account (sqid or name; default \"ops\")\n --account-id <id> account sqid, matched as a sqid ONLY\n --console <origin> console to act through (default: the only logged-in one)\n\nSigned-in only (carlos auth login): a schedule is a console-authorized write,\nthe same shape as carlos restart — boxes act on it within seconds. The write\nitself wakes nothing; a box's runner wakes a hibernating instance when its\ntick is due (within ~15s of a run, or at the schedule's next occurrence).\n"} |
| +{"case":"schedule | bare","argv":["schedule"],"exit":1,"stdout":"","stderr":"usage: carlos schedule <ls|set|rm|run> [flags]\n\n ls --app <a> [flags]\n this app's declared schedules, plus what each instance\n reports it will do next and what happened last\n set --app <a> --name <n> (--every <dur> [--aligned] | --cron \"<5 fields>\") --path </p> [flags]\n declare a schedule, or replace one already declared under\n the same name. an --every schedule is spread: each\n instance fires at its own fixed point in the period, so\n the app's instances are not all woken at once. --aligned\n fires every instance together on the period's boundary\n rm --app <a> --name <n> [flags]\n remove a declared schedule\n run --app <a> --name <n> [flags]\n request an out-of-band run on every instance now, on top\n of its normal schedule\n\n --account <a> account (sqid or name; default \"ops\")\n --account-id <id> account sqid, matched as a sqid ONLY\n --console <origin> console to act through (default: the only logged-in one)\n\nSigned-in only (carlos auth login): a schedule is a console-authorized write,\nthe same shape as carlos restart — boxes act on it within seconds. The write\nitself wakes nothing; a box's runner wakes a hibernating instance when its\ntick is due (within ~15s of a run, or at the schedule's next occurrence).\n"} |
| +{"case":"schedule | help","argv":["schedule","help"],"exit":1,"stdout":"","stderr":"usage: carlos schedule <ls|set|rm|run> [flags]\n\n ls --app <a> [flags]\n this app's declared schedules, plus what each instance\n reports it will do next and what happened last\n set --app <a> --name <n> (--every <dur> [--aligned] | --cron \"<5 fields>\") --path </p> [flags]\n declare a schedule, or replace one already declared under\n the same name. an --every schedule is spread: each\n instance fires at its own fixed point in the period, so\n the app's instances are not all woken at once. --aligned\n fires every instance together on the period's boundary\n rm --app <a> --name <n> [flags]\n remove a declared schedule\n run --app <a> --name <n> [flags]\n request an out-of-band run on every instance now, on top\n of its normal schedule\n\n --account <a> account (sqid or name; default \"ops\")\n --account-id <id> account sqid, matched as a sqid ONLY\n --console <origin> console to act through (default: the only logged-in one)\n\nSigned-in only (carlos auth login): a schedule is a console-authorized write,\nthe same shape as carlos restart — boxes act on it within seconds. The write\nitself wakes nothing; a box's runner wakes a hibernating instance when its\ntick is due (within ~15s of a run, or at the schedule's next occurrence).\n"} |
| +{"case":"schedule | zz-unknown","argv":["schedule","zz-unknown"],"exit":1,"stdout":"","stderr":"usage: carlos schedule <ls|set|rm|run> [flags]\n\n ls --app <a> [flags]\n this app's declared schedules, plus what each instance\n reports it will do next and what happened last\n set --app <a> --name <n> (--every <dur> [--aligned] | --cron \"<5 fields>\") --path </p> [flags]\n declare a schedule, or replace one already declared under\n the same name. an --every schedule is spread: each\n instance fires at its own fixed point in the period, so\n the app's instances are not all woken at once. --aligned\n fires every instance together on the period's boundary\n rm --app <a> --name <n> [flags]\n remove a declared schedule\n run --app <a> --name <n> [flags]\n request an out-of-band run on every instance now, on top\n of its normal schedule\n\n --account <a> account (sqid or name; default \"ops\")\n --account-id <id> account sqid, matched as a sqid ONLY\n --console <origin> console to act through (default: the only logged-in one)\n\nSigned-in only (carlos auth login): a schedule is a console-authorized write,\nthe same shape as carlos restart — boxes act on it within seconds. The write\nitself wakes nothing; a box's runner wakes a hibernating instance when its\ntick is due (within ~15s of a run, or at the schedule's next occurrence).\n"} |
| {"case":"secrets fingerprint | --zz-unknown-flag","argv":["secrets","fingerprint","--zz-unknown-flag"],"exit":2,"stdout":"","stderr":"flag provided but not defined: -zz-unknown-flag\nusage: carlos secrets fingerprint [--file <path>]\nflags:\n --file <string> the host.env-style file holding CARLOS_SECRETS_KEY (default: /etc/carlos/host.env)\n"} |
| {"case":"secrets fingerprint | -h","argv":["secrets","fingerprint","-h"],"exit":0,"stdout":"","stderr":"usage: carlos secrets fingerprint [--file <path>]\nflags:\n --file <string> the host.env-style file holding CARLOS_SECRETS_KEY (default: /etc/carlos/host.env)\n"} |
| {"case":"secrets genkey | skipped","skipped":"prints a freshly generated key pair: no two runs agree"} |