diff --git a/CHANGELOG.md b/CHANGELOG.md index b54cade..65b2cc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Keep scheduler due checks scoped to the exact job and repository when colon-containing names share a legacy 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. diff --git a/README.md b/README.md index 5989393..785e997 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,9 @@ Discovery reports malformed metadata and missing manifest IDs in the app's Legacy fallback also recognizes supported binaries selected by absolute or relative executable path. +Scheduler due checks use the exact job and repository identity, so colon-containing +names do not share scheduling history. + If a write is interrupted, history reads ignore a truncated final JSON value and the next run repairs that tail before appending. Valid final records without a trailing newline are retained; complete corrupt records still report an error. History reads accept the full records written by the runner, including long diff --git a/scheduler/run.go b/scheduler/run.go index 652ac46..928829a 100644 --- a/scheduler/run.go +++ b/scheduler/run.go @@ -52,7 +52,14 @@ func Run(ctx context.Context, opts RunOptions) ([]RunRecord, error) { if err != nil { return nil, err } - last := LastRecords(history) + type jobKey struct { + name string + repo string + } + last := make(map[jobKey]RunRecord, len(history)) + for _, record := range history { + last[jobKey{record.Job, record.Repo}] = record + } names := selectedNames(opts.Config, opts.Names) records := []RunRecord{} @@ -72,7 +79,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[jobKey{name, item.repo}] if len(opts.Names) == 0 && !jobDue(now(), job, lastRun, ok) { continue } @@ -91,15 +98,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 diff --git a/scheduler/scheduler_test.go b/scheduler/scheduler_test.go index 9e1ba1e..dbdc613 100644 --- a/scheduler/scheduler_test.go +++ b/scheduler/scheduler_test.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "io" "os" "path/filepath" @@ -537,3 +538,57 @@ func TestPlanInstallCronIntervals(t *testing.T) { }) } } + +func TestRunKeepsJobAndRepoHistoryDistinct(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 + }{ + {"direct job", "sync:other", "", "sync", "other"}, + {"repository job", "sync", "other", "sync:other", ""}, + {"colon in repository", "sync", "other:repo", "sync:other", "repo"}, + } { + for _, alreadyRun := range []bool{false, true} { + t.Run(fmt.Sprintf("%s/alreadyRun=%t", tc.name, alreadyRun), func(t *testing.T) { + paths, err := DefaultPaths(filepath.Join(t.TempDir(), "crawlctl.toml")) + if err != nil { + t.Fatal(err) + } + if alreadyRun { + if err := appendHistory(paths.History, RunRecord{Job: tc.job, Repo: tc.repo, Status: "success", FinishedAt: now.Format(time.RFC3339)}); err != nil { + t.Fatal(err) + } + } + status := "success" + if alreadyRun { + status = "failed" + } + if err := appendHistory(paths.History, RunRecord{Job: tc.otherJob, Repo: tc.otherRepo, Status: status, FinishedAt: now.Format(time.RFC3339)}); err != nil { + t.Fatal(err) + } + job := Job{Enabled: true, Every: "10m", 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.Add(time.Minute) }}) + if err != nil { + t.Fatal(err) + } + if alreadyRun { + if len(records) != 0 { + t.Fatalf("job ran again despite its recent success: %+v", records) + } + } else if len(records) != 1 || records[0].Job != tc.job || records[0].Repo != tc.repo || records[0].Status != "success" { + t.Fatalf("unrelated history suppressed due job: %+v", records) + } + }) + } + } +}