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
4 changes: 2 additions & 2 deletions .github/scripts/github-api-with-retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function logWithCore(core, level, message) {
core[level](message);
return;
}
const logFn = level === 'error' ? console.error : level === 'warning' ? console.warn : console.log;
const logFn = level === 'error' ? console.error : level === 'warning' ? console.warn : console.error;
logFn(message);
}

Expand Down Expand Up @@ -428,7 +428,7 @@ async function withRetry(fn, options = {}) {
? 'rate limit'
: 'transient error';

console.log(
console.error(
`${retryReason} (attempt ${attempt + 1}/${maxRetries + 1}). ` +
`Retrying in ${Math.round(actualDelay / 1000)}s...`
);
Expand Down
68 changes: 53 additions & 15 deletions .github/workflows/agents-issue-format-guard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ jobs:
with:
persist-credentials: false

- name: Setup API client
uses: ./.github/actions/setup-api-client
with:
# This guard only reads issue comments with the workflow token. Do not
# expose the repository-wide secret bundle to the composite action.
github_token: ${{ github.token }}

- name: Resolve issue
id: issue
env:
Expand Down Expand Up @@ -132,35 +139,66 @@ jobs:
fi
fingerprint="$(sha256sum body.md | cut -c1-12)"
marker="<!-- format-guard:$fingerprint -->"
# Only trust exact HTML markers authored by automation bots (not user text).
trusted_marker=false
if gh issue view "$NUMBER" --repo "$GITHUB_REPOSITORY" --json comments \
--jq '.comments[] | select((.author.login // "") | test("\\[bot\\]$|github-actions"; "i")) | .body' \
| grep -qF "$marker"; then
trusted_marker=true
fi
# Only trust exact HTML markers authored by github-actions[bot]
# (immutable account id 41898282 when the REST payload includes user.id).
trusted_marker="$(FORMAT_GUARD_MARKER="$marker" node - <<'NODE'
(async () => {
const { Octokit } = require('@octokit/rest');
const { createTokenAwareRetry } = require('./.github/scripts/github-api-with-retry.js');
const github = new Octokit({ auth: process.env.GH_TOKEN });
const core = { info: () => {}, warning: console.warn, debug: () => {} };
const { paginateWithRetry } = await createTokenAwareRetry({
github,
core,
env: process.env,
task: 'issue-format-guard',
capabilities: ['issues:read'],
});
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
const comments = await paginateWithRetry(
github.rest.issues.listComments,
{ owner, repo, issue_number: Number(process.env.NUMBER), per_page: 100 }
);
const trusted = comments.some((comment) =>
comment.user?.login === 'github-actions[bot]'
&& (comment.user?.id == null || comment.user.id === 41898282)
&& (comment.body || '').includes(process.env.FORMAT_GUARD_MARKER)
);
process.stdout.write(trusted ? 'true' : 'false');
})().catch((error) => {
console.error(error);
process.exit(1);
});
NODE
)"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
has_format_label=false
if jq -e '[.labels[].name] | any(. == "agents:format")' live.json >/dev/null; then
has_format_label=true
fi
# Dedup completed handoffs, but retry when a prior dispatch/optimizer run
# left agents:format set (marker without a finished optimizer pass).
# The marker is written only after dispatch succeeds. Keep the label as
# the in-flight lease: a repeated guard run must not enqueue another
# optimizer while that lease is still present. If the label was removed,
# retry the dispatch because the earlier handoff no longer owns the work.
dispatch=true
if [[ "$trusted_marker" == true && "$has_format_label" != true ]]; then
echo "Identical invalid body was already routed; skipping duplicate dispatch."
if [[ "$trusted_marker" == true && "$has_format_label" == true ]]; then
echo "Identical invalid body is already routed and in flight; skipping duplicate dispatch."
dispatch=false
Comment thread
stranske marked this conversation as resolved.
elif [[ "$trusted_marker" == true && "$has_format_label" == true ]]; then
echo "Prior format-guard marker present but agents:format still set — retrying optimizer dispatch."
elif [[ "$trusted_marker" == true ]]; then
echo "Prior format-guard marker present but agents:format is absent — retrying optimizer dispatch."
Comment thread
stranske marked this conversation as resolved.
fi
if jq -e '[.labels[].name] | any(. == "agents:formatted")' live.json >/dev/null; then
gh issue edit "$NUMBER" --repo "$GITHUB_REPOSITORY" --remove-label "agents:formatted" \
|| echo "::warning::could not remove agents:formatted"
fi
gh issue edit "$NUMBER" --repo "$GITHUB_REPOSITORY" --add-label "agents:format" \
|| echo "::warning::could not apply agents:format (label missing in this repo?)"
if [[ "$dispatch" != true ]]; then
exit 0
fi
# Acquiring the label is the handoff lease. Do not dispatch without it:
# otherwise a trusted marker alone could repeat the optimizer dispatch.
if ! gh issue edit "$NUMBER" --repo "$GITHUB_REPOSITORY" --add-label "agents:format"; then
echo "::error::could not acquire agents:format lease; refusing optimizer dispatch"
exit 1
fi
# GITHUB_TOKEN label edits do not start issues:labeled workflows; dispatch is explicit.
# Persist the completion marker only after a successful workflow_dispatch so a
# failed run remains retryable on the next guard pass.
Expand Down
56 changes: 33 additions & 23 deletions .github/workflows/agents-issue-optimizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ concurrency:
group: >-
agents-issue-optimizer-${{
github.repository }}-${{
github.event.issue.number || github.run_id }}
github.event.issue.number || inputs.issue_number || github.run_id }}
cancel-in-progress: false

jobs:
Expand Down Expand Up @@ -106,11 +106,6 @@ jobs:
with:
node-version: 24

- name: Install load balancer dependencies
if: steps.check.outputs.should_run == 'true'
run: |
set -euo pipefail
npm install --no-save --no-package-lock @octokit/rest @octokit/auth-app

- name: Setup API client
if: steps.check.outputs.should_run == 'true'
Expand Down Expand Up @@ -354,41 +349,45 @@ jobs:
});
NODE

python - <<'PY' || true
python - <<'PY'
import json
from scripts.langchain import issue_dedup

with open('/tmp/issue.json', encoding='utf-8') as f:
issue = json.load(f)
with open('/tmp/open_issues.json', encoding='utf-8') as f:
open_issues = json.load(f)
with open('/tmp/dedup_comments.json', encoding='utf-8') as f:
with open('/tmp/dedup_comments.json', encoding='utf-8') as f:
comments = json.load(f)

marker = issue_dedup.SIMILAR_ISSUES_MARKER
for comment in comments or []:
marker = issue_dedup.SIMILAR_ISSUES_MARKER
for comment in comments or []:
body = (comment or {}).get('body') or ''
if marker in body:
raise SystemExit(0)
raise SystemExit(0)

# Conservative defaults; can be tuned later.
threshold = 0.82
store = issue_dedup.build_issue_vector_store(open_issues)
if store is None:
store = issue_dedup.build_issue_vector_store(open_issues)
if store is None:
raise SystemExit(0)

title = (issue.get('title') or '').strip()
body = (issue.get('body') or '').strip()
query = f"{title}\n{body}".strip() if body else title
if not query:
title = (issue.get('title') or '').strip()
body = (issue.get('body') or '').strip()
query = f"{title}\n{body}".strip() if body else title
if not query:
raise SystemExit(0)

matches = issue_dedup.find_similar_issues(store, query, threshold=threshold, k=5)
comment = issue_dedup.format_similar_issues_comment(matches, max_items=5)
if comment:
matches = issue_dedup.find_similar_issues(store, query, threshold=threshold, k=5)
comment = issue_dedup.format_similar_issues_comment(matches, max_items=5)
if comment:
with open('/tmp/dedup_comment.md', 'w', encoding='utf-8') as out:
out.write(comment)
out.write(comment)
PY
dedup_rc=$?
if [[ $dedup_rc -ne 0 ]]; then
echo "::warning::issue dedup python exited with $dedup_rc; continuing without similar-issues comment"
fi

if [[ -f /tmp/dedup_comment.md ]]; then
node - <<'NODE'
Expand Down Expand Up @@ -510,7 +509,7 @@ jobs:

# Do not publish agents:formatted for apply-phase output that fails
# the same fleet contract enforced by the issue-event guard.
python .github/scripts/issue_format.py /tmp/updated_body.md
python3 .github/scripts/issue_format.py /tmp/updated_body.md

