fix: server startup panic (DI) and git clone auth against self-hosted GitLab#1
Open
yg-codes wants to merge 2 commits into
Open
fix: server startup panic (DI) and git clone auth against self-hosted GitLab#1yg-codes wants to merge 2 commits into
yg-codes wants to merge 2 commits into
Conversation
The server paniced on startup with 'could not find service ReviewJobStore' for every store driver. provideStores registers the individual store interfaces (ReviewJobStore, ReplyJobStore, ...) as a side effect and is lazy; cmd/server invokes worker.Pool first, which needs those interfaces before anything invokes *store.Stores, so the registrations never ran. Eagerly invoke *store.Stores after config validation, mirroring the CLI.
… header GitLab's git-over-HTTP smart protocol does not honor the 'PRIVATE-TOKEN' http.extraHeader (nor Authorization: Bearer) used for API calls, so the CLI clone got 401 and fell back to interactive username prompting, failing with 'could not read Username' in a non-interactive context. Build the clone URL with oauth2:<token> basic-auth embedded (the method GitLab accepts for git transport) and set GIT_TERMINAL_PROMPT=0 so auth failures fail fast instead of hanging. The slow go-git fallback is no longer routinely hit.
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.
1.
fix(server): initialize store container before worker poolcmd/serverpanics on startup for everySTORE_DRIVER:panic: DI: could not find service .../domain.ReviewJobStore,
path: worker.Pool -> review.Pipeline -> ReviewJobStore
provideStores(internal/di/infra.go) registers the individual store interfaces (ReviewJobStore,ReplyJobStore, …) as a side effect and isdo.Lazy. Incmd/serverthe first invoke that needs them isworker.Pool, and nothing invokes*store.Storesfirst, so theregistrations never run. The CLI works only because it invokes
*store.Storesearly.Fix: eagerly invoke
*store.Storesright after config validation incmd/server/main.go, mirroring the CLI.2.
fix(git): authenticate clone/fetch with oauth2 URL, not PRIVATE-TOKEN headerReview jobs enqueue, then the clone fails:
fatal: could not read Username for 'https://gitlab...': No such device or address
internal/pkg/git/manager.goauthenticates the git CLI withhttp.extraHeader: PRIVATE-TOKEN. GitLab's git-over-HTTP smart protocol does not honorPRIVATE-TOKEN(norAuthorization: Bearer) — onlyoauth2:<token>basic-auth in the URL works. Verified against GitLab18.11.3:
git -c http.extraHeader="PRIVATE-TOKEN: $T" ls-remote # fails (prompts for username)
git ls-remote "https://oauth2:$T@host/.git" # works
So the CLI got a 401 and fell back to interactive prompting (fails in a service context); it only limped along via the slow go-git fallback.
Fix: build the clone URL with
oauth2:<token>embedded (authCloneURL), and setGIT_TERMINAL_PROMPT=0so auth failures fail fast instead of hanging.Trade-off note: embedding the token persists it in
<repo>/.git/config. A credential helper would avoid on-disk storage — happy to switch to that if you prefer.