Skip to content

zebra: drop job credentials once they are no longer usable - #1399

Open
loadez wants to merge 2 commits into
mainfrom
mf/zebra-finished-job-cleaner
Open

loadez wants to merge 2 commits into
mainfrom
mf/zebra-finished-job-cleaner

Conversation

@loadez

@loadez loadez commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Drop job credentials once they are no longer usable.

  • The debug SSH key is cleared on every terminal transition (finish, stop, force finish, bulk force finish). It is only served while a job is running.
  • The agent auth token is still needed by post-job processing, so it is not cleared at finish. A new periodic worker, FinishedJobCleaner, clears the token (and the SSH key, for older rows) on jobs finished more than a configurable number of days ago (default 3).
  • The worker walks finished jobs by (finished_at, id) on the existing index in throttled batches, keeps its position in a new job_cleanup_cursors table (migration in github_hooks), runs on one replica at a time (SKIP LOCKED), skips rows deleted mid-batch, and is off by default behind START_FINISHED_JOB_CLEANER.

Settings: FINISHED_JOB_CLEANER_CUTOFF_DAYS (3), FINISHED_JOB_CLEANER_BATCH_SIZE (250), FINISHED_JOB_CLEANER_NAPTIME_MS (1000), FINISHED_JOB_CLEANER_LONGNAPTIME_MS (600000).

Deploy order: github_hooks (migration), then zebra, then enable the flag on a single deployment.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T13:08:21.373205Z 3888c4a PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.
The cleaner used to update its batch with a plain UPDATE, which waits on
rows held by another transaction (for example a retention worker that
claimed the row) until the query times out, failing the tick.

The batch rows are now claimed with FOR UPDATE SKIP LOCKED and the batch
is cut before the first row that could not be claimed. The cursor stops
there, so the row is visited again on the next tick, which comes after
the short nap.

New metrics: finished_job_cleaner.locked (tick skipped because another
instance holds the cursor), finished_job_cleaner.lock_skipped (rows cut
from a batch) and finished_job_cleaner.cursor_lag_seconds (how far the
cursor is behind the cutoff, 0 once caught up).

The test mirror of job_cleanup_cursors now uses timestamp(6) for
updated_at, matching the github_hooks migration.
@loadez
loadez force-pushed the mf/zebra-finished-job-cleaner branch from 3888c4a to fcfb1d1 Compare December 4, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants