From 243d36d3ce7505ada2b8857b64f80a7b84839353 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 23:50:56 +0000 Subject: [PATCH 1/3] Initial plan From 5dbb8750164872de1683d833f416ca5a3ff3f688 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 23:53:43 +0000 Subject: [PATCH 2/3] Refactor duplicate guard integer parsing --- .../api-proxy/guards/effective-token-guard.js | 11 ++------ containers/api-proxy/guards/guard-utils.js | 12 ++++++++ .../api-proxy/guards/guard-utils.test.js | 28 +++++++++++++++++++ containers/api-proxy/guards/max-runs-guard.js | 11 ++------ .../api-proxy/guards/timeout-steering.js | 10 ++----- 5 files changed, 48 insertions(+), 24 deletions(-) create mode 100644 containers/api-proxy/guards/guard-utils.js create mode 100644 containers/api-proxy/guards/guard-utils.test.js diff --git a/containers/api-proxy/guards/effective-token-guard.js b/containers/api-proxy/guards/effective-token-guard.js index bc7aeaf3c..f7fa65752 100644 --- a/containers/api-proxy/guards/effective-token-guard.js +++ b/containers/api-proxy/guards/effective-token-guard.js @@ -1,5 +1,7 @@ 'use strict'; +const { parsePositiveInteger } = require('./guard-utils'); + const ET_WARNING_THRESHOLDS = [80, 90, 95, 99]; const ET_DEFAULT_WEIGHTS = Object.freeze({ @@ -33,13 +35,6 @@ const effectiveTokenConfigCache = { parsed: { max: null, multipliers: {} }, }; -function parseMaxEffectiveTokens(raw) { - if (raw === undefined || raw === null || String(raw).trim() === '') return null; - const parsed = Number(raw); - if (!Number.isInteger(parsed) || parsed <= 0) return null; - return parsed; -} - function parseModelMultipliers(raw) { if (!raw || String(raw).trim() === '') return {}; try { @@ -69,7 +64,7 @@ function getEffectiveTokenConfig() { effectiveTokenConfigCache.rawMultipliers = rawMultipliers; const parsedMultipliers = Object.freeze(parseModelMultipliers(rawMultipliers)); effectiveTokenConfigCache.parsed = { - max: parseMaxEffectiveTokens(rawMax), + max: parsePositiveInteger(rawMax), multipliers: parsedMultipliers, }; return effectiveTokenConfigCache.parsed; diff --git a/containers/api-proxy/guards/guard-utils.js b/containers/api-proxy/guards/guard-utils.js new file mode 100644 index 000000000..84b0a9c72 --- /dev/null +++ b/containers/api-proxy/guards/guard-utils.js @@ -0,0 +1,12 @@ +'use strict'; + +function parsePositiveInteger(raw) { + if (raw === undefined || raw === null || String(raw).trim() === '') return null; + const parsed = Number(raw); + if (!Number.isInteger(parsed) || parsed <= 0) return null; + return parsed; +} + +module.exports = { + parsePositiveInteger, +}; diff --git a/containers/api-proxy/guards/guard-utils.test.js b/containers/api-proxy/guards/guard-utils.test.js new file mode 100644 index 000000000..b4f06257f --- /dev/null +++ b/containers/api-proxy/guards/guard-utils.test.js @@ -0,0 +1,28 @@ +const { parsePositiveInteger } = require('./guard-utils'); + +describe('guard-utils', () => { + describe('parsePositiveInteger', () => { + it.each([ + undefined, + null, + '', + ' ', + 0, + '0', + -1, + '-1', + '1.5', + 'abc', + ])('returns null for %p', (raw) => { + expect(parsePositiveInteger(raw)).toBeNull(); + }); + + it.each([ + [1, 1], + ['1', 1], + [' 42 ', 42], + ])('returns %p for raw value %p', (raw, expected) => { + expect(parsePositiveInteger(raw)).toBe(expected); + }); + }); +}); diff --git a/containers/api-proxy/guards/max-runs-guard.js b/containers/api-proxy/guards/max-runs-guard.js index 13f598e21..e6d153a20 100644 --- a/containers/api-proxy/guards/max-runs-guard.js +++ b/containers/api-proxy/guards/max-runs-guard.js @@ -1,5 +1,7 @@ 'use strict'; +const { parsePositiveInteger } = require('./guard-utils'); + let maxRunsGuardState = { configKey: null, invocationCount: 0, @@ -10,20 +12,13 @@ const maxRunsConfigCache = { parsed: null, }; -function parseMaxRuns(raw) { - if (raw === undefined || raw === null || String(raw).trim() === '') return null; - const parsed = Number(raw); - if (!Number.isInteger(parsed) || parsed <= 0) return null; - return parsed; -} - function getMaxRunsConfig() { const rawMax = process.env.AWF_MAX_RUNS; if (maxRunsConfigCache.rawMax === rawMax) { return maxRunsConfigCache.parsed; } maxRunsConfigCache.rawMax = rawMax; - maxRunsConfigCache.parsed = parseMaxRuns(rawMax); + maxRunsConfigCache.parsed = parsePositiveInteger(rawMax); return maxRunsConfigCache.parsed; } diff --git a/containers/api-proxy/guards/timeout-steering.js b/containers/api-proxy/guards/timeout-steering.js index 58406fb22..035527b7e 100644 --- a/containers/api-proxy/guards/timeout-steering.js +++ b/containers/api-proxy/guards/timeout-steering.js @@ -1,6 +1,7 @@ 'use strict'; const { ET_WARNING_THRESHOLDS } = require('./effective-token-guard'); +const { parsePositiveInteger } = require('./guard-utils'); const TIMEOUT_STEERING_MESSAGES = { 80: 'You have used 80% of your allotted run time. Begin planning to wrap up your current work.', @@ -25,20 +26,13 @@ const timeoutSteeringConfigCache = { parsedMinutes: null, }; -function parseAgentTimeoutMinutes(raw) { - if (raw === undefined || raw === null || String(raw).trim() === '') return null; - const parsed = Number(raw); - if (!Number.isInteger(parsed) || parsed <= 0) return null; - return parsed; -} - function getTimeoutSteeringConfig() { const rawMinutes = process.env.AWF_AGENT_TIMEOUT_MINUTES; if (timeoutSteeringConfigCache.rawMinutes === rawMinutes) { return timeoutSteeringConfigCache.parsedMinutes; } timeoutSteeringConfigCache.rawMinutes = rawMinutes; - timeoutSteeringConfigCache.parsedMinutes = parseAgentTimeoutMinutes(rawMinutes); + timeoutSteeringConfigCache.parsedMinutes = parsePositiveInteger(rawMinutes); return timeoutSteeringConfigCache.parsedMinutes; } From 65c141b09a83d505d3b5a46c2a87b258d36bbb8f Mon Sep 17 00:00:00 2001 From: Landon Cox Date: Thu, 21 May 2026 18:04:02 -0700 Subject: [PATCH 3/3] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- containers/api-proxy/guards/guard-utils.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/containers/api-proxy/guards/guard-utils.test.js b/containers/api-proxy/guards/guard-utils.test.js index b4f06257f..9edcfe7f7 100644 --- a/containers/api-proxy/guards/guard-utils.test.js +++ b/containers/api-proxy/guards/guard-utils.test.js @@ -21,7 +21,7 @@ describe('guard-utils', () => { [1, 1], ['1', 1], [' 42 ', 42], - ])('returns %p for raw value %p', (raw, expected) => { + ])('for raw value %p returns %p', (raw, expected) => { expect(parsePositiveInteger(raw)).toBe(expected); }); });