-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(coderd/database): add schema for task pause/resume lifecycle #21557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(coderd/database): add schema for task pause/resume lifecycle #21557
Conversation
43354bf to
83364af
Compare
Creates migration 000409 with the database foundation for pausing and resuming task workspaces. The task_snapshots table stores conversation history (AgentAPI messages) so users can view task logs even when the workspace is stopped. Each task gets one snapshot, overwritten on each pause. Three new build_reason values (task_auto_pause, task_manual_pause, task_resume) let us distinguish task lifecycle events in telemetry and audit logs from regular workspace operations. Uses a regular table rather than UNLOGGED for snapshots. While UNLOGGED would be faster, losing snapshots on database crash creates user confusion (logs disappear until next pause). We can switch to UNLOGGED post-GA if write performance becomes a problem. Closes coder/internal#1250
83364af to
1beffe1
Compare
| CREATE TABLE task_snapshots ( | ||
| task_id UUID NOT NULL PRIMARY KEY REFERENCES tasks (id) ON DELETE CASCADE, | ||
| log_snapshot JSONB NOT NULL, | ||
| log_snapshot_at TIMESTAMPTZ NOT NULL DEFAULT NOW() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: created_at for consistency with other database fields, but definitely not a blocker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the purpose behind the consistency? I have seen other tables that do not have it. We have audit logs that track creation and other changes, right? What does the created_at field give us?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistency for consistency's sake more than anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed in 573d6d7.
| ALTER TABLE ONLY task_snapshots | ||
| ADD CONSTRAINT task_snapshots_task_id_fkey FOREIGN KEY (task_id) REFERENCES tasks(id) ON DELETE CASCADE; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to add a constraint such that a task snapshot cannot be inserted after the related task is deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add that, we also need to add them to dbpurge I suppose (for soft deleted tasks).
SasSwart
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
One question of my own and then one question in response to @johnstcn.
|
|
||
| -- Add build reasons for task lifecycle events. | ||
| -- These distinguish task pause/resume operations from regular workspace lifecycle events. | ||
| ALTER TYPE build_reason ADD VALUE IF NOT EXISTS 'task_auto_pause'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this warning not apply to this migration?
| WARNING: Migrations now all run in a single transaction. This makes upgrades |
Is there any risk we might reference these values in a future migration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No risk. Since task pause/resume is something we're implementing now, there's no motivation to migrate old data. 👍🏻
|
Follow-up issue for dbpurge (non-critical): coder/internal#1283 |
Creates migration 000409 with the database foundation for pausing and
resuming task workspaces.
The task_snapshots table stores conversation history (AgentAPI messages)
so users can view task logs even when the workspace is stopped. Each task
gets one snapshot, overwritten on each pause.
Three new build_reason values (task_auto_pause, task_manual_pause,
task_resume) let us distinguish task lifecycle events in telemetry and
audit logs from regular workspace operations.
Uses a regular table rather than UNLOGGED for snapshots. While UNLOGGED
would be faster, losing snapshots on database crash creates user confusion
(logs disappear until next pause). We can switch to UNLOGGED post-GA if
write performance becomes a problem.
Closes coder/internal#1250