From dc16c9476685d147c4f0bba6a762d0ac8288effd Mon Sep 17 00:00:00 2001 From: rcourtman Date: Mon, 19 Jan 2026 19:24:45 +0000 Subject: [PATCH] fix: Add robustness improvements to approval, auth, and server approval/store.go: - Make Approve() idempotent - return success if already approved - Handles double-clicks and race conditions gracefully auth.go: - Add dev mode admin bypass (disabled by default) - When ALLOW_ADMIN_BYPASS=1, sets X-Authenticated-User header server.go: - Call router.StopOpenCodeAI() during shutdown - Ensures AI service stops cleanly on server termination --- internal/ai/approval/store.go | 5 +++++ internal/api/auth.go | 10 ++++++++++ pkg/server/server.go | 3 +++ 3 files changed, 18 insertions(+) diff --git a/internal/ai/approval/store.go b/internal/ai/approval/store.go index b30a59f17..bb5929e14 100644 --- a/internal/ai/approval/store.go +++ b/internal/ai/approval/store.go @@ -221,6 +221,11 @@ func (s *Store) Approve(id, username string) (*ApprovalRequest, error) { return nil, fmt.Errorf("approval request not found: %s", id) } + // Idempotent: if already approved, return success (handles double-clicks, race conditions) + if req.Status == StatusApproved { + return req, nil + } + if req.Status != StatusPending { return nil, fmt.Errorf("approval request is not pending (status: %s)", req.Status) } diff --git a/internal/api/auth.go b/internal/api/auth.go index bb03c01af..098dcef07 100644 --- a/internal/api/auth.go +++ b/internal/api/auth.go @@ -183,6 +183,16 @@ func CheckProxyAuth(cfg *config.Config, r *http.Request) (bool, string, bool) { // CheckAuth checks both basic auth and API token func CheckAuth(cfg *config.Config, w http.ResponseWriter, r *http.Request) bool { + // Dev mode bypass for all auth (disabled by default) + if adminBypassEnabled() { + if w != nil { + // Set headers for standard admin user + w.Header().Set("X-Authenticated-User", "admin") + w.Header().Set("X-Auth-Method", "bypass") + } + return true + } + config.Mu.RLock() defer config.Mu.RUnlock() diff --git a/pkg/server/server.go b/pkg/server/server.go index d66f1780e..cca526cf2 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -304,6 +304,9 @@ shutdown: log.Error().Err(err).Msg("Server shutdown error") } + // Stop OpenCode AI service (kills sidecar process group) + router.StopOpenCodeAI(shutdownCtx) + cancel() reloadableMonitor.Stop()