Skip to content

gce launcher: a job lost to a spot preemption is rerun once its run completes - #217

Merged
SSFSKIM merged 5 commits into
mainfrom
gce-preempt-rerun
Nov 19, 2026
Merged

SSFSKIM merged 5 commits into
mainfrom
gce-preempt-rerun

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Why

When GCE preempts a spot VM mid-job, GitHub fails the job and a human reruns it (e.g. MAWS run 44468141412, static-local on ci-kit-gce-ht8ps9vecf, preempted 52 s after creation; about 9 a week). The launcher already finalizes such a row preempted with the job it held; it now reruns that job itself.

Design

  • Owed. finalRow marks a row ending preempted with a job rerun: {state: 'owed'}. Every end goes through it, so GCE preemptions and EC2 Server.SpotInstanceTermination are both covered. The ledger row is the persisted state, so it survives a restart. The end column reads preempted, rerun owed.
  • Checked at a modest cadence. Once per tick, at most every 5 min (process-local), settleReruns reads each run that is owed a rerun. That is one conditional GET run per run, nothing for rows that owe nothing. A run still in progress is left alone, because GitHub refuses reruns before a run completes.
  • Fired once. Once the run completes, the launcher reads the lost job (GET actions/jobs/<id>). It reruns only if the job's run_attempt equals the run's, the run concluded failure and the job concluded failure:
    • one owed job: POST actions/jobs/<id>/rerun, which reruns that job plus the jobs that need it and leaves genuine red jobs alone;
    • several owed jobs in one run: POST runs/<id>/rerun-failed-jobs.
      The row then settles to fired (with the attempt and how) or dropped (with the reason: cancelled, success, already re-attempted, the job didn't fail).
  • Bounded. A fired rerun moves the run to its next attempt, so the attempt check stops a second rerun of the same attempt, even across overlapping ticks, restarts or a stale writer. An attempt that fails on its own is left to a human.
  • Failures. A 4xx refusal is dropped and logged at ERROR (rerun-refused). A 5xx, network error or rate limit leaves the rerun owed. Rows leave the ledger's 26 h window, so a rerun that is never settled ages out.
  • Ledger store. A final row now takes exactly one more write: settling its owed rerun (settlesRerun). Every other rule that keeps a row from moving back is unchanged.

Credential

The launcher uses the ci-kit-runners App installation token unscoped (gce/launcher/github.mjs, no scope). The App's permissions (GET /apps/ci-kit-runners) include actions: write, and the design doc records that the installation held it on 2026-10-17. Nothing to widen.

Tests

New test/gce/launcher-rerun.test.mjs runs against fake-world.mjs, which now has run/job reads and reruns that GitHub-style refuse a run still in progress. It covers:

  • owed recorded, and none for a row with no job;
  • not fired while the run is in progress, at the cadence;
  • fired once on a failed completion, and not again when the next attempt fails;
  • dropped for cancelled, success, a newer attempt, and a job that didn't fail;
  • survives a restart;
  • several lost jobs use rerun-failed-jobs once;
  • refused is dropped with an ERROR, transient stays owed.

node --test test/gce/*.test.mjs: 531 pass.

Not deployed.

Since review (a3cdcd1)

Some of the design above has changed:

  • Lost runner only: a rerun fires only when the job's runner was lost. The evidence is a step that never concluded (as in MAWS run 44468141412), or a job that ended at or after the VM's preemption (a graceful guest shutdown). A red job that reported before its VM was reclaimed is dropped as not a lost runner.
  • Read cadence: each owed run is read at most every 5 min, at most 5 runs per tick. The read times are kept in the server's shared state (rerunChecks), because the server builds a new Launcher every tick.
  • Attempt cap: no automatic rerun once the run is at attempt 3 or higher (attempt cap).
  • Settling the row: ledger.settleRerun re-reads the stored row and changes only its rerun, and only while that row still owes one for the same job. upsert's rule that a final row is never rewritten is unchanged.
  • Refusals: an already running refusal (another launcher's rerun won) stays owed, and a later read settles it from the run's attempt.
  • Served repos: a repo no longer in gce.json, or a public repo's run for an event the pool doesn't serve, is dropped as not served.
  • Deferred: remaining items are tracked in GCE launcher: deferred edge cases (tech debt) #218 and ci-gate: deferred edge cases (tech debt) #201.

Sminos-Session: CI-opt#a45b97a3 (doperpowers on macbook)

…ompletes

A row finalized `preempted` while it held a job now owes that job's run a rerun
(`rerun: {state: 'owed'}` on the ledger row, from finalRow, so GCE and EC2 alike).
GitHub reruns only completed runs, so every 5 minutes the launcher reads each run
owed one and, once it has completed, settles the row once: when the run failed in
the attempt the lost job ran in and the job failed, it reruns the job
(actions/jobs/<id>/rerun) or, for several lost jobs of one run, the run's failed
jobs (`fired`); otherwise (cancelled, green, already re-attempted, the job not
failed) `dropped` with the reason. The attempt check makes a second rerun of one
attempt impossible across overlapping ticks and restarts. The ledger store lets a
final row take that one write; a refused rerun logs at ERROR, a transient failure
stays owed.

Sminos-Session: CI-opt#a45b97a3 (doperpowers on macbook)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 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-19T06:23:43.063665Z d00249e 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.

Repeated preemptions would otherwise chain reruns one attempt after another.
A completed run at run_attempt >= 3 settles its owed reruns as dropped
('attempt cap') without reading its jobs.

Sminos-Session: CI-opt#a45b97a3 (doperpowers on macbook)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d00249e468

ℹ️ 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".

Comment thread gce/launcher/launcher.mjs Outdated
Comment on lines +899 to +900
if (!owed.length || this.now() - (this.rerunsCheckedAt ?? -Infinity) < RERUN_EVERY_MS) return;
this.rerunsCheckedAt = this.now();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the rerun polling timestamp across production ticks

In the deployed launcher, reconcile() in gce/launcher/server.mjs constructs a new Launcher for every tick, so this.rerunsCheckedAt is always undefined when this guard runs. Consequently, every owed run is polled on every scheduled or webhook-triggered tick—potentially every 10 seconds—instead of every five minutes. This adds up to 30 times the intended REST requests while a lost job's run remains active, including repeated requests during transient failures. Keep the timestamp in process-lived dependencies, as the server already does for stockout and provider state; the current cadence test misses this because it reuses one launcher across ticks.

Useful? React with 👍 / 👎.

From the review of 3dc2e4f:
- A failed job is rerun only when its runner was lost: a step GitHub never
  heard end, or the job's end at or after the VM's preemption
  (logic.mjs lostRunner). A red that reported before its VM was
  reclaimed settles as dropped 'not a lost runner'.
- The per-run read times live in the server's shared state (rerunChecks),
  since every tick builds a new Launcher; each run owed one is read at
  most every 5 min, at most 5 runs a tick, least recently read first.
- Settling rewrites only the stored row's `rerun`, read fresh, and only
  while it still owes one for the same job (ledger-store settleRerun);
  upsert's final-row rule is unchanged again.
- A refusal because the run is running again (another launcher's rerun
  won) stays owed; a later read settles it from the attempt.
- A repo no longer in gce.json, or a public repo's run for an event the
  pool does not serve, settles as dropped 'not served'.

Deferred items are recorded in #218 and #201.

Sminos-Session: CI-opt#a45b97a3 (doperpowers on macbook)
…time budget per sweep

From the second review of a3cdcd1:
- lostRunner: a step that concluded failure before the VM's preemption
  makes the job a real red, even when the preemption cut a later step
  (an upload) short. A failed step that ended at or after the preemption
  is the guest's shutdown failing it (sandbox run 38927837115), and still
  counts as lost.
- The sweep starts no GitHub or ledger call past 30 s in a tick; what it
  leaves stays owed, its run read first next tick. The writes recording a
  rerun just sent still run.

Two more deferred items are on #218.

Sminos-Session: CI-opt#a45b97a3 (doperpowers on macbook)
…runner

Only a failed step whose completed_at is before the preemption makes the
job a real red; one with no time leaves the unfinished-step and late-end
signals to decide. Deferred items from the third review are on #218.

Sminos-Session: CI-opt#a45b97a3 (doperpowers on macbook)
@SSFSKIM
SSFSKIM merged commit 5b35812 into main Nov 19, 2026
4 checks passed
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.

1 participant