From cda7a9d4f453a9c197016050a9f626435b06a252 Mon Sep 17 00:00:00 2001 From: Jon Ayers Date: Wed, 1 Jul 2026 21:24:42 -0500 Subject: [PATCH] fix: reword autostop reminder to use relative countdown (#26948) --- coderd/autobuild/lifecycle_executor.go | 4 ++-- coderd/autobuild/lifecycle_executor_test.go | 6 +++--- .../migrations/000535_autostop_reminder_wording.down.sql | 2 ++ .../migrations/000535_autostop_reminder_wording.up.sql | 3 +++ coderd/notifications/notifications_test.go | 4 ++-- .../smtp/TemplateWorkspaceAutostopReminder.html.golden | 7 +++---- .../webhook/TemplateWorkspaceAutostopReminder.json.golden | 6 +++--- 7 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 coderd/database/migrations/000535_autostop_reminder_wording.down.sql create mode 100644 coderd/database/migrations/000535_autostop_reminder_wording.up.sql diff --git a/coderd/autobuild/lifecycle_executor.go b/coderd/autobuild/lifecycle_executor.go index c2dee11f92..af386bc9a0 100644 --- a/coderd/autobuild/lifecycle_executor.go +++ b/coderd/autobuild/lifecycle_executor.go @@ -565,8 +565,8 @@ func (e *Executor) runOnce(t time.Time) Stats { ws.OwnerID, notifications.TemplateWorkspaceAutostopReminder, map[string]string{ - "workspace": ws.Name, - "deadline": reminderDeadline.UTC().Format(time.RFC1123), + "workspace": ws.Name, + "timeTilShutdown": humanize.Time(reminderDeadline), }, "lifecycle_executor", // Associate this notification with all the related entities. diff --git a/coderd/autobuild/lifecycle_executor_test.go b/coderd/autobuild/lifecycle_executor_test.go index 973043d69d..cba3be57a7 100644 --- a/coderd/autobuild/lifecycle_executor_test.go +++ b/coderd/autobuild/lifecycle_executor_test.go @@ -1994,7 +1994,7 @@ func TestExecutorAutostopReminder(t *testing.T) { require.Len(t, sent, 1) require.Equal(t, workspace.OwnerID, sent[0].UserID) require.Equal(t, workspace.Name, sent[0].Labels["workspace"]) - require.Equal(t, deadline.UTC().Format(time.RFC1123), sent[0].Labels["deadline"]) + require.NotEmpty(t, sent[0].Labels["timeTilShutdown"]) require.Contains(t, sent[0].Targets, workspace.ID) require.Contains(t, sent[0].Targets, workspace.OwnerID) require.Contains(t, sent[0].Targets, workspace.TemplateID) @@ -2169,7 +2169,7 @@ func TestExecutorAutostopReminder(t *testing.T) { testutil.TryReceive(ctx, t, statsCh) sent := notifyEnq.Sent(notificationstest.WithTemplateID(notifications.TemplateWorkspaceAutostopReminder)) require.Len(t, sent, 1) - require.Equal(t, deadline.UTC().Format(time.RFC1123), sent[0].Labels["deadline"]) + require.NotEmpty(t, sent[0].Labels["timeTilShutdown"]) // Move the deadline well into the future. The marker now differs from // the build deadline, re-arming the reminder. @@ -2188,7 +2188,7 @@ func TestExecutorAutostopReminder(t *testing.T) { testutil.TryReceive(ctx, t, statsCh) sent = notifyEnq.Sent(notificationstest.WithTemplateID(notifications.TemplateWorkspaceAutostopReminder)) require.Len(t, sent, 2) - require.Equal(t, newDeadline.UTC().Format(time.RFC1123), sent[1].Labels["deadline"]) + require.NotEmpty(t, sent[1].Labels["timeTilShutdown"]) }) // ExceedsLifetime: a time_til_autostop_notify larger than the diff --git a/coderd/database/migrations/000535_autostop_reminder_wording.down.sql b/coderd/database/migrations/000535_autostop_reminder_wording.down.sql new file mode 100644 index 0000000000..7739f160d6 --- /dev/null +++ b/coderd/database/migrations/000535_autostop_reminder_wording.down.sql @@ -0,0 +1,2 @@ +-- Revert to the body introduced by migration 000528. +UPDATE notification_templates SET body_template = E'Your workspace **{{.Labels.workspace}}** is scheduled to automatically stop at {{.Labels.deadline}}.\n\nConnect to it or extend the deadline to keep it running.' WHERE id = '6f6cb984-c167-4fa5-bb87-1058dd642779'; diff --git a/coderd/database/migrations/000535_autostop_reminder_wording.up.sql b/coderd/database/migrations/000535_autostop_reminder_wording.up.sql new file mode 100644 index 0000000000..eb7d3a8441 --- /dev/null +++ b/coderd/database/migrations/000535_autostop_reminder_wording.up.sql @@ -0,0 +1,3 @@ +-- Reword the autostop reminder to use a relative countdown instead of an +-- absolute timestamp. +UPDATE notification_templates SET body_template = E'Your workspace **{{.Labels.workspace}}** will automatically stop {{.Labels.timeTilShutdown}}.\n\nConnect to it or extend the deadline to keep it running.' WHERE id = '6f6cb984-c167-4fa5-bb87-1058dd642779'; diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 839958f91c..157982a048 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -851,8 +851,8 @@ func TestNotificationTemplates_Golden(t *testing.T) { UserEmail: "bobby@coder.com", UserUsername: "bobby", Labels: map[string]string{ - "workspace": "bobby-workspace", - "deadline": "2024-03-15 14:00 UTC", + "workspace": "bobby-workspace", + "timeTilShutdown": "1 hour from now", }, }, }, diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutostopReminder.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutostopReminder.html.golden index 5de6e57afd..350896eb0e 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutostopReminder.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutostopReminder.html.golden @@ -12,8 +12,7 @@ Content-Type: text/plain; charset=UTF-8 Hi Bobby, -Your workspace bobby-workspace is scheduled to automatically stop at 2024-0= -3-15 14:00 UTC. +Your workspace bobby-workspace will automatically stop 1 hour from now. Connect to it or extend the deadline to keep it running. @@ -49,8 +48,8 @@ argin: 8px 0 32px; line-height: 1.5;">

Hi Bobby,

-

Your workspace bobby-workspace is scheduled to = -automatically stop at 2024-03-15 14:00 UTC.

+

Your workspace bobby-workspace will automatical= +ly stop 1 hour from now.

Connect to it or extend the deadline to keep it running.

diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutostopReminder.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutostopReminder.json.golden index 5adad98d69..5bfad86166 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutostopReminder.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutostopReminder.json.golden @@ -16,7 +16,7 @@ } ], "labels": { - "deadline": "2024-03-15 14:00 UTC", + "timeTilShutdown": "1 hour from now", "workspace": "bobby-workspace" }, "data": null, @@ -24,6 +24,6 @@ }, "title": "Your workspace \"bobby-workspace\" will stop soon", "title_markdown": "Your workspace \"bobby-workspace\" will stop soon", - "body": "Your workspace bobby-workspace is scheduled to automatically stop at 2024-03-15 14:00 UTC.\n\nConnect to it or extend the deadline to keep it running.", - "body_markdown": "Your workspace **bobby-workspace** is scheduled to automatically stop at 2024-03-15 14:00 UTC.\n\nConnect to it or extend the deadline to keep it running." + "body": "Your workspace bobby-workspace will automatically stop 1 hour from now.\n\nConnect to it or extend the deadline to keep it running.", + "body_markdown": "Your workspace **bobby-workspace** will automatically stop 1 hour from now.\n\nConnect to it or extend the deadline to keep it running." } \ No newline at end of file