Skip to content

Add endpoint deleting workflow run #34337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 38 commits into
base: main
Choose a base branch
from

Conversation

NorthRealm
Copy link
Contributor

@NorthRealm NorthRealm commented May 1, 2025

Add endpoint deleting workflow run
Resolves #26219

/claim #26219

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 1, 2025
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels May 1, 2025
@NorthRealm NorthRealm marked this pull request as ready for review May 2, 2025 10:22
@github-actions github-actions bot added modifies/translation modifies/templates This PR modifies the template files labels May 3, 2025
@NorthRealm NorthRealm requested a review from ChristopherHX May 7, 2025 09:19
@wxiaoguang
Copy link
Contributor

FYI: there are some "Details" in Clear the data/log for jobs in Gitea Actions that are too old #24256 , if these are all addressed, then we could move on.

@NorthRealm
Copy link
Contributor Author

FYI: there are some "Details" in Clear the data/log for jobs in Gitea Actions that are too old #24256 , if these are all addressed, then we could move on.

You mean there's somewhere missing out in this pr?

@wxiaoguang
Copy link
Contributor

You mean there's somewhere missing out in this pr?

Just FYI, I haven't fully read this PR or that issue, I just recalled there are some "details".

@NorthRealm
Copy link
Contributor Author

You mean there's somewhere missing out in this pr?

Just FYI, I haven't fully read this PR or that issue, I just recalled there are some "details".

I referred a lot from DeleteRepositoryDirectly in services/repository/delete.go.
According to #24256 #26275, most concerns in details should be addressed already in this PR.

update NumActionRuns and NumClosedActionRuns of Repository.

Do we have to touch these explicitly?

@wxiaoguang
Copy link
Contributor

update NumActionRuns and NumClosedActionRuns of Repository.

Do we have to touch these explicitly?

IIRC there is a updateRepoRunsNumbers

@NorthRealm
Copy link
Contributor Author

update NumActionRuns and NumClosedActionRuns of Repository.

Do we have to touch these explicitly?

IIRC there is a updateRepoRunsNumbers

Then I think #24256 details are all addressed. I just updated the function deleting ActionTaskOutput
Just simply delete database records, and files on storage.

@ChristopherHX
Copy link
Contributor

ChristopherHX commented May 8, 2025

Since you delete potentially the only task an ephemeral act_runner has ever run, please delete the affected runners first.

one of

  • call cleanup ephemeral runners first
  • delete affected ephemeral act_runners
  • I would make ephemeral runners fully delete directly before formally finishing the task

@NorthRealm
Copy link
Contributor Author

NorthRealm commented May 8, 2025

Do you mean there's a chance where ephemeral doesn't get deleted from database because of missing task record?
I just looked at services/actions/task.go, in PickTask, deletion is triggered by runner fetching tasks.
This is out of context of this pr imo. Surely can have a better way to delete ephemeral runners.

@ChristopherHX
Copy link
Contributor

Do you mean there's a chance where ephemeral doesn't get deleted from database because of missing task record?

Yes exactly, the pickTask detection is only triggered when trying to exploit gitea.
A well behaving runner will never call pickTask that way.

Calling this method before deletion is for me in scope of secure deletion

func CleanupEphemeralRunners(ctx context.Context) error {

@NorthRealm
Copy link
Contributor Author

NorthRealm commented May 8, 2025

Do you mean there's a chance where ephemeral doesn't get deleted from database because of missing task record? I just looked at services/actions/task.go, in PickTask, deletion is triggered by runner fetching tasks. This is out of context of the pr imo. Surely can have a better way to delete ephemeral runners.

Do you mean there's a chance where ephemeral doesn't get deleted from database because of missing task record?

Yes exactly, the pickTask detection is only triggered when trying to exploit gitea. A well behaving runner will never call pickTask that way.

Calling this method before deletion is for me in scope of secure deletion

func CleanupEphemeralRunners(ctx context.Context) error {

So to say, under current ephemeral runner implementation that relies on existing task record deliberately throwing error killing remote runner daemon, "ephemeral" will be broken (fetching another task).

@NorthRealm
Copy link
Contributor Author

NorthRealm commented May 8, 2025

@ChristopherHX
Isn't it possible/ok to just immediately delete ephemeral runner once task status gets updated to done (Success, Failure, Cancelled, Skipped)? In routers/api/actions/runner/runner.go at task.Status.IsDone() In UpdateTask

@NorthRealm
Copy link
Contributor Author

Anyway let us keep focus on deletion in this pr.

@ChristopherHX
Copy link
Contributor

So to say, under current ephemeral runner implementation that relies on existing task record deliberately throwing error killing remote runner daemon, "ephemeral" will be broken (fetching another task).

Yes also CleanupEphemeralRunners will no longer delete the runner after the task is away.

routers/api/actions/runner/runner.go at task.Status.IsDone() In UpdateTask

The Gitea code is more complex. You can set the task status to completed by

  • abandoning jobs
  • cancel jobs

UpdateTask is skipped.

IMHO a single CleanupEphemeralRunners call before deleting anything else and I am fine.

@ChristopherHX
Copy link
Contributor

ChristopherHX commented May 8, 2025

Anyway let us keep focus on deletion in this pr.

Sure we can, if you think this is not related to your pr.

I am silent now about this topic, no problem :)

@NorthRealm
Copy link
Contributor Author

NorthRealm commented May 8, 2025

Anyway let us keep focus on deletion in this pr.

Sure we can, if you think this is not related to your pr.

I am silent now about this topic, no problem :)

@ChristopherHX One more thing. Surely can have a more solid way to delete ephemeral runners. Basically for a ephemeral need to track whether it has taken a task or not. A solution I can come up with is adding another boolean field for ephemeral runner, which is set to true once it takes a task.

@NorthRealm
Copy link
Contributor Author

Anyway let us keep focus on deletion in this pr.

Sure we can, if you think this is not related to your pr.

I am silent now about this topic, no problem :)

@ChristopherHX I just tried adding CleanupEphemeralRunners to modules/actions/run.go and cannot compile. Import cycle error.

@ChristopherHX
Copy link
Contributor

@ChristopherHX I just tried adding CleanupEphemeralRunners to modules/actions/run.go and cannot compile. Import cycle error.

Just a random idea:
Move your code from actions modules to actions services? so both are in the same module.

AFAIK Web and rest api can reference service, but I didn't think about where your deletion code is, relative to my cleanup function.

Anything else about ephemeral runners might be better discussed in a new issue / proposal. The old code works, because tasks that are finished within 24h are never deleted yet.

@NorthRealm
Copy link
Contributor Author

@ChristopherHX I just tried adding CleanupEphemeralRunners to modules/actions/run.go and cannot compile. Import cycle error.

Just a random idea: Move your code from actions modules to actions services? so both are in the same module.

AFAIK Web and rest api can reference service, but I didn't think about where your deletion code is, relative to my cleanup function.

Anything else about ephemeral runners might be better discussed in a new issue / proposal. The old code works, because tasks that are finished within 24h are never deleted yet.

Just pushed new commits. Please check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 Bounty claim lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/translation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Delete workflow runs
6 participants