Skip to content

fix(sfcompute): build instance name from RefID and environment ID - #158

Merged
patelspratik merged 1 commit into
mainfrom
BREV-12012/SFCompute-duplicate-name-fix
Sep 22, 2026
Merged

patelspratik merged 1 commit into
mainfrom
BREV-12012/SFCompute-duplicate-name-fix

Conversation

@jainvishesh11

Copy link
Copy Markdown
Contributor

Problem

Environment creation on SFCompute v2 fails with:

status 400: {"error":{"type":"invalid_request_error","message":"an instance with this
name already exists","details":[{"field":"name","code":"duplicate"}]}}

Root Cause

SFCompute treats the instance name as a unique key per workspace, and every Brev environment on a cloud credential shares one workspace. CreateInstance sent only the sanitized user-supplied environment name, while the globally unique RefID went to tags only, which SFCompute ignores for uniqueness.

Fix

Compose the name from Brev IDs instead of the user's supplied environment name:

func makeSFCName(refID string, tags v1.Tags) string {
    return sanitizeSFCName(refID + "-" + tags["dev-plane-x-environmentId"])
}

Giving e.g. inst-2toqsvHXfalevkjPXY2QNJZL9HF-p82qfn5qs. The Instance ID is a primary key so the name is unique per instance and the environment ID is also included for searchability.

Files changed

v1/providers/sfcomputev2/instance.go : added makeSFCName; CreateInstance uses it instead of sanitizeSFCName(attrs.Name)
v1/providers/sfcomputev2/instance_test.go : added tests for determinism (retry safety) and uniqueness across instances

Related Ticket

BREV-12012

@jainvishesh11 jainvishesh11 self-assigned this Sep 18, 2026
@jainvishesh11
jainvishesh11 marked this pull request as ready for review September 21, 2026 06:13
@jainvishesh11
jainvishesh11 requested a review from a team as a code owner September 21, 2026 06:13
}

func makeSFCName(refID string, tags v1.Tags) string {
return sanitizeSFCName(refID + "-" + tags["dev-plane-x-environmentId"])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is there a size limit on the name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, SFCompute supports names up to 255 characters, and our logic keeps the generated name well within this limit. The RefID (Instance ID) is a fixed 32 characters and the environment ID is 9, so the name will be 42 characters
(refID + "-" + envID). sanitizeSFCName truncating at 255 characters is a final safeguard.

@patelspratik
patelspratik merged commit 859a026 into main Sep 22, 2026
4 checks passed
@patelspratik
patelspratik deleted the BREV-12012/SFCompute-duplicate-name-fix branch September 22, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants