Skip to content

Delete live Kubernetes task Jobs after pre-start failure - #134

Draft
warp-agent-staging[bot] wants to merge 2 commits into
mainfrom
factory/k8s-unschedulable-job-cleanup
Draft

Delete live Kubernetes task Jobs after pre-start failure#134
warp-agent-staging[bot] wants to merge 2 commits into
mainfrom
factory/k8s-unschedulable-job-cleanup

Conversation

@warp-agent-staging

@warp-agent-staging warp-agent-staging Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes REMOTE-3079: after an unschedulable timeout the Kubernetes backend reported ExecuteTask failure but left the still-Pending Job in place. TTLSecondsAfterFinished never starts until the Job completes, so cluster autoscaler could later schedule the orphaned pod against an already-ended execution.

Changes

  • Delete the task Job on pre-start / unfinished failures (unschedulable timeout, image pull, watch errors) unless NoCleanup is set.
  • Keep finished JobFailed Jobs, and Jobs whose task container already terminated, for post-mortem TTL cleanup. Successful Jobs still delete immediately.
  • Bound ExecuteTask Job deletion with context.WithTimeout(context.Background(), BackendShutdownTimeout) so a wedged API server cannot block the worker.
  • Implement KubernetesBackend.CancelTask to delete the Job (no-op when NoCleanup is set). ExecuteTask context cancellation still only stops local watching so worker disruption can preserve running Jobs.

Verification

  • gofmt -s clean on the changed files
  • go vet ./...
  • go test ./...
  • go build -v ./...
  • Fake-client tests: unschedulable timeout deletes the Job; image pull failure deletes the Job; terminated task container before JobFailed retains the Job; blocking delete returns at BackendShutdownTimeout; NoCleanup retains unschedulable Jobs; CancelTask deletes (and is a no-op for missing Jobs / NoCleanup); existing success, JobFailed, and context-cancel retention tests still pass

REMOTE-2831 (retry/timeout policy for pre-start k8s infra failures) is complementary and out of scope.

Unschedulable timeout left the Job Pending, so TTL never started and
autoscaler could still boot the agent against an already-ended
execution. Delete Jobs that fail before JobFailed, and make CancelTask
delete the Job. Preserve NoCleanup, finished-JobFailed post-mortem
retention, and ExecuteTask context-cancel retention for worker disruption.
@warp-agent-staging

Copy link
Copy Markdown
Contributor Author

This PR was generated with Warp.

Comment @warp-factory on this PR to send it follow-up work.

View run View conversation View on Slack

Keep post-mortem TTL cleanup when the task container already exited
before JobFailed arrives. Bound ExecuteTask Job deletion with an
independent BackendShutdownTimeout so a wedged API server cannot
block the worker forever.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants