Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: avoid re-using AuthInstanceID for sub agents#22196

Merged
DanielleMaywood merged 2 commits intomainfrom
danielle/fix-reconnect-agent-issue
Feb 19, 2026
Merged

fix: avoid re-using AuthInstanceID for sub agents#22196
DanielleMaywood merged 2 commits intomainfrom
danielle/fix-reconnect-agent-issue

Conversation

@DanielleMaywood
Copy link
Contributor

@DanielleMaywood DanielleMaywood commented Feb 19, 2026

Issue

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:

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

Solution

  1. Do not re-use AuthInstanceID for sub agents.
  2. Update GetWorkspaceAgentByInstanceID to filter out sub agents.

We only need a single approach, but we're going with both to minimize future risk.

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.
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest filtering out sub agents from the aforementioned query as well, should guard us against sub agents ever trying to use the parent auth.

}
})

t.Run("CreateSubAgentDoesNotInheritAuthInstanceID", func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fails when I revert the change in subagent.go 👍

@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
@DanielleMaywood DanielleMaywood marked this pull request as ready for review February 19, 2026 16:10
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@DanielleMaywood DanielleMaywood merged commit 911d734 into main Feb 19, 2026
32 checks passed
@DanielleMaywood DanielleMaywood deleted the danielle/fix-reconnect-agent-issue branch February 19, 2026 16:56
@github-actions github-actions bot locked and limited conversation to collaborators Feb 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants