Add conditional architecture detection for CODEX_ARCH environment variable#595
Add conditional architecture detection for CODEX_ARCH environment variable#595aeltorio wants to merge 2 commits into
Conversation
…ian Bookworm if it is not set in env
icebear0828
left a comment
There was a problem hiding this comment.
uname -p 在 Alpine 上返回 unknown,建议改用 uname -m(Linux/macOS 上一致返回 aarch64/x86_64)。
- UNAME_ARCH=$(uname -p)
+ UNAME_ARCH=$(uname -m)其余 LGTM。
icebear0828
left a comment
There was a problem hiding this comment.
Thanks for the PR! A few things need to be addressed before merge.
Bug: else branch passes raw uname -m output into CODEX_ARCH (docker-entrypoint.sh)
On any arch that isn't aarch64 or x86_64 (e.g. armv7l, riscv64), CODEX_ARCH gets set to the raw kernel string. This value ends up in the User-Agent header sent to chatgpt.com, which may cause fingerprint mismatches or silent request failures.
Please either fail fast with a clear error on unrecognized architectures, or drop to a known safe default:
else
echo "[Error] Unsupported architecture: $UNAME_ARCH (expected aarch64 or x86_64)" >&2
exit 1
fiIncorrect flag in PR description
The description says uname -p, but the code uses uname -m. These are different — uname -p returns "unknown" on most Linux systems. Please correct the description.
Clarify what CODEX_ARCH actually controls
The PR description implies this affects native addon loading, but native/index.js uses process.arch (Node.js built-in), not CODEX_ARCH. In practice CODEX_ARCH only affects the User-Agent string and the /health endpoint output. Please update the description to reflect this so reviewers aren't misled.
No tests
Please add automated tests (e.g. bats) covering the three mapping scenarios: aarch64→arm64, x86_64→x64, and the unrecognized-arch path (whichever behavior you choose above).
Maps aarch64→arm64, x86_64→x64; passes unknown arches through. Respects pre-set CODEX_ARCH. Includes 5 shell-level tests using mock uname via PATH injection. Addresses #595.
|
Thanks! The arch auto-detection + 5 shell-level tests have been landed on dev (f18a879). Covers aarch64→arm64, x86_64→x64, unknown passthrough, preset CODEX_ARCH, and empty CODEX_ARCH. |
- CHANGELOG: CORS allowlist, Docker arch detection, OS cert store, output backfill - README/README_EN: add @aeltorio, @williamjameshandley, @FlavienKlr to contributors
Summary
This PR adds architecture detection logic for the
CODEX_ARCHenvironment variable in the Docker entrypoint script, but only when the variable is not already set or is empty. This change provides better flexibility for container deployments while maintaining backward compatibility. The main objective is for using the Docker image in multi-architecture Kubernetes environments.Changes Made
docker-entrypoint.shTechnical Details
Before
The script had no architecture detection, which could cause issues in environments where architecture-specific behavior was needed.
After
The script now includes conditional architecture detection that:
[ -z "${CODEX_ARCH}" ]to test if the variable is empty or unsetuname -pto detect the system architectureaarch64→arm64andx86_64→x64for consistencyArchitecture Mapping
aarch64→arm64x86_64→x64uname -poutputBenefits
Testing
The implementation has been tested with three scenarios:
Use Cases
This change is particularly useful for:
Impact
uname,export)The change follows the principle of "convention over configuration" while still allowing explicit configuration when needed.