From 3a37e1b5fa244e7f2b5fd5c6bcedc01dd03a8e13 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Mon, 16 Nov 2026 10:51:18 +0800 Subject: [PATCH 1/3] fix(crawlctl): preserve status across colliding history keys --- CHANGELOG.md | 2 ++ cmd/crawlctl/main.go | 9 +++---- cmd/crawlctl/main_test.go | 51 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b54cade..be84017 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Preserve each job's text status when distinct job and repository histories share the same summary 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/cmd/crawlctl/main.go b/cmd/crawlctl/main.go index ba3a273..2907d32 100644 --- a/cmd/crawlctl/main.go +++ b/cmd/crawlctl/main.go @@ -294,7 +294,7 @@ func (a *app) runStatus(args []string) error { if job.Enabled { state = "never" } - if record, ok := latestRecordForJob(last, name); ok { + if record, ok := latestRecordForJob(history, name); ok { state = record.Status detail = " " + record.FinishedAt } @@ -303,13 +303,10 @@ func (a *app) runStatus(args []string) error { return nil } -func latestRecordForJob(last map[string]scheduler.RunRecord, name string) (scheduler.RunRecord, bool) { - if record, ok := last[name]; ok && record.Job == name { - return record, true - } +func latestRecordForJob(history []scheduler.RunRecord, name string) (scheduler.RunRecord, bool) { var latest scheduler.RunRecord found := false - for _, record := range last { + for _, record := range history { if record.Job != name { continue } diff --git a/cmd/crawlctl/main_test.go b/cmd/crawlctl/main_test.go index dd3136c..00dcf6e 100644 --- a/cmd/crawlctl/main_test.go +++ b/cmd/crawlctl/main_test.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "os" "path/filepath" "runtime" @@ -38,9 +39,9 @@ func TestResolveVersion(t *testing.T) { } func TestLatestRecordForJobAggregatesRepoRuns(t *testing.T) { - records := map[string]scheduler.RunRecord{ - "gitcrawl:openclaw/old": {Job: "gitcrawl", Repo: "openclaw/old", Status: "success", FinishedAt: "2026-05-22T10:00:00Z"}, - "gitcrawl:openclaw/new": {Job: "gitcrawl", Repo: "openclaw/new", Status: "failed", FinishedAt: "2026-05-22T11:00:00Z"}, + records := []scheduler.RunRecord{ + {Job: "gitcrawl", Repo: "openclaw/old", Status: "success", FinishedAt: "2026-05-22T10:00:00Z"}, + {Job: "gitcrawl", Repo: "openclaw/new", Status: "failed", FinishedAt: "2026-05-22T11:00:00Z"}, } record, ok := latestRecordForJob(records, "gitcrawl") if !ok { @@ -91,6 +92,50 @@ func TestStatusDoesNotUseAnotherJobsHistory(t *testing.T) { } } +func TestStatusKeepsJobsWithCollidingHistoryKeys(t *testing.T) { + for _, reversed := range []bool{false, true} { + t.Run(fmt.Sprint(reversed), func(t *testing.T) { + configPath := filepath.Join(t.TempDir(), "crawlctl.toml") + cfg := scheduler.DefaultConfig() + for _, name := range []string{"sync", "sync:owner/repo"} { + cfg.Jobs[name] = scheduler.Job{Enabled: true, Command: []string{"unused"}} + } + paths, err := scheduler.Save(configPath, cfg, false) + if err != nil { + t.Fatal(err) + } + records := []scheduler.RunRecord{ + {Job: "sync:owner/repo", Status: "failed", FinishedAt: "2026-05-22T10:00:00Z"}, + {Job: "sync", Repo: "owner/repo", Status: "success", FinishedAt: "2026-05-22T11:00:00Z"}, + } + if reversed { + records[0], records[1] = records[1], records[0] + } + var history bytes.Buffer + for _, record := range records { + if err := json.NewEncoder(&history).Encode(record); err != nil { + t.Fatal(err) + } + } + if err := os.MkdirAll(filepath.Dir(paths.History), 0o700); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(paths.History, history.Bytes(), 0o600); err != nil { + t.Fatal(err) + } + var stdout bytes.Buffer + a := app{stdout: &stdout, stderr: ioDiscard{}, config: configPath} + if err := a.runStatus(nil); err != nil { + t.Fatal(err) + } + want := "sync: success 2026-05-22T11:00:00Z\nsync:owner/repo: failed 2026-05-22T10:00:00Z\n" + if stdout.String() != want { + t.Fatalf("status = %q, want %q", stdout.String(), want) + } + }) + } +} + func TestRunJSONDoesNotIncludeProgress(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("uses POSIX echo") From 55fb9c0dfb5bd05ea291dd59f0e036eed008a49c Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Mon, 16 Nov 2026 10:52:10 +0800 Subject: [PATCH 2/3] fix(scheduler): keep discovered executables independent of cwd --- CHANGELOG.md | 2 ++ README.md | 3 ++- scheduler/discover.go | 5 +++++ scheduler/discover_test.go | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be84017..3d84a2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Save discovered executables as absolute paths so relative app selections work from another runner directory. + - Preserve each job's text status when distinct job and repository histories share the same summary key. - Keep scheduler status scoped to the exact job name when another job or repository history key shares its prefix. diff --git a/README.md b/README.md index 5989393..1ac87a4 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,8 @@ schedule source-specific commands such as Photos' `import_apple`. Discovery reports malformed metadata and missing manifest IDs in the app's `error` field. Supported legacy binaries retain their fallback manifests. Legacy fallback also recognizes supported binaries selected by absolute or -relative executable path. +relative executable path. Discovery records an absolute executable path so saved +jobs keep working when the runner starts from another directory. 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. diff --git a/scheduler/discover.go b/scheduler/discover.go index 12f1ce1..3acf8b4 100644 --- a/scheduler/discover.go +++ b/scheduler/discover.go @@ -51,6 +51,11 @@ func discoverOne(ctx context.Context, binary string) App { app.Error = err.Error() return app } + path, err = filepath.Abs(path) + if err != nil { + app.Error = err.Error() + return app + } app.Found = true app.Path = path cmd := exec.CommandContext(ctx, path, "metadata", "--json") diff --git a/scheduler/discover_test.go b/scheduler/discover_test.go index 578d999..f3a80a2 100644 --- a/scheduler/discover_test.go +++ b/scheduler/discover_test.go @@ -149,3 +149,38 @@ func TestDiscoverLegacyBinaryPaths(t *testing.T) { } } } + +func TestDiscoveredRelativeExecutableRunsFromAnotherDirectory(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("synthetic POSIX executable fixture") + } + binDir := t.TempDir() + executable := filepath.Join(binDir, "wacrawl") + if err := os.WriteFile(executable, []byte("#!/bin/sh\nif [ \"$1\" = metadata ]; then exit 2; fi\nprintf 'synthetic crawler ran\\n'\n"), 0o700); err != nil { + t.Fatal(err) + } + t.Chdir(binDir) + app := Discover(context.Background(), []string{"./wacrawl"})[0] + job, ok := DefaultJobForApp(app, nil) + if !app.Found || !app.Legacy || !ok { + t.Fatalf("relative discovery = %+v, job = %+v", app, job) + } + cfg := DefaultConfig() + cfg.Jobs = map[string]Job{"wacrawl": job} + paths, err := Save(filepath.Join(t.TempDir(), "crawlctl.toml"), cfg, false) + if err != nil { + t.Fatal(err) + } + t.Chdir(t.TempDir()) + loaded, _, err := Load(paths.ConfigPath) + if err != nil { + t.Fatal(err) + } + records, err := Run(context.Background(), RunOptions{Config: loaded, Paths: paths, Names: []string{"wacrawl"}}) + if err != nil || len(records) != 1 || records[0].Status != "success" { + t.Fatalf("relative selection from another directory: records = %+v, error = %v", records, err) + } + if app.Path != executable || loaded.Jobs["wacrawl"].Command[0] != executable { + t.Fatalf("selected executable not retained absolutely: app = %+v, command = %v", app, loaded.Jobs["wacrawl"].Command) + } +} From 2cc09d72a694d8484d67d924a7979ed52a9b876a Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Mon, 16 Nov 2026 10:53:16 +0800 Subject: [PATCH 3/3] fix(crawlctl): prefer later history when finish times tie --- CHANGELOG.md | 2 +- cmd/crawlctl/main.go | 2 +- cmd/crawlctl/main_test.go | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d84a2a..268a59b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - Save discovered executables as absolute paths so relative app selections work from another runner directory. -- Preserve each job's text status when distinct job and repository histories share the same summary key. +- Preserve each job's latest text status when history keys collide or runs finish in the same second. - Keep scheduler status scoped to the exact job name when another job or repository history key shares its prefix. diff --git a/cmd/crawlctl/main.go b/cmd/crawlctl/main.go index 2907d32..c34c699 100644 --- a/cmd/crawlctl/main.go +++ b/cmd/crawlctl/main.go @@ -310,7 +310,7 @@ func latestRecordForJob(history []scheduler.RunRecord, name string) (scheduler.R if record.Job != name { continue } - if !found || record.FinishedAt > latest.FinishedAt { + if !found || record.FinishedAt >= latest.FinishedAt { latest = record found = true } diff --git a/cmd/crawlctl/main_test.go b/cmd/crawlctl/main_test.go index 00dcf6e..b6a08d1 100644 --- a/cmd/crawlctl/main_test.go +++ b/cmd/crawlctl/main_test.go @@ -52,6 +52,17 @@ func TestLatestRecordForJobAggregatesRepoRuns(t *testing.T) { } } +func TestLatestRecordForJobUsesLastEntryAtSameTime(t *testing.T) { + history := []scheduler.RunRecord{ + {Job: "sync", Status: "failed", FinishedAt: "2026-05-22T10:00:00Z"}, + {Job: "sync", Status: "success", FinishedAt: "2026-05-22T10:00:00Z"}, + } + record, ok := latestRecordForJob(history, "sync") + if !ok || record.Status != "success" { + t.Fatalf("latest record = %+v, found = %v; want the later successful run", record, ok) + } +} + func TestStatusDoesNotUseAnotherJobsHistory(t *testing.T) { for _, tc := range []struct { name, job, recordedJob, repo string