Skip to content

fix(cron): start scheduler so CRON_SCHEDULE handlers fire#109

Merged
shawnburke merged 2 commits into
mainfrom
fix/cron-scheduler-not-started
Jun 10, 2026
Merged

fix(cron): start scheduler so CRON_SCHEDULE handlers fire#109
shawnburke merged 2 commits into
mainfrom
fix/cron-scheduler-not-started

Conversation

@shawnburke

Copy link
Copy Markdown
Collaborator

Problem

A customer reported that the Go SDK's cron-interval handlers don't run. Investigation traced this to the agent server's cron wrapper, not the SDK surface.

server/cron/cron.go built a robfig/cron/v3 scheduler with cronLib.New() but never called Start():

func New() Cron {
    return &cronLibWrapper{ cron: cronLib.New() }  // never started
}

In robfig/cron v3, cron.New() starts with running: false. AddFuncSchedule only appends entries to an internal slice while not running — jobs are dispatched solely by the goroutine that Start() launches:

func (c *Cron) Schedule(...) EntryID {
    if !c.running {
        c.entries = append(c.entries, entry)   // registered but dormant
    } else {
        c.add <- entry
    }
}

So CRON_SCHEDULE handlers were registered but never invoked. RUN_INTERVAL handlers were unaffected because they use their own time.NewTicker goroutine, independent of robfig/cron — which is why only the cron-schedule path was broken. Because both the Go and Python SDKs talk to this same Go agent server, cron-scheduled handlers were broken for both.

Why tests didn't catch it

TestApplyOption_CronSchedule uses a fakeCron whose Add runs the command immediately (go cmd()), so it never exercised the real "must be started" contract.

Fix

Call c.Start() in New(). Start() is idempotent, and adding/removing entries while running is fully supported (routed through the scheduler's channels).

Test plan

  • Added server/cron/cron_test.go exercising the real wrapper with an @every 1s job.
    • Before fix: FAIL — cron job never fired; scheduler was not started (3s timeout)
    • After fix: PASS (0.20s)
  • go test ./... across the agent module is green, including existing cron and handler tests.

🤖 Generated with Claude Code

The cron wrapper built a robfig/cron scheduler via cronLib.New() but
never called Start(). In robfig/cron v3, AddFunc/Schedule only appends
entries to an internal slice while the scheduler is not running; jobs
are dispatched solely by the goroutine that Start() launches. As a
result, CRON_SCHEDULE handlers were registered but never invoked.

RUN_INTERVAL handlers were unaffected because they use their own
time.NewTicker goroutine, independent of robfig/cron.

The existing TestApplyOption_CronSchedule masked this: its fakeCron
fires the command immediately on Add(), so it never exercised the
real "must be started" contract. Added cron_test.go which uses the
real wrapper and an "@every 1s" job to verify a job actually fires.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shawnburke shawnburke requested a review from ashiramin June 10, 2026 23:17
The Trivy PR scan flagged 45 CRITICAL/HIGH CVEs in openssl/libssl3t64
whose fixes are already in Debian's archive; the build was serving a
stale apt layer. Bump APT_CACHE_BUST to invalidate that layer.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shawnburke shawnburke merged commit a8230f5 into main Jun 10, 2026
17 checks passed
@shawnburke shawnburke deleted the fix/cron-scheduler-not-started branch June 10, 2026 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants