Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
17 changes: 14 additions & 3 deletions .github/scripts/opencode-post-step.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 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.
Expand Down Expand Up @@ -57,7 +58,9 @@ function findLatestAgentComment(comments) {
return '';
}

function decideAgentLabel({ existing, conclusion, latestComment, labels, isPR }) {
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
// comment already landed). Failure maps to failed only with no report.
Expand All @@ -76,6 +79,9 @@ function decideAgentLabel({ existing, conclusion, latestComment, labels, isPR })
if (isPRCreationComment(latestComment)) {
return { label: 'agent/done', reason: 'PR creation comment detected' };
}
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' };
}
Expand All @@ -101,11 +107,13 @@ 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 || '';
core.info('Preflight outcome: ' + (preflightOutcome || '(none)'));

core.info('Post-step for #' + number + ' (isPR=' + isPR + ', conclusion=' + conclusion + ')');

Expand Down Expand Up @@ -139,6 +147,7 @@ module.exports = async ({ github, context, core }) => {
latestComment,
labels,
isPR,
preflightOutcome,
});
core.info('Decision: ' + decision.label + ' (' + decision.reason + ')');

Expand Down Expand Up @@ -211,3 +220,5 @@ module.exports = async ({ github, context, core }) => {
core.info('Not closing #' + number);
}
};

module.exports = _runPostStep;
36 changes: 36 additions & 0 deletions .github/scripts/tests/opencode-post-step.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,40 @@ 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'));
});

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'));
});
});
34 changes: 34 additions & 0 deletions .github/scripts/tests/workflow-opencode-pin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,37 @@ 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, /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);
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");
}
});
19 changes: 18 additions & 1 deletion .github/workflows/opencode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ 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
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'
# Role -> model + effort variant, from .github/scripts/model-config.js.
Expand Down Expand Up @@ -155,7 +171,7 @@ jobs:
if: steps.dedupe.outputs.should_run == 'true' && steps.cache-iso.outputs.cache-hit != 'true'
run: sh build.sh cd-x86-lite
- name: Run opencode
if: steps.dedupe.outputs.should_run == 'true'
if: steps.dedupe.outputs.should_run == 'true' && steps.preflight.outcome == 'success'
id: run_agent
timeout-minutes: 85
uses: anomalyco/opencode/github@v1.19.6
Expand All @@ -172,6 +188,7 @@ jobs:
if: (success() || failure() || cancelled()) && steps.dedupe.outputs.should_run == 'true'
env:
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 }}
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,23 @@ 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
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'
id: run_agent
timeout-minutes: 15
uses: anomalyco/opencode/github@v1.19.6
Expand All @@ -85,6 +101,7 @@ jobs:
if: success() || failure() || cancelled()
env:
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 }}
Expand Down
18 changes: 17 additions & 1 deletion .github/workflows/wiki-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,24 @@ 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
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'
id: run_agent
timeout-minutes: 45
uses: anomalyco/opencode/github@v1.19.6
Expand Down
Loading