Skip to content

fix(actions): run every due schedule exactly once per occurrence - #39078

Merged
bircni merged 10 commits into
go-gitea:mainfrom
bircni:fix/actions-schedule-continue-on-failure
Aug 29, 2026
Merged

fix(actions): run every due schedule exactly once per occurrence#39078
bircni merged 10 commits into
go-gitea:mainfrom
bircni:fix/actions-schedule-continue-on-failure

Conversation

@bircni

@bircni bircni commented Aug 24, 2026

Copy link
Copy Markdown
Member

A schedule whose workflow could not be turned into a run returned an error out of the "Start actions schedule tasks" loop, so every remaining due schedule in that pass was skipped. The spec's next run time was not advanced either, so the same failure repeated once a minute, each time writing an admin notice.

Each spec is now advanced to its next occurrence before its run is created. A failure costs that one occurrence instead of the whole pass, and a failed update can no longer insert the same run twice. Failures are counted and reported once per pass, so the admin notice appears per occurrence rather than per minute.

Two related bugs in the same loop:

  1. Offset paging re-queried next <= now after advancing the previous page, so above 50 due specs half of them were skipped until the next pass. It now pages by id.
  2. A valid but unsatisfiable cron such as 0 0 30 2 * stores a negative next, which stayed due forever and created a run on every pass. Those specs are no longer inserted or selected.

The offending workflow itself is still rejected and logged rather than recorded as a failed run. Persisting a startup failure as a visible run is a separate change, since the same code path also covers cross-repo permission denials, where not persisting a run is intentional.

Fixes #39065

A per-spec failure returned from the schedule task loop, so a single
workflow that could not be turned into a run stopped every remaining
due schedule. The spec's next run time was not advanced either, leaving
the same failure to repeat on every pass.

Handle each spec on its own: log the failure, keep going, and always
move the spec to its next occurrence.
@bircni
bircni requested a review from Zettat123 August 24, 2026 17:34
@bircni bircni added the backport/v1.27 This PR should be backported to Gitea 1.27 label Aug 24, 2026
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Aug 24, 2026
@github-actions github-actions Bot added topic/gitea-actions related to the actions of Gitea type/bug labels Aug 24, 2026
@silverwind
silverwind requested a lite review from Copilot August 24, 2026 18:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts the Actions scheduler cron pass so one broken scheduled workflow no longer aborts processing for all other due schedules, and adds regression coverage to ensure valid schedules still run while failing ones don’t block the pass.

Changes:

  • Refactors the scheduler loop to process each due schedule spec independently, logging per-spec failures instead of aborting the full pass.
  • Ensures schedule specs advance to their next occurrence even when run creation fails (to prevent repeated once-per-minute failures).
  • Adds a unit test to verify a failing spec doesn’t prevent other specs from being scheduled and that both specs’ Next timestamps advance.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
services/actions/schedule_tasks.go Refactors scheduled-run processing into a per-spec helper and changes failure handling so the cron pass continues.
services/actions/schedule_tasks_test.go Adds a regression test ensuring one broken spec doesn’t block others and specs advance.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread services/actions/schedule_tasks.go Outdated
Comment thread services/actions/schedule_tasks.go Outdated
Advancing first makes the "always advanced" guarantee hold, which the
skip paths broke, and stops a failed spec update from inserting the
same run again on the next pass.

Two more ways the loop mishandled due specs are fixed as well. Offset
paging skipped specs, because advancing them drops them out of the
"next <= now" filter. A valid but unsatisfiable cron such as
"0 0 30 2 *" stored a negative next that stayed due forever and created
a run on every pass.

Per-spec failures are now counted and reported once per pass, so the
cron task still records an admin notice for them.

Assisted-by: Claude Code:claude-opus-5
@silverwind silverwind changed the title fix(actions): do not let one failing schedule abort the whole cron pass fix(actions): run every due schedule exactly once per occurrence Aug 24, 2026

@silverwind silverwind left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleaned up in 340f111.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Aug 24, 2026
Comment thread services/actions/schedule_tasks.go Outdated
Next: now.Unix(),
ListOptions: db.ListOptions{Page: 1, PageSize: pageSize},
Next: now.Unix(),
BeforeID: beforeID,

@wxiaoguang wxiaoguang Aug 25, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have refactored "db.Iterate" recently.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, can you or your AI remember the useful information? If your AI can't remember, then human should remember.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The best/only way to remember is to put it in docs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you refuse to read and understand code, how do you know what should be put into docs? Whether the contents docs are still correct?

@bircni bircni Aug 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with db.Iterate — it already does this keyset walk

Comment thread services/actions/schedule_tasks.go
Comment thread services/actions/schedule_tasks.go
@wxiaoguang
wxiaoguang marked this pull request as draft August 25, 2026 04:53
lunny and others added 2 commits August 27, 2026 10:23
Add comment clarifying behavior for archived repositories.

Signed-off-by: Lunny Xiao <xiaolunwen@gmail.com>
@bircni
bircni marked this pull request as ready for review August 28, 2026 21:11
@bircni
bircni requested a review from wxiaoguang August 28, 2026 21:11
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Aug 29, 2026
@bircni
bircni enabled auto-merge (squash) August 29, 2026 06:18
@bircni
bircni merged commit 3c0bfe9 into go-gitea:main Aug 29, 2026
23 checks passed
@GiteaBot GiteaBot added this to the 28.0.0 milestone Aug 29, 2026
@GiteaBot GiteaBot added the backport/done All backports for this PR have been created label Aug 29, 2026
@bircni
bircni deleted the fix/actions-schedule-continue-on-failure branch August 29, 2026 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/done All backports for this PR have been created backport/v1.27 This PR should be backported to Gitea 1.27 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. topic/gitea-actions related to the actions of Gitea type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Actions: one invalid scheduled workflow prevents all other scheduled workflows from starting

6 participants