#!/usr/bin/env bash # One review: clone the change, hand it to an agent in a sandbox, then publish what it proved. # # Runs as root so it can hold the token and the model key. The agent runs as uid 10001 with an # empty environment, so neither secret is reachable from the code being reviewed — that split is # the reason a review can clone and run a pull request at all. # # Inputs (environment, from the workflow): # GOBY_REPO GOBY_PR GOBY_HEAD GOBY_BASE GITHUB_TOKEN # GOBY_PROVIDER GOBY_MODEL (optional; the image has a default) # CORALBRICKS_API_KEY / ANTHROPIC_API_KEY / OPENAI_API_KEY # Budgets default from /opt/goby/defaults.env; a same-named workflow variable overrides one. set -euo pipefail # shellcheck source=/dev/null source /opt/goby/lib.sh # shellcheck source=/dev/null source /opt/goby/defaults.env # Gate mode rechecks eligibility only: no clone, no model, no key. It answers "is the evidence on # this pull request still sufficient", which is what a workflow_run handoff needs. if [[ "${GOBY_MODE:-review}" == "gate" ]]; then : "${GOBY_REPO:-}"; : "${GITHUB_TOKEN:-}" if [[ -z "$GOBY_REPO" || -z "$GITHUB_TOKEN" ]]; then goby_log "error: gate mode needs GOBY_REPO and GITHUB_TOKEN" exit 2 fi GOBY_OUT="${GOBY_OUT:-/workspace/out}" GOBY_EVENT_FILE="${GOBY_EVENT_FILE:-}" \ GITHUB_EVENT_NAME="${GITHUB_EVENT_NAME:-}" GOBY_PR="${GOBY_PR:-}" GOBY_HEAD="${GOBY_HEAD:-}" \ GOBY_VERIFY="${GOBY_VERIFY:-off}" \ node /opt/goby/reviewRun.js gate exit $? fi # Named, not a bare `${var:?}`: the point of this check is that whoever wired the job can read # which input is missing without opening the script. missing=() for name in GOBY_REPO GOBY_PR GOBY_HEAD GOBY_BASE; do [[ -n "${!name:-}" ]] || missing+=("$name") done if [[ ${#missing[@]} -gt 0 ]]; then goby_log "error: missing required input(s): ${missing[*]}" exit 2 fi # The verification pass runs as its own uid: it executes the reviewed repository's commands, and # it must not be able to reach the token or the model key any more than the agent can. GOBY_VERIFY_USER="${GOBY_VERIFY_USER:-verifier}" GOBY_VERIFY_UID="${GOBY_VERIFY_UID:-10002}" goby_run_as_verifier() { local extra_env=("$@") runuser -u "$GOBY_VERIFY_USER" -- env -i \ PATH=/usr/local/bin:/usr/bin:/bin \ HOME="/home/$GOBY_VERIFY_USER" TMPDIR=/tmp \ "${extra_env[@]}" } # Cosmetic only (src/progress.ts): a "Goby is reviewing" note on the pull request, started once a # review will actually run and marked done on every exit after that. Wall-clocked and `|| true`, so # it can neither hang a review nor change how one ends. goby_progress() { timeout 30 node /opt/goby/progress.js "$1" || true; } # A review that cannot run has to resolve the statuses it declared open. `prepare` posts "Review in # progress" before the clone now, so a failure in this shell would otherwise leave a pull request # blocked on a check that never concludes — the same reason the "reviewer never reported" path # below calls this, and the same rule as review/INVARIANTS.md 1. goby_fail() { goby_log "error: $1" GOBY_REPO="$GOBY_REPO" GOBY_HEAD="$GOBY_HEAD" GITHUB_TOKEN="$GITHUB_TOKEN" \ GOBY_FAIL_REASON="$1" node /opt/goby/reviewRun.js fail || true exit 1 } PROVIDER="${GOBY_PROVIDER:-coral}" MODEL="${GOBY_MODEL:-deepseek-v4.1-flash-fast}" MAX_DIFF_LINES="$GOBY_MAX_DIFF_LINES" WORK="${GOBY_WORK:-/workspace}" REPO_DIR="$WORK/repo" SANDBOX="$WORK/sandbox" OUT="$WORK/out" export GOBY_OUT="$OUT" AGENT_HOME="/home/$GOBY_AGENT_USER/.pi-agent" # The credential's header is the provider's: Anthropic reads `x-api-key` with no scheme, and a # proxy that rewrites only `authorization` would send it the agent's dummy instead. KEY_HEADER="authorization"; KEY_SCHEME="Bearer " case "$PROVIDER" in coral) KEY="${CORALBRICKS_API_KEY:-}"; UPSTREAM="https://inference.coralbricks.ai" ;; anthropic) KEY="${ANTHROPIC_API_KEY:-}"; UPSTREAM="https://api.anthropic.com" KEY_HEADER="x-api-key"; KEY_SCHEME="" ;; openai) KEY="${OPENAI_API_KEY:-}"; UPSTREAM="https://api.openai.com" ;; # Any OpenAI-compatible endpoint: the key is whatever the workflow named, the URL is explicit. # A provider with a fixed upstream cannot be pointed at a gateway, which is the whole point. # The host only, no path: the agent's models file names `/v1`, and the proxy prepends the # upstream's own pathname to the request path. custom) KEY="${GOBY_API_KEY:-${OPENAI_API_KEY:-}}"; UPSTREAM="${GOBY_UPSTREAM:-}" ;; *) goby_log "error: unknown provider $PROVIDER"; exit 2 ;; esac [[ -n "$KEY" ]] || { goby_log "error: no key for provider $PROVIDER"; exit 2; } [[ -n "${UPSTREAM:-}" ]] || { goby_log "error: provider $PROVIDER needs GOBY_UPSTREAM"; exit 2; } mkdir -p "$OUT" "$AGENT_HOME" # The runner stops a job with SIGTERM — its own `timeout-minutes`, a new push under # `cancel-in-progress`, an operator's stop — and nothing in this shell answered it. So a review # killed at minute 14 left `Goby Review` pending on the head with the note still saying "is # reviewing": the pull request is blocked with nothing to read, which review/INVARIANTS.md 1 # forbids. Installed before `prepare`, because `prepare` is what posts the statuses this resolves; # the EXIT trap further down only puts the note away. `GOBY_AGENT_TIMEOUT_S` should fire long # before the runner does — this is the handler for a kill that is not the deadline's. # # Three paths publish and then end: a reused head, a skipped diff, and the review itself. Each sets # this immediately before its publish, and a cancel after that writes nothing — the reuse branch # posts no pending status to begin with, so "the review was cancelled" there would be a red status # appearing over a green one, out of nothing, with a reason that is not true. VERDICT_POSTED=0 on_cancel() { # One handler, one exit: clearing the traps stops the EXIT one from running this a second time, # so the two cleanups it owns are done here instead. trap - EXIT TERM INT if [[ "$VERDICT_POSTED" == 1 ]]; then goby_log "cancelled after this run posted its verdict; leaving it alone" else goby_log "error: cancelled; resolving the statuses this review opened" GOBY_REPO="$GOBY_REPO" GOBY_HEAD="$GOBY_HEAD" GITHUB_TOKEN="$GITHUB_TOKEN" \ GOBY_FAIL_REASON="the review was cancelled before it finished" \ node /opt/goby/reviewRun.js fail || true fi goby_progress stop goby_proxy_stop exit 1 } trap on_cancel TERM INT # --- what this run is ------------------------------------------------------------------- # Prepare asks GitHub everything the reuse decision needs — the API's diff digest for this head and # base, the PR's head and base, the receipt on a previous review of this commit, the reviews this # bot already posted — and needs no clone to answer it. So it runs first: a head that was already # reviewed is a status refresh, and paying for a full clone and a diff that nothing will read was # most of what such a run cost. It still talks to GitHub as root, before any drop, with the token # in this process. GOBY_REPO="$GOBY_REPO" GOBY_PR="$GOBY_PR" GOBY_HEAD="$GOBY_HEAD" GOBY_BASE="$GOBY_BASE" \ GOBY_MODEL="$MODEL" GITHUB_TOKEN="$GITHUB_TOKEN" GOBY_OUT="$OUT" \ GOBY_GATE="${GOBY_GATE:-off}" \ node /opt/goby/reviewRun.js prepare | tee "$OUT/prepare.json" if grep -q '"reuse":true' "$OUT/prepare.json"; then goby_log "this head was already reviewed; refreshing the gate only" VERDICT_POSTED=1 GOBY_REPO="$GOBY_REPO" GOBY_PR="$GOBY_PR" GOBY_HEAD="$GOBY_HEAD" GOBY_BASE="$GOBY_BASE" \ GOBY_MODEL="$MODEL" GITHUB_TOKEN="$GITHUB_TOKEN" GOBY_OUT="$OUT" GOBY_VERIFY="${GOBY_VERIFY:-off}" \ node /opt/goby/reviewRun.js finish exit $? fi # --- the change ------------------------------------------------------------------------- rm -rf "${REPO_DIR:?}" "${SANDBOX:?}"; mkdir -p "$REPO_DIR" "$SANDBOX" # AUTH goes in a per-command header, never the URL: a URL lands in .git/config inside the tree the # reviewer reads, and the sandbox copy would carry it. Not a partial clone either: a blobless clone # fetches blobs lazily, and that lazy fetch would go out unauthenticated from inside the sandbox. AUTH=(-c "http.extraHeader=AUTHORIZATION: basic $(printf 'x-access-token:%s' "$GITHUB_TOKEN" | base64 -w0)") goby_log "clone $GOBY_REPO@${GOBY_HEAD:0:10} (base ${GOBY_BASE:0:10})" if ! git "${AUTH[@]}" -c advice.detachedHead=false clone --quiet --no-checkout \ "https://github.com/${GOBY_REPO}.git" "$REPO_DIR"; then goby_fail "the clone of $GOBY_REPO failed" fi git -C "$REPO_DIR" remote set-url origin "https://github.com/${GOBY_REPO}.git" # The merge base comes from GitHub, so three commits at depth 1 are enough: the head, the base the # pull request was opened against, and the commit the diff is actually taken from. Guessing a depth # of history means either fetching far more than needed or discovering, on a quiet day, that the # merge base was never downloaded and the diff is against the wrong thing. MERGE_BASE="" if MERGE_BASE=$(GOBY_REPO="$GOBY_REPO" GOBY_HEAD="$GOBY_HEAD" GOBY_BASE="$GOBY_BASE" \ GITHUB_TOKEN="$GITHUB_TOKEN" node /opt/goby/reviewRun.js merge-base 2>/dev/null); then goby_log "merge base ${MERGE_BASE:0:10}" else # A compare that fails (an enormous range, a transient error) is not a reason to review nothing: # fall back to the base commit, which is what a two-dot diff uses anyway. MERGE_BASE="$GOBY_BASE" goby_log "warn: no merge base from the API; diffing against the base commit" fi if ! git "${AUTH[@]}" -C "$REPO_DIR" fetch --quiet --depth 1 origin "$GOBY_HEAD" "$MERGE_BASE"; then goby_fail "cannot fetch $GOBY_HEAD/$MERGE_BASE; refusing to review a different commit" fi if [[ "$(git -C "$REPO_DIR" rev-parse HEAD 2>/dev/null)" != "$GOBY_HEAD" ]] \ && ! git -C "$REPO_DIR" -c advice.detachedHead=false checkout --quiet "$GOBY_HEAD"; then goby_fail "checkout of $GOBY_HEAD failed; refusing to review a different commit" fi DIFF="$OUT/diff.patch" if ! git -C "$REPO_DIR" diff --find-renames "$MERGE_BASE" "$GOBY_HEAD" > "$DIFF"; then goby_fail "the diff ${MERGE_BASE:0:10}..${GOBY_HEAD:0:10} could not be taken" fi goby_log "diff merge-base..head (${MERGE_BASE:0:10}..${GOBY_HEAD:0:10})" DIFF_LINES=$(wc -l < "$DIFF" | tr -d ' ') goby_log "diff $DIFF_LINES lines" if [[ "$DIFF_LINES" -gt "$MAX_DIFF_LINES" ]]; then # Skipping is a verdict, not a crash: the review says so, and the gate fails closed. goby_log "skipped: diff is $DIFF_LINES lines (cap $MAX_DIFF_LINES)" VERDICT_POSTED=1 GOBY_REPO="$GOBY_REPO" GOBY_PR="$GOBY_PR" GOBY_HEAD="$GOBY_HEAD" GOBY_BASE="$GOBY_BASE" \ GOBY_MODEL="$MODEL" GOBY_SKIP_REASON="diff is $DIFF_LINES lines (cap $MAX_DIFF_LINES)" \ node /opt/goby/reviewRun.js skip || true exit 0 fi # --- secrets, then the agent's world ----------------------------------------------------- goby_key_to_file "$KEY" goby_token_to_file export GOBY_KEY_FILE GOBY_TOKEN_FILE goby_proxy_start "$UPSTREAM" "$KEY_HEADER" "$KEY_SCHEME" # The progress stop is a no-op until `goby_progress start` below; it goes first as it cannot fail. trap 'goby_progress stop; goby_proxy_stop' EXIT # Only here, with a diff that will actually be read and a proxy that answered: a reuse refreshed a # status, a skipped diff posted its verdict, and a failure in the clone or the proxy above has # already resolved the statuses it opened. Past this point the note is started, and the EXIT trap # just installed owns marking it done, whatever happens next. goby_progress start # The reference tree is what findings quote; the sandbox is what the reviewer may change. cp -a "$REPO_DIR/." "$SANDBOX/" chown -R "$GOBY_AGENT_USER:$GOBY_AGENT_USER" "$SANDBOX" chown -R root:root "$REPO_DIR" "$OUT" chmod -R a-w "$REPO_DIR" chmod 755 "$OUT" # git 2.35+ refuses a repository owned by another user, and this tree is root-owned on purpose. git config --system --add safe.directory "$REPO_DIR" cp "/opt/goby/models/models.json" "$AGENT_HOME/models.json" # A provider's model list is a catalog, not a constraint: a deployment names its own model id in # GOBY_MODEL, and an id the image never heard of has to work or every gateway is unusable. GOBY_PROVIDER="$PROVIDER" GOBY_MODEL="$MODEL" python3 - "$AGENT_HOME/models.json" <<'PYCATALOG' import json, os, sys path = sys.argv[1] with open(path, encoding="utf-8") as handle: catalog = json.load(handle) provider = catalog.setdefault("providers", {}).setdefault(os.environ["GOBY_PROVIDER"], { "baseUrl": "http://127.0.0.1:8787/v1", "api": "openai-completions", "apiKey": "$GOBY_MODEL_KEY", "models": [], }) models = provider.setdefault("models", []) if not any(model.get("id") == os.environ["GOBY_MODEL"] for model in models): models.append({"id": os.environ["GOBY_MODEL"]}) with open(path, "w", encoding="utf-8") as handle: json.dump(catalog, handle, indent=2) PYCATALOG chown -R "$GOBY_AGENT_USER:$GOBY_AGENT_USER" "$AGENT_HOME" chmod 700 "$AGENT_HOME" GOBY_REPO="$GOBY_REPO" GOBY_HEAD="$GOBY_HEAD" GOBY_BASE="$GOBY_BASE" \ GOBY_SANDBOX="$SANDBOX" GOBY_REFERENCE="$REPO_DIR" GOBY_PROMPT=/opt/goby/prompt.md GOBY_DIFF="$DIFF" \ GOBY_PROMPT_OUT="$OUT/prompt.md" python3 - <<'PYTEMPLATE' import os, pathlib template = pathlib.Path(os.environ["GOBY_PROMPT"]).read_text() diff = pathlib.Path(os.environ["GOBY_DIFF"]).read_text() for key, value in { "{{REPO}}": os.environ["GOBY_REPO"], "{{HEAD}}": os.environ["GOBY_HEAD"], "{{BASE}}": os.environ["GOBY_BASE"], "{{SANDBOX}}": os.environ["GOBY_SANDBOX"], "{{REFERENCE}}": os.environ["GOBY_REFERENCE"], "{{OUT}}": os.environ["GOBY_OUT"], "{{DIFF}}": diff, }.items(): template = template.replace(key, value) pathlib.Path(os.environ["GOBY_PROMPT_OUT"]).write_text(template) PYTEMPLATE chmod 644 "$OUT/prompt.md" AGENT_OUT="$OUT/agent" mkdir -p "$AGENT_OUT" "$AGENT_OUT/scratch" chown -R "$GOBY_AGENT_USER:$GOBY_AGENT_USER" "$AGENT_OUT" chmod 700 "$AGENT_OUT" # One script, so the unprivileged side is not assembled out of nested quotes. # # `--mode json`, not `--print`: the event stream is the only record of where the run's wall clock # went, and it is written by the agent itself, into the one directory it owns. Its stderr is pi's # own diagnostics, kept because a refusal to start (a bad flag, a rejected key) leaves no events at # all and this file would then be the only evidence of why. Neither stream decides the verdict — # `report_findings` does, as before. # # `timeout` is the deadline, and it sits inside the agent's own process tree on purpose: it is pi's # direct parent, so SIGTERM reaches the process that is actually spending the time, and # `--kill-after` ends one that does not exit. A run stopped this way exits 124, which is how the # failure path below tells "the model was slow enough to spend the whole budget" apart from # "something stopped the agent with no verdict". # A provider failure is not a review verdict. pi spends its own retries inside a turn and then ends # the run; `/opt/common/summarize_run.py --status` says so from the last assistant message's # `stopReason`, never from its text, which is upstream wording. One more attempt, sharing the same # agent budget, and only while enough of it is left to be worth spending: two attempts can never # outlive `GOBY_AGENT_TIMEOUT_S`, so the job timeout still holds. The second attempt *is* the run — # its stream overwrites the first, and the log line below is what says a retry happened. AGENT_BUDGET="$GOBY_AGENT_TIMEOUT_S" AGENT_SPENT=0 AGENT_ATTEMPTS=2 AGENT_ATTEMPT=1 while :; do cat > "$OUT/run-agent.sh" < "$AGENT_OUT/events.jsonl" 2> "$AGENT_OUT/stderr.log" RUN chmod 755 "$OUT/run-agent.sh" goby_log "review $GOBY_REPO#$GOBY_PR model=$MODEL max_tool_calls=$GOBY_MAX_TOOL_CALLS agent_deadline=${AGENT_BUDGET}s attempt=$AGENT_ATTEMPT/$AGENT_ATTEMPTS" AGENT_STARTED=$SECONDS set +e # Backgrounded and waited on, not run in the foreground, and that is what makes the cancel handler # above reachable: bash defers a trapped signal until the command it is waiting for returns, and the # agent is the one command that may never return. `wait` is interruptible, so a SIGTERM from the # runner runs `on_cancel` while the agent is still working — a second and a half before the runner # stops the container, which is all the time the status write gets. goby_run_as_agent \ PI_CODING_AGENT_DIR="$AGENT_HOME" \ PI_SKIP_VERSION_CHECK=1 PI_TELEMETRY=0 \ GOBY_MODEL_KEY=dummy-proxy-key \ GOBY_SESSION_ID="review-pr${GOBY_PR}-${GOBY_HEAD:0:10}" \ GOBY_AGENT_OUT="$AGENT_OUT" GOBY_OUT="$OUT" GOBY_SCRATCH="$AGENT_OUT/scratch" \ GOBY_SANDBOX="$SANDBOX" GOBY_REPO="$GOBY_REPO" GOBY_HEAD="$GOBY_HEAD" GOBY_BASE="$GOBY_BASE" \ GOBY_MAX_TOOL_CALLS="$GOBY_MAX_TOOL_CALLS" \ GOBY_MAX_TURNS="$GOBY_MAX_TURNS" \ GOBY_AGENT_TIMEOUT_S="$AGENT_BUDGET" \ GOBY_BASH_TIMEOUT_S="$GOBY_BASH_TIMEOUT_S" \ bash "$OUT/run-agent.sh" & AGENT_PID=$! wait "$AGENT_PID" AGENT_STATUS=$? AGENT_ELAPSED=$((SECONDS - AGENT_STARTED)) set -e AGENT_SPENT=$((AGENT_SPENT + AGENT_ELAPSED)) # Anything was answered, or the clock ended it: both are final. Only a *model* error is worth # another attempt, and only with a fifth of the budget left to spend on it. if grep -q '"kind":"findings"' "$AGENT_OUT/findings.jsonl" 2>/dev/null; then break; fi if [[ "$AGENT_STATUS" -eq 124 || "$AGENT_STATUS" -eq 137 ]]; then break; fi AGENT_MODEL_ERROR=0 python3 /opt/common/summarize_run.py --status "$AGENT_OUT/events.jsonl" > /dev/null \ || AGENT_MODEL_ERROR=$? if [[ "$AGENT_MODEL_ERROR" -ne 3 ]]; then break; fi AGENT_LEFT=$((GOBY_AGENT_TIMEOUT_S - AGENT_SPENT)) if [[ "$AGENT_ATTEMPT" -ge "$AGENT_ATTEMPTS" || "$AGENT_LEFT" -lt $((GOBY_AGENT_TIMEOUT_S / 5)) ]]; then break fi goby_log "attempt $AGENT_ATTEMPT of $AGENT_ATTEMPTS ended on a model error after ${AGENT_ELAPSED}s; retrying with ${AGENT_LEFT}s left of the ${GOBY_AGENT_TIMEOUT_S}s budget" AGENT_ATTEMPT=$((AGENT_ATTEMPT + 1)) AGENT_BUDGET="$AGENT_LEFT" done # What the run did, from its own record. All of it is instrumentation: every call is `|| true`, # because an instrument that can end a review is a new way for a review to fail. The timing line is # the one that answers "where did the agent's two minutes go" — model turns, the tool calls' own # clocks, and the calls that took the longest — and it goes to the log and to the job summary, so a # review that reports its own cost needs no second mechanism. EVENTS="$AGENT_OUT/events.jsonl" if [[ -s "$EVENTS" ]]; then SUMMARY="$(python3 /opt/common/summarize_run.py "$EVENTS" || true)" if [[ -n "$SUMMARY" ]]; then goby_log "$SUMMARY"; fi # Printed only when the model call failed: pi exits 0 with stopReason=error, so the exit code # above cannot carry it. Not a verdict here — a missing findings record is what fails a review. MODEL_ERROR="$(python3 /opt/common/summarize_run.py --status "$EVENTS" || true)" if [[ -n "$MODEL_ERROR" ]]; then goby_log "warn: $MODEL_ERROR"; fi TIMING="$(python3 /opt/common/timing.py "$EVENTS" --agent-seconds "$AGENT_ELAPSED" \ --findings "$AGENT_OUT/findings.jsonl" --calls || true)" if [[ -n "$TIMING" ]]; then # One log line per tool call, then the summary line: the summary says the ratio, the sequence # says what the reviewer did with it, and "is it batching its probes" is only answerable from # the second. Every line is prefixed like the phase checkpoints so the log stays greppable. while IFS= read -r trace_line; do goby_log "$trace_line"; done <<< "$TIMING" SUMMARY_LINE="$(printf '%s\n' "$TIMING" | tail -n 1)" if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]] \ && ! printf -- '- %s\n' "${SUMMARY_LINE#timing }" >> "$GITHUB_STEP_SUMMARY"; then goby_log "warn: could not write the timing line to the job summary" fi fi # The same numbers as a record, in the one place a review is kept forever: the job summary above # has no API and expires with the log, so from here on "what did this review cost" was answerable # for ninety days out of a zip. `runrecord.py` takes its clock and its price from the same two # functions the line above used, so the record and the line cannot disagree. # # Instrumentation, like everything in this block: a record that cannot be written is a missing # field for a reader, never a failed review. MODEL_CATALOG=() if [[ -f "$REPO_DIR/.goby/models.json" ]]; then # The same convention the cleaners and the tide follow: a repository that commits a price # table gets money in its records, and one that does not gets `null` and the reason. MODEL_CATALOG=(--models-json "$REPO_DIR/.goby/models.json") fi if ! python3 /opt/common/runrecord.py "$AGENT_OUT" --agent-seconds "$AGENT_ELAPSED" \ --model "$MODEL" "${MODEL_CATALOG[@]}" > "$OUT/run-record.json"; then rm -f "$OUT/run-record.json" goby_log "warn: could not write the run record" fi else goby_log "warn: the agent produced no event stream" fi goby_log "agent exit=$AGENT_STATUS findings=$(grep -c '"kind":"findings"' "$AGENT_OUT/findings.jsonl" 2>/dev/null || echo 0)" # A review that produced no findings record did not answer. Treat it as a failed review rather # than as "no bugs": those two are the failure this design exists to keep apart. if ! grep -q '"kind":"findings"' "$AGENT_OUT/findings.jsonl" 2>/dev/null; then # Not "no bugs": the reviewer never answered. Both statuses have to resolve, or the gate stays # pending forever and the pull request is blocked with nothing to read. # # 124 is `timeout` in run-agent.sh and 137 is the `--kill-after` behind it. The two reasons have # different next steps — one says the model was too slow for the budget, the other that something # ended the agent — so the status carries which one, rather than "exit 124" for a reader to look up. if [[ "$AGENT_STATUS" -eq 124 || "$AGENT_STATUS" -eq 137 ]]; then REASON="the reviewer spent its ${AGENT_BUDGET}s wall clock without reporting" else REASON="the reviewer exited without reporting (exit $AGENT_STATUS)" fi goby_log "error: the reviewer never reported (exit $AGENT_STATUS)" # pi's own diagnostics, which is where the reason is when it never got as far as a turn: a key # the provider rejected writes a session header and nothing else, so the stream above says the # split is unavailable without saying why. if [[ -f "$AGENT_OUT/stderr.log" ]]; then tail -20 "$AGENT_OUT/stderr.log"; fi GOBY_REPO="$GOBY_REPO" GOBY_HEAD="$GOBY_HEAD" GITHUB_TOKEN="$GITHUB_TOKEN" \ GOBY_FAIL_REASON="$REASON" \ node /opt/goby/reviewRun.js fail || true exit 1 fi # --- verification ----------------------------------------------------------------------- # The reviewer answered; this decides which of its answers survived. The probes it was told to # record are re-run on the head and on the merge base, in two throw-away worktrees, as its own uid. # It changes nothing the reviewer said: it writes a verdict that `finish` reads. VERIFY_MODE="${GOBY_VERIFY:-off}" VERIFY_DIR="$OUT/verify" if [[ "$VERIFY_MODE" != "off" ]]; then DIFF_DIGEST="$(jq -r '.diff_digest // empty' "$OUT/job.json" 2>/dev/null || true)" if [[ -z "$DIFF_DIGEST" ]]; then goby_log "warn: no diff digest in job.json; skipping verification" else goby_log "verify $VERIFY_MODE: re-running reported probes against head and ${MERGE_BASE:0:10}" rm -rf "$VERIFY_DIR"; mkdir -p "$VERIFY_DIR" if git -C "$REPO_DIR" worktree add --detach --quiet "$VERIFY_DIR/head" "$GOBY_HEAD" \ && git -C "$REPO_DIR" worktree add --detach --quiet "$VERIFY_DIR/base" "$MERGE_BASE"; then chown -R "$GOBY_VERIFY_UID:$GOBY_VERIFY_UID" "$VERIFY_DIR" if ! goby_run_as_verifier python3 /opt/goby/verify.py \ --findings "$AGENT_OUT/findings.jsonl" \ --head-dir "$VERIFY_DIR/head" --base-dir "$VERIFY_DIR/base" --out "$VERIFY_DIR" \ --head "$GOBY_HEAD" --diff-sha256 "$DIFF_DIGEST" \ --mode "$VERIFY_MODE" --max-probes "$GOBY_MAX_PROBES" \ --probe-timeout "$GOBY_PROBE_TIMEOUT_S" --budget "$GOBY_VERIFY_BUDGET_S"; then goby_log "warn: the verification pass did not run; finish will treat this as unverified" fi else goby_log "warn: could not create the verification worktrees" fi fi fi # The review has answered, so from here the only thing left is this run's own publish — and a # SIGTERM during it must not be turned into an error status over a review that was posted. goby_proxy_stop VERDICT_POSTED=1 GOBY_REPO="$GOBY_REPO" GOBY_PR="$GOBY_PR" GOBY_HEAD="$GOBY_HEAD" GOBY_BASE="$GOBY_BASE" \ GOBY_MODEL="$MODEL" GITHUB_TOKEN="$GITHUB_TOKEN" GOBY_OUT="$OUT" GOBY_AGENT_OUT="$AGENT_OUT" \ GOBY_ELAPSED_S="$AGENT_ELAPSED" GOBY_GATE="${GOBY_GATE:-off}" GOBY_VERIFY="$VERIFY_MODE" \ node /opt/goby/reviewRun.js finish