fix: cleanup zombie tasks#1276
Conversation
There was a problem hiding this comment.
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)toServerand propagate it through SBT / Scala-CLI load balancers. - Introduce a
CleanUpStaleTasksmessage 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.
There was a problem hiding this comment.
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)toServer,SbtLoadBalancer, andScalaCliLoadBalancer. - Schedule and handle a new
CleanUpStaleTasksmessage inDispatchActor,SbtDispatcher, andScalaCliDispatcher. - Introduce
stale-task-max-ageconfig (default2m) 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.
There was a problem hiding this comment.
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
TaskwithlastSeenand add APIs to refresh it and to purge stale tasks into history. - Add
cleanUpStaleTasks/refreshTaskLastSeenpropagation on both SBT and Scala-CLI load balancers, and refreshlastSeenon incoming progress updates. - Schedule periodic cleanup via
DispatchActor, configurable viastale-task-max-ageinreference.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.
There was a problem hiding this comment.
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
lastSeentracking toTaskplus APIs to refresh and clean up stale tasks at theServerlevel. - Propagate
refreshTaskLastSeen/cleanUpStaleTasksacross SBT and Scala CLI load balancers and dispatchers, and schedule cleanup fromDispatchActor. - Introduce
stale-task-max-ageconfiguration (default2m) 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.
There was a problem hiding this comment.
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
Taskwith alastSeentimestamp and add APIs to refresh it and to clean up stale tasks into server history. - Add scheduled
CleanUpStaleTaskspropagation fromDispatchActorto 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.
Fixes #1275