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(invoice): separate scheduled evaluation from PR checks (#1895)
Michael D'Angelo6f9490dfbc1f
diff --git a/.github/scripts/invoice-desk-target.mjs b/.github/scripts/invoice-desk-target.mjsindex 43bb6412b..fc01ecf2e 100644--- a/.github/scripts/invoice-desk-target.mjs+++ b/.github/scripts/invoice-desk-target.mjs@@ -11,14 +11,9 @@ function eligible(pr, repository, sha) {);}-export async function resolveScanTargets(- context,- getPullRequest,- pullRequestsForCommit,- dispatchedScanTitles,-) {+export async function resolveScanTargets(context, getPullRequest) {const { eventName, event, repository, sha, target } = context;- // After approval, recheck this matrix entry rather than other PRs on the same commit.+ // After approval, keep the scan bound to its original PR and source commit.if (target) {if (target.pr === 0) return [{ pr: 0, sha }];const pr = await getPullRequest(String(target.pr));@@ -26,26 +21,7 @@ export async function resolveScanTargets(? [{ pr: pr.number, sha: target.sha }]: [];}- if (eventName === "workflow_run") {- const run = event.workflow_run;- if (run.event !== "pull_request" || run.conclusion === "cancelled")- return [];- // GitHub can suppress target events for automated PRs and some branch names.- const requests = await pullRequestsForCommit(run.head_sha);- const numbers = new Set(run.pull_requests.map((pr) => pr.number));- const candidates = requests.filter(- (pr) =>- eligible(pr, repository, run.head_sha) &&- (numbers.size === 0 || numbers.has(pr.number)),- );- if (candidates.length === 0) return [];- const dispatched = new Set(await dispatchedScanTitles(sha));- return candidates.flatMap((pr) =>- !dispatched.has(`Invoice Desk scan — PR #${pr.number} @ ${pr.head.sha}`)- ? { pr: pr.number, sha: pr.head.sha }- : [],- );- }+ if (eventName === "schedule") return [{ pr: 0, sha }];if (eventName !== "workflow_dispatch") return [];const { pr_number: number = "", source_sha: sourceSha = "" } =event.inputs ?? {};@@ -62,8 +38,6 @@ export async function resolveScanTargets(}if (isMain(import.meta.url)) {- const api = (args, options = {}) =>- execFileSync("gh", ["api", ...args], { encoding: "utf8", ...options });const repository = process.env.GITHUB_REPOSITORY;const targets = await resolveScanTargets({@@ -79,56 +53,23 @@ if (isMain(import.meta.url)) {sha: process.env.SOURCE_SHA,},},- (number) => JSON.parse(api([`repos/${repository}/pulls/${number}`])),- (sha) =>+ (number) =>JSON.parse(- api([- "--paginate",- "--slurp",- `repos/${repository}/commits/${sha}/pulls?per_page=100`,- ]),- ).flat(),- (sha) =>- JSON.parse(- api(- [- "--paginate",- "--slurp",- `repos/${repository}/actions/workflows/invoice-desk-scan.yml/runs?event=workflow_dispatch&branch=main&head_sha=${sha}&per_page=100`,- ],- { maxBuffer: Infinity },- ),- ).flatMap((page) => page.workflow_runs.map((run) => run.display_title)),+ execFileSync("gh", ["api", `repos/${repository}/pulls/${number}`], {+ encoding: "utf8",+ }),+ ),);- const fallback = process.env.GITHUB_EVENT_NAME === "workflow_run";- if (fallback) {- for (const { pr, sha } of targets) {- execFileSync("gh", [- "workflow",- "run",- "invoice-desk-scan.yml",- "--repo",- repository,- "--ref",- "main",- "-f",- `pr_number=${pr}`,- "-f",- `source_sha=${sha}`,- ]);- }- }appendFileSync(process.env.GITHUB_OUTPUT,- `targets=${JSON.stringify(fallback ? [] : targets)}\n`,+ `targets=${JSON.stringify(targets)}\n`,);const message =targets.length === 0? "Skipped: no eligible PR revision needs a scan.": targets.map(- ({ pr, sha }) =>- `${fallback ? "Queued " : ""}${pr ? `PR #${pr}` : "Main baseline"} at ${sha}`,+ ({ pr, sha }) => `${pr ? `PR #${pr}` : "Main baseline"} at ${sha}`,).join("\n");console.log(message);diff --git a/.github/scripts/invoice-desk-target.test.mjs b/.github/scripts/invoice-desk-target.test.mjsindex ad9fcf5f8..237eef4ea 100644--- a/.github/scripts/invoice-desk-target.test.mjs+++ b/.github/scripts/invoice-desk-target.test.mjs@@ -101,196 +101,106 @@ test("ignores unexpected events without querying GitHub", async () => {);});-const automationContext = {- ...context,- eventName: "workflow_run",- event: {- workflow_run: {- event: "pull_request",- actor: { login: "github-actions[bot]" },- conclusion: "success",- head_sha: sourceSha,- pull_requests: [{ number: 7 }],- },- },-};--test("falls back to completed behavior runs for GITHUB_TOKEN-created PRs", async () => {- for (const conclusion of ["success", "failure"]) {- const run = structuredClone(automationContext);- run.event.workflow_run.conclusion = conclusion;- assert.deepEqual(- await resolveScanTargets(- run,- () => assert.fail("unexpected direct lookup"),- async (sha) => {- assert.equal(sha, sourceSha);- return [- pullRequest(),- pullRequest({ number: 8 }),- pullRequest({ state: "closed" }),- ];- },- async (sha) => {- assert.equal(sha, mainSha);- return [];- },- ),- [{ pr: 7, sha: sourceSha }],- );- }-});--test("fallback rechecks current heads and handles empty association metadata", async () => {- const run = structuredClone(automationContext);- run.event.workflow_run.pull_requests = [];- const lookup = async () => [- pullRequest(),- pullRequest({ head: { sha: mainSha } }),- ];+test("scheduled baseline scans use the trusted workflow commit", async () => {assert.deepEqual(- await resolveScanTargets(run, null, lookup, async () => []),- [{ pr: 7, sha: sourceSha }],+ await resolveScanTargets(+ { ...context, eventName: "schedule", event: { schedule: "17 3 * * 1" } },+ () => assert.fail("unexpected API call"),+ ),+ [{ pr: 0, sha: mainSha }],);+});++test("completed behavior workflows no longer queue inference", async () => {assert.deepEqual(- await resolveScanTargets(run, null, async () => [- pullRequest({ state: "closed" }),- ]),+ await resolveScanTargets(+ {+ ...context,+ eventName: "workflow_run",+ event: {+ workflow_run: {+ event: "pull_request",+ conclusion: "success",+ head_sha: sourceSha,+ pull_requests: [{ number: 7 }],+ },+ },+ },+ () => assert.fail("unexpected API call"),+ ),[],);});-test("target events and cancelled runs do not queue fallback scans", async () => {+test("approval recheck stays bound to its matrix PR and source revision", async () => {+ const run = { ...context, target: { pr: 7, sha: sourceSha } };for (const changed of [- { event: "pull_request_target" },- { conclusion: "cancelled" },+ { state: "closed" },+ { base: { ref: "release", repo: { full_name: repository } } },+ { head: { sha: mainSha } },]) {- const run = structuredClone(automationContext);- Object.assign(run.event.workflow_run, changed);assert.deepEqual(- await resolveScanTargets(run, null, () =>- assert.fail("unexpected association lookup"),- ),+ await resolveScanTargets(run, async (number) => {+ assert.equal(number, "7");+ return pullRequest(changed);+ }),[],);}-});--test("approval recheck stays bound to its matrix PR even when another PR shares the commit", async () => {- const run = { ...automationContext, target: { pr: 7, sha: sourceSha } };- assert.deepEqual(- await resolveScanTargets(- run,- async (number) => {- assert.equal(number, "7");- return pullRequest({ state: "closed" });- },- () => assert.fail("must not select another associated PR"),- ),- [],- );assert.deepEqual(await resolveScanTargets(run, async () => pullRequest()), [{ pr: 7, sha: sourceSha },]);});-test("fallback covers human PRs when GitHub suppresses a target event", async () => {- const run = structuredClone(automationContext);- run.event.workflow_run.actor.login = "contributor";- run.event.workflow_run.head_branch = sourceSha;- assert.deepEqual(- await resolveScanTargets(- run,- null,- async () => [pullRequest()],- async () => [],- ),- [{ pr: 7, sha: sourceSha }],- );-});--test("fallback skips only the PR and head already dispatched from the same workflow revision", async () => {- const run = structuredClone(automationContext);- run.event.workflow_run.pull_requests = [];- assert.deepEqual(- await resolveScanTargets(- run,- null,- async () => [pullRequest(), pullRequest({ number: 8 })],- async (sha) => {- assert.equal(sha, mainSha);- return [- `Invoice Desk scan — PR #7 @ ${sourceSha}`,- `Invoice Desk scan — PR #8 @ ${mainSha}`,- ];- },- ),- [{ pr: 8, sha: sourceSha }],- );+test("baseline approval recheck retains the original trusted workflow commit", async () => {+ for (const eventName of ["workflow_dispatch", "schedule"]) {+ assert.deepEqual(+ await resolveScanTargets(+ { ...context, eventName, target: { pr: 0, sha: mainSha } },+ () => assert.fail("unexpected API call"),+ ),+ [{ pr: 0, sha: mainSha }],+ );+ }});-test("fallback CLI dispatches a keyed run once and leaves inference to that run", (t) => {- const root = mkdtempSync(join(tmpdir(), "invoice-desk-dispatch-"));+test("resolver CLI emits the requested target without dispatching another workflow", (t) => {+ const root = mkdtempSync(join(tmpdir(), "invoice-desk-target-"));t.after(() => rmSync(root, { recursive: true, force: true }));- const statePath = join(root, "dispatches.json");const eventPath = join(root, "event.json");const outputPath = join(root, "output.txt");- writeFileSync(statePath, "[]");- writeFileSync(eventPath, JSON.stringify(automationContext.event));+ writeFileSync(eventPath, JSON.stringify(context.event));const scriptUrl = new URL("./invoice-desk-target.mjs", import.meta.url);const script = `import assert from "node:assert/strict";import childProcess from "node:child_process";- import { readFileSync, writeFileSync } from "node:fs";import { syncBuiltinESMExports } from "node:module";- const statePath = ${JSON.stringify(statePath)};- const dispatches = JSON.parse(readFileSync(statePath, "utf8"));childProcess.execFileSync = (command, args) => {assert.equal(command, "gh");- if (args[0] === "workflow") {- assert.deepEqual(args, [- "workflow", "run", "invoice-desk-scan.yml", "--repo", ${JSON.stringify(repository)},- "--ref", "main", "-f", "pr_number=7", "-f", ${JSON.stringify(`source_sha=${sourceSha}`)}- ]);- dispatches.push(${JSON.stringify(`Invoice Desk scan — PR #7 @ ${sourceSha}`)});- writeFileSync(statePath, JSON.stringify(dispatches));- return "";- }- assert.equal(args[0], "api");- const endpoint = args.at(-1);- if (endpoint === ${JSON.stringify(`repos/${repository}/pulls/7`)})- return JSON.stringify(${JSON.stringify(pullRequest())});- if (endpoint === ${JSON.stringify(`repos/${repository}/commits/${sourceSha}/pulls?per_page=100`)})- return JSON.stringify([[${JSON.stringify(pullRequest())}]]);- assert.equal(endpoint, ${JSON.stringify(`repos/${repository}/actions/workflows/invoice-desk-scan.yml/runs?event=workflow_dispatch&branch=main&head_sha=${mainSha}&per_page=100`)});- return JSON.stringify([{ workflow_runs: dispatches.map(display_title => ({ display_title })) }]);+ assert.deepEqual(args, ["api", ${JSON.stringify(`repos/${repository}/pulls/7`)}]);+ return JSON.stringify(${JSON.stringify(pullRequest())});};syncBuiltinESMExports();process.argv[1] = ${JSON.stringify(fileURLToPath(scriptUrl))};await import(${JSON.stringify(scriptUrl.href)});`;- const run = (eventName) =>- execFileSync(process.execPath, ["--input-type=module", "--eval", script], {+ const result = execFileSync(+ process.execPath,+ ["--input-type=module", "--eval", script],+ {encoding: "utf8",env: {GITHUB_REPOSITORY: repository,GITHUB_SHA: mainSha,- GITHUB_EVENT_NAME: eventName,+ GITHUB_EVENT_NAME: "workflow_dispatch",GITHUB_EVENT_PATH: eventPath,GITHUB_OUTPUT: outputPath,},- });- assert.match(run("workflow_run"), /Queued PR #7/);- assert.match(run("workflow_run"), /Skipped/);- assert.deepEqual(JSON.parse(readFileSync(statePath, "utf8")), [- `Invoice Desk scan — PR #7 @ ${sourceSha}`,- ]);- assert.equal(readFileSync(outputPath, "utf8"), "targets=[]\ntargets=[]\n");-- writeFileSync(eventPath, JSON.stringify(context.event));- run("workflow_dispatch");+ },+ );+ assert.match(result, /PR #7/);assert.equal(- readFileSync(outputPath, "utf8").trim().split("\n").at(-1),- `targets=${JSON.stringify([{ pr: 7, sha: sourceSha }])}`,+ readFileSync(outputPath, "utf8"),+ `targets=${JSON.stringify([{ pr: 7, sha: sourceSha }])}\n`,);});diff --git a/.github/workflows/invoice-desk-scan.yml b/.github/workflows/invoice-desk-scan.ymlindex 5350ec305..10a9d8fe5 100644--- a/.github/workflows/invoice-desk-scan.yml+++ b/.github/workflows/invoice-desk-scan.yml@@ -1,10 +1,9 @@name: Invoice Desk OpenAI scan-run-name: "Invoice Desk scan — ${{ inputs.pr_number && format('PR #{0} @ {1}', inputs.pr_number, inputs.source_sha) || (github.event_name == 'workflow_run' && 'PR fallback' || 'main baseline') }}"+run-name: "Invoice Desk scan — ${{ inputs.pr_number && format('PR #{0} @ {1}', inputs.pr_number, inputs.source_sha) || 'main baseline' }}"on:- workflow_run:- workflows: ["Invoice Desk sample"]- types: [completed]+ schedule:+ - cron: "17 3 * * 1"workflow_dispatch:inputs:pr_number:@@ -19,10 +18,6 @@ on:permissions:contents: read-concurrency:- group: invoice-desk-scan-${{ github.event_name == 'workflow_dispatch' && (inputs.pr_number && format('pr-{0}-{1}', inputs.pr_number, inputs.source_sha) || 'main') || format('fallback-{0}', github.run_id) }}- cancel-in-progress: true-env:CODEX_SECURITY_VERSION: "0.1.30"@@ -31,13 +26,11 @@ jobs:# Only a workflow on protected main can request the inference environment.if: >-github.ref == 'refs/heads/main' && github.ref_protected &&- (github.event_name == 'workflow_dispatch' ||- github.event.workflow_run.event == 'pull_request')+ (github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')runs-on: ubuntu-24.04# This job reads only trusted helpers and event metadata before caching public packages.cache-mode: writepermissions:- actions: writecontents: readpull-requests: readoutputs:@@ -93,6 +86,11 @@ jobs:fail-fast: falsematrix:target: ${{ fromJSON(needs.target.outputs.targets) }}+ # Rejected requests must not cancel an eligible scan or its approval request.+ # A delayed target job must not cancel a scan of a different revision.+ concurrency:+ group: invoice-desk-scan-${{ matrix.target.pr && format('pr-{0}', matrix.target.pr) || 'main' }}-${{ matrix.target.sha }}+ cancel-in-progress: trueenvironment: codex-security-smoke-testruns-on: ubuntu-24.04timeout-minutes: 60diff --git a/.github/workflows/invoice-desk.yml b/.github/workflows/invoice-desk.ymlindex b166fde80..9fbdc9212 100644--- a/.github/workflows/invoice-desk.yml+++ b/.github/workflows/invoice-desk.yml@@ -4,41 +4,21 @@ on:pull_request:branches: [main]types: [opened, reopened, synchronize, edited]- pull_request_target:- branches: [main]- types: [opened, reopened, synchronize, edited]+ paths:+ - "examples/invoice-desk/**"+ - ".github/workflows/invoice-desk*.yml"+ - ".github/scripts/invoice-desk-*.mjs"+ - "sdk/typescript/scripts/is-main.mjs"permissions:contents: readjobs:- request-scan:- # The default-branch dispatcher handles only event metadata, never PR code.- if: >-- github.event_name == 'pull_request_target' &&- github.ref == 'refs/heads/main' && github.ref_protected &&- (github.event.action != 'edited' || github.event.changes.base != null)- runs-on: ubuntu-24.04- concurrency:- group: invoice-desk-request-${{ github.event.pull_request.number }}- cancel-in-progress: true- permissions:- actions: write- steps:- - name: Queue the protected scan workflow on main- env:- GH_TOKEN: ${{ github.token }}- PR_NUMBER: ${{ github.event.pull_request.number }}- SOURCE_SHA: ${{ github.event.pull_request.head.sha }}- run: |- gh workflow run invoice-desk-scan.yml --repo "$GITHUB_REPOSITORY" \- --ref main -f "pr_number=$PR_NUMBER" -f "source_sha=$SOURCE_SHA"-behavior:- if: github.event_name == 'pull_request'+ if: github.event.action != 'edited' || github.event.changes.base != nullruns-on: ubuntu-latestconcurrency:- group: invoice-desk-behavior-${{ github.event.pull_request.number }}-${{ github.sha }}-${{ matrix.node }}+ group: invoice-desk-behavior-${{ github.event.pull_request.number }}-${{ matrix.node }}cancel-in-progress: truestrategy:matrix:diff --git a/.github/zizmor.yml b/.github/zizmor.ymlindex db89c1c8b..3b3952927 100644--- a/.github/zizmor.yml+++ b/.github/zizmor.yml@@ -7,8 +7,3 @@ rules:- release-progress.yml:3# Requires successful push CI on main and verifies commit ancestry before tagging.- node-release-cut.yml:3- # The protected-main dispatcher reads event metadata and never checks out PR code.- - invoice-desk.yml:3- # The fallback runs trusted helpers on protected main and only dispatches a scan.- # Inference requires environment approval and treats extracted PR source as data.- - invoice-desk-scan.yml:4diff --git a/examples/README.md b/examples/README.mdindex 5a434bce9..165311b79 100644--- a/examples/README.md+++ b/examples/README.md@@ -26,9 +26,10 @@ Examples and templates for using Codex Security:synthetic invoice app, inspect saved findings and coverage, explicitly requesta patch, and verify the original boundary. The app has ten seeded scenariosand no dependencies or external services. Its- [CI workflow](invoice-desk/README.md#ci-and-openai-scans) runs behavior tests and- automatic OpenAI scans. Guides and expected findings stay outside the scan- input; scan results include finding metrics and downloadable reports.+ [CI workflow](invoice-desk/README.md#ci-and-openai-scans) runs behavior tests,+ manual PR evaluations, and scheduled OpenAI baselines. Guides and expected+ findings stay outside the scan input; scan results include finding metrics and+ downloadable reports.- [Azure Pipelines with Amazon Bedrock](azure-pipelines/README.md): centrally runmanual full or committed-diff scans against Azure Repos, with OIDC credentials,diff --git a/examples/github-actions/README.md b/examples/github-actions/README.mdindex 50083060e..683496d7c 100644--- a/examples/github-actions/README.md+++ b/examples/github-actions/README.md@@ -62,10 +62,10 @@ Findings are report-only by default. Set `FAIL_ON_SEVERITY: "high"` to fail onhigh or critical findings, then make the check required in your repository rulesif it should block merging.-| CLI exit code | Workflow result |-| ------------- | ----------------------------------------------------------------------- |-| `0` | Completed scan; export and upload SARIF |-| `1` | Severity-policy violation; upload SARIF and keep the job failed |+| CLI exit code | Workflow result |+| ------------- | ------------------------------------------------------------------------- |+| `0` | Completed scan; export and upload SARIF |+| `1` | Severity-policy violation; upload SARIF and keep the job failed || Other nonzero | Execution failed or was interrupted; fail the job without uploading SARIF |For exit `2`, inspect the logs and result JSON for the execution error. Scope@@ -99,16 +99,18 @@ you are authorized to submit to the configured inference provider.The repository's [Invoice Desk workflow](../../.github/workflows/invoice-desk.yml)adapts this example to `--provider openai --auth api-key` using an`OPENAI_API_KEY` secret in the protected `codex-security-smoke-test` GitHub-environment. Pull requests to `main` run behavior tests without inference-credentials. A trusted dispatcher-handles only PR metadata and starts a separate-[scan workflow](../../.github/workflows/invoice-desk-scan.yml) on protected `main`.-It scans each PR's application source, including forks and drafts, unattended.+environment. Relevant pull requests to `main` run behavior tests without inference+credentials. The separate+[scan workflow](../../.github/workflows/invoice-desk-scan.yml) runs on protected+`main`: maintainers can manually evaluate an open PR, including forks and drafts,+by providing its number and exact current head SHA. Weekly scheduled runs evaluate+the `main` baseline; manual baseline runs leave both inputs empty. Inference jobs+retain the environment's approval policy.The Actions summary shows the PR number, source commit,finding counts, requested scope, elapsed time, and package-cache reuse. Reports, metricsJSON, and SARIF are saved as artifacts.Only public CLI package downloads are cached; analysis and authentication state-are fresh for each scan. Manual baseline scans remain available. The scan does+are fresh for each scan. The scan doesnot create a PR status check, upload the sample's intentional vulnerabilities toCode Scanning, or post PR comments.See the [setup and reporting guide](../invoice-desk/README.md#ci-and-openai-scans).diff --git a/examples/invoice-desk/README.md b/examples/invoice-desk/README.mdindex 77666a94a..afb91b31e 100644--- a/examples/invoice-desk/README.md+++ b/examples/invoice-desk/README.md@@ -54,18 +54,23 @@ installing dependencies.## CI and OpenAI scansThe [Invoice Desk workflow](../../.github/workflows/invoice-desk.yml) runs behavior-tests on PRs targeting `main`, including drafts and forks, regardless of which-files changed. A separate [OpenAI scan workflow](../../.github/workflows/invoice-desk-scan.yml)-scans the entire application at the PR's exact head. Scans run automatically-without a manual approval step. Failed behavior tests do not suppress a scan.+tests on PRs targeting `main`, including drafts and forks, when the sample,+its workflow helpers, or its workflows change. Title and description edits do not+rerun those checks. Behavior tests do not use inference or request environment+approval.++A separate [OpenAI scan workflow](../../.github/workflows/invoice-desk-scan.yml)+provides manual evaluation of an exact PR head or `main`, plus a weekly `main`+baseline on Mondays at 03:17 UTC. Inference is not triggered by ordinary PR+updates or behavior-test completion.### Setup-Both workflows must be on `main` before automatic scans can run. Configure the-`codex-security-smoke-test` environment without required reviewers or a wait timer,-and with a deployment branch rule allowing only protected `main`. Store a-dedicated service-account key in its `OPENAI_API_KEY` environment secret, with-access to `gpt-5.6-sol` and permission to use the API from the selected runner's+The scan workflow must be on protected `main`. Configure the+`codex-security-smoke-test` environment with a deployment branch rule allowing+only protected `main`. Keep the environment's approval and wait policies for both+manual and scheduled runs. Store a dedicated service-account key in its+`OPENAI_API_KEY` environment secret, with access to `gpt-5.6-sol` and permission to use the API from the selected runner'snetwork. Creating a service account alone does not grant that network access.Do not use a repository or organization Actions secret for this workflow. Amissing key fails the scan with a setup error.@@ -78,9 +83,8 @@ endpoint.The workflow on protected `main` selects and extracts the exact PR source beforeinference. Behavior tests receive no inference credentials; GitHub may separately-require approval to run them for a first-time contributor. Adding required-reviewers to the inference environment makes every scan wait for approval and-disables unattended scanning.+require approval to run them for a first-time contributor. Inference waits for any+approval required by the protected environment, including scheduled baselines.For a manual baseline, select **Actions → Invoice Desk OpenAI scan → Runworkflow** on `main` and leave both inputs empty. To scan an open PR, provide its@@ -88,34 +92,29 @@ number and exact current head SHA.The scan adapts the existing [GitHub Actions example](../github-actions/README.md)to OpenAI inference. It uses CLI 0.1.30, standard mode, high effort, Node.js 24,-and Python 3.12. Each run scans the full application so unchanged cases remain-in scope. Inference consumes API usage.+and Python 3.12. This evaluates the sample with the pinned published CLI; it does+not build or validate SDK changes from the PR. Candidate SDK behavior is covered+by the repository's package and runtime checks. Each evaluation scans the full+application so unchanged cases remain in scope. Inference consumes API usage.### Triggers and source selection-A [default-branch dispatcher](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request_target)-queues scans when a PR is opened, reopened, updated, or retargeted to `main`.-It handles only the PR number and head SHA, with no checkout or inference secret,-and starts the scan on protected `main`. PR edits cannot disable that dispatcher.-Title and description edits do not request another scan.--GitHub can suppress `pull_request_target` for PRs created using `GITHUB_TOKEN`-and for certain branch names. A `workflow_run` fallback handles completed-behavior workflows, including failed tests. It looks up the current PR and skips-PR/head pairs already dispatched from the same `main` workflow revision. It-queues eligible revisions through the same dispatch path, whose run title includes-the PR number and full source SHA. Later fallback events can find those runs and-avoid rescanning an unchanged revision.--If GitHub suppresses the target event and no behavior workflow completes,-automatic scanning cannot start. Use the manual PR dispatch above with the current-head SHA; the same protected workflow and source checks apply.+Manual runs on protected `main` accept an open PR number and its exact current+head SHA, or empty inputs for a baseline. Scheduled runs use the trusted `main`+workflow commit. PR events and behavior-test completion no longer dispatch+inference.The scan checks the PR's base and exact head through GitHub's API before queuingand again immediately before inference. Closed, retargeted, and superseded PR-revisions are skipped. Repeated scans of the same PR revision cancel older runs-of that revision. A scan that has already started-inference may finish after the PR head changes; its reports identify the source SHA.+revisions are skipped. After target validation succeeds, duplicate scan jobs for+the same PR and exact SHA share a concurrency group, replacing any active or+pending duplicate. Different revisions use separate groups so a delayed request+cannot cancel a newer revision's scan. A superseded revision waiting for approval+can be cancelled manually; if approved, it skips inference after the eligibility+recheck. Invalid requests do not cancel an active scan. Manual and scheduled `main`+baselines share a concurrency group only when they evaluate the same exact SHA.+Updating a PR alone does not start a replacement scan; dispatch the new head when+another evaluation is needed. Reports identify the source SHA that was scanned.The workflow installs the CLI outside the checkout and copies committed `app/`blobs into a fresh directory. Archive attributes cannot omit or substitute files;@@ -175,8 +174,9 @@ so cache availability is a performance signal, not a pass/fail condition.After merging this setup, run a main baseline and inspect the completed reports.Run the same revision again to verify a cache hit and compare elapsed time and-token use. Then use an ordinary PR to verify the automatic dispatcher and the-reported source SHA.+token use. Then select **Actions → Invoice Desk OpenAI scan → Run workflow** on+`main`, enter an open PR's number in `pr_number` and its exact current head SHA in+`source_sha`, and verify that the reports identify that source SHA.Review actual findings against the ten root causes in the QA manifest. Recordmatched cases, misses, uncertain cases, duplicates, and additional findings;diff --git a/sdk/typescript/tests-ts/invoice-desk-workflow.test.ts b/sdk/typescript/tests-ts/invoice-desk-workflow.test.tsindex 48b39a78a..aef6f7d48 100644--- a/sdk/typescript/tests-ts/invoice-desk-workflow.test.ts+++ b/sdk/typescript/tests-ts/invoice-desk-workflow.test.ts@@ -23,7 +23,18 @@ const workflow = parse(),"utf8",),-) as { env: Record<string, string>; jobs: { scan: { steps: Step[] } } };+) as {+ env: Record<string, string>;+ concurrency?: unknown;+ jobs: {+ scan: {+ needs: string;+ if: string;+ concurrency: { group: string; "cancel-in-progress": boolean };+ steps: Step[];+ };+ };+};const steps = workflow.jobs.scan.steps;const scan = steps.find((step) => step.id === "scan")!;const sarif = steps.find(@@ -37,6 +48,36 @@ const temporaryDirectories = createTemporaryDirectoriesSync();afterEach(temporaryDirectories.cleanup);+test("Invoice Desk cancels only duplicate scans of an eligible target revision", () => {+ expect(workflow.concurrency).toBeUndefined();+ const job = workflow.jobs.scan;+ expect(job.needs).toBe("target");+ const selected = new Function("needs", `return (${job.if});`);+ expect(selected({ target: { outputs: { targets: "[]" } } })).toBe(false);+ expect(+ selected({+ target: {+ outputs: { targets: JSON.stringify([{ pr: 7, sha: sourceSha }]) },+ },+ }),+ ).toBe(true);+ expect(job.concurrency["cancel-in-progress"]).toBe(true);+ const group = (pr: number, sha: string) =>+ job.concurrency.group.replace(/\$\{\{(.*?)\}\}/g, (_, expression: string) =>+ new Function("matrix", "format", `return (${expression});`)(+ { target: { pr, sha } },+ (template: string, value: unknown) =>+ template.replace("{0}", String(value)),+ ),+ );+ expect(group(7, sourceSha)).toBe(`invoice-desk-scan-pr-7-${sourceSha}`);+ expect(group(7, sourceSha)).not.toBe(group(7, "b".repeat(40)));+ expect(group(7, sourceSha)).not.toBe(group(8, sourceSha));+ expect(group(7, sourceSha)).not.toBe(group(0, sourceSha));+ expect(group(0, sourceSha)).toBe(`invoice-desk-scan-main-${sourceSha}`);+ expect(group(0, sourceSha)).not.toBe(group(0, "b".repeat(40)));+});+function fixture() {const directory = temporaryDirectories.create("invoice workflow ");const bin = join(directory, "codex-security-cli/node_modules/.bin");