Skip to content

fix(scheduler): persist terminal job state before cache eviction - #2037

Merged
andygrove merged 1 commit into
apache:mainfrom
spiceai:phillip/upstream-terminal-status-order
Jul 15, 2026
Merged

fix(scheduler): persist terminal job state before cache eviction#2037
andygrove merged 1 commit into
apache:mainfrom
spiceai:phillip/upstream-terminal-status-order

Conversation

@phillipleblanc

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #2036

Rationale for this change

Terminal jobs were removed from the scheduler's active cache before their final state was saved. During that window, status requests could fall back to shared state and incorrectly report the job as Running.

Abort handling had a related failure mode. If terminal-state persistence failed, abort_job returned before dispatching cancellation for running executor tasks.

This PR keeps terminal jobs visible in the active cache until persistence finishes. It applies the same ordering to successful, failed, and cancelled jobs.

What changes are included in this PR?

  • Persist terminal state before removing jobs from the active cache.
  • Count only cached Running jobs in the running-job metric.
  • Dispatch executor task cancellation before abort persistence, so save failures cannot suppress cancellation.

Are there any user-facing changes?

No

@milenkovicm milenkovicm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks @phillipleblanc i think this make sense, one comment, should we do retry as part of job state implementation rather than part of task manager? to me it looks like retry ability is implementation specific ? wdyt ?

Comment thread ballista/scheduler/src/state/task_manager.rs Outdated
Keep successful and aborted jobs in the active cache until terminal-state
persistence completes, preventing status readers from observing stale state.
Snapshot graphs before asynchronous work so graph locks are not held across
persistence.

Leave retry policy to JobState implementations because generic saves are not
guaranteed to be idempotent. Exclude terminal entries from running-job metrics
and evict after a failed save so shared state remains authoritative. Dispatch
executor task cancellation before abort persistence so save failures cannot
suppress cancellation.

Add deterministic coverage for success, save failure, lock availability,
metrics, and abort cancellation when persistence fails.
@phillipleblanc
phillipleblanc force-pushed the phillip/upstream-terminal-status-order branch from df258a8 to 610b4c1 Compare July 15, 2026 01:58
@milenkovicm

Copy link
Copy Markdown
Contributor

Thanks @phillipleblanc & @lukekim

@andygrove
andygrove merged commit f45996c into apache:main Jul 15, 2026
17 checks passed
@phillipleblanc
phillipleblanc deleted the phillip/upstream-terminal-status-order branch July 15, 2026 23:47
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.

Terminal jobs can appear as Running while their final state is persisted

4 participants