Skip to content

Commit 4d16e5e

Browse files
lpcoxCopilot
andcommitted
fix: correct double-indentation of [shell_environment_policy] in Codex config.toml
The postprocess script had an extra ${indent} before $3 in the replacement string, but $3 already captures the indent prefix. This caused [shell_environment_policy] to be double-indented (20 spaces instead of 10). Fix: remove the redundant ${indent} from the replacement string. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent bd3fde7 commit 4d16e5e

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

.github/workflows/secret-digger-codex.lock.yml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/smoke-codex.lock.yml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/ci/postprocess-smoke-workflows.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,27 @@ for (const workflowPath of workflowPaths) {
714714
}
715715
}
716716

717+
// Matches the Codex config.toml heredoc opening followed (possibly with
718+
// previously-injected lines in between) by [shell_environment_policy], so we
719+
// can inject [model_providers.openai] config at the top of the config.toml
720+
// before the shell environment policy section. The non-greedy (?:...)* skips
721+
// any lines previously inserted by earlier versions of this script, making the
722+
// transformation idempotent and upgradable. The hash in the heredoc delimiter
723+
// varies across compiler versions, so we match \w+ instead of a literal hash.
724+
//
725+
// Codex v0.121+ ignores OPENAI_BASE_URL env var when constructing WebSocket URLs
726+
// for the responses API (wss://api.openai.com/v1/responses), connecting directly
727+
// to OpenAI and sending the api-proxy placeholder key → 401 Unauthorized.
728+
// Setting supports_websockets=false disables WebSocket transport, forcing Codex
729+
// to use REST for all API calls. REST calls respect OPENAI_BASE_URL (set by AWF's
730+
// docker-manager to http://172.30.0.30:10000), which routes them through the
731+
// api-proxy sidecar that injects the real OpenAI API key.
732+
//
733+
// See: https://developers.openai.com/codex/config-reference
734+
const codexConfigTomlHeredocRegex =
735+
/^(\s+)(cat > "\/tmp\/gh-aw\/mcp-config\/config\.toml" << GH_AW_CODEX_SHELL_POLICY_\w+_EOF\n)(?:\1[^\n]*\n)*?(\1\[shell_environment_policy\])/m;
736+
const CODEX_OPENAI_BASE_URL_SENTINEL = 'supports_websockets = false';
737+
717738
// Apply Codex-specific transformations to OpenAI/Codex workflow files only.
718739
// These transformations must not be applied to Claude, Copilot, or other
719740
// non-OpenAI workflows.
@@ -727,6 +748,37 @@ for (const workflowPath of codexWorkflowPaths) {
727748
}
728749
let modified = false;
729750

751+
// Inject [model_providers.openai] with supports_websockets=false into the Codex
752+
// config.toml heredoc to disable WebSocket transport for the OpenAI provider.
753+
// Codex v0.121+ ignores OPENAI_BASE_URL for WebSocket URL construction and
754+
// connects directly to wss://api.openai.com/v1/responses with the api-proxy
755+
// placeholder key, causing 401 Unauthorized. With WebSocket disabled, Codex
756+
// falls back to REST, which correctly routes through OPENAI_BASE_URL
757+
// (http://172.30.0.30:10000) → api-proxy sidecar → real OpenAI API key.
758+
if (!content.includes(CODEX_OPENAI_BASE_URL_SENTINEL)) {
759+
const heredocMatch = content.match(codexConfigTomlHeredocRegex);
760+
if (heredocMatch) {
761+
const indent = heredocMatch[1];
762+
const modelProvidersBlock =
763+
`${indent}[model_providers.openai]\n` +
764+
`${indent}${CODEX_OPENAI_BASE_URL_SENTINEL}\n` +
765+
`${indent}\n`;
766+
content = content.replace(
767+
codexConfigTomlHeredocRegex,
768+
`$1$2${modelProvidersBlock}$3`
769+
);
770+
modified = true;
771+
console.log(` Injected [model_providers.openai] supports_websockets=false into Codex config.toml heredoc`);
772+
} else {
773+
console.warn(
774+
` WARNING: Could not find Codex config.toml heredoc pattern to inject model_providers config. ` +
775+
`The compiled lock file may have changed structure. Manual review required.`
776+
);
777+
}
778+
} else {
779+
console.log(` [model_providers.openai] supports_websockets=false already present in Codex config.toml`);
780+
}
781+
730782
// Preserve empty lines as truly empty (no trailing whitespace) to keep the
731783
// YAML block scalar clean and diff-friendly.
732784
function buildXpiaHeredoc(indent: string, appendSuffix: string): string {

0 commit comments

Comments
 (0)