fix: null user_id for env bootstrap keys + H2 support for registry fetches#2370
Merged
kmendell merged 8 commits intogetarcaneapp:mainfrom Apr 20, 2026
Merged
Conversation
… fetches Two bugs in one branch: 1. Deploying a swarm node-level agent from the agent itself failed with a FK violation because CreateEnvironmentApiKey was inserting user_id='agent' (the synthetic agent user) which doesn't exist in the users table. Environment bootstrap keys belong to the system, not a user — make user_id nullable in api_keys and pass nil when creating env keys (migration 046). 2. Fetching remote template registries over HTTPS broke with "net/http: HTTP/1.x transport connection broken: malformed HTTP response" because the custom http.Transport used throughout the app didn't have ForceAttemptHTTP2 set, so Go disabled H2 negotiation entirely when a custom DialContext was applied in the safe-HTTP wrapper. Add ForceAttemptHTTP2: true to both constructors in httpx/client.go. Closes getarcaneapp#2369 Closes getarcaneapp#2367
Member
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Contributor
Author
|
working on it |
|
This pull request has merge conflicts. Please resolve the conflicts so the PR can stay up-to-date and reviewed. |
added 2 commits
April 16, 2026 14:03
ValidateApiKey now rejects keys with user_id=NULL (bootstrap keys), so the proxy validator fell back to 401 when forwarding to an env whose apiUrl resolved back to the manager itself (common in CI/self-hosted). Fall through to GetEnvironmentByApiKey so bootstrap keys are still accepted by the proxy middleware.
kmendell
approved these changes
Apr 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
🐞 Bug: Deploying node level swarm agent fails on token create #2369 — Deploying a swarm node-level agent failed with
ERROR: insert or update on table "api_keys" violates foreign key constraint "api_keys_user_id_fkey". When the agent processesGetNodeAgentDeploymentit authenticates via the syntheticagentSudomiddleware user (id = "agent"), which doesn't exist in the users table. Environment bootstrap API keys belong to the system, not a user —user_idis now nullable for these keys (migration 046, Postgres + SQLite).CreateEnvironmentApiKeypassesnil;GetUserByApiKeyrejects nil-user keys, which is correct since those keys are used for env pairing, not user authentication.🐞 Bug: Failed to fetch remote template registries due to malformed HTTP response HTTP/2 vs HTTP/1.x mismatch #2367 — Fetching remote template registries (including
registry.getarcane.appand private Gitea instances) failed withnet/http: HTTP/1.x transport connection broken: malformed HTTP response. Root cause: the custom*http.Transportcreated inhttpx/client.godidn't setForceAttemptHTTP2: true. Go conservatively disables HTTP/2 negotiation on any transport that has a customDialContext; the safe-HTTP wrapper adds one, so H2 was silently dropped. AddingForceAttemptHTTP2: trueto both transport constructors re-enables ALPN negotiation for HTTPS connections.Test plan
TestEnvironmentService_EnsureSwarmNodeAgentEnvironment_*passes with updated nil-UserID assertiongo test ./internal/services/... ./pkg/utils/httpx/... ./internal/huma/...— all greendown.sql) — env bootstrap keys with NULL user_id are deleted cleanlyCloses #2369
Closes #2367
Disclaimer Greptiles Reviews use AI, make sure to check over its work.
To better help train Greptile on our codebase, if the comment is useful and valid Like the comment, if its not helpful or invalid Dislike
To have Greptile Re-Review the changes, mention
greptileai.Greptile Summary
This PR fixes two production bugs: a foreign-key violation when swarm node agent environments create bootstrap API keys (by making
user_idnullable via migration 046 for both Postgres and SQLite), and broken HTTP/2 negotiation for registry fetches (by addingForceAttemptHTTP2: trueto both transport constructors inhttpx/client.go). The model, DTO, service logic, and tests are all updated consistently. Both fixes are correct and well-scoped.Confidence Score: 5/5
Safe to merge; both bug fixes are correct and all remaining findings are P2 style issues.
No P0/P1 issues found. The nullable user_id migration, the nil guard in ValidateApiKey, and the ForceAttemptHTTP2 additions are all correct. The two P2 findings (dead userID parameter and markApiKeyUsedAsync ordering) do not affect correctness or security.
No files require special attention; api_key_service.go has two minor P2 style issues.
Comments Outside Diff (1)
backend/internal/services/api_key_service.go, line 308 (link)userIDparameter still accepteduserIDis accepted but silently ignored — the function now always passesniltocreateAPIKeyWithRawKey. All three call-sites (environments.go:426,environments.go:578,environment_service.go:297) still forward a realuser.ID, so developers reading those call-sites will reasonably believe the user is recorded on the key. Removing the parameter makes the contract explicit.Prompt To Fix With AI
Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix: allow null user_id on env bootstrap..." | Re-trigger Greptile