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

Skip to content

fix(coderd/agentapi): make sub agent slugs more unique #18581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 25, 2025

Conversation

DanielleMaywood
Copy link
Contributor

The incorrect assumption that slugs were unique per-agent was made when the subagent API was implemented. Whilst this PR doesn't completely enforce that, we instead compute a stable hash to prefix the slug that should provide a reasonable level of probability that the slug will be unique.

The incorrect assumption that slugs were unique per-agent was made when
the subagent API was implemented. Whilst this PR doesn't completely
enforce that, we instead compute a stable hash to prefix the slug that
should provide a reasonable level of probability that the slug will be
unique.
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses the incorrect assumption of unique subagent slugs per agent by prefixing each slug with a stable CRC32 hash computed from the subagent name and original slug.

  • Updated test expectations in subagent_test.go to check for the new hash-prefixed slug format.
  • Modified the slug generation in subagent.go to compute and append a CRC32 hash to the original slug.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
coderd/agentapi/subagent_test.go Updated test cases to expect new hash-prefixed slugs.
coderd/agentapi/subagent.go Added CRC32-based hash computation to generate unique slugs.

@DanielleMaywood DanielleMaywood marked this pull request as ready for review June 25, 2025 15:42
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.

Except for my confidence in crc32, otherwise LGTM 👍

// there is no database-layer enforcement of this constraint.
// We can get around this by creating a slug that *should* be
// unique (at least highly probable).
slugHash := fmt.Sprintf("%08x", crc32.ChecksumIEEE([]byte(subAgent.Name+"/"+app.Slug)))
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should use crypto/sha256 or hash/fnv instead? Crc32 isn’t particularly good for collision prevention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good! I've made the change in 3e9f2f3.

Now we use a sha256 hash, encode it with base32 encoding, truncate it to 8 characters, then lower case it.

@DanielleMaywood DanielleMaywood merged commit 6c713d5 into main Jun 25, 2025
34 checks passed
@DanielleMaywood DanielleMaywood deleted the dm-subagent-slugs branch June 25, 2025 16:36
@github-actions github-actions bot locked and limited conversation to collaborators Jun 25, 2025
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.

2 participants