# Update issue body
node - <<'NODE'
Expand Down Expand Up @@ -580,7 +579,7 @@ jobs:

# Do not advertise a formatted issue until it satisfies the same
# fleet contract enforced by the issue-event guard.
python .github/scripts/issue_format.py /tmp/formatted_body.md
python3 .github/scripts/issue_format.py /tmp/formatted_body.md

# Update issue body with formatted version
node - <<'NODE'
Expand Down Expand Up @@ -718,3 +717,14 @@ jobs:
NODE
echo "Labels updated: removed format, added formatted"
fi

- name: Release failed format lease
if: (failure() || cancelled()) && steps.check.outputs.should_run == 'true' && steps.check.outputs.phase == 'format'
env:
GH_TOKEN: ${{ github.token }}
ISSUE_NUMBER: ${{ steps.check.outputs.issue_number }}
run: |
set -euo pipefail
# A guard retry may proceed only after the failed format run releases its lease.
gh issue edit "$ISSUE_NUMBER" --remove-label "agents:format" \
|| echo "::warning::could not release failed agents:format lease"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
6 changes: 3 additions & 3 deletions config/template-drift-allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ reason = Intentional divergence re-baselined 2026-06-30: root and consumer guard
[pair.11]
main = .github/workflows/agents-issue-optimizer.yml
template = templates/consumer-repo/.github/workflows/agents-issue-optimizer.yml
main_sha256 = d99f29c3433fa3430c68338cffe0c9ad7c6e22801303fea1916ddeab4040dc90
template_sha256 = a4ab5b6f0039c1c20d3fb3133fed3a38902f7943cd46c951cf7695a0d3e41858
reason = Intentional divergence re-baselined 2026-08-08: root and consumer issue-optimizer workflows keep different auth plumbing/action pin surfaces. Both validate format output before adding agents:formatted; the consumer explicitly sparse-checks out .github/scripts/issue_format.py plus config/scripts/langchain/tools from Workflows, while root runs those files in-tree. Do not align wholesale because that would strip consumer action pins/token setup.
main_sha256 = ccf1cd3ccdba84c54743d2950367308df15c5928b95c1e7400a5d2858b7c1fa5
template_sha256 = a4d50beb165724ff9266a18390d738105538fe0c13a5eb3a620fb8c9297fe80f
reason = Intentional divergence re-baselined 2026-08-08b: root remains in-tree (scripts/langchain + .github/scripts/issue_format.py); consumer vendors those via Workflows sparse-checkout under workflows-scripts/. Shared behavioral contract this round: concurrency includes inputs.issue_number for workflow_dispatch dedupe, cancel-safe (failure()||cancelled()) agents:format lease release, and fixed issue_dedup Python indentation with visible non-zero exit warnings. Do not align wholesale that would strip consumer action pins/token setup.

[pair.12]
main = .github/workflows/agents-keepalive-loop-reporter.yml
Expand Down
4 changes: 2 additions & 2 deletions langsmith-fleet-worker-attempt.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"agent": "codex",
"cli_version": "0.144.1",
"emitted_at": "2026-08-08T05:39:15.569084Z",
"emitted_at": "2026-08-08T11:32:33.483036Z",
"execution_profile": "codex-default",
"fallback_models": [
"gpt-5.5"
],
"operation_role": "worker",
"pr_number": "2982",
"pr_number": "2981",
"requested_model": "gpt-5.6-terra",
"runner": "reusable-codex-run",
"schema": "langsmith-fleet/v1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function logWithCore(core, level, message) {
core[level](message);
return;
}
const logFn = level === 'error' ? console.error : level === 'warning' ? console.warn : console.log;
const logFn = level === 'error' ? console.error : level === 'warning' ? console.warn : console.error;
logFn(message);
}

Expand Down Expand Up @@ -428,7 +428,7 @@ async function withRetry(fn, options = {}) {
? 'rate limit'
: 'transient error';

console.log(
console.error(
`${retryReason} (attempt ${attempt + 1}/${maxRetries + 1}). ` +
`Retrying in ${Math.round(actualDelay / 1000)}s...`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ jobs:
with:
persist-credentials: false

- name: Setup API client
uses: ./.github/actions/setup-api-client
with:
# This guard only reads issue comments with the workflow token. Do not
# expose the repository-wide secret bundle to the composite action.
github_token: ${{ github.token }}

- name: Resolve issue
id: issue
env:
Expand Down Expand Up @@ -132,35 +139,66 @@ jobs:
fi
fingerprint="$(sha256sum body.md | cut -c1-12)"
marker="<!-- format-guard:$fingerprint -->"
# Only trust exact HTML markers authored by automation bots (not user text).
trusted_marker=false
if gh issue view "$NUMBER" --repo "$GITHUB_REPOSITORY" --json comments \
--jq '.comments[] | select((.author.login // "") | test("\\[bot\\]$|github-actions"; "i")) | .body' \
| grep -qF "$marker"; then
trusted_marker=true
fi
# Only trust exact HTML markers authored by github-actions[bot]
# (immutable account id 41898282 when the REST payload includes user.id).
trusted_marker="$(FORMAT_GUARD_MARKER="$marker" node - <<'NODE'
(async () => {
const { Octokit } = require('@octokit/rest');
const { createTokenAwareRetry } = require('./.github/scripts/github-api-with-retry.js');
const github = new Octokit({ auth: process.env.GH_TOKEN });
const core = { info: () => {}, warning: console.warn, debug: () => {} };
const { paginateWithRetry } = await createTokenAwareRetry({
github,
core,
env: process.env,
task: 'issue-format-guard',
capabilities: ['issues:read'],
});
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
const comments = await paginateWithRetry(
github.rest.issues.listComments,
{ owner, repo, issue_number: Number(process.env.NUMBER), per_page: 100 }
);
const trusted = comments.some((comment) =>
comment.user?.login === 'github-actions[bot]'
&& (comment.user?.id == null || comment.user.id === 41898282)
&& (comment.body || '').includes(process.env.FORMAT_GUARD_MARKER)
);
process.stdout.write(trusted ? 'true' : 'false');
})().catch((error) => {
console.error(error);
process.exit(1);
});
NODE
)"
has_format_label=false
if jq -e '[.labels[].name] | any(. == "agents:format")' live.json >/dev/null; then
has_format_label=true
fi
# Dedup completed handoffs, but retry when a prior dispatch/optimizer run
# left agents:format set (marker without a finished optimizer pass).
# The marker is written only after dispatch succeeds. Keep the label as
# the in-flight lease: a repeated guard run must not enqueue another
# optimizer while that lease is still present. If the label was removed,
# retry the dispatch because the earlier handoff no longer owns the work.
dispatch=true
if [[ "$trusted_marker" == true && "$has_format_label" != true ]]; then
echo "Identical invalid body was already routed; skipping duplicate dispatch."
if [[ "$trusted_marker" == true && "$has_format_label" == true ]]; then
echo "Identical invalid body is already routed and in flight; skipping duplicate dispatch."
dispatch=false
elif [[ "$trusted_marker" == true && "$has_format_label" == true ]]; then
echo "Prior format-guard marker present but agents:format still set — retrying optimizer dispatch."
elif [[ "$trusted_marker" == true ]]; then
echo "Prior format-guard marker present but agents:format is absent — retrying optimizer dispatch."
fi
if jq -e '[.labels[].name] | any(. == "agents:formatted")' live.json >/dev/null; then
gh issue edit "$NUMBER" --repo "$GITHUB_REPOSITORY" --remove-label "agents:formatted" \
|| echo "::warning::could not remove agents:formatted"
fi
gh issue edit "$NUMBER" --repo "$GITHUB_REPOSITORY" --add-label "agents:format" \
|| echo "::warning::could not apply agents:format (label missing in this repo?)"
if [[ "$dispatch" != true ]]; then
exit 0
fi
# Acquiring the label is the handoff lease. Do not dispatch without it:
# otherwise a trusted marker alone could repeat the optimizer dispatch.
if ! gh issue edit "$NUMBER" --repo "$GITHUB_REPOSITORY" --add-label "agents:format"; then
echo "::error::could not acquire agents:format lease; refusing optimizer dispatch"
exit 1
fi
# GITHUB_TOKEN label edits do not start issues:labeled workflows; dispatch is explicit.
# Persist the completion marker only after a successful workflow_dispatch so a
# failed run remains retryable on the next guard pass.
Expand Down
Loading
Loading