Skip to content

Generate time-plus-random Proxmox VMIDs instead of calling /cluster/nextid - #489

Merged
runleveldev merged 4 commits into
mainfrom
copilot/fix-container-creation-ctid-conflict
Oct 2, 2026
Merged

runleveldev merged 4 commits into
mainfrom
copilot/fix-container-creation-ctid-conflict

Conversation

Copilot AI commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Proxmox's /cluster/nextid endpoint returns the same ID to callers that ask at the same time. When two container-creation jobs run concurrently, both get one ID, and the slower createLxc call fails with a CTID conflict.

This PR has the manager generate the VMID itself, so no coordination or retries are needed.

Changes

  • utils/vmid.js (new): generateVmid() builds an ID in the style of UUIDv7, packed into Proxmox's VMID range of 100–999999999:
    VMID = 100 + (epochSeconds % 9999) * 100000 + crypto.randomInt(100000)
    • The high digits are a time slot of one second. The slots cycle about every 2.8 h.
    • The low 5 digits are random, from a CSPRNG.
    • The largest possible value is 999,899,999.
  • ProxmoxApi.nextId(): returns generateVmid() and no longer makes an HTTP call. Callers don't change.
  • bin/create-container.js: only the comment and log text change.
  • Tests: utils/__tests__/vmid.test.js checks the range bounds, that IDs randomize within one second, and that IDs from different seconds never overlap.

Collision properties

Scenario Probability
Two allocations in the same second 1 / 100,000
Allocations in different seconds, within one cycle 0
New ID vs. N existing containers ≈ N / 10⁹

Review notes

  • The generator doesn't check which VMIDs are already in use, and a failed create isn't retried; the issue asked for neither. A collision still fails the job the same way it does today, just much less often.
  • Docker nodes still let Docker assign the ID. DummyApi is unchanged.

Copilot AI linked an issue Oct 1, 2026 that may be closed by this pull request
Co-authored-by: runleveldev <44057501+runleveldev@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix container creation CTID conflict due to race condition Generate time-plus-random Proxmox VMIDs instead of calling /cluster/nextid Oct 1, 2026
Copilot AI requested a review from runleveldev October 1, 2026 22:05
@runleveldev
runleveldev requested a balanced review from Copilot October 1, 2026 22:07
@runleveldev
runleveldev marked this pull request as ready for review October 1, 2026 22:07

Copilot AI left a comment

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.

Copilot review overview

🟢 Approval recommended

The implementation matches the accepted probabilistic design, with only minor documentation clarifications remaining.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Replaces Proxmox’s /cluster/nextid calls with locally generated VMIDs to reduce concurrent container-creation conflicts reported in #488.

Changes:

  • Adds a time-slot and cryptographic-random VMID generator.
  • Connects Proxmox allocation to the generator and adds tests.
  • Updates allocation comments and log text without changing Docker behavior.
File Description
create-a-container/​utils/​vmid.js Adds local VMID generation.
create-a-container/​utils/​proxmox-api.js Replaces the allocation HTTP request.
create-a-container/​utils/​__tests__/​vmid.test.js Tests bounds, randomness, and adjacent-second separation.
create-a-container/​bin/​create-container.js Updates allocation comments and logging.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +21 to +22
const timeSlot = Math.floor(now / 1000) % TIME_SLOTS;
return VMID_MIN + timeSlot * RANDOM_SPACE + crypto.randomInt(RANDOM_SPACE);
Copilot AI balanced review requested due to automatic review settings October 1, 2026 22:27

Copilot AI left a comment

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.

Copilot review overview

🟡 Changes recommended

Conflict detection misses response-body error text, causing affected collisions to fail without retrying.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)

Comment thread create-a-container/utils/vmid.js

@cmyers-mieweb cmyers-mieweb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved, we will need to see how the retry logic added works within the ongoing environment once this is merged to spot for any creation bugs. Only other thing I can think is check logic if the job-runner already has an ID it is using in an ongoing build, though the event in itself after the randomization makes it rare.

@runleveldev

Copy link
Copy Markdown
Collaborator

@copilot resolve merge conlficts

…-creation-ctid-conflict

# Conflicts:
#	create-a-container/bin/create-container.js
#	create-a-container/utils/proxmox-api.js

Co-authored-by: runleveldev <44057501+runleveldev@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 2, 2026 13:54

Copilot AI commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve merge conlficts

Resolved the conflicts and merged latest main in 1688958, preserving volume provisioning and VMID retries. All 58 targeted tests pass; review and CodeQL found no issues. The full manager suite failed in unchanged MCP proxy tests and then aborted with a SQLite closed-handle error.

Copilot AI requested a review from runleveldev October 2, 2026 13:56
@runleveldev
runleveldev merged commit 21462f2 into main Oct 2, 2026
8 checks passed
@runleveldev
runleveldev deleted the copilot/fix-container-creation-ctid-conflict branch October 2, 2026 13:57

Copilot AI left a comment

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.

Copilot review overview

🟢 Approval recommended

No blocking issues remain; the PR description needs only a non-blocking clarification of retry behavior.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (1)

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.

[Bug]: Container creation CTID conflict

4 participants