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
35 changes: 28 additions & 7 deletions .github/workflows/agent-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ jobs:
outcome: ${{ steps.agent.outcome }}
exit_code: ${{ steps.agent.outputs.exit_code }}
skipped: ${{ steps.key.outputs.skipped }}
# Empty if the job reported no step: GitHub ended it before it got a
# runner (refused by the environment, or cancelled while queued), or
# the runner was lost. 'publish' then says so.
started: ${{ steps.started.outputs.started }}
env: &review-env
# The sandbox's working area. AWF mounts the workspace read-write, so
# everything under it is untrusted once the sandbox has run.
Expand All @@ -372,6 +376,11 @@ jobs:
# the host either (no 'services:', no daemon in a step): the sandbox
# reaches every host port bound to 0.0.0.0 through AWF's network gateway.
steps:
- &mark-started
name: Record that the job started
id: started
run: echo "started=true" >> "$GITHUB_OUTPUT"

- *fetch-trusted

# Caller configuration: the validated inputs, and the addendum from the
Expand Down Expand Up @@ -702,6 +711,7 @@ jobs:
outputs: *review-outputs
env: *review-env
steps:
- *mark-started
- *fetch-trusted
- *fetch-config
- *prepare-inputs
Expand Down Expand Up @@ -822,23 +832,34 @@ jobs:
{ echo "result=posted"; echo "comment_url=${url}"; } >> "$GITHUB_OUTPUT"

# A failed or rejected review is a warning, not a red run: the check is
# advisory.
# advisory. 'publish-comment explain' words the reason from the review
# job's result and outputs only (no token, nothing from the review): a
# job that reported no step (refused by the environment's protection
# rules, cancelled while queued, or its runner lost) has no sandbox
# logs to point at. At most one of the two review jobs ran.
- name: Report a missing review
if: steps.render.outputs.result == 'missing' || steps.render.outputs.result == 'invalid'
env:
RESULT: ${{ steps.render.outputs.result }}
KEYED: ${{ needs.authorize.outputs.keyed }}
REVIEW_RESULT: ${{ needs.authorize.outputs.keyed == 'true' && needs.review.result || needs.review-keyless.result }}
STARTED: ${{ needs.review.outputs.started || needs.review-keyless.outputs.started }}
ENVIRONMENT: ${{ inputs.environment }}
FETCH_OUTCOME: ${{ needs.review.outputs.fetch_outcome || needs.review-keyless.outputs.fetch_outcome }}
OUTCOME: ${{ needs.review.outputs.outcome || needs.review-keyless.outputs.outcome }}
EXIT_CODE: ${{ needs.review.outputs.exit_code || needs.review-keyless.outputs.exit_code }}
PATH: /usr/bin:/bin
run: |
case "${RESULT}" in
missing) reason="the agent produced no review (fetch outcome '${FETCH_OUTCOME}', review outcome '${OUTCOME}', exit code '${EXIT_CODE}')" ;;
invalid) reason="the review was rejected as invalid (not UTF-8, empty, or not a regular file within the size cap)" ;;
esac
echo "::warning title=Agent review failed::No review was posted: ${reason}. See the 'Fetch the pull request in the sandbox' and 'Run the review in the sandbox' logs."
text=$(/usr/bin/python3 -I -S -B "${RUNNER_TEMP}/trusted/bin/publish-comment" explain \
--result "${RESULT}" --keyed "${KEYED}" --review-result "${REVIEW_RESULT}" --started "${STARTED}" \
--environment "${ENVIRONMENT}" --fetch-outcome "${FETCH_OUTCOME}" --outcome "${OUTCOME}" \
--exit-code "${EXIT_CODE}")
{ IFS= read -r reason; IFS= read -r where; } <<< "${text}"
echo "::warning title=Agent review failed::No review was posted: ${reason}. ${where}"
{
echo "### Agent review failed"
echo
echo "No review was posted: ${reason}; the run is green because the check is advisory."
echo "The cause is in the \`Fetch the pull request in the sandbox\` or \`Run the review in the sandbox\` log of the \`review\` job; see https://github.com/GridTools/ci-workflows/blob/main/docs/agent-review.md."
echo
echo "${where} See https://github.com/GridTools/ci-workflows/blob/main/docs/agent-review.md#troubleshooting."
} >> "$GITHUB_STEP_SUMMARY"
2 changes: 1 addition & 1 deletion agent-review/harnesses/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ the pull request or the calling repository.
| File | Contract |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `install.sh` | `install.sh <prefix>`. Runs in the secretless `prepare` job. Installs an **exact** version with integrity checks (npm: `npm ci` against a committed `package-lock.json`; binaries: release URL plus SHA-256) into `<prefix>`, and writes the version to `<prefix>/VERSION`. It must not execute any harness code (no install scripts, no `--version`): `prepare` runs on the host with sudo and a cache-capable token; `run.sh` checks the version inside the sandbox with `check_version` from `common.sh`. The prefix is unpacked to `/opt/agent-review/harness/<name>` (read-only) and must run from there without network access. |
| `run.sh` | Runs inside the sandbox from the PR checkout, under `timeout`. Environment: `PROMPT_FILE`, `REPO_DIR`, `OUT_DIR`, `CONTEXT_DIR`, `MODEL`, `HARNESS_PREFIX`, `PR_NUMBER`, and AWF's `AWF_API_PROXY_OPENAI_URL`. Keeps its configuration in a scratch home under `$TMPDIR` (a directory in the workspace), built from environment variables only; disables auto-update, telemetry, sharing and remote model catalogues; runs headless and writes `$OUT_DIR/review.md`. Exit codes: 0 review written, 2 ran but no review, anything else a failure. **Return 2, not 0, when the harness exits 0 without a real answer** (a step cap, a stall detector or a tool-call-only last turn can all do that): `run-review` posts whatever `review.md` holds after exit 0. Harness output goes to files in `$OUT_DIR`, which are not collected; print diagnostics only through `diag` in `common.sh`, which prefixes every line so that the harness's output cannot be read as a workflow command. |
| `run.sh` | Runs inside the sandbox from the PR checkout, under `timeout`. Environment: `PROMPT_FILE`, `REPO_DIR`, `OUT_DIR`, `CONTEXT_DIR`, `MODEL`, `HARNESS_PREFIX`, `PR_NUMBER`, and AWF's `AWF_API_PROXY_OPENAI_URL`. Keeps its configuration in a scratch home under `$TMPDIR` (a directory in the workspace), built from environment variables only; disables auto-update, telemetry, sharing and remote model catalogues; sets the harness's request timeouts so that a request that stalls ends and is retried, without shortening how long the run waits for a silent service (`../tests/test-harness-stall.sh`); runs headless and writes `$OUT_DIR/review.md`. Exit codes: 0 review written, 2 ran but no review, anything else a failure. **Return 2, not 0, when the harness exits 0 without a real answer** (a step cap, a stall detector or a tool-call-only last turn can all do that): `run-review` posts whatever `review.md` holds after exit 0. Harness output goes to files in `$OUT_DIR`, which are not collected; print diagnostics only through `diag` in `common.sh`, which prefixes every line so that the harness's output cannot be read as a workflow command. |
| `wire` | One line: `openai-chat` or `none`. `openai-chat` passes the key to AWF as `OPENAI_API_KEY`; every harness uses AWF's OpenAI listener, `$AWF_API_PROXY_OPENAI_URL` (an origin): clients that append only `/chat/completions` (opencode, Pi) need `$AWF_API_PROXY_OPENAI_URL/v1`. There is no `anthropic-messages` wire: with `ANTHROPIC_API_KEY`, AWF v0.29.12 opens an Anthropic listener whose `POST /messages` is not counted by `maxTurns`, and its entrypoint fails under `filesystem.allowWrite`. An Anthropic-API client can use the OpenAI listener, which forwards `/v1/messages` with a Bearer token (CSCS accepts it). |
| `README.md` | Pinned version, how to upgrade it, the paths it reads as instructions or configuration (add them to `../instruction-files.txt`), and any outbound calls it tries to make. |

Expand Down
16 changes: 16 additions & 0 deletions agent-review/harnesses/opencode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ release still has the flags and environment variables used in `run.sh`.
`apiProxy.maxTurns`. opencode makes one more request first, for the session
title. At the last step tools are disabled, so the model has to answer.

- **Request timeouts** are provider settings, both 300 s. `headerTimeout`
is the wait for response headers (opencode's default, set explicitly).
`chunkTimeout` is the wait for the next event of a streamed response,
including the first one after the headers (the default is 900 s, most of
the harness timeout); a stream that keeps sending is never cut. opencode
retries a timed-out request after 2, 4 and 8 s, but at most 3 times per
run, and that limit cannot be configured: a run waits at most 4 x the
timeout for a service that answers nothing. That is why neither value is
lower: in the v0.1.0 release validation, a review succeeded after 13
minutes without an answer, and one request was answered after 185 s
without headers. A service that sends its headers at once and then
queues the request is silent in the same way under `chunkTimeout`, so it
gets the same wait. `../../tests/test-harness-stall.sh` checks this
against a server that stalls; run it after changing these values or the
pinned version, since the retry limit may change with it.

## Outbound calls

`models.opencode.ai` (model catalogue), suppressed with
Expand Down
22 changes: 20 additions & 2 deletions agent-review/harnesses/opencode/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ adapter_init opencode
# at the last step tools are disabled and the model has to answer.
readonly MAX_STEPS=35

# Request timeouts, in milliseconds. opencode retries a timed-out request,
# but at most 3 times per run, and that count cannot be configured: the
# time a run can wait for a service that answers nothing is 4 x the
# timeout. So the wait for response headers stays at opencode's default,
# set here so that an upgrade cannot change it unnoticed: a lower value
# would end runs that succeed today after a long wait (in the v0.1.0
# release validation, 13 minutes without an answer, and a request answered
# after 185 s without headers). The chunk timeout is the wait for the next
# event of a streamed response, and also for the FIRST one after the
# headers: a service that sends headers at once and then queues the
# request, or a model that thinks for a while before its first token, is
# silent there just as long. So it gets the same value as the header wait,
# not less; opencode's default is 900 s, with which one stream that stops
# uses most of the harness time limit. A stream that keeps sending is never
# cut, however long it takes.
readonly HEADER_TIMEOUT_MS=300000 CHUNK_TIMEOUT_MS=300000

bin="${HARNESS_PREFIX}/node_modules/@opencode/cli-linux-x64-baseline/bin/opencode"

# Ignore the repository's opencode.json(c) and .opencode/ (plugins there are
Expand All @@ -31,7 +48,7 @@ check_version "opencode v$(head -n 1 "${HARNESS_PREFIX}/VERSION")" "${bin}" --ve
# token and replaced by AWF's sidecar. Tools that edit, reach the web, ask
# questions or spawn subagents are denied; 'shell' stays for git and grep.
OPENCODE_CONFIG_CONTENT=$(jq -n --arg model "${MODEL}" --arg base "${AWF_API_PROXY_OPENAI_URL%/}/v1" \
--argjson steps "${MAX_STEPS}" '{
--argjson steps "${MAX_STEPS}" --argjson header "${HEADER_TIMEOUT_MS}" --argjson chunk "${CHUNK_TIMEOUT_MS}" '{
model: ("awf-proxy/" + $model), update: "disable", share: "disabled",
experimental: {policies: [
{action: "provider.use", resource: "*", effect: "deny"},
Expand All @@ -40,7 +57,8 @@ OPENCODE_CONFIG_CONTENT=$(jq -n --arg model "${MODEL}" --arg base "${AWF_API_PRO
| map({action: ., resource: "*", effect: "deny"})),
agents: {build: {steps: $steps}},
providers: {"awf-proxy": {name: "AWF proxy", package: "@opencode/ai/providers/openai-compatible",
settings: {baseURL: $base, apiKey: "awf-placeholder"}, models: {($model): {name: $model}}}}}')
settings: {baseURL: $base, apiKey: "awf-placeholder", headerTimeout: $header, chunkTimeout: $chunk},
models: {($model): {name: $model}}}}}')
export OPENCODE_CONFIG_CONTENT

cd "${REPO_DIR}" || exit 1
Expand Down
20 changes: 17 additions & 3 deletions agent-review/harnesses/pi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,23 @@ To upgrade, set the version in `package.json` and regenerate the lockfile with
cannot be restricted; the sandbox is the boundary.
- The prompt is passed on stdin: with stdin open and no prompt, Pi waits
forever.
- **No turn cap and no stall detection**: AWF's `apiProxy.maxTurns` stops a
well-behaved run; the bound is AWF's request rate limits and the harness
timeout (see `../../awf.yaml`).
- **No turn cap**: AWF's `apiProxy.maxTurns` stops a well-behaved run; the
bound is AWF's request rate limits and the harness timeout (see
`../../awf.yaml`).
- **Request timeouts and retries** come from `settings.json` in the same
directory. `httpIdleTimeoutMs` is 240 s (Pi's default is 300 s; one
setting for both waits): a request that gets no response headers, or no
further chunk of a streamed response, for that long is ended and retried;
a stream that keeps sending is never cut. It is not lower because, in the
v0.1.0 release validation, a request was answered after 185 s without
headers. `retry.maxRetries` is 5 (default 3; the delay doubles from
`retry.baseDelayMs`, 2 s as by default, and the count starts again after
a successful request): 6 attempts of
240 s exceed the harness timeout, so a run waits for a silent service as
long as it did with the defaults (4 x 300 s). Every attempt counts
against AWF's request limits. `../../tests/test-harness-stall.sh` checks
this against a server that stalls; run it after changing these values or
the pinned version.

## Outbound calls

Expand Down
23 changes: 20 additions & 3 deletions agent-review/harnesses/pi/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
# CSCS does not serve). Exit codes: 0 review written, 2 no final answer,
# other: failure.
#
# Pi has no turn cap and no stall detection, and exits 0 when every request
# failed: AWF's apiProxy.maxTurns stops a well-behaved run; AWF's rate limits
# and run-review's timeout bound it (see awf.yaml).
# Pi has no turn cap, and exits 0 when every request failed: AWF's
# apiProxy.maxTurns stops a well-behaved run; AWF's rate limits and
# run-review's timeout bound it (see awf.yaml). A request that stalls is
# ended by the idle timeout below and retried.

set -uo pipefail
# shellcheck source=SCRIPTDIR/../common.sh
Expand All @@ -20,6 +21,19 @@ adapter_init pi
# Model metadata Pi needs for context management.
readonly CONTEXT_WINDOW=128000 MAX_TOKENS=16384

# A request that sends nothing for this long (no response headers, or no
# further chunk of a streamed response) is ended and retried; Pi's default
# is 300 s, and it has one setting for both waits. A live stream sends a
# chunk every few seconds; its total duration is not limited. Not lower: in
# the v0.1.0 release validation a request was answered after 185 s without
# headers, and whether a new request would have been answered sooner is not
# known. The retries (Pi's default is 3; the delay doubles from 2 s, Pi's
# default, set here so that the stall test can scale it) are
# raised so that the time a run can wait for a service that answers nothing
# is not shortened: 6 attempts of 240 s exceed the harness time limit, which
# stays the bound. Each attempt counts against AWF's request limits.
readonly IDLE_TIMEOUT_MS=240000 MAX_RETRIES=5 RETRY_BASE_DELAY_MS=2000

export PI_CODING_AGENT_DIR="${SCRATCH}/agent" PI_OFFLINE=1 PI_TELEMETRY=0
mkdir -p "${PI_CODING_AGENT_DIR}"
pi_cli="${HARNESS_PREFIX}/node_modules/@earendil-works/pi-coding-agent/dist/bundle/cli.js"
Expand All @@ -32,6 +46,9 @@ jq -n --arg id "${MODEL}" --arg base "${AWF_API_PROXY_OPENAI_URL%/}/v1" \
{providers: {"awf-proxy": {baseUrl: $base, api: "openai-completions", apiKey: "awf-placeholder",
models: [{id: $id, name: $id, reasoning: false, input: ["text"], contextWindow: $ctx, maxTokens: $max}]}}}' \
>"${PI_CODING_AGENT_DIR}/models.json"
jq -n --argjson idle "${IDLE_TIMEOUT_MS}" --argjson retries "${MAX_RETRIES}" --argjson delay "${RETRY_BASE_DELAY_MS}" \
'{httpIdleTimeoutMs: $idle, retry: {enabled: true, maxRetries: $retries, baseDelayMs: $delay}}' \
>"${PI_CODING_AGENT_DIR}/settings.json"

cd "${REPO_DIR}" || exit 1
# --no-approve ignores the repository's .pi/ (extensions there are executed,
Expand Down
Loading
Loading