Skip to content

Scheduler jobs register but never execute; listJobs() returns empty immediately after runJob() (reproduces on published unlisted app) #259

@eugenefrancis

Description

@eugenefrancis

Summary

context.scheduler.runJob() returns a valid job UUID, but the job never executes. context.scheduler.listJobs() returns an empty array immediately after runJob() returns. This affects both recurring cron jobs and one-shot runAt jobs. Menu item handlers and AppInstall / AppUpgrade triggers fire correctly on the same app, so the issue is isolated to the scheduler itself.

The behavior reproduces on both an uploaded (private) app and a published (unlisted) app, ruling out publish status as a factor.

Environment

  • App slug: rapids-match-bot
  • App URL: https://developers.reddit.com/apps/rapids-match-bot
  • Devvit CLI: 0.12.13
  • @devvit/public-api: latest at time of build
  • App versions tested: 0.0.3 through 0.0.14 (all exhibit the bug)
  • Publish status when bug reproduces: both uploaded (v0.0.13) and published unlisted (v0.0.14)
  • Test subreddit: r/rapids_match_bot_dev (private dev sub, mod-installed)
  • Node: 22

Steps to reproduce

  1. Register a scheduler job at the top level:
   Devvit.addSchedulerJob({
     name: JOB_CHECK_MATCHES,
     onRun: checkMatchesJob,
   });
  1. In an AppInstall / AppUpgrade trigger, first iterate listJobs() and cancelJob() each (per Reinstalling an application creates a ghost of its schedules #239 mitigation), then call:
   const jobId = await context.scheduler.runJob({
     name: JOB_CHECK_MATCHES,
     runAt: new Date(Date.now() + 60_000),
   });
   await context.redis.set('cronJobId', jobId);
  1. Note that jobId is a valid UUID and is persisted to Redis successfully.
  2. Immediately call context.scheduler.listJobs() from a moderator menu item.

Observed behavior

  • runJob() returns a valid UUID (e.g. 9225215c-f9df-4304-8069-4bf8c4f1da2c).
  • listJobs() returns [].
  • The registered job never executes. No onRun invocation. No log output. No side effects (no Reddit post submitted from inside the handler, even when the handler is reduced to a single submitPost call as a smoke test).
  • This is true for both cron recurring jobs and runAt one-shot jobs.
  • This is true on the uploaded version (v0.0.13) and on the published unlisted version (v0.0.14).

Expected behavior

  • runJob() returns a UUID.
  • listJobs() returns a non-empty array containing that UUID.
  • The job's onRun handler executes at the scheduled time.

Diagnostic evidence

A moderator menu item posts a self-post showing the stored job ID and the result of listJobs():

Scheduler Status — 0 active job(s)
Stored cronJobId: 9225215c-f9df-4304-8069-4bf8c4f1da2c
Active jobs: No active jobs found.

The stored ID changes across upgrades (v0.0.13 stored 085a820b-da46-4235-bf05-febac368531d; v0.0.14 stored 9225215c-f9df-4304-8069-4bf8c4f1da2c), confirming the AppUpgrade trigger is firing and runJob() is being called and returning successfully each time. The job simply never appears in listJobs() and never executes.

What I've already tried (ruled out as causes)

  • Cron expression syntax. Failure reproduces with runAt: new Date(...) one-shot jobs, not just cron.
  • runAt vs when parameter. Confirmed against the installed @devvit/public-api types that runAt is the correct parameter; when produces a TS2353 type error. Both forms fail at runtime regardless.
  • Ghost schedules (Reinstalling an application creates a ghost of its schedules #239). Cleanup loop iterating listJobs() and cancelJob() runs at the top of every AppInstall / AppUpgrade trigger before any new runJob() calls. No effect.
  • Self-rescheduling one-shot pattern. Replaced cron with a runAt job that re-schedules itself at the end of onRun. Same failure: the first job never fires, so the chain never starts.
  • Trigger registration. AppInstall and AppUpgrade triggers are confirmed firing (Redis writes happen, console logs appear in devvit logs).
  • Menu items. Menu item onPress handlers execute correctly, including submitPost calls. The app is fully functional except for scheduled execution.
  • App publish status. Bug reproduces on both uploaded and published-unlisted versions.

Question

Is there a known issue with scheduler execution on apps installed in private subreddits, or some other configuration gate I'm missing? Given that runJob() returns successfully but listJobs() shows nothing, it looks like the scheduler is silently dropping registered jobs. Any guidance on how to debug further from the application side would be appreciated.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions