Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Keep scheduler due checks independent when job names and repository values produce the same colon-separated history key.

- Keep scheduler status scoped to the exact job name when another job or repository history key shares its prefix.

- Allow native independent review in either Codex or OpenClaw while preserving pinned, isolated, read-only review and existing validation gates.
Expand Down
17 changes: 6 additions & 11 deletions scheduler/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ func Run(ctx context.Context, opts RunOptions) ([]RunRecord, error) {
if err != nil {
return nil, err
}
last := LastRecords(history)
type runKey struct{ job, repo string }
last := make(map[runKey]RunRecord, len(history))
for _, record := range history {
last[runKey{record.Job, record.Repo}] = record
}

names := selectedNames(opts.Config, opts.Names)
records := []RunRecord{}
Expand All @@ -72,7 +76,7 @@ func Run(ctx context.Context, opts RunOptions) ([]RunRecord, error) {
continue
}
for _, item := range expanded {
lastRun, ok := lastRecord(last, name, item.repo)
lastRun, ok := last[runKey{name, item.repo}]
if len(opts.Names) == 0 && !jobDue(now(), job, lastRun, ok) {
continue
}
Expand All @@ -91,15 +95,6 @@ func Run(ctx context.Context, opts RunOptions) ([]RunRecord, error) {
return records, historyErr
}

func lastRecord(records map[string]RunRecord, name, repo string) (RunRecord, bool) {
if repo != "" {
record, ok := records[name+":"+repo]
return record, ok
}
record, ok := records[name]
return record, ok
}

func jobDue(now time.Time, job Job, last RunRecord, ok bool) bool {
if !ok || last.Status != "success" {
return true
Expand Down
58 changes: 58 additions & 0 deletions scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -263,6 +264,63 @@ func TestRunSkipsJobsThatAreNotDue(t *testing.T) {
}
}

func TestRunKeepsCollidingHistoryIdentitiesSeparate(t *testing.T) {
exe, err := os.Executable()
if err != nil {
t.Fatal(err)
}
now := time.Date(2026, 5, 22, 12, 0, 0, 0, time.UTC)
for _, tc := range []struct {
name, job, repo, otherJob, otherRepo string
}{
{"plain job", "sync:repo", "", "sync", "repo"},
{"repository job", "sync", "repo", "sync:repo", ""},
{"colon in repository", "sync", "group:repo", "sync:group", "repo"},
} {
for _, due := range []bool{true, false} {
t.Run(fmt.Sprintf("%s/due=%t", tc.name, due), func(t *testing.T) {
dir := t.TempDir()
paths := Paths{LogDir: filepath.Join(dir, "logs"), StateDir: filepath.Join(dir, "state"), LockPath: filepath.Join(dir, "state", "lock"), History: filepath.Join(dir, "state", "runs.jsonl")}
finished := now.Add(-time.Minute)
otherStatus := "failed"
if due {
finished = now.Add(-2 * time.Hour)
otherStatus = "success"
}
for _, record := range []RunRecord{
{Job: tc.job, Repo: tc.repo, Status: "success", FinishedAt: finished.Format(time.RFC3339)},
{Job: tc.otherJob, Repo: tc.otherRepo, Status: otherStatus, FinishedAt: now.Format(time.RFC3339)},
} {
if err := appendHistory(paths.History, record); err != nil {
t.Fatal(err)
}
}
job := Job{Enabled: true, Every: "1h", Command: []string{exe, "-test.run=^$"}}
if tc.repo != "" {
job.Command = append(job.Command, "--", "{repo}")
job.Repos = []string{tc.repo}
}
cfg := DefaultConfig()
cfg.Jobs[tc.job] = job
records, err := Run(t.Context(), RunOptions{Config: cfg, Paths: paths, Now: func() time.Time { return now }})
if err != nil {
t.Fatal(err)
}
want := 0
if due {
want = 1
}
if len(records) != want {
t.Fatalf("runs = %d, want %d: %#v", len(records), want, records)
}
if due && (records[0].Job != tc.job || records[0].Repo != tc.repo || records[0].Status != "success") {
t.Fatalf("unexpected run: %#v", records[0])
}
})
}
}
}

func TestParseEveryRejectsSubMinute(t *testing.T) {
if _, err := ParseEvery("30s"); err == nil {
t.Fatal("expected reject error")
Expand Down
Loading