Skip to content

Commit e74042f

Browse files
authored
refactor: extract DEFAULT_VALIDATION_TIMEOUT_MS and fix JSDoc
Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/7ec635c1-158c-4da1-b031-1cb92243b56d
1 parent abbf467 commit e74042f

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

containers/api-proxy/server.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,18 @@ if (!proxyAgent) {
336336
logRequest('warn', 'startup', { message: 'No HTTPS_PROXY configured, requests will go direct' });
337337
}
338338

339+
// Default per-probe timeout for key validation (10 seconds).
340+
// Validation runs after startup and before the agent processes any requests,
341+
// so a short timeout is acceptable. If the network isn't ready yet, the probe
342+
// will time out and log a warning rather than blocking startup indefinitely.
343+
const DEFAULT_VALIDATION_TIMEOUT_MS = 10000;
344+
339345
/**
340346
* Send a lightweight probe request to validate an API key.
341347
* Routes through proxyAgent (Squid) for the same path as real requests.
342348
* Never throws — all errors are captured in the result.
343349
*
344-
* @param {string} provider - Provider name for logging
350+
* @param {string} provider - Provider name used for log context only; does not affect validation behavior
345351
* @param {string} target - Upstream hostname (e.g. 'api.openai.com')
346352
* @param {string} path - URL path for the probe (e.g. '/v1/models')
347353
* @param {string} method - HTTP method ('GET' or 'POST')
@@ -350,11 +356,11 @@ if (!proxyAgent) {
350356
* @param {number[]} successStatuses - Status codes that indicate the key is valid
351357
* @param {number[]} failStatuses - Status codes that indicate the key is invalid/rejected
352358
* @param {object} [opts={}] - Options
353-
* @param {number} [opts.timeoutMs=10000] - Per-request timeout in milliseconds
359+
* @param {number} [opts.timeoutMs] - Per-request timeout in ms (default: DEFAULT_VALIDATION_TIMEOUT_MS)
354360
* @returns {Promise<{result: 'success'|'failed'|'timeout'|'error', status?: number, duration_ms: number, error?: string}>}
355361
*/
356362
function validateKey(provider, target, path, method, body, headers, successStatuses, failStatuses, opts = {}) {
357-
const timeoutMs = opts.timeoutMs || 10000;
363+
const timeoutMs = opts.timeoutMs || DEFAULT_VALIDATION_TIMEOUT_MS;
358364
const startTime = Date.now();
359365

360366
return new Promise((resolve) => {
@@ -444,7 +450,7 @@ async function validateApiKeys(overrides = {}) {
444450
const geminiTarget = overrides.geminiTarget !== undefined ? overrides.geminiTarget : GEMINI_API_TARGET;
445451
const geminiBasePath = overrides.geminiBasePath !== undefined ? overrides.geminiBasePath : GEMINI_API_BASE_PATH;
446452
const probeOpts = overrides.timeoutMs !== undefined ? { timeoutMs: overrides.timeoutMs } : {};
447-
const timeoutSecs = Math.round((probeOpts.timeoutMs || 10000) / 1000);
453+
const timeoutSecs = Math.round((probeOpts.timeoutMs || DEFAULT_VALIDATION_TIMEOUT_MS) / 1000);
448454

449455
const tasks = [];
450456

0 commit comments

Comments
 (0)