feat: skip autostop reminder for active workspaces (#26772)

This commit is contained in:
Jon Ayers
2026-06-30 00:24:29 -05:00
committed by GitHub
parent 64eb60d464
commit 7179be24fa
5 changed files with 264 additions and 23 deletions
+24 -1
View File
@@ -873,6 +873,10 @@ WHERE
-- * The workspace is not dormant and its owner is not suspended.
-- * The build has a deadline in the future (we never remind about a stop already due).
-- * The template opts in (time_til_autostop_notify > 0) and now is within the lead window.
-- * The owner is not active in a way that can keep the workspace
-- alive: either they have not used it within the active threshold
-- (15 minutes), or activity bumps are disabled, or the max_deadline
-- ceiling pins the stop inside the lead window so a bump cannot save it.
-- * A reminder has not yet been sent for THIS deadline.
--
-- NOTE: time_til_autostop_notify has no upper bound. If it exceeds a
@@ -893,7 +897,26 @@ WHERE
workspace_builds.deadline > @now::timestamptz AND
templates.time_til_autostop_notify > 0 AND
workspace_builds.deadline <= (@now::timestamptz) + (INTERVAL '1 millisecond' * (templates.time_til_autostop_notify / 1000000)) AND
workspace_builds.notified_autostop_deadline != workspace_builds.deadline
workspace_builds.notified_autostop_deadline != workspace_builds.deadline AND
-- Keep the reminder unless the user is active AND an activity bump can
-- still move the deadline out of the lead window. This block is the
-- exact complement of the skip-guard in shouldRemindAutostop (Go)
-- (userActive AND bumpEnabled AND NOT maxDeadlineTraps), so the
-- pre-filter and the re-check agree on the boundary.
(
-- Not used within the active threshold (15 minutes). This is the exact
-- complement of the < autostopReminderActiveThreshold guard in
-- shouldRemindAutostop (Go); keep the two in sync.
(@now :: timestamptz) - workspaces.last_used_at >= INTERVAL '15 minutes'
-- ...or activity bumps are disabled (deadline can't move)...
OR templates.activity_bump <= 0
-- ...or the hard max_deadline ceiling is within the lead window, so
-- the workspace will stop regardless of activity.
OR (
workspace_builds.max_deadline != '0001-01-01 00:00:00+00'::timestamptz
AND workspace_builds.max_deadline <= (@now::timestamptz) + (INTERVAL '1 millisecond' * (templates.time_til_autostop_notify / 1000000))
)
)
)
)
AND workspaces.deleted = 'false'