Skip to content

Commit dadd6a0

Browse files
chore: sync actions from [email protected] (#177)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 2ad2a51 commit dadd6a0

17 files changed

Lines changed: 725 additions & 198 deletions

‎setup/js/add_comment.cjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ async function main(config = {}) {
435435
const requiredLabels = Array.isArray(config.required_labels) ? config.required_labels : [];
436436
const requiredTitlePrefix = config.required_title_prefix || "";
437437
const mentionsDisabled = config.mentions === false || config.mentions?.enabled === false;
438+
const preResolvedMentionAliases =
439+
!mentionsDisabled && Array.isArray(config.allowedMentionAliases) ? config.allowedMentionAliases.map(alias => (typeof alias === "string" ? alias.trim().replace(/^@+/, "") : "")).filter(alias => alias.length > 0) : [];
438440
const configuredMentionAliases =
439441
!mentionsDisabled && Array.isArray(config.mentions?.allowed) ? config.mentions.allowed.map(alias => (typeof alias === "string" ? alias.trim().replace(/^@+/, "") : "")).filter(alias => alias.length > 0) : [];
440442

@@ -656,7 +658,7 @@ async function main(config = {}) {
656658
}
657659
}
658660
}
659-
const allowedMentionAliases = deduplicateCaseInsensitive([...parentAuthors, ...configuredMentionAliases]);
661+
const allowedMentionAliases = deduplicateCaseInsensitive([...parentAuthors, ...preResolvedMentionAliases, ...configuredMentionAliases]);
660662

661663
if (allowedMentionAliases.length > 0) {
662664
core.info(`[MENTIONS] Allowing aliases in comment: ${allowedMentionAliases.join(", ")}`);

‎setup/js/allowed_issue_fields.cjs‎

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ const { ERR_VALIDATION } = require("./error_codes.cjs");
99
* @returns {string[]}
1010
*/
1111
function parseAllowedIssueFields(value) {
12-
if (value == null || value === "") {
13-
return [];
14-
}
12+
if (value == null || value === "") return [];
1513
const raw = Array.isArray(value) ? value : String(value).split(",");
16-
const uniqueFields = new Set();
17-
for (const item of raw) {
18-
const normalized = String(item).trim();
19-
if (normalized) {
20-
uniqueFields.add(normalized);
21-
}
22-
}
23-
return [...uniqueFields];
14+
return [...new Set(raw.map(item => String(item).trim()).filter(Boolean))];
15+
}
16+
17+
/**
18+
* Build a lowercased Set from allowedFields.
19+
* Returns null when no restriction applies (empty list, non-array, or wildcard "*").
20+
* @param {string[]} allowedFields
21+
* @returns {Set<string>|null}
22+
*/
23+
function buildAllowedFieldSet(allowedFields) {
24+
if (!Array.isArray(allowedFields) || allowedFields.length === 0 || allowedFields.includes("*")) return null;
25+
return new Set(allowedFields.map(f => f.toLowerCase()));
2426
}
2527

2628
/**
@@ -30,14 +32,10 @@ function parseAllowedIssueFields(value) {
3032
* @returns {void}
3133
*/
3234
function validateAllowedIssueFieldName(fieldName, allowedFields) {
33-
if (!fieldName) {
34-
return;
35-
}
36-
if (!Array.isArray(allowedFields) || allowedFields.length === 0 || allowedFields.includes("*")) {
37-
return;
38-
}
39-
const allowedFieldSet = new Set(allowedFields.map(field => field.toLowerCase()));
40-
if (!allowedFieldSet.has(fieldName.toLowerCase())) {
35+
if (!fieldName) return;
36+
const fieldSet = buildAllowedFieldSet(allowedFields);
37+
if (!fieldSet) return;
38+
if (!fieldSet.has(fieldName.toLowerCase())) {
4139
throw new Error(`${ERR_VALIDATION}: issue field "${fieldName}" is not in the allowed-fields list: ${allowedFields.join(", ")}`);
4240
}
4341
}
@@ -49,18 +47,11 @@ function validateAllowedIssueFieldName(fieldName, allowedFields) {
4947
* @returns {void}
5048
*/
5149
function validateAllowedIssueFields(issueFields, allowedFields) {
52-
if (!Array.isArray(issueFields) || issueFields.length === 0) {
53-
return;
54-
}
55-
if (!Array.isArray(allowedFields) || allowedFields.length === 0) {
56-
return;
57-
}
58-
const allowedFieldSet = new Set(allowedFields.map(field => field.toLowerCase()));
59-
if (allowedFieldSet.has("*")) {
60-
return;
61-
}
50+
if (!Array.isArray(issueFields) || issueFields.length === 0) return;
51+
const fieldSet = buildAllowedFieldSet(allowedFields);
52+
if (!fieldSet) return;
6253
for (const field of issueFields) {
63-
if (!allowedFieldSet.has(field.name.toLowerCase())) {
54+
if (!fieldSet.has(field.name.toLowerCase())) {
6455
throw new Error(`${ERR_VALIDATION}: issue field "${field.name}" is not in the allowed-fields list: ${allowedFields.join(", ")}`);
6556
}
6657
}

‎setup/js/awf_reflect.cjs‎

Lines changed: 175 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,166 @@ async function fetchAWFReflect(options) {
321321
}
322322
}
323323

324+
/**
325+
* Returns true when the model name matches well-known Anthropic naming patterns:
326+
* "claude-*" prefix, or "-opus", "-haiku", or "-sonnet" as a segment or suffix.
327+
*
328+
* @param {string} model - Lower-cased, trimmed model name.
329+
* @returns {boolean}
330+
*/
331+
function isAnthropicModelName(model) {
332+
return model.startsWith("claude-") || model.includes("-opus-") || model.endsWith("-opus") || model.includes("-haiku-") || model.endsWith("-haiku") || model.includes("-sonnet-") || model.endsWith("-sonnet");
333+
}
334+
335+
/**
336+
* Returns true when the model name matches well-known OpenAI naming patterns:
337+
* "gpt-*" prefix, or o1/o3/o4 reasoning models.
338+
*
339+
* @param {string} model - Lower-cased, trimmed model name.
340+
* @returns {boolean}
341+
*/
342+
function isOpenAIModelName(model) {
343+
return model.startsWith("gpt-") || /^o[134][-.]/.test(model) || model === "o1" || model === "o3" || model === "o4";
344+
}
345+
346+
/**
347+
* Look up a model entry in the models.json catalog, case-insensitively.
348+
*
349+
* @param {object | null | undefined} modelsJson
350+
* @param {string} modelName
351+
* @param {string | null | undefined} [providerName]
352+
* @returns {object | null}
353+
*/
354+
function getCatalogModelEntry(modelsJson, modelName, providerName) {
355+
const model = String(modelName || "")
356+
.toLowerCase()
357+
.trim();
358+
const provider = String(providerName || "")
359+
.toLowerCase()
360+
.trim();
361+
if (!model || modelsJson == null || typeof modelsJson !== "object" || Array.isArray(modelsJson)) {
362+
return null;
363+
}
364+
const providers = modelsJson.providers;
365+
if (!providers || typeof providers !== "object" || Array.isArray(providers)) {
366+
return null;
367+
}
368+
const providerEntries = provider
369+
? Object.entries(providers).filter(
370+
([name]) =>
371+
String(name || "")
372+
.toLowerCase()
373+
.trim() === provider
374+
)
375+
: Object.entries(providers);
376+
for (const [, providerData] of providerEntries) {
377+
const models = providerData && typeof providerData === "object" ? providerData.models : null;
378+
if (!models || typeof models !== "object" || Array.isArray(models)) continue;
379+
for (const [catalogModel, catalogEntry] of Object.entries(models)) {
380+
if (
381+
String(catalogModel || "")
382+
.toLowerCase()
383+
.trim() === model
384+
) {
385+
return catalogEntry && typeof catalogEntry === "object" && !Array.isArray(catalogEntry) ? catalogEntry : null;
386+
}
387+
}
388+
}
389+
return null;
390+
}
391+
392+
/**
393+
* Infer the Copilot SDK provider type for a given endpoint provider name and model name.
394+
*
395+
* The SDK's `ProviderConfig.type` field determines which API format the SDK uses when
396+
* communicating with the `baseUrl` endpoint:
397+
* - "anthropic" — Anthropic Messages API (required for direct Anthropic API endpoints)
398+
* - "azure" — Azure OpenAI API
399+
* - "openai" — OpenAI-compatible API (default; used for Copilot, OpenAI, Gemini, etc.)
400+
*
401+
* Resolution order:
402+
* 1. Endpoint provider name mapping (most authoritative for BYOK endpoints).
403+
* 2. Model catalog lookup via the `modelsJson` catalog (explicit `provider_type` field).
404+
* 3. Well-known model name heuristics (e.g. "claude-*" → "anthropic", "gpt-*" → "openai").
405+
* 4. Default: "openai".
406+
*
407+
* @param {string} endpointProvider - The `provider` field from the AWF reflect endpoint entry.
408+
* @param {string} modelName - The resolved model name to use for heuristic fallback.
409+
* @param {object | null | undefined} catalogEntryOrModelsJson - Matching models.json catalog entry or full catalog (optional).
410+
* @returns {"openai" | "azure" | "anthropic"}
411+
*/
412+
function inferProviderTypeForModel(endpointProvider, modelName, catalogEntryOrModelsJson) {
413+
// 1. Endpoint provider name mapping.
414+
const ep = String(endpointProvider || "")
415+
.toLowerCase()
416+
.trim();
417+
if (ep === "anthropic") return "anthropic";
418+
if (ep === "azure" || ep === "azure-openai" || ep === "azure_openai") return "azure";
419+
if (ep === "openai") return "openai";
420+
// For "copilot", "github-copilot", and unknown providers, fall through to model-based lookup.
421+
422+
const model = String(modelName || "")
423+
.toLowerCase()
424+
.trim();
425+
const catalogEntry =
426+
catalogEntryOrModelsJson && typeof catalogEntryOrModelsJson === "object" && !Array.isArray(catalogEntryOrModelsJson) && "providers" in catalogEntryOrModelsJson
427+
? getCatalogModelEntry(catalogEntryOrModelsJson, model)
428+
: catalogEntryOrModelsJson;
429+
430+
// 2. Model catalog lookup.
431+
if (model) {
432+
const pt = catalogEntry && typeof catalogEntry.provider_type === "string" ? catalogEntry.provider_type.trim() : "";
433+
if (pt === "anthropic" || pt === "azure" || pt === "openai") return /** @type {"openai" | "azure" | "anthropic"} */ pt;
434+
}
435+
436+
// 3. Well-known model name heuristics.
437+
if (model) {
438+
if (isAnthropicModelName(model)) return "anthropic";
439+
if (isOpenAIModelName(model)) return "openai";
440+
}
441+
442+
// 4. Default.
443+
return "openai";
444+
}
445+
446+
/**
447+
* Infer the SDK wire API for a model.
448+
*
449+
* Resolution order:
450+
* 1. For Anthropic provider types: undefined (wireApi ignored by SDK).
451+
* 2. `models.json` explicit `wire_api`/`wireApi`.
452+
* 3. Heuristic default for OpenAI/Azure-compatible models: "completions".
453+
*
454+
* @param {"openai" | "azure" | "anthropic"} providerType
455+
* @param {string} modelName
456+
* @param {object | null | undefined} catalogEntryOrModelsJson
457+
* @returns {"completions" | "responses" | undefined}
458+
*/
459+
function inferWireApiForModel(providerType, modelName, catalogEntryOrModelsJson) {
460+
if (providerType === "anthropic") {
461+
return undefined;
462+
}
463+
const model = String(modelName || "").trim();
464+
if (!model) return undefined;
465+
const catalogEntry =
466+
catalogEntryOrModelsJson && typeof catalogEntryOrModelsJson === "object" && !Array.isArray(catalogEntryOrModelsJson) && "providers" in catalogEntryOrModelsJson
467+
? getCatalogModelEntry(catalogEntryOrModelsJson, model)
468+
: catalogEntryOrModelsJson;
469+
// Keep the camelCase fallback for defensive compatibility with injected catalog
470+
// objects that bypass the normalized models.json pipeline.
471+
const rawWireApi = typeof catalogEntry?.wire_api === "string" ? catalogEntry.wire_api : typeof catalogEntry?.wireApi === "string" ? catalogEntry.wireApi : "";
472+
const normalizedWireApi = String(rawWireApi || "")
473+
.toLowerCase()
474+
.trim();
475+
if (normalizedWireApi === "responses" || normalizedWireApi === "completions") {
476+
return /** @type {"responses" | "completions"} */ normalizedWireApi;
477+
}
478+
return "completions";
479+
}
480+
324481
/**
325482
* Resolve Copilot SDK BYOK custom provider configuration from AWF /reflect data.
326-
* Chooses a configured endpoint and maps it to an OpenAI-compatible provider base URL.
483+
* Chooses a configured endpoint and maps it to a provider base URL and type.
327484
* Returns null when no suitable endpoint is found (e.g. no reflect data, or endpoints not
328485
* configured).
329486
*
@@ -333,9 +490,10 @@ async function fetchAWFReflect(options) {
333490
* model?: string,
334491
* provider?: string,
335492
* reflectData: object | null | undefined,
493+
* modelsJson?: object | null,
336494
* logger?: (msg: string) => void,
337495
* }} [options]
338-
* @returns {{ model: string, provider: { type: "openai", baseUrl: string } } | null}
496+
* @returns {{ model: string, provider: { type: "openai" | "azure" | "anthropic", baseUrl: string, wireApi?: "completions" | "responses" } } | null}
339497
*/
340498
function resolveCopilotSDKCustomProviderFromReflect(options) {
341499
const configuredModel = typeof options?.model === "string" ? options.model.trim() : "";
@@ -386,10 +544,20 @@ function resolveCopilotSDKCustomProviderFromReflect(options) {
386544
return null;
387545
}
388546

389-
logger(`sdk-mode: custom provider resolved from awf-reflect (provider=${String(endpoint.provider || "unknown")} baseUrl=${baseUrl} model=${model})`);
547+
const endpointProvider = String(endpoint.provider || "");
548+
const catalogProviderName =
549+
String(endpointProvider || "")
550+
.toLowerCase()
551+
.trim() === "copilot"
552+
? "github-copilot"
553+
: endpointProvider;
554+
const catalogEntry = getCatalogModelEntry(options?.modelsJson ?? null, model, catalogProviderName);
555+
const providerType = inferProviderTypeForModel(endpointProvider, model, catalogEntry);
556+
const wireApi = inferWireApiForModel(providerType, model, catalogEntry);
557+
logger(`sdk-mode: custom provider resolved from awf-reflect (provider=${String(endpoint.provider || "unknown")} type=${providerType} baseUrl=${baseUrl} model=${model}${wireApi ? ` wireApi=${wireApi}` : ""})`);
390558
return {
391559
model,
392-
provider: { type: "openai", baseUrl },
560+
provider: { type: providerType, baseUrl, ...(wireApi ? { wireApi } : {}) },
393561
};
394562
}
395563

@@ -407,6 +575,9 @@ if (typeof module !== "undefined" && module.exports) {
407575
extractModelIds,
408576
fetchAWFReflect,
409577
fetchModelsFromUrl,
578+
getCatalogModelEntry,
579+
inferProviderTypeForModel,
580+
inferWireApiForModel,
410581
resolveCopilotSDKCustomProviderFromReflect,
411582
};
412583
}

‎setup/js/codex_harness.cjs‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const MAX_DELAY_MS = 60000;
6464
// the human-readable message Codex emits inside "Reconnecting..." / error lines:
6565
// "Rate limit reached for <model> in organization <org> on tokens per min (TPM): ..."
6666
const RATE_LIMIT_ERROR_PATTERN = /rate_limit_exceeded|429 Too Many Requests|RateLimitError|Rate limit reached for [^\s]+(?: in organization [^\s]+)? on tokens per min/i;
67+
const TOKEN_PER_MIN_RATE_LIMIT_PATTERN = /Rate limit reached for [^\s]+(?: in organization [^\s]+)? on tokens per min/i;
6768

6869
// Pattern to detect when Codex's internal stream-reconnect budget is fully spent.
6970
// Codex emits "Reconnecting... N/N (reason)" where both numbers are the same when
@@ -106,6 +107,17 @@ function isRateLimitError(output) {
106107
return RATE_LIMIT_ERROR_PATTERN.test(output);
107108
}
108109

110+
/**
111+
* Determines if the collected output indicates OpenAI token-per-minute exhaustion.
112+
* This limit is workload-dependent and immediate fresh-run retries can consume
113+
* additional budget without making progress.
114+
* @param {string} output - Collected stdout+stderr from the process
115+
* @returns {boolean}
116+
*/
117+
function isTokenPerMinuteRateLimitError(output) {
118+
return TOKEN_PER_MIN_RATE_LIMIT_PATTERN.test(output);
119+
}
120+
109121
/**
110122
* Determines if the collected output contains an authentication failed error.
111123
* @param {string} output - Collected stdout+stderr from the process
@@ -436,6 +448,7 @@ async function main() {
436448
}
437449

438450
const isRateLimit = isRateLimitError(result.output);
451+
const isTokenPerMinuteRateLimit = isTokenPerMinuteRateLimitError(result.output);
439452
const isAuthenticationFailed = isAuthenticationFailedError(result.output);
440453
const isMissingApiKey = isMissingApiKeyError(result.output);
441454
const isServer = isServerError(result.output);
@@ -446,6 +459,7 @@ async function main() {
446459
`attempt ${attempt + 1} failed:` +
447460
` exitCode=${result.exitCode}` +
448461
` isRateLimitError=${isRateLimit}` +
462+
` isTokenPerMinuteRateLimitError=${isTokenPerMinuteRateLimit}` +
449463
` isAuthenticationFailedError=${isAuthenticationFailed}` +
450464
` isMissingApiKeyError=${isMissingApiKey}` +
451465
` isServerError=${isServer}` +
@@ -506,6 +520,14 @@ async function main() {
506520
break;
507521
}
508522

523+
// Token-per-minute limits indicate exhausted budget for the current workload profile.
524+
// Fresh-run retries immediately repeat the same prompt workload and can quickly
525+
// drain available credits without making forward progress.
526+
if (isTokenPerMinuteRateLimit) {
527+
log(`attempt ${attempt + 1}: token-per-minute rate limit detected — not retrying (fresh runs can further drain token budget)`);
528+
break;
529+
}
530+
509531
// Codex's internal stream-reconnect retries are exhausted and the root cause is a
510532
// rate-limit error. Each reconnect attempt immediately failed with the same limit,
511533
// so a fresh harness run will encounter the same rate-limit at the same point in the
@@ -545,6 +567,7 @@ if (typeof module !== "undefined" && module.exports) {
545567
resolveCodexPromptFileArgs,
546568
injectJsonFlag,
547569
isRateLimitError,
570+
isTokenPerMinuteRateLimitError,
548571
isAuthenticationFailedError,
549572
isMissingApiKeyError,
550573
isServerError,

0 commit comments

Comments
 (0)