coder / coder/coder

Prebuild workspaces show incorrect "last used" timestamp when claimed

Open
#20,170 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
14.5k
Forks
1.5k
Avg merge
1d 20h
Merged PRs (30d)
601

Description

## Bug Description
When a user claims a prebuild workspace, the workspace displays when the prebuild was originally created (e.g., "7 hours ago") rather than when the user actually claimed it (e.g., "7 minutes ago"). This is confusing for users who expect to see how recently they started using the workspace.

## Steps to Reproduce
1. Create a prebuild workspace and wait several hours
2. Have a user claim the prebuild workspace
3. Check the workspace list UI
4. Notice the timestamp shows hours ago instead of minutes ago

## Expected Behavior
The workspace should show when the user claimed it (e.g., "7 minutes ago")

## Actual Behavior
The workspace shows when the prebuild was originally created (e.g., "7 hours ago")

## Root Cause
In `coderd/workspaces.go`, when a prebuild workspace is claimed, the `LastUsedAt` field is not updated. The workspace retains its original `LastUsedAt` timestamp from when the prebuild was created.

## Proposed Fix
Update the `LastUsedAt` field when claiming a prebuild workspace:

```go
// Prebuild found!
workspaceID = claimedWorkspace.ID
initiatorID = prebuildsClaimer.Initiator()

// Update the LastUsedAt field to reflect when the user claimed the prebuild
err = db.UpdateWorkspaceLastUsedAt(ctx, database.UpdateWorkspaceLastUsedAtParams{
ID: workspaceID,
LastUsedAt: now,
})
if err != nil {
return xerrors.Errorf("update workspace last used at: %w", err)
}
```

This ensures the timestamp reflects when the user actually started using the workspace, not when it was originally created as a prebuild.

Context: [Slack](https://codercom.slack.com/archives/C07NVVAC4G2/p1759535259483439?thread_ts=1759535056.092909&cid=C07NVVAC4G2)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.