Skip to content

fix: cleanup zombie tasks#1276

Draft
warcholjakub wants to merge 5 commits into
scalacenter:mainfrom
warcholjakub:fix/zombie-tasks
Draft

fix: cleanup zombie tasks#1276
warcholjakub wants to merge 5 commits into
scalacenter:mainfrom
warcholjakub:fix/zombie-tasks

Conversation

@warcholjakub
Copy link
Copy Markdown
Collaborator

Fixes #1275

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds periodic cleanup of stale queued tasks in the balancer so dispatchers don’t keep tracking tasks indefinitely when they become “stuck”.

Changes:

  • Add cleanUpStaleTasks(maxAge) to Server and propagate it through SBT / Scala-CLI load balancers.
  • Introduce a CleanUpStaleTasks message handled by both dispatchers to prune old mailbox entries.
  • Schedule periodic cleanup from DispatchActor.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
balancer/src/main/scala/org/scastie/balancer/Server.scala Adds mailbox pruning based on task timestamp age.
balancer/src/main/scala/org/scastie/balancer/ScalaCliLoadBalancer.scala Propagates stale-task cleanup across Scala-CLI servers.
balancer/src/main/scala/org/scastie/balancer/ScalaCliDispatcher.scala Handles cleanup message and updates balancer state/logging.
balancer/src/main/scala/org/scastie/balancer/SbtLoadBalancer.scala Propagates stale-task cleanup across SBT servers.
balancer/src/main/scala/org/scastie/balancer/SbtDispatcher.scala Handles cleanup message and updates balancer state/logging.
balancer/src/main/scala/org/scastie/balancer/DispatchActor.scala Defines cleanup message and schedules periodic cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread balancer/src/main/scala/org/scastie/balancer/DispatchActor.scala Outdated
Comment thread balancer/src/main/scala/org/scastie/balancer/SbtDispatcher.scala
Comment thread balancer/src/main/scala/org/scastie/balancer/Server.scala Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds periodic “stale task” cleanup to the balancer so that server mailboxes don’t stay artificially busy forever when tasks stop progressing, with configuration and unit tests around the cleanup logic.

Changes:

  • Add cleanUpStaleTasks(maxAge) to Server, SbtLoadBalancer, and ScalaCliLoadBalancer.
  • Schedule and handle a new CleanUpStaleTasks message in DispatchActor, SbtDispatcher, and ScalaCliDispatcher.
  • Introduce stale-task-max-age config (default 2m) and add tests validating cleanup behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
balancer/src/main/scala/org/scastie/balancer/Server.scala Adds per-server mailbox cleanup based on task age.
balancer/src/main/scala/org/scastie/balancer/SbtLoadBalancer.scala Propagates cleanup across SBT servers.
balancer/src/main/scala/org/scastie/balancer/ScalaCliLoadBalancer.scala Propagates cleanup across Scala-CLI servers.
balancer/src/main/scala/org/scastie/balancer/SbtDispatcher.scala Handles cleanup message and updates balancer/state reporting.
balancer/src/main/scala/org/scastie/balancer/ScalaCliDispatcher.scala Handles cleanup message and updates balancer/state reporting.
balancer/src/main/scala/org/scastie/balancer/DispatchActor.scala Schedules periodic cleanup + ping, and cancels schedules on stop.
balancer/src/main/resources/reference.conf Adds stale-task-max-age default.
balancer/src/test/scala/org/scastie/balancer/LoadBalancerTest.scala Adds unit tests for cleanup behavior on Server and both balancers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread balancer/src/main/scala/org/scastie/balancer/Server.scala Outdated
Comment thread balancer/src/main/scala/org/scastie/balancer/DispatchActor.scala Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces stale-task tracking/cleanup in the balancer layer to prevent long-running or “stuck” tasks from indefinitely occupying server mailboxes, and wires periodic cleanup into the dispatch lifecycle.

Changes:

  • Extend Task with lastSeen and add APIs to refresh it and to purge stale tasks into history.
  • Add cleanUpStaleTasks / refreshTaskLastSeen propagation on both SBT and Scala-CLI load balancers, and refresh lastSeen on incoming progress updates.
  • Schedule periodic cleanup via DispatchActor, configurable via stale-task-max-age in reference.conf, and add tests for the new cleanup behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
