Skip to content

Clean up invalid FuzzerJob entities in cleanup task - #5409

Open
javanlacerda wants to merge 1 commit into
masterfrom
cleanup-invalid-fuzzer-jobs
Open

Clean up invalid FuzzerJob entities in cleanup task#5409
javanlacerda wants to merge 1 commit into
masterfrom
cleanup-invalid-fuzzer-jobs

Conversation

@javanlacerda

@javanlacerda javanlacerda commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

fix b/538683766

Problem

When Job or Fuzzer entities are deleted, orphaned FuzzerJob mappings can linger in Datastore because the cleanup cron task does not detect and prune them.

Solution

  • Added cleanup_invalid_fuzzer_jobs() in src/clusterfuzz/_internal/cron/cleanup.py to delete FuzzerJob entities referencing non-existent Fuzzer or Job entities.
  • Called cleanup_invalid_fuzzer_jobs() in cleanup.py's main().
  • Added unit tests in src/clusterfuzz/_internal/tests/appengine/handlers/cron/cleanup_test.py.

Testing

python butler.py py_unittest -t appengine -p cleanup_test.py
python butler.py lint

Add cleanup_invalid_fuzzer_jobs to cleanup.py to detect and delete
FuzzerJob entities referencing non-existent Fuzzer or Job entities.
Also add unit tests covering this cleanup behavior in cleanup_test.py.
@javanlacerda
javanlacerda requested a review from a team as a code owner August 1, 2026 18:43
@javanlacerda
javanlacerda requested a review from dylanjew August 1, 2026 19:26

@ViniciustCosta ViniciustCosta left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It should be ok to add this in cleanup, but I think this deletion is already done in fuzzer_selection.py here: https://github.com/google/clusterfuzz/blob/master/src/clusterfuzz/_internal/fuzzing/fuzzer_selection.py#L32,

which should be called by the update/delete handlers (ex: https://github.com/google/clusterfuzz/blob/master/src/appengine/handlers/fuzzers.py#L303)

@dylanjew

dylanjew commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

It should be ok to add this in cleanup, but I think this deletion is already done in fuzzer_selection.py here: https://github.com/google/clusterfuzz/blob/master/src/clusterfuzz/_internal/fuzzing/fuzzer_selection.py#L32,

which should be called by the update/delete handlers (ex: https://github.com/google/clusterfuzz/blob/master/src/appengine/handlers/fuzzers.py#L303)

I think there's still a possibility that we're left with dangling FuzzerJobs in the Datastore. If you remove a fuzzer from a job via the /jobs page, we only look for existing fuzzers with the Job.name in Fuzzer.jobs when we go to delete the associated FuzzerJobs here

This means that if there exists a FuzzerJob that doesn't have a corresponding entry in Fuzzer.jobs, we will never delete it. It's not supposed to happen, but it's possible there's a bug somewhere that introduces the invalid config.

We don't validate the Fuzzer actually exists before we schedule FuzzerJobs, so having this repair cron would allow us to recover from these scenarios.

@dylanjew

dylanjew commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

It should be ok to add this in cleanup, but I think this deletion is already done in fuzzer_selection.py here: https://github.com/google/clusterfuzz/blob/master/src/clusterfuzz/_internal/fuzzing/fuzzer_selection.py#L32,
which should be called by the update/delete handlers (ex: https://github.com/google/clusterfuzz/blob/master/src/appengine/handlers/fuzzers.py#L303)

I think there's still a possibility that we're left with dangling FuzzerJobs in the Datastore. If you remove a fuzzer from a job via the /jobs page, we only look for existing fuzzers with the Job.name in Fuzzer.jobs when we go to delete the associated FuzzerJobs here

This means that if there exists a FuzzerJob that doesn't have a corresponding entry in Fuzzer.jobs, we will never delete it. It's not supposed to happen, but it's possible there's a bug somewhere that introduces the invalid config.

We don't validate the Fuzzer actually exists before we schedule FuzzerJobs, so having this repair cron would allow us to recover from these scenarios.

I wonder if we should expand this repair cron to just keep the Fuzzer.jobs list in sync with the FuzzerJobs, rather than only deleting dangling/invalid FuzzerJobs?

@ViniciustCosta

Copy link
Copy Markdown
Collaborator

I wonder if we should expand this repair cron to just keep the Fuzzer.jobs list in sync with the FuzzerJobs, rather than only deleting dangling/invalid FuzzerJobs?

I agree that this might be a cleaner solution

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.

3 participants