8000 skip inbox runs while the previous run is still active by dominicgisler · Pull Request #84 · dominicgisler/imap-spam-cleaner · GitHub
[go: up one dir, main page]

Skip to content

skip inbox runs while the previous run is still active - #84

Merged
dominicgisler merged 1 commit into
masterfrom
fix/no-overlapping-runs
Oct 27, 2026
Merged

dominicgisler merged 1 commit into
masterfrom
fix/no-overlapping-runs

Conversation

@dominicgisler
Copy link
Copy Markdown
Owner

Inbox jobs were scheduled without singleton mode, so gocron started a new run on time even while the previous run for the same inbox was still going. When a run took longer than the interval (a big inbox, a slow model, or a hung API call), runs piled up:

  • every overlapping run opened another IMAP connection, and servers often cap connections per user (Dovecot's default is 10), so eventually new runs couldn't log in at all
  • with no per-message state, overlapping runs scored the same messages again (paying for duplicate LLM calls) and both tried to move them

Change

gocron.WithSingletonMode(gocron.LimitModeReschedule) on each inbox job. If a run is still active when the next one is due, that run is skipped and the job waits for its next scheduled time. Runs are not queued (LimitModeWait would fire them one after another). Each inbox has its own job, so a slow inbox doesn't hold up the others. -now doesn't use the scheduler and is unaffected.

Documented in docs/configuration/inboxes.md and AGENTS.md.

Testing

  • go build, go vet and golangci-lint pass (0 issues). mkdocs build --strict passes.
  • Checked gocron v2.22.0's behaviour with a scratch test (not committed): a 2.5s task on a 1s schedule for about 6s.
    • without singleton mode: 6 runs, up to 3 at once
    • with LimitModeReschedule: 2 runs, never more than 1 at once

Related: #83 adds request timeouts to the AI providers, so a hung call can no longer hold a run (and, with this PR, its inbox) open forever.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dominicgisler
dominicgisler merged commit 3d454c2 into master Oct 27, 2026
1 check passed
@dominicgisler
dominicgisler deleted the fix/no-overlapping-runs branch October 27, 2026 21:53
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.

1 participant

0