OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
ci: limit duplicate native builds during merge bursts (#1999)
Michael D'Angeloc5dbc050be0c
diff --git a/.github/actionlint.yaml b/.github/actionlint.yamlindex 3d67b58db..3734e1945 100644--- a/.github/actionlint.yaml+++ b/.github/actionlint.yaml@@ -1,9 +1,14 @@paths:- .github/workflows/{container-release,node-github-release,node-release-cut,node-release-pr,node-release,release-progress}.yml:+ .github/workflows/{container-release,node-github-release,node-ci,node-release-cut,node-release-pr,node-release,release-progress}.yml:ignore:- # actionlint 1.7.12 predates GitHub's queue: max support. Keep release queuing.+ # actionlint 1.7.12 predates GitHub's queue: max support. Keep the supported queue setting.# https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/control-workflow-concurrency- '^unexpected key "queue" for "concurrency" section\.'+ .github/workflows/native-artifacts.yml:+ ignore:+ # actionlint 1.7.12 predates GitHub’s reference to the defining workflow's commit.+ # https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#jobsjob_idstepsuses+ - '^specifying action "\$/\.github/actions/native-cache-key" in invalid format because ref is missing\.'.github/workflows/invoice-desk-scan.yml:ignore:# actionlint 1.7.12 predates GitHub's job-level cache permissions.diff --git a/.github/actions/native-cache-key/action.yml b/.github/actions/native-cache-key/action.ymlnew file mode 100644index 000000000..a89cf98f1--- /dev/null+++ b/.github/actions/native-cache-key/action.yml@@ -0,0 +1,12 @@+name: Native cache key+description: Fingerprint the checked-out native build and proof inputs.+outputs:+ key:+ description: Exact key for this source and UTC week.+ value: ${{ steps.key.outputs.key }}+runs:+ using: composite+ steps:+ - id: key+ shell: bash+ run: bash "$GITHUB_ACTION_PATH/key.sh" >> "$GITHUB_OUTPUT"diff --git a/.github/actions/native-cache-key/key.sh b/.github/actions/native-cache-key/key.shnew file mode 100644index 000000000..70e7b87e4--- /dev/null+++ b/.github/actions/native-cache-key/key.sh@@ -0,0 +1,42 @@+#!/usr/bin/env bash+set -euo pipefail+# Include filenames and modes, not only file contents. Windows proofs+# bundle MCP helpers, including their schema and workbench dependencies.+empty_tree="$(git hash-object -t tree --stdin </dev/null)"+# These existing CI entrypoints run outside the native jobs.+ci_only=':(exclude).github/scripts/'+source_hash="$(git diff-tree -r -z --no-abbrev "$empty_tree" HEAD -- \+ .gitattributes .cargo .npmrc .pnpmfile.cjs package.json pnpm-workspace.yaml \+ .github/actions/{native-cache-key,setup-tools} .github/scripts \+ "${ci_only}"invoice-desk-{source,target}{,.test}.mjs \+ "${ci_only}"{check-ci-results,select-ci-checks,test-ci-selection,test-release-guide}.mjs \+ "${ci_only}"{verify-pr-source,test-verify-pr-source,release-progress,test_release_progress}.mjs \+ "${ci_only}"{install-ripgrep.sh,require_native_python_report.py,test_require_native_python_report.py} \+ .github/workflows/native-artifacts.yml \+ .github/workflows/native-unix.yml \+ .github/workflows/native-windows.yml \+ .github/workflows/native-musl.yml \+ sdk/typescript/.npmrc sdk/typescript/.pnpmfile.cjs \+ sdk/typescript/package.json sdk/typescript/pnpm-lock.yaml \+ sdk/typescript/pnpm-workspace.yaml \+ sdk/typescript/tsconfig.json sdk/typescript/tsconfig.ci.json \+ plugins/codex-security/native plugins/codex-security/mcp-app \+ ':(exclude)plugins/codex-security/mcp-app/tests' \+ plugins/codex-security/schemas plugins/codex-security/scripts \+ plugins/codex-security/shared | git hash-object --stdin)"+# Hosted runner images can change without a source change.+# Keep a protected push in the week it was classified, including at UTC rollover.+week=${NATIVE_CACHE_WEEK:-0}+if [[ $week == 0 ]]; then week="$(date -u +%G%V)"; fi+key="native-universal-v1-${week:0:4}-${week:4}-$source_hash"+if [[ ${1-} == cold-group ]]; then+ printf 'week=%s\n' "$week"+ # The listing is only a scheduling hint. prepare always restores or builds.+ hit="$(timeout 5s gh cache list --ref refs/heads/main --key "$key" --limit 1 --json key --jq '.[0].key // empty')"+ # Three lanes per 300 workflow numbers keep each group within GitHub's 100-pending limit.+ if [[ "$hit" != "$key" ]]; then+ printf 'cold-group=%s-%s-%s\n' "$key" "$((GITHUB_RUN_NUMBER / 300))" "$((GITHUB_RUN_NUMBER % 3))"+ fi+else+ printf 'key=%s\n' "$key"+fidiff --git a/.github/workflows/native-artifacts.yml b/.github/workflows/native-artifacts.ymlindex ad82eff43..e7b64fa93 100644--- a/.github/workflows/native-artifacts.yml+++ b/.github/workflows/native-artifacts.yml@@ -11,6 +11,10 @@ on:description: Reuse this week's verified payload when all native build and proof inputs match.type: booleandefault: false+ cache-week:+ description: UTC ISO year and week selected by the source CI classifier; zero uses the current week.+ type: number+ default: 0workflow_dispatch:permissions:@@ -30,35 +34,10 @@ jobs:persist-credentials: false- name: Identify native build and proof inputsid: key- shell: bash- run: |- set -euo pipefail- # Include filenames and modes, not only file contents. Windows proofs- # bundle MCP helpers, including their schema and workbench dependencies.- empty_tree="$(git hash-object -t tree --stdin </dev/null)"- # These existing CI entrypoints run outside the native jobs.- ci_only=':(exclude).github/scripts/'- source_hash="$(git diff-tree -r -z --no-abbrev "$empty_tree" HEAD -- \- .gitattributes .cargo .npmrc .pnpmfile.cjs package.json pnpm-workspace.yaml \- .github/actions/setup-tools .github/scripts \- "${ci_only}"invoice-desk-{source,target}{,.test}.mjs \- "${ci_only}"{check-ci-results,select-ci-checks,test-ci-selection,test-release-guide}.mjs \- "${ci_only}"{verify-pr-source,test-verify-pr-source,release-progress,test_release_progress}.mjs \- "${ci_only}"{install-ripgrep.sh,require_native_python_report.py,test_require_native_python_report.py} \- .github/workflows/native-artifacts.yml \- .github/workflows/native-unix.yml \- .github/workflows/native-windows.yml \- .github/workflows/native-musl.yml \- sdk/typescript/.npmrc sdk/typescript/.pnpmfile.cjs \- sdk/typescript/package.json sdk/typescript/pnpm-lock.yaml \- sdk/typescript/pnpm-workspace.yaml \- sdk/typescript/tsconfig.json sdk/typescript/tsconfig.ci.json \- plugins/codex-security/native plugins/codex-security/mcp-app \- ':(exclude)plugins/codex-security/mcp-app/tests' \- plugins/codex-security/schemas plugins/codex-security/scripts \- plugins/codex-security/shared | git hash-object --stdin)"- # Hosted runner images can change without a source change.- printf 'key=native-universal-v1-%s-%s\n' "$(date -u +%G-%V)" "$source_hash" >> "$GITHUB_OUTPUT"+ # Resolve the helper from this workflow even when the caller selects an older checkout.+ uses: $/.github/actions/native-cache-key+ env:+ NATIVE_CACHE_WEEK: ${{ inputs.cache-week }}- name: Restore verified native payloadif: inputs.reuse-verifiedid: restorediff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.ymlindex c7d21f48c..f2c6d61af 100644--- a/.github/workflows/node-ci.yml+++ b/.github/workflows/node-ci.yml@@ -29,6 +29,8 @@ jobs:actions: readpull-requests: readoutputs:+ native-cache-group: ${{ steps.native-cache.outputs.cold-group }}+ native-cache-week: ${{ steps.native-cache.outputs.week }}source-run: ${{ steps.proof.outputs.source-run }}edit-attempt: ${{ steps.proof.outputs.edit-attempt }}source-required: ${{ steps.scope.outputs.source-required }}@@ -61,6 +63,14 @@ jobs:BASE_CHANGED: ${{ github.event.action == 'edited' }}run: node .github/scripts/select-ci-checks.mjs+ - name: Group protected pushes waiting for the same native cache+ id: native-cache+ if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.ref_protected && github.run_attempt == 1+ continue-on-error: true+ env:+ GH_TOKEN: ${{ github.token }}+ run: bash .github/actions/native-cache-key/key.sh cold-group >> "$GITHUB_OUTPUT"+workflow-quality:needs: classify-changesif: needs.classify-changes.outputs.workflow-quality == 'true'@@ -119,9 +129,14 @@ jobs:native:if: needs.classify-changes.outputs.package-required == 'true'needs: classify-changes+ # Hits and PRs keep a unique group. Every entrant restores or rebuilds on its own commit.+ concurrency:+ group: native-producer-${{ github.run_attempt == 1 && needs.classify-changes.outputs.native-cache-group || github.run_id }}+ queue: maxuses: ./.github/workflows/native-artifacts.ymlwith:reuse-verified: true+ cache-week: ${{ fromJSON(github.run_attempt == 1 && needs.classify-changes.outputs.native-cache-week || '0') }}container-validate:needs: [classify-changes, native, static-checks]diff --git a/docs/ci.md b/docs/ci.mdindex 643a48a0c..c213def12 100644--- a/docs/ci.md+++ b/docs/ci.md@@ -124,16 +124,18 @@ execution time, prerequisite waits, runner scheduling, approval waits, andmanual retry delays. Compare matching revisions and test configurations, andrecord failures as well as successful runs.-When a batch of merges can wait, check **Restore verified native payload** in-an active `node-ci` push or scheduled run on `main`. On a miss, another push-with the same inputs can start all eight platform builds again. Before merging-a PR that leaves those inputs unchanged, look for the exact key in-`gh cache list --ref refs/heads/main --key KEY`. Once it is there, it does not-matter which `main` run saved it. Different inputs can build in parallel.--The key uses the UTC week and the paths listed in **Identify native build and-proof inputs**. Repository scripts are included by default: a native proof can-load a helper at runtime. The workflow excludes known CI entrypoints that run-elsewhere. Compare the next change against current `main`: its PR run may have-tested an older base or skipped native preparation. PRs cannot populate this+Protected `main` pushes that miss the same native cache use three queues per+300 workflow numbers, keeping each queue within GitHub’s capacity. Each run looks+up the verified payload again; a miss still builds and proves all eight+platforms. The cache listing only selects a queue. Hits, unavailable listings,+different inputs, and PR checks can start independently.++When a batch can wait, look for the first protected cache save before landing+more changes with the same inputs: `gh cache list --ref refs/heads/main --key KEY`.+The key uses the UTC week selected for the run and the paths in+[the native key action](../.github/actions/native-cache-key/key.sh). Repository+scripts are included by default: a native proof can load a helper at runtime.+The workflow excludes known CI entrypoints that run elsewhere. Compare the+next change against current `main`: its PR run may have tested an older base+or skipped native preparation. PRs cannot populate thiscache for `main`.diff --git a/sdk/typescript/tests-ts/native-artifact-cache.test.ts b/sdk/typescript/tests-ts/native-artifact-cache.test.tsindex 9216cdd30..b4b686154 100644--- a/sdk/typescript/tests-ts/native-artifact-cache.test.ts+++ b/sdk/typescript/tests-ts/native-artifact-cache.test.ts@@ -38,12 +38,14 @@ function workflow(name: string) {const native = workflow("native-artifacts");const prepare = native.jobs["prepare"]!;-const keyScript = prepare.steps!.find((step) => step.id === "key")!.run!;+const keyScript = readFileSync(+ new URL("../../../.github/actions/native-cache-key/key.sh", import.meta.url),+ "utf8",+);test("native reuse hashes committed inputs with Git alone across platforms", () => {const root = mkdtempSync(join(tmpdir(), "native-cache-"));const repository = join(root, "repository");- const output = join(root, "output");const source = "plugins/codex-security/native/src/lib.rs";const helper = "plugins/codex-security/mcp-app/src/native.ts";const proof = "plugins/codex-security/native/proof.mjs";@@ -62,15 +64,21 @@ test("native reuse hashes committed inputs with Git alone across platforms", ()git(repository, "add", ".");git(repository, "commit", "-qm", "fixture");};- const key = (week = "2026-43") => {- writeSource(root, "output", "");+ const key = (+ week = "2026-43",+ run?: number,+ cached = "",+ admittedWeek = "0",+ ) => {const result = spawnSync(Bun.which(bashCommand())!,["--noprofile","--norc","-c",- `git() { "$TEST_GIT" "$@"; }\ndate() { printf '%s\\n' "$TEST_WEEK"; }\n${keyScript}`,+ `git() { "$TEST_GIT" "$@"; }\ndate() { printf '%s\\n' "$TEST_WEEK"; }\ntimeout() { printf '%s\\n' "$TEST_CACHED"; }\n${keyScript}`,+ "native-cache-key",+ ...(run === undefined ? [] : ["cold-group"]),],{cwd: repository,@@ -81,18 +89,21 @@ test("native reuse hashes committed inputs with Git alone across platforms", ()// available here; the workflow's date command is fixed for this test.PATH: root,TEST_GIT: Bun.which("git")!,- GITHUB_OUTPUT: output,- TEST_WEEK: week,+ TEST_WEEK: week.replace("-", ""),+ NATIVE_CACHE_WEEK: admittedWeek,+ TEST_CACHED: cached,+ GITHUB_RUN_NUMBER: String(run),},},);expect(result.status, result.stderr).toBe(0);- return readFileSync(output, "utf8").trim();+ return result.stdout.trim();};try {commit();const initial = key();expect(initial).toMatch(/^key=native-universal-v1-2026-43-[a-f0-9]{40}$/);+ const fingerprint = initial.slice("key=".length);expect(runProof()).toBe(0);write("README.md", "updated documentation\n");@@ -108,7 +119,7 @@ test("native reuse hashes committed inputs with Git alone across platforms", ()}write("plugins/codex-security/mcp-app/tests/support/new.ts", "fixture\n");commit();- expect(key()).toBe(initial);+ expect(key("2026-43", 4, fingerprint)).toBe("week=202643");let previous = initial;const expectNewKey = () => {@@ -131,7 +142,16 @@ test("native reuse hashes committed inputs with Git alone across platforms", ()join(repository, "plugins/codex-security/native/src/renamed.rs"),);expectNewKey();- expect(key("2026-44")).not.toBe(previous);+ const nextWeek = previous+ .slice("key=".length)+ .replace("2026-43", "2026-44");+ const cold = key("2026-44", 4, fingerprint);+ expect(cold).toBe(`week=202644\ncold-group=${nextWeek}-0-1`);+ const admittedWeek = cold.split("\n")[0]!.slice("week=".length);+ expect(key("2026-45", undefined, "", admittedWeek)).toBe(`key=${nextWeek}`);+ expect(key("2026-44", 304, fingerprint)).toBe(+ `week=202644\ncold-group=${nextWeek}-1-1`,+ );} finally {rmSync(root, { recursive: true, force: true });}diff --git a/sdk/typescript/tests-ts/release-automation.test.ts b/sdk/typescript/tests-ts/release-automation.test.tsindex e68172f0c..983b49113 100644--- a/sdk/typescript/tests-ts/release-automation.test.ts+++ b/sdk/typescript/tests-ts/release-automation.test.ts@@ -3975,6 +3975,7 @@ PATH="$RUNNER_TEMP:$PATH" verify`,const flags = Object.keys(classifierOutputs).filter((key) =>!["source-run", "edit-attempt"].includes(key) &&+ !key.startsWith("native-cache-") &&!key.endsWith("-matrix"),);for (const enabled of flags) {