From f5f487ee5d5d5fed56276036dd22bcd380f2b199 Mon Sep 17 00:00:00 2001 From: Anton_Yeromin Date: Tue, 17 Mar 2026 21:53:13 +0100 Subject: [PATCH 1/2] fix(proxy): detect git branch per-request to fix stale branch header --- .../plugins/sso/proxy/plugins/header-injection.plugin.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/providers/plugins/sso/proxy/plugins/header-injection.plugin.ts b/src/providers/plugins/sso/proxy/plugins/header-injection.plugin.ts index c7dea19d..a1f344a8 100644 --- a/src/providers/plugins/sso/proxy/plugins/header-injection.plugin.ts +++ b/src/providers/plugins/sso/proxy/plugins/header-injection.plugin.ts @@ -10,6 +10,7 @@ import { ProxyPlugin, PluginContext, ProxyInterceptor } from './types.js'; import { ProxyContext } from '../proxy-types.js'; import { ProviderRegistry } from '../../../../core/registry.js'; import { logger } from '../../../../../utils/logger.js'; +import { detectGitBranch } from '../../../../../utils/processes.js'; export class HeaderInjectionPlugin implements ProxyPlugin { id = '@codemie/proxy-headers'; @@ -66,8 +67,9 @@ class HeaderInjectionInterceptor implements ProxyInterceptor { if (config.repository) { context.headers['X-CodeMie-Repository'] = config.repository; } - if (config.branch) { - context.headers['X-CodeMie-Branch'] = config.branch; + const currentBranch = await detectGitBranch(process.cwd()) ?? config.branch; + if (currentBranch) { + context.headers['X-CodeMie-Branch'] = currentBranch; } if (config.project) { context.headers['X-CodeMie-Project'] = config.project; From b62596211f314300d17ae74969de532b6f07b2cf Mon Sep 17 00:00:00 2001 From: Anton_Yeromin Date: Wed, 18 Mar 2026 07:35:57 +0100 Subject: [PATCH 2/2] fix(proxy): cache branch detection with 30s TTL to avoid git call per request --- .../sso/proxy/plugins/header-injection.plugin.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/providers/plugins/sso/proxy/plugins/header-injection.plugin.ts b/src/providers/plugins/sso/proxy/plugins/header-injection.plugin.ts index a1f344a8..e0c992da 100644 --- a/src/providers/plugins/sso/proxy/plugins/header-injection.plugin.ts +++ b/src/providers/plugins/sso/proxy/plugins/header-injection.plugin.ts @@ -23,11 +23,25 @@ export class HeaderInjectionPlugin implements ProxyPlugin { } } +const BRANCH_CACHE_TTL_MS = 30_000; + class HeaderInjectionInterceptor implements ProxyInterceptor { name = 'header-injection'; + private cachedBranch: string | undefined; + private branchCachedAt = 0; + constructor(private context: PluginContext) {} + private async getCurrentBranch(): Promise { + if (Date.now() - this.branchCachedAt < BRANCH_CACHE_TTL_MS) { + return this.cachedBranch; + } + this.cachedBranch = await detectGitBranch(process.cwd()) ?? this.context.config.branch; + this.branchCachedAt = Date.now(); + return this.cachedBranch; + } + async onRequest(context: ProxyContext): Promise { // Request and session ID headers context.headers['X-CodeMie-Request-ID'] = context.requestId; @@ -67,7 +81,7 @@ class HeaderInjectionInterceptor implements ProxyInterceptor { if (config.repository) { context.headers['X-CodeMie-Repository'] = config.repository; } - const currentBranch = await detectGitBranch(process.cwd()) ?? config.branch; + const currentBranch = await this.getCurrentBranch(); if (currentBranch) { context.headers['X-CodeMie-Branch'] = currentBranch; }