fix: avoid re-using `AuthInstanceID` for sub agents by DanielleMaywood · Pull Request #22196 · coder/coder

@DanielleMaywood

When creating child agents, we re-used `AuthInstanceID`. Unfortunately
this causes an issue when the parent agents disconnect.

Our `GetWorkspaceAgentByInstanceID` query is defined as follows:

```sql
-- name: GetWorkspaceAgentByInstanceID :one
SELECT
	*
FROM
	workspace_agents
WHERE
	auth_instance_id = @auth_instance_id :: TEXT
	-- Filter out deleted sub agents.
	AND deleted = FALSE
ORDER BY
	created_at DESC;
```

When the parent agent attempts to refetch its manifest via its
`auth_instance_id`, it will fetch the _last created agent with this
instance ID_. This will be the last created sub agent, meaning the
parent will fetch the manifest for a child, instead of itself.

mafredri

johnstcn

@DanielleMaywood

@DanielleMaywood DanielleMaywood changed the title fix(coderd/agentapi): do not re-use AuthInstanceID fix: do not re-use AuthInstanceID

Feb 19, 2026

@DanielleMaywood DanielleMaywood changed the title fix: do not re-use AuthInstanceID fix: do not re-use AuthInstanceID for sub agents

Feb 19, 2026

@DanielleMaywood DanielleMaywood changed the title fix: do not re-use AuthInstanceID for sub agents fix: avoid re-using AuthInstanceID for sub agents

Feb 19, 2026

johnstcn

mafredri