Skip to content
Merged
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 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.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 9 additions & 11 deletions scheduler/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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
}
Expand All @@ -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
Expand Down
55 changes: 55 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 @@ -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)
}
})
}
}
}
Loading