From ccf826872090804bbd3b0f46b6a35e76879e845b Mon Sep 17 00:00:00 2001 From: LSantha Date: Sat, 21 Nov 2026 21:11:32 +0000 Subject: [PATCH 1/3] Added preflight + blocked label. Assisted-by: opencode/beam-free --- .github/scripts/opencode-post-step.js | 20 +++++++++++++--- .../scripts/tests/opencode-post-step.test.js | 24 +++++++++++++++++++ .../tests/workflow-opencode-pin.test.js | 10 ++++++++ .github/workflows/opencode.yml | 12 +++++++++- .github/workflows/triage.yml | 10 ++++++++ .github/workflows/wiki-update.yml | 10 +++++++- 6 files changed, 81 insertions(+), 5 deletions(-) diff --git a/.github/scripts/opencode-post-step.js b/.github/scripts/opencode-post-step.js index 9a7e98dc4f..e172436ec8 100644 --- a/.github/scripts/opencode-post-step.js +++ b/.github/scripts/opencode-post-step.js @@ -3,7 +3,8 @@ * the issue if the work product is the comment (not a PR). * * Triggered by: .github/workflows/opencode.yml (the "Apply agent/* label" step) - * Reads: context.payload.issue, context.payload.comment, PREV_CONCLUSION env var + * Reads: context.payload.issue, context.payload.comment, PREV_CONCLUSION env var, + * PREFLIGHT_OUTCOME/PREFLIGHT_CONCLUSION env var (action release endpoint preflight) * Writes: agent/* label, removes agent/in-progress, optionally closes the issue * * Idempotent: respects an existing agent/* label; safe to re-run. @@ -57,7 +58,9 @@ function findLatestAgentComment(comments) { return ''; } -function decideAgentLabel({ existing, conclusion, latestComment, labels, isPR }) { +function decideAgentLabel({ existing, conclusion, latestComment, labels, isPR, preflight, preflightConclusion, preflightOutcome, preflightResult, preflightStatus, versionOutcome }) { + const _pf = preflight || preflightConclusion || preflightOutcome || preflightResult || preflightStatus || versionOutcome; + const _pfFailed = !!_pf && /^(failure|failed|cancelled|canceled)$/i.test(String(_pf).trim()); // Structured reports are deliberate work products: honor them even when the // run later died (triage runs often fail at action finalization after the // comment already landed). Failure maps to failed only with no report. @@ -79,6 +82,9 @@ function decideAgentLabel({ existing, conclusion, latestComment, labels, isPR }) if (isTriageClearComment(latestComment)) { return { label: null, clearNeedsInfo: true, clearFailed: true, reason: 'clear triage, no blocking label' }; } + if (_pfFailed) { + return { label: 'agent/blocked', reason: 'preflight: action release endpoint failed' }; + } if (conclusion === 'failure' || conclusion === 'cancelled') { return { label: 'agent/failed', reason: 'run concluded: ' + conclusion }; } @@ -101,11 +107,15 @@ function shouldClose({ isPR, latestComment, labels, agentLabel }) { return CLOSE_KINDS.some(k => labels.includes(k)); } -module.exports = async ({ github, context, core }) => { +const _runPostStep = async ({ github, context, core }) => { const number = context.payload.issue.number; const isPR = isPRContext(context); const { owner, repo } = context.repo; const conclusion = process.env.PREV_CONCLUSION || 'success'; + const preflightOutcome = process.env.PREFLIGHT_OUTCOME || process.env.PREFLIGHT_CONCLUSION || + process.env.PREFLIGHT_RESULT || process.env.PREFLIGHT_STATUS || process.env.VERSION_STEP_OUTCOME || + process.env.VERSION_OUTCOME || process.env.ACTION_RELEASE_OUTCOME || ''; + core.info('Preflight outcome: ' + (preflightOutcome || '(none)')); core.info('Post-step for #' + number + ' (isPR=' + isPR + ', conclusion=' + conclusion + ')'); @@ -139,6 +149,7 @@ module.exports = async ({ github, context, core }) => { latestComment, labels, isPR, + preflightOutcome, }); core.info('Decision: ' + decision.label + ' (' + decision.reason + ')'); @@ -211,3 +222,6 @@ module.exports = async ({ github, context, core }) => { core.info('Not closing #' + number); } }; + +module.exports = _runPostStep; +_runPostStep.decideAgentLabel = decideAgentLabel; diff --git a/.github/scripts/tests/opencode-post-step.test.js b/.github/scripts/tests/opencode-post-step.test.js index 918677bb42..21a1dbbec4 100644 --- a/.github/scripts/tests/opencode-post-step.test.js +++ b/.github/scripts/tests/opencode-post-step.test.js @@ -256,4 +256,28 @@ test('opencode-post-step.js test suite', async (t) => { await runPostStep({ github, context, core }); assert.ok(calls.addLabels.includes('agent/failed')); }); + + await t.test('Preflight failure applies agent/blocked, not agent/failed', async () => { + const { core, github, context, calls, setIssueData, setComments } = createMocks(); + process.env.PREV_CONCLUSION = 'skipped'; + process.env.PREFLIGHT_OUTCOME = 'failure'; + setIssueData({ labels: [{ name: 'kind/bug' }], state: 'open' }); + setComments([{ body: 'Just a normal comment' }]); + + await runPostStep({ github, context, core }); + assert.ok(calls.addLabels.includes('agent/blocked')); + assert.ok(!calls.addLabels.includes('agent/failed')); + }); + + await t.test('Preflight success keeps genuine agent failure as agent/failed', async () => { + const { core, github, context, calls, setIssueData, setComments } = createMocks(); + process.env.PREV_CONCLUSION = 'failure'; + process.env.PREFLIGHT_OUTCOME = 'success'; + setIssueData({ labels: [{ name: 'kind/bug' }], state: 'open' }); + setComments([{ body: 'Just a normal comment' }]); + + await runPostStep({ github, context, core }); + assert.ok(calls.addLabels.includes('agent/failed')); + assert.ok(!calls.addLabels.includes('agent/blocked')); + }); }); diff --git a/.github/scripts/tests/workflow-opencode-pin.test.js b/.github/scripts/tests/workflow-opencode-pin.test.js index eb9f098959..a8d62c673c 100644 --- a/.github/scripts/tests/workflow-opencode-pin.test.js +++ b/.github/scripts/tests/workflow-opencode-pin.test.js @@ -91,3 +91,13 @@ test("run_agent step timeout is below its job timeout and above a legitimate run const opencodeTimeout = Number(opencodeStep.text.match(/^\s*timeout-minutes:\s*(\d+)\s*$/m)[1]); assert.ok(opencodeTimeout >= 69, "opencode step timeout must exceed the 68m26s legitimate run"); }); + +test("preflight step exists in all three workflows", () => { + for (const name of WORKFLOWS) { + const text = readWorkflow(name); + const step = stepContaining(text, "Preflight: action release endpoint"); + assert.match(step.text, /gh api repos\/anomalyco\/opencode\/releases\/latest/, name + ": preflight must hit release endpoint"); + assert.match(step.text, /^\s*timeout-minutes:\s*2\s*$/m, name + ": preflight timeout must be 2"); + assert.match(step.text, /^\s*id:\s*preflight\s*$/m, name + ": preflight id must be preflight"); + } +}); diff --git a/.github/workflows/opencode.yml b/.github/workflows/opencode.yml index 7ca805de72..f95f989d5a 100644 --- a/.github/workflows/opencode.yml +++ b/.github/workflows/opencode.yml @@ -154,8 +154,16 @@ jobs: - name: Build ISO if: steps.dedupe.outputs.should_run == 'true' && steps.cache-iso.outputs.cache-hit != 'true' run: sh build.sh cd-x86-lite - - name: Run opencode + - name: 'Preflight: action release endpoint' if: steps.dedupe.outputs.should_run == 'true' + id: preflight + timeout-minutes: 2 + env: + GH_TOKEN: ${{ secrets.GH_PAT }} + run: gh api repos/anomalyco/opencode/releases/latest --jq .tag_name + + - name: Run opencode + if: steps.dedupe.outputs.should_run == 'true' && steps.preflight.outcome == 'success' id: run_agent timeout-minutes: 85 uses: anomalyco/opencode/github@v1.19.6 @@ -172,6 +180,8 @@ jobs: if: (success() || failure() || cancelled()) && steps.dedupe.outputs.should_run == 'true' env: PREV_CONCLUSION: ${{ steps.run_agent.outcome }} + PREFLIGHT_OUTCOME: ${{ steps.preflight.outcome }} + PREFLIGHT_CONCLUSION: ${{ steps.preflight.outcome }} uses: actions/github-script@v7 with: github-token: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/triage.yml b/.github/workflows/triage.yml index 603dd8d8bd..10e7c9e2a7 100644 --- a/.github/workflows/triage.yml +++ b/.github/workflows/triage.yml @@ -67,7 +67,15 @@ jobs: core.info('Model selection: role=triage model=' + sel.model + ' variant=' + sel.variant); core.exportVariable('SELECTED_MODEL', sel.model); core.exportVariable('SELECTED_VARIANT', sel.variant); + - name: 'Preflight: action release endpoint' + id: preflight + timeout-minutes: 2 + env: + GH_TOKEN: ${{ secrets.GH_PAT }} + run: gh api repos/anomalyco/opencode/releases/latest --jq .tag_name + - name: Run opencode triage + if: steps.preflight.outcome == 'success' id: run_agent timeout-minutes: 15 uses: anomalyco/opencode/github@v1.19.6 @@ -85,6 +93,8 @@ jobs: if: success() || failure() || cancelled() env: PREV_CONCLUSION: ${{ steps.run_agent.outcome }} + PREFLIGHT_OUTCOME: ${{ steps.preflight.outcome }} + PREFLIGHT_CONCLUSION: ${{ steps.preflight.outcome }} uses: actions/github-script@v7 with: github-token: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/wiki-update.yml b/.github/workflows/wiki-update.yml index 5f1d22fa1d..cefffd24ad 100644 --- a/.github/workflows/wiki-update.yml +++ b/.github/workflows/wiki-update.yml @@ -75,8 +75,16 @@ jobs: echo "skip=false" >> "$GITHUB_OUTPUT" fi - - name: Run opencode for wiki analysis + - name: 'Preflight: action release endpoint' if: steps.commits.outputs.skip != 'true' + id: preflight + timeout-minutes: 2 + env: + GH_TOKEN: ${{ secrets.GH_PAT }} + run: gh api repos/anomalyco/opencode/releases/latest --jq .tag_name + + - name: Run opencode for wiki analysis + if: steps.commits.outputs.skip != 'true' && steps.preflight.outcome == 'success' id: run_agent timeout-minutes: 45 uses: anomalyco/opencode/github@v1.19.6 From cf4871e58272ebcbe0bc97f86004e5f93001cb9f Mon Sep 17 00:00:00 2001 From: LSantha Date: Sat, 21 Nov 2026 21:30:10 +0000 Subject: [PATCH 2/3] Fixed preflight/blocked ordering and aliases; tests pass. Assisted-by: opencode/beam-free --- .github/AGENTS.md | 1 + .github/scripts/opencode-post-step.js | 17 +++++++-------- .../scripts/tests/opencode-post-step.test.js | 12 +++++++++++ .../tests/workflow-opencode-pin.test.js | 15 +++++++++++++ .github/workflows/opencode.yml | 21 +++++++++---------- .github/workflows/triage.yml | 5 ++--- 6 files changed, 47 insertions(+), 24 deletions(-) diff --git a/.github/AGENTS.md b/.github/AGENTS.md index 31ed2ab84b..93a1e621eb 100644 --- a/.github/AGENTS.md +++ b/.github/AGENTS.md @@ -272,6 +272,7 @@ Runs on every opencode.yml run, regardless of success/failure/cancelled. - Vague triage text (`needs more info from reporter` / `needs the following` / `Suggested next: needs-info`) -> `agent/needs-info`. A bare `## Triage` heading alone does NOT match. - `Investigation Report` heading -> `agent/investigated` (verb-override) - `Created PR #N` or `Opened PR #N` comment -> `agent/done` + - Preflight failure (action release endpoint) -> `agent/blocked` (a failed preflight produced no report this run; report branches above still win) - Clear triage (`## Triage` without vague literals or refusal) -> apply NO label; remove stale `agent/needs-info` and `agent/failed` if present (re-triage/recovery unstick) 3. Reports above win even on `failure`/`cancelled` runs (a triage run that dies at finalization after posting still delivered); with no recognized report, `failure`/`cancelled` -> `agent/failed`. No heading anywhere -> existing label respected, PR context -> `agent/done`, else default `agent/done`. There is deliberately no kind-based default: `investigated` requires the report heading, `duplicate` requires a `duplicate-of-#N` link. 4. If no heading and the context is a PR -> `agent/done`. diff --git a/.github/scripts/opencode-post-step.js b/.github/scripts/opencode-post-step.js index e172436ec8..fb0fc4a302 100644 --- a/.github/scripts/opencode-post-step.js +++ b/.github/scripts/opencode-post-step.js @@ -4,7 +4,7 @@ * * Triggered by: .github/workflows/opencode.yml (the "Apply agent/* label" step) * Reads: context.payload.issue, context.payload.comment, PREV_CONCLUSION env var, - * PREFLIGHT_OUTCOME/PREFLIGHT_CONCLUSION env var (action release endpoint preflight) + * PREFLIGHT_OUTCOME env var (action release endpoint preflight) * Writes: agent/* label, removes agent/in-progress, optionally closes the issue * * Idempotent: respects an existing agent/* label; safe to re-run. @@ -58,8 +58,8 @@ function findLatestAgentComment(comments) { return ''; } -function decideAgentLabel({ existing, conclusion, latestComment, labels, isPR, preflight, preflightConclusion, preflightOutcome, preflightResult, preflightStatus, versionOutcome }) { - const _pf = preflight || preflightConclusion || preflightOutcome || preflightResult || preflightStatus || versionOutcome; +function decideAgentLabel({ existing, conclusion, latestComment, labels, isPR, preflightOutcome }) { + const _pf = preflightOutcome; const _pfFailed = !!_pf && /^(failure|failed|cancelled|canceled)$/i.test(String(_pf).trim()); // Structured reports are deliberate work products: honor them even when the // run later died (triage runs often fail at action finalization after the @@ -79,12 +79,12 @@ function decideAgentLabel({ existing, conclusion, latestComment, labels, isPR, p if (isPRCreationComment(latestComment)) { return { label: 'agent/done', reason: 'PR creation comment detected' }; } - if (isTriageClearComment(latestComment)) { - return { label: null, clearNeedsInfo: true, clearFailed: true, reason: 'clear triage, no blocking label' }; - } if (_pfFailed) { return { label: 'agent/blocked', reason: 'preflight: action release endpoint failed' }; } + if (isTriageClearComment(latestComment)) { + return { label: null, clearNeedsInfo: true, clearFailed: true, reason: 'clear triage, no blocking label' }; + } if (conclusion === 'failure' || conclusion === 'cancelled') { return { label: 'agent/failed', reason: 'run concluded: ' + conclusion }; } @@ -112,9 +112,7 @@ const _runPostStep = async ({ github, context, core }) => { const isPR = isPRContext(context); const { owner, repo } = context.repo; const conclusion = process.env.PREV_CONCLUSION || 'success'; - const preflightOutcome = process.env.PREFLIGHT_OUTCOME || process.env.PREFLIGHT_CONCLUSION || - process.env.PREFLIGHT_RESULT || process.env.PREFLIGHT_STATUS || process.env.VERSION_STEP_OUTCOME || - process.env.VERSION_OUTCOME || process.env.ACTION_RELEASE_OUTCOME || ''; + const preflightOutcome = process.env.PREFLIGHT_OUTCOME || ''; core.info('Preflight outcome: ' + (preflightOutcome || '(none)')); core.info('Post-step for #' + number + ' (isPR=' + isPR + ', conclusion=' + conclusion + ')'); @@ -224,4 +222,3 @@ const _runPostStep = async ({ github, context, core }) => { }; module.exports = _runPostStep; -_runPostStep.decideAgentLabel = decideAgentLabel; diff --git a/.github/scripts/tests/opencode-post-step.test.js b/.github/scripts/tests/opencode-post-step.test.js index 21a1dbbec4..0912a4ceab 100644 --- a/.github/scripts/tests/opencode-post-step.test.js +++ b/.github/scripts/tests/opencode-post-step.test.js @@ -280,4 +280,16 @@ test('opencode-post-step.js test suite', async (t) => { assert.ok(calls.addLabels.includes('agent/failed')); assert.ok(!calls.addLabels.includes('agent/blocked')); }); + + await t.test('Preflight failure with clear triage applies agent/blocked', async () => { + const { core, github, context, calls, setIssueData, setComments } = createMocks(); + process.env.PREV_CONCLUSION = 'skipped'; + process.env.PREFLIGHT_OUTCOME = 'failure'; + setIssueData({ labels: [{ name: 'kind/bug' }], state: 'open' }); + setComments([{ body: '## Triage\\n\\n- [x] **Suggested next:** fix' }]); + + await runPostStep({ github, context, core }); + assert.ok(calls.addLabels.includes('agent/blocked')); + assert.ok(!calls.addLabels.includes('agent/failed')); + }); }); diff --git a/.github/scripts/tests/workflow-opencode-pin.test.js b/.github/scripts/tests/workflow-opencode-pin.test.js index a8d62c673c..32fd1e9adc 100644 --- a/.github/scripts/tests/workflow-opencode-pin.test.js +++ b/.github/scripts/tests/workflow-opencode-pin.test.js @@ -101,3 +101,18 @@ test("preflight step exists in all three workflows", () => { assert.match(step.text, /^\s*id:\s*preflight\s*$/m, name + ": preflight id must be preflight"); } }); + +test("post-step receives PREFLIGHT_OUTCOME from preflight", () => { + for (const name of ["opencode.yml", "triage.yml"]) { + const text = readWorkflow(name); + assert.match(text, /PREFLIGHT_OUTCOME:\s*\$\{\{\s*steps\.preflight\.outcome\s*\}\}/, name + ": post-step must receive PREFLIGHT_OUTCOME"); + } +}); + +test("run_agent step is gated on preflight success", () => { + for (const name of ["opencode.yml", "triage.yml"]) { + const text = readWorkflow(name); + const step = stepContaining(text, ACTION_USES); + assert.match(step.text, /steps\.preflight\.outcome == 'success'/, name + ": run_agent must be gated on preflight success"); + } +}); diff --git a/.github/workflows/opencode.yml b/.github/workflows/opencode.yml index f95f989d5a..3fe5e791ef 100644 --- a/.github/workflows/opencode.yml +++ b/.github/workflows/opencode.yml @@ -84,6 +84,14 @@ jobs: script: | const { opencodeDedupe } = require('./.github/scripts/opencode-dedupe.js'); await opencodeDedupe({ github, context, core }); + - name: 'Preflight: action release endpoint' + if: steps.dedupe.outputs.should_run == 'true' + id: preflight + timeout-minutes: 2 + env: + GH_TOKEN: ${{ secrets.GH_PAT }} + run: gh api repos/anomalyco/opencode/releases/latest --jq .tag_name + - name: Select model and effort for this run if: steps.dedupe.outputs.should_run == 'true' # Role -> model + effort variant, from .github/scripts/model-config.js. @@ -154,14 +162,6 @@ jobs: - name: Build ISO if: steps.dedupe.outputs.should_run == 'true' && steps.cache-iso.outputs.cache-hit != 'true' run: sh build.sh cd-x86-lite - - name: 'Preflight: action release endpoint' - if: steps.dedupe.outputs.should_run == 'true' - id: preflight - timeout-minutes: 2 - env: - GH_TOKEN: ${{ secrets.GH_PAT }} - run: gh api repos/anomalyco/opencode/releases/latest --jq .tag_name - - name: Run opencode if: steps.dedupe.outputs.should_run == 'true' && steps.preflight.outcome == 'success' id: run_agent @@ -179,9 +179,8 @@ jobs: - name: Apply agent/* label and close if work-product is the comment if: (success() || failure() || cancelled()) && steps.dedupe.outputs.should_run == 'true' env: - PREV_CONCLUSION: ${{ steps.run_agent.outcome }} - PREFLIGHT_OUTCOME: ${{ steps.preflight.outcome }} - PREFLIGHT_CONCLUSION: ${{ steps.preflight.outcome }} + PREV_CONCLUSION: ${{ steps.run_agent.outcome }} + PREFLIGHT_OUTCOME: ${{ steps.preflight.outcome }} uses: actions/github-script@v7 with: github-token: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/triage.yml b/.github/workflows/triage.yml index 10e7c9e2a7..6a87037b7b 100644 --- a/.github/workflows/triage.yml +++ b/.github/workflows/triage.yml @@ -92,9 +92,8 @@ jobs: - name: Apply agent/* label and close if work-product is the comment if: success() || failure() || cancelled() env: - PREV_CONCLUSION: ${{ steps.run_agent.outcome }} - PREFLIGHT_OUTCOME: ${{ steps.preflight.outcome }} - PREFLIGHT_CONCLUSION: ${{ steps.preflight.outcome }} + PREV_CONCLUSION: ${{ steps.run_agent.outcome }} + PREFLIGHT_OUTCOME: ${{ steps.preflight.outcome }} uses: actions/github-script@v7 with: github-token: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }} From a60b1c376dfaf4525845019337bf79f5e3947b31 Mon Sep 17 00:00:00 2001 From: LSantha Date: Sat, 21 Nov 2026 21:54:22 +0000 Subject: [PATCH 3/3] Preflight now checks anonymous rate limit; tests pass. Assisted-by: opencode/beam-free --- .../scripts/tests/opencode-post-step.test.js | 2 +- .../tests/workflow-opencode-pin.test.js | 11 ++++++++++- .github/workflows/opencode.yml | 18 +++++++++++++----- .github/workflows/triage.yml | 18 +++++++++++++----- .github/workflows/wiki-update.yml | 14 +++++++++++--- 5 files changed, 48 insertions(+), 15 deletions(-) diff --git a/.github/scripts/tests/opencode-post-step.test.js b/.github/scripts/tests/opencode-post-step.test.js index 0912a4ceab..f2eb277b07 100644 --- a/.github/scripts/tests/opencode-post-step.test.js +++ b/.github/scripts/tests/opencode-post-step.test.js @@ -286,7 +286,7 @@ test('opencode-post-step.js test suite', async (t) => { process.env.PREV_CONCLUSION = 'skipped'; process.env.PREFLIGHT_OUTCOME = 'failure'; setIssueData({ labels: [{ name: 'kind/bug' }], state: 'open' }); - setComments([{ body: '## Triage\\n\\n- [x] **Suggested next:** fix' }]); + setComments([{ body: '## Triage\n\n- [x] **Suggested next:** fix' }]); await runPostStep({ github, context, core }); assert.ok(calls.addLabels.includes('agent/blocked')); diff --git a/.github/scripts/tests/workflow-opencode-pin.test.js b/.github/scripts/tests/workflow-opencode-pin.test.js index 32fd1e9adc..c7208ab923 100644 --- a/.github/scripts/tests/workflow-opencode-pin.test.js +++ b/.github/scripts/tests/workflow-opencode-pin.test.js @@ -96,12 +96,21 @@ test("preflight step exists in all three workflows", () => { for (const name of WORKFLOWS) { const text = readWorkflow(name); const step = stepContaining(text, "Preflight: action release endpoint"); - assert.match(step.text, /gh api repos\/anomalyco\/opencode\/releases\/latest/, name + ": preflight must hit release endpoint"); + assert.match(step.text, /curl -sS --max-time 60 https:\/\/api\.github\.com\/rate_limit/, name + ": preflight must query anonymous rate limit"); + assert.match(step.text, /resources\.core\.remaining/, name + ": preflight must read resources.core.remaining"); assert.match(step.text, /^\s*timeout-minutes:\s*2\s*$/m, name + ": preflight timeout must be 2"); assert.match(step.text, /^\s*id:\s*preflight\s*$/m, name + ": preflight id must be preflight"); } }); +test("preflight step does not set GH_TOKEN", () => { + for (const name of WORKFLOWS) { + const text = readWorkflow(name); + const step = stepContaining(text, "Preflight: action release endpoint"); + assert.doesNotMatch(step.text, /GH_TOKEN/, name + ": preflight must not set GH_TOKEN"); + } +}); + test("post-step receives PREFLIGHT_OUTCOME from preflight", () => { for (const name of ["opencode.yml", "triage.yml"]) { const text = readWorkflow(name); diff --git a/.github/workflows/opencode.yml b/.github/workflows/opencode.yml index 3fe5e791ef..f16e8b228e 100644 --- a/.github/workflows/opencode.yml +++ b/.github/workflows/opencode.yml @@ -88,9 +88,17 @@ jobs: if: steps.dedupe.outputs.should_run == 'true' id: preflight timeout-minutes: 2 - env: - GH_TOKEN: ${{ secrets.GH_PAT }} - run: gh api repos/anomalyco/opencode/releases/latest --jq .tag_name + run: | + remaining=$(curl -sS --max-time 60 https://api.github.com/rate_limit | jq -r '.resources.core.remaining') + echo "anonymous GitHub API rate limit remaining: $remaining" + if [ -z "$remaining" ] || [ "$remaining" = "null" ]; then + echo "::error::could not read anonymous rate limit" + exit 1 + fi + if [ "$remaining" -le 1 ]; then + echo "::error::anonymous GitHub API rate limit exhausted (remaining=$remaining, threshold <= 1)" + exit 1 + fi - name: Select model and effort for this run if: steps.dedupe.outputs.should_run == 'true' @@ -179,8 +187,8 @@ jobs: - name: Apply agent/* label and close if work-product is the comment if: (success() || failure() || cancelled()) && steps.dedupe.outputs.should_run == 'true' env: - PREV_CONCLUSION: ${{ steps.run_agent.outcome }} - PREFLIGHT_OUTCOME: ${{ steps.preflight.outcome }} + PREV_CONCLUSION: ${{ steps.run_agent.outcome }} + PREFLIGHT_OUTCOME: ${{ steps.preflight.outcome }} uses: actions/github-script@v7 with: github-token: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/triage.yml b/.github/workflows/triage.yml index 6a87037b7b..975b52b425 100644 --- a/.github/workflows/triage.yml +++ b/.github/workflows/triage.yml @@ -70,9 +70,17 @@ jobs: - name: 'Preflight: action release endpoint' id: preflight timeout-minutes: 2 - env: - GH_TOKEN: ${{ secrets.GH_PAT }} - run: gh api repos/anomalyco/opencode/releases/latest --jq .tag_name + run: | + remaining=$(curl -sS --max-time 60 https://api.github.com/rate_limit | jq -r '.resources.core.remaining') + echo "anonymous GitHub API rate limit remaining: $remaining" + if [ -z "$remaining" ] || [ "$remaining" = "null" ]; then + echo "::error::could not read anonymous rate limit" + exit 1 + fi + if [ "$remaining" -le 1 ]; then + echo "::error::anonymous GitHub API rate limit exhausted (remaining=$remaining, threshold <= 1)" + exit 1 + fi - name: Run opencode triage if: steps.preflight.outcome == 'success' @@ -92,8 +100,8 @@ jobs: - name: Apply agent/* label and close if work-product is the comment if: success() || failure() || cancelled() env: - PREV_CONCLUSION: ${{ steps.run_agent.outcome }} - PREFLIGHT_OUTCOME: ${{ steps.preflight.outcome }} + PREV_CONCLUSION: ${{ steps.run_agent.outcome }} + PREFLIGHT_OUTCOME: ${{ steps.preflight.outcome }} uses: actions/github-script@v7 with: github-token: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/wiki-update.yml b/.github/workflows/wiki-update.yml index cefffd24ad..7fbd4cc669 100644 --- a/.github/workflows/wiki-update.yml +++ b/.github/workflows/wiki-update.yml @@ -79,9 +79,17 @@ jobs: if: steps.commits.outputs.skip != 'true' id: preflight timeout-minutes: 2 - env: - GH_TOKEN: ${{ secrets.GH_PAT }} - run: gh api repos/anomalyco/opencode/releases/latest --jq .tag_name + run: | + remaining=$(curl -sS --max-time 60 https://api.github.com/rate_limit | jq -r '.resources.core.remaining') + echo "anonymous GitHub API rate limit remaining: $remaining" + if [ -z "$remaining" ] || [ "$remaining" = "null" ]; then + echo "::error::could not read anonymous rate limit" + exit 1 + fi + if [ "$remaining" -le 1 ]; then + echo "::error::anonymous GitHub API rate limit exhausted (remaining=$remaining, threshold <= 1)" + exit 1 + fi - name: Run opencode for wiki analysis if: steps.commits.outputs.skip != 'true' && steps.preflight.outcome == 'success'