Skip to content

Prebuild workspaces show incorrect "last used" timestamp when claimed #20170

@blink-so

Description

@blink-so

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:

// 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    prebuildsArea: Prebuildss3Bugs that confuse, annoy, or are purely cosmetic

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions