Repository navigation
Conversation
jobs.private_ssh_key and jobs.agent_auth_token were kept forever. The debug SSH key is only served while the job is running, so it is cleared on every transition to finished (finish, stop, force_finish, bulk_force_finish). force_change is used because bulk_force_finish loads the job without that column. The agent auth token is still needed by post-job processing for a while after the job finishes, so it is cleared later by a new periodic worker, FinishedJobCleaner (START_FINISHED_JOB_CLEANER, off by default). It walks finished jobs in (finished_at, id) order, which the existing jobs index serves, and clears the token and the SSH key of jobs finished more than FINISHED_JOB_CLEANER_CUTOFF_DAYS (default 3) ago. Each tick handles at most FINISHED_JOB_CLEANER_BATCH_SIZE rows (default 250) and sleeps FINISHED_JOB_CLEANER_NAPTIME_MS (default 1000) while there is work, or FINISHED_JOB_CLEANER_LONGNAPTIME_MS (default 600000) once caught up. Progress is stored in the new job_cleanup_cursors table, so a restart resumes where it stopped, and the cursor row is locked with SKIP LOCKED so only one replica works at a time. Updates are guarded by the same predicates, so a second pass changes nothing.
Once a job is finished, the only part of jobs.request that is still read is the SEMAPHORE_GIT_* env vars, which the public job API appends to the job spec. The commands and the rest of the payload duplicate jobs.spec. FinishedJobCleaner now also reduces the request of jobs finished before its cutoff to those env vars (JobRequest.finished_payload/1), kept in their original shape and under their original key. Jobs that are not finished, or finished within the cutoff, are not touched. The cursor name is bumped so the worker makes a new pass from the oldest finished job. The trim cannot be undone, so a row is only rewritten when the public job API would serve exactly the same git env vars from the trimmed request; other rows are left as they are and counted. A row deleted by retention while a tick runs is skipped without failing the batch.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 83562c6d8a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| case List.last(batch) do | ||
| nil -> :ok | ||
| {finished_at, id} -> move_cursor(worker.cursor_name, finished_at, id) |
There was a problem hiding this comment.
Ensure backdated copies cannot fall behind the cursor
When Job.create_copy/2 runs during the initial v2 sweep, it can read an old job before this transaction trims it and insert a new finished row containing the full request while preserving the source's historical finished_at (zebra/lib/zebra/models/job.ex:119,130). Advancing the cursor to the batch's last (finished_at, id) means that copy is permanently skipped whenever its timestamp is earlier than the batch endpoint (or its UUID sorts behind the cursor), so some requests remain untrimmed until another cursor-version reset. Trim the request when creating a copy or use a scan strategy that eventually revisits backdated inserts.
Useful? React with 👍 / 👎.
3888c4a to
fcfb1d1
Compare
Trim the request of old finished jobs to their git env vars.
Builds on the finished job cleaner (base branch of this PR). Past the same cutoff, the worker replaces a finished job's stored request with a payload that keeps only the
SEMAPHORE_GIT_*env vars, in both the current and the legacy shape, which is all the public job API reads after a job finishes. The write happens only when the git vars extracted before and after are identical; otherwise the row is left alone and counted in afinished_job_cleaner.trim_skippedmetric. Running jobs are never touched. A new cursor name starts a fresh pass.Tests: the public job API returns the same git vars before and after the trim in both shapes,
create_copystill works on a trimmed job, and a second pass changes nothing.