Skip to content

Fix agent auth during shutdown scripts (#19467) #1249

Closed
coder/coder
#21538

Description

@mafredri

Repo: coder/coder

Scope: Fix agent token validation so run_on_stop scripts can make authenticated API calls.

Problem: The agent auth query joins with the latest build. When a stop build is created, the agent from the previous start build fails authorization before shutdown scripts complete.

Changes:

  • Modify agent token validation query in coderd/database/queries/workspaceagents.sql
  • Ensure agent token remains valid during the shutdown window
  • Add tests for shutdown script auth scenarios

Files:

  • coderd/database/queries/workspaceagents.sql (L285-325)
  • coderd/httpmw/workspaceagent.go
  • Tests

Acceptance criteria:

  • Agent token valid during run_on_stop script execution
  • Shutdown scripts can POST to coderd endpoints
  • No regression in normal agent auth flows
  • Test coverage for shutdown auth scenario

Dependencies: None (prerequisite for others)

References:

Activity

  1. added theissue type on Jan 15, 2026
  2. self-assigned this
    on Jan 16, 2026
  3. added a commit that references this issue on Jan 21, 2026
    97e8a5b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions