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
5 changes: 5 additions & 0 deletions .github/workflows/reusable-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ jobs:
persist-credentials: false

- name: Validate inputs
id: validate
env:
ISSUE_NUMBER: ${{ fromJSON(inputs.event_payload).issue.number }}
REPO_FULL_NAME: ${{ inputs.source_repo }}
Expand All @@ -138,12 +139,14 @@ jobs:
run: bash scripts/pre-code.sh

- name: Setup GCP and prepare credentials
if: steps.validate.outputs.skipped != 'true'
uses: ./.defaults/.github/actions/setup-gcp
with:
gcp_wif_provider: ${{ secrets.FULLSEND_GCP_WIF_PROVIDER }}
gcp_project_id: ${{ secrets.FULLSEND_GCP_PROJECT_ID }}

- name: Resolve bot identity
if: steps.validate.outputs.skipped != 'true'
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
Expand All @@ -157,6 +160,7 @@ jobs:
echo "GIT_BOT_EMAIL=${GIT_BOT_EMAIL}" >> "${GITHUB_ENV}"

- name: Setup agent environment
if: steps.validate.outputs.skipped != 'true'
env:
AGENT_PREFIX: CODE_
CODE_GH_TOKEN: ${{ steps.app-token.outputs.token }}
Expand All @@ -167,6 +171,7 @@ jobs:
run: bash .github/scripts/setup-agent-env.sh

- name: Run code agent
if: steps.validate.outputs.skipped != 'true'
uses: ./.defaults/
env:
GITHUB_ISSUE_URL: ${{ fromJSON(inputs.event_payload).issue.html_url }}
Expand Down
23 changes: 22 additions & 1 deletion .github/workflows/reusable-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
contents: read
pull-requests: read
outputs:
stage: ${{ steps.role-check.outputs.skipped != 'true' && steps.route.outputs.stage || '' }}
stage: ${{ steps.role-check.outputs.skipped != 'true' && steps.pr-check.outputs.skipped != 'true' && steps.route.outputs.stage || '' }}
Comment thread
jhutar marked this conversation as resolved.
Resolved
Comment thread
jhutar marked this conversation as resolved.
Resolved

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] logic-error

When pr-check sets skipped=true, intermediate steps still run. Harmless read-only validations with minor inefficiency.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] fail-open

The pr-check guard fails open on API errors. Intentional fail-open for defense-in-depth.

trigger_source: ${{ steps.route.outputs.trigger_source }}
event_payload: ${{ steps.payload.outputs.event_payload }}
steps:
Expand Down Expand Up @@ -234,6 +234,27 @@ jobs:
echo "stage=${STAGE}" >> "${GITHUB_OUTPUT}"
echo "trigger_source=${TRIGGER_SOURCE}" >> "${GITHUB_OUTPUT}"

- name: Check for existing PRs
id: pr-check
if: steps.route.outputs.stage == 'code'
env:
GH_TOKEN: ${{ github.token }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
SOURCE_REPO: ${{ github.repository }}
run: |
set -euo pipefail
BOT_LOGIN="fullsend-ai[bot]"
CODER_BOT_LOGIN="fullsend-ai-coder[bot]"
MENTIONING_PRS="$(gh pr list --repo "${SOURCE_REPO}" --state open \
--search "${ISSUE_NUMBER} in:title,body" \
Comment thread
jhutar marked this conversation as resolved.
Resolved
Comment thread
jhutar marked this conversation as resolved.
Resolved
--json number,author \
--jq "[.[] | select(.author.login != \"${BOT_LOGIN}\" and .author.login != \"${CODER_BOT_LOGIN}\")] | .[].number" \
2>/dev/null || true)"
if [[ -n "${MENTIONING_PRS}" ]]; then
echo "::notice::Open PR(s) mentioning issue #${ISSUE_NUMBER} found — skipping code dispatch"
echo "skipped=true" >> "${GITHUB_OUTPUT}"
fi

- name: Validate routed stage
if: steps.route.outputs.stage != ''
env:
Expand Down
35 changes: 28 additions & 7 deletions internal/scaffold/fullsend-repo/.github/workflows/dispatch.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# lint-workflow-size: max-lines=392
# lint-workflow-size: max-lines=414
# Dispatcher workflow that routes events to agent workflows based on stage.
# Routing logic determines the stage from event context — the shim only
# forwards the raw event. Adding a new stage requires only a case branch
Expand Down Expand Up @@ -194,8 +194,29 @@ jobs:
echo "stage=${STAGE}" >> "${GITHUB_OUTPUT}"
echo "trigger_source=${TRIGGER_SOURCE}" >> "${GITHUB_OUTPUT}"

- name: Check for existing PRs
id: pr-check
if: steps.route.outputs.stage == 'code'
env:
GH_TOKEN: ${{ github.token }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
SOURCE_REPO: ${{ github.repository }}
run: |
set -euo pipefail
BOT_LOGIN="fullsend-ai[bot]"
CODER_BOT_LOGIN="fullsend-ai-coder[bot]"
Comment thread
jhutar marked this conversation as resolved.
Resolved
MENTIONING_PRS="$(gh pr list --repo "${SOURCE_REPO}" --state open \
--search "${ISSUE_NUMBER} in:title,body" \
--json number,author \
--jq "[.[] | select(.author.login != \"${BOT_LOGIN}\" and .author.login != \"${CODER_BOT_LOGIN}\")] | .[].number" \
2>/dev/null || true)"
if [[ -n "${MENTIONING_PRS}" ]]; then
echo "::notice::Open PR(s) mentioning issue #${ISSUE_NUMBER} found — skipping code dispatch"
echo "skipped=true" >> "${GITHUB_OUTPUT}"
fi

- name: Mint dispatch token via OIDC
if: steps.route.outputs.stage != ''
if: steps.route.outputs.stage != '' && steps.pr-check.outputs.skipped != 'true'
id: oidc-mint
env:
MINT_URL: ${{ vars.FULLSEND_MINT_URL }}
Expand Down Expand Up @@ -227,14 +248,14 @@ jobs:
echo "token=$TOKEN" >> "$GITHUB_OUTPUT"

- name: Checkout repository
if: steps.route.outputs.stage != ''
if: steps.route.outputs.stage != '' && steps.pr-check.outputs.skipped != 'true'
uses: actions/checkout@v6
with:
repository: ${{ job.workflow_repository }}
token: ${{ steps.oidc-mint.outputs.token }}

- name: Validate routed stage
if: steps.route.outputs.stage != ''
if: steps.route.outputs.stage != '' && steps.pr-check.outputs.skipped != 'true'
env:
STAGE: ${{ steps.route.outputs.stage }}
TRIGGER_SOURCE: ${{ steps.route.outputs.trigger_source }}
Expand All @@ -254,7 +275,7 @@ jobs:
fi

- name: Check kill switch
if: steps.route.outputs.stage != ''
if: steps.route.outputs.stage != '' && steps.pr-check.outputs.skipped != 'true'
run: |
set -euo pipefail
KILL_SWITCH=$(yq '.kill_switch // false' config.yaml)
Expand All @@ -266,7 +287,7 @@ jobs:

- name: Check role is enabled
id: role-check
if: steps.route.outputs.stage != ''
if: steps.route.outputs.stage != '' && steps.pr-check.outputs.skipped != 'true'
env:
STAGE: ${{ steps.route.outputs.stage }}
run: |
Expand Down Expand Up @@ -305,7 +326,7 @@ jobs:
fi

- name: Find and trigger agent workflows for stage
if: steps.route.outputs.stage != '' && steps.role-check.outputs.skipped != 'true'
if: steps.route.outputs.stage != '' && steps.role-check.outputs.skipped != 'true' && steps.pr-check.outputs.skipped != 'true'
env:
GH_TOKEN: ${{ steps.oidc-mint.outputs.token }}
STAGE: ${{ steps.route.outputs.stage }}
Expand Down
3 changes: 3 additions & 0 deletions internal/scaffold/fullsend-repo/agents/triage.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ Also look for **blocking relationships** — open issues or PRs that must be res
- The issue describes a feature that depends on infrastructure or API changes tracked in another issue
- The issue references an upstream library, service, or repository that has a known open bug
- A PR is already in flight that would conflict with or must land before work on this issue
- An open PR already addresses this issue, even partially — the work is already in progress
- The issue's fix requires a design decision that is being discussed in another issue

**Existing PR gate (HARD CONSTRAINT):** If an open PR already addresses this issue — even partially — treat it as a prerequisite. Use `action: "prerequisites"` with the PR URL in the `existing` array. Do not emit `action: "sufficient"` when an open PR covers the reported problem; dispatching a second implementation would create duplicates. Only skip this rule if the PR is closed without merging (the work was abandoned) or if the PR is clearly unrelated despite mentioning the issue number.

If the issue mentions other repositories, libraries, or upstream projects, search those too:

```
Expand Down
87 changes: 87 additions & 0 deletions internal/scaffold/fullsend-repo/scripts/pre-code-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ run_test() {
local mock_bin
mock_bin="$(build_mock "${pr_list_output}")"
local gh_log="${TMPDIR}/gh-calls.log"
local gh_output="${TMPDIR}/github-output.txt"
: > "${gh_output}"

# Set base env vars for the script.
local env_cmd=(
Expand All @@ -99,6 +101,7 @@ run_test() {
REPO_FULL_NAME="test-org/test-repo"
GITHUB_ISSUE_URL="https://github.com/test-org/test-repo/issues/42"
GH_TOKEN="fake-token"
GITHUB_OUTPUT="${gh_output}"
)

# Add extra env vars if provided (read line-by-line to support values with spaces).
Expand Down Expand Up @@ -143,6 +146,8 @@ run_test_stdout() {

local mock_bin
mock_bin="$(build_mock "${pr_list_output}")"
local gh_output="${TMPDIR}/github-output.txt"
: > "${gh_output}"

local env_cmd=(
env
Expand All @@ -151,6 +156,7 @@ run_test_stdout() {
REPO_FULL_NAME="test-org/test-repo"
GITHUB_ISSUE_URL="https://github.com/test-org/test-repo/issues/42"
GH_TOKEN="fake-token"
GITHUB_OUTPUT="${gh_output}"
)

if [[ -n "${extra_env}" ]]; then
Expand Down Expand Up @@ -191,6 +197,8 @@ run_test_stdout_excludes() {

local mock_bin
mock_bin="$(build_mock "${pr_list_output}")"
local gh_output="${TMPDIR}/github-output.txt"
: > "${gh_output}"

local env_cmd=(
env
Expand All @@ -199,6 +207,7 @@ run_test_stdout_excludes() {
REPO_FULL_NAME="test-org/test-repo"
GITHUB_ISSUE_URL="https://github.com/test-org/test-repo/issues/42"
GH_TOKEN="fake-token"
GITHUB_OUTPUT="${gh_output}"
)

if [[ -n "${extra_env}" ]]; then
Expand Down Expand Up @@ -374,6 +383,84 @@ run_test_stdout "no-force-reaches-pr-search" \
0 \
"COMMENT_BODY=/fs-code"

# --- GITHUB_OUTPUT skip signal tests (issue #1312) ---

# Helper: run pre-code.sh and check GITHUB_OUTPUT contains expected key=value.
run_test_github_output() {
local test_name="$1"
local pr_list_output="$2"
local expected_output="$3" # e.g. "skipped=true"
local expect_exit="$4"
local extra_env="${5:-}"

local mock_bin
mock_bin="$(build_mock "${pr_list_output}")"
local gh_output="${TMPDIR}/github-output.txt"
: > "${gh_output}"

local env_cmd=(
env
PATH="${mock_bin}:${PATH}"
ISSUE_NUMBER="42"
REPO_FULL_NAME="test-org/test-repo"
GITHUB_ISSUE_URL="https://github.com/test-org/test-repo/issues/42"
GH_TOKEN="fake-token"
GITHUB_OUTPUT="${gh_output}"
)

if [[ -n "${extra_env}" ]]; then
while IFS= read -r kv; do
[[ -n "${kv}" ]] && env_cmd+=("${kv}")
done <<< "${extra_env}"
fi

local exit_code=0
"${env_cmd[@]}" bash "${PRE_SCRIPT}" > "${TMPDIR}/stdout.log" 2>&1 || exit_code=$?

if [[ ${exit_code} -ne ${expect_exit} ]]; then
echo "FAIL: ${test_name} — expected exit ${expect_exit}, got ${exit_code}"
cat "${TMPDIR}/stdout.log"
FAILURES=$((FAILURES + 1))
return
fi

if ! grep -qF "${expected_output}" "${gh_output}" 2>/dev/null; then
echo "FAIL: ${test_name} — expected GITHUB_OUTPUT to contain '${expected_output}'"
echo "Actual GITHUB_OUTPUT:"
cat "${gh_output}" 2>/dev/null || echo "(empty)"
FAILURES=$((FAILURES + 1))
return
fi

echo "PASS: ${test_name}"
}

# Existing human PR → GITHUB_OUTPUT must contain skip=true.
run_test_github_output "skip-output-set-on-existing-pr" \
"${HUMAN_PR_JSON}" \
"skipped=true" \
0

# No existing PRs → GITHUB_OUTPUT must contain skip=false.
run_test_github_output "skip-output-false-on-no-prs" \
"" \
"skipped=false" \
0

# Force override → GITHUB_OUTPUT must NOT contain skip=true (force exits before PR check).
run_test_github_output "skip-output-not-set-on-force" \
"${HUMAN_PR_JSON}" \
"skipped=false" \
0 \
"CODE_FORCE=true"

# No GH_TOKEN → GITHUB_OUTPUT must contain skip=false (proceeds without PR check).
run_test_github_output "skip-output-false-on-no-token" \
"" \
"skipped=false" \
0 \
"GH_TOKEN="

# --- Summary ---

echo ""
Expand Down
4 changes: 4 additions & 0 deletions internal/scaffold/fullsend-repo/scripts/pre-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ echo " GITHUB_ISSUE_URL=${GITHUB_ISSUE_URL}"
# Skip if GH_TOKEN is not available (best-effort check).
if [[ -z "${GH_TOKEN:-}" ]]; then
Comment thread
jhutar marked this conversation as resolved.
Resolved
Comment thread
jhutar marked this conversation as resolved.
Resolved
echo "GH_TOKEN not set — skipping existing-PR check"
echo "skipped=false" >> "${GITHUB_OUTPUT}"
exit 0
fi

# Allow override when --force is in the trigger comment or CODE_FORCE is set.
echo "Evaluating force override: CODE_FORCE='${CODE_FORCE:-}' COMMENT_BODY='${COMMENT_BODY:-}'"
if [[ "${CODE_FORCE:-}" == "true" ]] || [[ "${COMMENT_BODY:-}" == *--force* ]]; then
echo "Force override — skipping existing-PR check"
echo "skipped=false" >> "${GITHUB_OUTPUT}"
exit 0
fi

Expand Down Expand Up @@ -113,7 +115,9 @@ To override, comment \`/fs-code --force\` on this issue.
--repo "${REPO_FULL_NAME}" --body-file - 2>/dev/null || true

echo "Skipping code agent — existing PR(s) found for issue #${ISSUE_NUMBER}"
echo "skipped=true" >> "${GITHUB_OUTPUT}"
exit 0
fi

echo "No existing human PRs found — proceeding with code agent"
echo "skipped=false" >> "${GITHUB_OUTPUT}"
Loading