feat: bump workspace last_used_at on chat heartbeat#23205
Conversation
d1214fe to
85f5a58
Compare
There was a problem hiding this comment.
Pull request overview
This PR wires the workspace usage tracker into the chat daemon so that active chats can bump a workspace’s last_used_at via periodic heartbeats, helping prevent workspaces from being considered idle while a chat is running.
Changes:
- Pass
WorkspaceUsageTrackerintochatd.Newfromcoderd.New. - Extend
chatd.Serverconfiguration with a configurable heartbeat interval plus an injectable clock, and bump workspace usage on each heartbeat tick. - Add end-to-end tests validating that heartbeats bump workspace usage when a chat is linked to a workspace, and do not when it isn’t.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
coderd/coderd.go |
Plumbs the existing WorkspaceUsageTracker into the chat daemon config. |
coderd/chatd/chatd.go |
Adds heartbeat configuration/clock injection and bumps usage on heartbeat ticks. |
coderd/chatd/chatd_test.go |
Adds coverage for usage bumping behavior with/without linked workspaces. |
💡 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.
Wires through UsageTracker to update chat workspace last_used_at on heartbeat.
Wires UsageTracker into the chatd Server so that while a chat is actively processing, the linked workspace's last_used_at is kept fresh. This prevents premature dormancy/deletion of workspaces that are being used by agentic chats. Only last_used_at is bumped (via UsageTracker.Add), not the autostop deadline. Chat activity alone should not extend build deadlines. Also makes the chat heartbeat interval configurable via Config.ChatHeartbeatInterval (default 30s) to support testing.
use testutil.IntervalMedium
672a52a to
ce92280
Compare
This comment was marked as outdated.
This comment was marked as outdated.
Good catch, but as chats are EA right now documenting this is premature. |
2341d5d to
e638dff
Compare
| // linking a workspace mid-conversation). The caller should store | ||
| // the returned value so that subsequent calls skip the DB lookup | ||
| // once a workspace has been found. | ||
| func (p *Server) trackWorkspaceUsage( |
There was a problem hiding this comment.
review: extracted this to its own function for clarity
|
@mafredri should be ready for round 2 now |
…workspaces The heartbeat goroutine captured the chat parameter by value at acquisition time. When create_workspace linked a workspace mid- conversation, the heartbeat never saw the updated WorkspaceID and never bumped last_used_at. Now, when WorkspaceID is not yet valid, the heartbeat re-reads the chat from the DB to pick up late associations. Once valid, the local copy is cached and no further reads are needed. The test is updated to cover the normal flow: chat created without a workspace, workspace linked later via UpdateChatWorkspace.
e638dff to
32a1210
Compare
options.WorkspaceUsageTrackerinto the chatd config.UsageTrackerand callsUsageTracker.Add(workspaceID)on each heartbeat ticklast_used_atbump behaviour