Skip to content
Merged
67 changes: 52 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,12 @@
with:
persist-credentials: false

- name: Setup API client
uses: ./.github/actions/setup-api-client
with:
secrets: ${{ toJSON(secrets) }}
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
github_token: ${{ github.token }}

- name: Resolve issue
id: issue
env:
Expand Down Expand Up @@ -132,35 +138,66 @@
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.
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.
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.
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
15 changes: 13 additions & 2 deletions .github/workflows/agents-issue-optimizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,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 +580,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 +718,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.
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 = 3ad86a30a866167dc78ec21150fc2dba475dc70b2504cfe3373906ed95a2502d
template_sha256 = 3f76718542ab27978fc819118a9e671a9f34439e388fa0ea6f0359937e7bbb57
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 with python3, require the agents:format lease before dispatch, and release that lease on a failed format run; 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.

[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-08T10:44:25.864057Z",
"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 @@ -39,6 +39,12 @@
with:
persist-credentials: false

- name: Setup API client
uses: ./.github/actions/setup-api-client
with:
secrets: ${{ toJSON(secrets) }}
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
github_token: ${{ github.token }}

- name: Resolve issue
id: issue
env:
Expand Down Expand Up @@ -132,35 +138,66 @@
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