balancer/src/main/scala/org/scastie/balancer/Server.scala Adds lastSeen to tasks plus server-level refresh/cleanup logic.
balancer/src/main/scala/org/scastie/balancer/SbtLoadBalancer.scala Adds refresh/cleanup propagation across SBT servers.
balancer/src/main/scala/org/scastie/balancer/ScalaCliLoadBalancer.scala Adds refresh/cleanup propagation across Scala-CLI servers.
balancer/src/main/scala/org/scastie/balancer/SbtDispatcher.scala Refreshes task lastSeen on progress and handles periodic cleanup/logging.
balancer/src/main/scala/org/scastie/balancer/ScalaCliDispatcher.scala Refreshes task lastSeen on progress and handles periodic cleanup/logging.
balancer/src/main/scala/org/scastie/balancer/DispatchActor.scala Introduces scheduled periodic cleanup (and refactors ping scheduling/cancellation).
balancer/src/main/resources/reference.conf Adds stale-task-max-age configuration setting.
balancer/src/test/scala/org/scastie/balancer/LoadBalancerTest.scala Adds unit tests covering stale cleanup + lastSeen refresh.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread balancer/src/main/scala/org/scastie/balancer/DispatchActor.scala Outdated
Comment thread balancer/src/main/scala/org/scastie/balancer/Server.scala Outdated
Comment thread balancer/src/main/scala/org/scastie/balancer/SbtDispatcher.scala Outdated
Comment thread balancer/src/main/scala/org/scastie/balancer/ScalaCliDispatcher.scala Outdated
@warcholjakub warcholjakub requested a review from Copilot March 18, 2026 19:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses “zombie” (stuck/stale) tasks in the balancer—particularly impacting SBT runners—by tracking task liveness and periodically cleaning up tasks that have not been “seen” recently.

Changes:

  • Add lastSeen tracking to Task plus APIs to refresh and clean up stale tasks at the Server level.
  • Propagate refreshTaskLastSeen / cleanUpStaleTasks across SBT and Scala CLI load balancers and dispatchers, and schedule cleanup from DispatchActor.
  • Introduce stale-task-max-age configuration (default 2m) and add unit tests for stale-task cleanup behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
balancer/src/test/scala/org/scastie/balancer/LoadBalancerTest.scala Adds tests for server and load balancer stale-task cleanup and lastSeen refresh behavior.
balancer/src/main/scala/org/scastie/balancer/Server.scala Extends Task with lastSeen; implements per-server refresh and cleanup of stale tasks.
balancer/src/main/scala/org/scastie/balancer/ScalaCliLoadBalancer.scala Adds balancer-level propagation for task lastSeen refresh and stale cleanup.
balancer/src/main/scala/org/scastie/balancer/ScalaCliDispatcher.scala Refreshes task lastSeen on progress updates and handles scheduled stale cleanup + logging.
balancer/src/main/scala/org/scastie/balancer/SbtLoadBalancer.scala Adds balancer-level propagation for task lastSeen refresh and stale cleanup.
balancer/src/main/scala/org/scastie/balancer/SbtDispatcher.scala Refreshes task lastSeen on progress updates and handles scheduled stale cleanup + logging.
balancer/src/main/scala/org/scastie/balancer/DispatchActor.scala Schedules periodic Ping and CleanUpStaleTasks, and cancels schedules on stop.
balancer/src/main/resources/reference.conf Adds stale-task-max-age default configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread balancer/src/main/scala/org/scastie/balancer/SbtDispatcher.scala
Comment thread balancer/src/main/scala/org/scastie/balancer/Server.scala Outdated
@warcholjakub warcholjakub requested a review from Copilot March 18, 2026 19:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #1275 by adding a “stale task” tracking mechanism in the balancer so tasks that stop reporting progress don’t remain indefinitely in runner status (i.e., “zombie tasks”), with periodic cleanup driven by the dispatch layer.

Changes:

  • Extend Task with a lastSeen timestamp and add APIs to refresh it and to clean up stale tasks into server history.
  • Add scheduled CleanUpStaleTasks propagation from DispatchActor to both SBT and Scala CLI dispatchers/load balancers.
  • Add configuration for staleness threshold (stale-task-max-age) and unit tests covering cleanup/refresh behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
balancer/src/main/scala/org/scastie/balancer/Server.scala Adds lastSeen, refreshTaskLastSeen, and cleanUpStaleTasks to support stale task eviction.
balancer/src/main/scala/org/scastie/balancer/SbtLoadBalancer.scala Propagates refresh/cleanup across servers for SBT.
balancer/src/main/scala/org/scastie/balancer/ScalaCliLoadBalancer.scala Propagates refresh/cleanup across servers for Scala CLI.
balancer/src/main/scala/org/scastie/balancer/SbtDispatcher.scala Refreshes lastSeen on progress and performs periodic stale cleanup with status updates.
balancer/src/main/scala/org/scastie/balancer/ScalaCliDispatcher.scala Refreshes lastSeen on progress and performs periodic stale cleanup with status updates.
balancer/src/main/scala/org/scastie/balancer/DispatchActor.scala Schedules periodic cleanup and forwards cleanup messages to both dispatchers; cancels schedules on stop.
balancer/src/main/resources/reference.conf Introduces stale-task-max-age default configuration.
balancer/src/test/scala/org/scastie/balancer/LoadBalancerTest.scala Adds tests validating cleanup/refresh semantics and propagation across load balancers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

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.

SBT Runners status zombie tasks?

2 participants