Skip to content

Commit 71767f2

Browse files
EvangelinkCopilot
andcommitted
Fix agentic workflow input and issue-type contracts
Use validated runtime manifests for build analysis and queue native Bug typing through scoped safe outputs. Preserve the aligned runtime and document validation limits. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 29f8046 commit 71767f2

12 files changed

Lines changed: 530 additions & 75 deletions

‎.github/agents/build-failure-analyst.agent.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ You do not write to the repository directly. Every change you make is staged as
1919

2020
## Inputs the Calling Workflow Provides
2121

22-
The caller (typically `build-failure-analysis.md` or `build-failure-analysis-command.md`) locates the failed **Azure DevOps** `microsoft.testfx` build, downloads the `.binlog` each build leg produced (it does **not** rebuild), uploads them as an artifact, and the gh-aw MCP gateway mounts them read-only into the `binlog-mcp` container under the directory `/data/binlogs` (one `*.binlog` per leg, enumerated in `GH_AW_BINLOG_LIST`). The caller also sets the environment variables below. You must read all of them before doing anything else.
22+
The caller (typically `build-failure-analysis.md` or `build-failure-analysis-command.md`) locates the failed **Azure DevOps** `microsoft.testfx` build, downloads the `.binlog` each build leg produced (it does **not** rebuild), uploads them as an artifact, and the gh-aw MCP gateway mounts them read-only into the `binlog-mcp` container under the directory `/data/binlogs` (one `*.binlog` per leg, enumerated in `GH_AW_BINLOG_LIST`). These workflows supply the inputs below in `/tmp/gh-aw/build-failure-analysis/analysis-inputs.json`; read it with a standalone `cat` command before doing anything else. Use its values rather than probing the process environment. Other callers may supply equivalent environment values.
23+
24+
The `/data/binlogs` mount is not a local agent directory. Query its paths only
25+
through `binlog-mcp`; failed local directory probes do not establish missing logs.
2326

2427
| Variable | Meaning |
2528
| ------------------------- | ------- |
26-
| `GH_AW_BINLOG_LIST` | Newline-separated list of in-container binlog paths — one per failed-build leg. The fetch step stages them under `/data/binlogs` with a unique numeric prefix per artifact/file (e.g. `/data/binlogs/1_0_Logs_Build_Linux_Release.binlog`), so match on the `.binlog` suffix rather than an exact leg name. Pass each as `binlog_file` on the `binlog_*` MCP tools. |
27-
| `GH_AW_BINLOG_DIR` | Directory the binlogs are mounted under (`/data/binlogs`); enumerate `*.binlog` here if `GH_AW_BINLOG_LIST` is unavailable. |
29+
| `GH_AW_BINLOG_LIST` | Array of in-container binlog paths in the workflow manifest (newline-separated for environment-only callers) — one per failed-build leg. The fetch step stages them under `/data/binlogs` with a unique numeric prefix per artifact/file (e.g. `/data/binlogs/1_0_Logs_Build_Linux_Release.binlog`). Pass every path verbatim as `binlog_file` on the `binlog_*` MCP tools. |
30+
| `GH_AW_BINLOG_DIR` | Directory the binlogs are mounted under inside `binlog-mcp` (`/data/binlogs`), not inside the agent sandbox. A missing required inventory is incomplete analysis, not a reason to probe this directory locally. |
2831
| `GH_AW_BINLOG_PATH` | The first entry of `GH_AW_BINLOG_LIST` — a single-path convenience for prompts/tools that expect one. Empty when no binlog was retrieved. |
2932
| `GH_AW_BINLOG_HOST_PATH` | URL of the originating Azure DevOps build (`https://dev.azure.com/dnceng-public/public/_build/results?buildId=…`). Use only for permalinks / human-facing references — read the binlog data via MCP. |
3033
| `GH_AW_BUILD_OUTCOME` | Always `failure` when this agent runs — the workflow only activates after the Azure DevOps `microsoft.testfx` build failed. |

‎.github/agents/pipeline-test-triage-analyst.agent.md‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,18 @@ Every pull-request comment must:
112112

113113
Every created issue must:
114114

115-
- provide a unique `temporary_id` and
116-
`fields: [{"name": "Type", "value": "Bug"}]` in the `create_issue` call so
117-
the native GitHub issue type is assigned atomically with issue creation;
115+
- provide a unique `temporary_id` in the `create_issue` call, then queue
116+
`set_issue_type` with `issue_type: "Bug"` and `issue_number` set to that
117+
same temporary ID, including its `#aw_` prefix. For example, creation with
118+
`temporary_id: "aw_triage123"` is followed by
119+
`set_issue_type({"issue_number": "#aw_triage123", "issue_type": "Bug"})`;
120+
- do not send `fields: [{"name": "Type", "value": "Bug"}]`: `fields` sets
121+
custom issue fields, not the native GitHub Issue Type. Creation and type
122+
assignment are separate queued operations; the publisher resolves the
123+
temporary ID only after successful creation. Do not guess or poll for a
124+
newly created issue number during this agent run. If the creation tool
125+
reports a duplicate, do not queue type assignment for it. Queue at most one
126+
type request; the publisher owns any deferred retry;
118127
- add exactly one relevant allowed label when applicable:
119128
`type/regression`, `type/flaky-test`, `area/dump`, or `area/performance`;
120129
- explain category and confidence, why the signal is actionable, first/last

‎.github/scripts/test_agentic_workflow_warning_contracts.py‎

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,140 @@ def commit(self, message: str) -> str:
257257
return self.git("rev-parse", "HEAD")
258258

259259

260+
class BuildAnalysisInputTests(unittest.TestCase):
261+
workflows = ("build-failure-analysis", "build-failure-analysis-command")
262+
263+
def export(self, workflow: str, *, files: tuple[str, ...] = ("1_Linux.binlog",),
264+
shadow_source: str | None = None,
265+
**overrides: str) -> tuple[subprocess.CompletedProcess, pathlib.Path, dict]:
266+
temporary = tempfile.TemporaryDirectory(
267+
prefix="gh-aw-build-inputs-", dir=os.environ.get("WORKFLOW_WARNING_TMP")
268+
)
269+
self.addCleanup(temporary.cleanup)
270+
root = pathlib.Path(temporary.name)
271+
binlogs, shared, tools = root / "binlogs", root / "shared", root / "tools"
272+
for directory in (binlogs, shared, tools, root / "home"):
273+
directory.mkdir()
274+
for name in files:
275+
(binlogs / name).write_bytes(b"fixture inventory; not parsed as a binary log")
276+
wrapper = tools / "python3"
277+
wrapper.write_text('#!/bin/bash\nexec "$FIXTURE_PYTHON" "$@"\n', encoding="utf-8")
278+
wrapper.chmod(0o755)
279+
env = {key: value for key, value in os.environ.items()
280+
if key.upper() in ("PATH", "SYSTEMROOT", "WINDIR", "TEMP", "TMP")}
281+
values = {
282+
"GH_AW_BINLOG_FOUND_VALUE": "true", "GH_AW_PR_NUMBER_VALUE": "73",
283+
"GH_AW_PR_HEAD_SHA_VALUE": "a" * 40, "GH_AW_PR_MERGE_SHA_VALUE": "b" * 40,
284+
"GH_AW_ADO_BUILD_URL_VALUE": "https://dev.azure.com/fixture/public/_build/results?buildId=420",
285+
"GH_AW_MISSING_LEGS_VALUE": 'Windows "Release"\n(unknown timeline)',
286+
"GH_AW_GITHUB_WORKSPACE": str(root / "workspace"),
287+
}
288+
values.update(overrides)
289+
env.update(values)
290+
if shadow_source is not None:
291+
location = root if shadow_source == "checkout" else root / "pythonpath"
292+
location.mkdir(exist_ok=True)
293+
(location / "json.py").write_text(
294+
'open("shadow-imported", "w").write("untrusted module executed")\n'
295+
'raise RuntimeError("PR-controlled json module imported")\n',
296+
encoding="utf-8",
297+
)
298+
if shadow_source == "pythonpath":
299+
env["PYTHONPATH"] = str(location)
300+
env.update({
301+
"HOME": str(root / "home"), "USERPROFILE": str(root / "home"),
302+
"GITHUB_REPOSITORY": REPOSITORY, "GITHUB_ENV": str(root / "context.env"),
303+
"FIXTURE_PYTHON": str(sys.executable), "FIXTURE_BIN": tools.as_posix(),
304+
"PYTHONDONTWRITEBYTECODE": "1",
305+
})
306+
source, _ = authored(workflow + ".md")
307+
script = next(step["run"] for step in source["steps"]
308+
if step.get("name") == "Export agent context")
309+
script = script.replace("/tmp/binlogs", binlogs.as_posix()).replace("/tmp/gh-aw", shared.as_posix())
310+
prelude = 'export PATH="$(cd "$FIXTURE_BIN" && pwd):$PATH"\n'
311+
result = subprocess.run(
312+
[str(BASH), "--noprofile", "--norc", "-s"], input=prelude + script,
313+
cwd=root, env=env, text=True, capture_output=True, timeout=TIMEOUT,
314+
)
315+
return result, shared / "build-failure-analysis/analysis-inputs.json", values
316+
317+
def test_build_context_is_readable_without_environment_probes(self) -> None:
318+
for workflow in self.workflows:
319+
with self.subTest(workflow=workflow):
320+
result, path, values = self.export(
321+
workflow, files=("2_Windows Release.binlog", "1_Linux.binlog"))
322+
self.assertEqual(0, result.returncode, result.stdout + result.stderr)
323+
self.assertTrue(path.is_file(), "The analyst needs a sandbox-visible input manifest")
324+
inputs = json.loads(path.read_text(encoding="utf-8"))
325+
self.assertEqual({
326+
"schema_version": 1, "repository": REPOSITORY,
327+
"GH_AW_BUILD_OUTCOME": "failure", "GH_AW_BINLOG_DIR": "/data/binlogs",
328+
"GH_AW_BINLOG_LIST": ["/data/binlogs/1_Linux.binlog", "/data/binlogs/2_Windows Release.binlog"],
329+
"GH_AW_BINLOG_PATH": "/data/binlogs/1_Linux.binlog",
330+
"GH_AW_PR_NUMBER": 73, "GH_AW_PR_HEAD_SHA": "a" * 40,
331+
"GH_AW_PR_MERGE_SHA": "b" * 40,
332+
"GH_AW_BINLOG_HOST_PATH": values["GH_AW_ADO_BUILD_URL_VALUE"],
333+
"GH_AW_WORKSPACE": values["GH_AW_GITHUB_WORKSPACE"],
334+
"GH_AW_MISSING_LEGS": values["GH_AW_MISSING_LEGS_VALUE"],
335+
}, inputs)
336+
prompt = authored("shared/build-failure-analysis-shared.md")[1]
337+
command = re.search(r"```bash\n(cat [^\n]+)\n", prompt)
338+
self.assertIsNotNone(command, "Give the analyst a standalone allowed manifest read")
339+
args = shlex.split(command[1])
340+
self.assertIn(args[0], authored(workflow + ".md")[0]["tools"]["bash"])
341+
self.assertEqual("/tmp/gh-aw/build-failure-analysis/analysis-inputs.json", args[1])
342+
read = subprocess.run(
343+
[str(BASH), "--noprofile", "--norc", "-c", 'cat "$1"', "fixture", path.as_posix()],
344+
env={"PATH": os.environ["PATH"], "SYSTEMROOT": os.environ.get("SYSTEMROOT", "")},
345+
text=True, capture_output=True, timeout=TIMEOUT,
346+
)
347+
self.assertEqual(0, read.returncode, read.stderr)
348+
self.assertEqual(inputs, json.loads(read.stdout))
349+
350+
def test_build_context_rejects_missing_inventory_or_invalid_identity(self) -> None:
351+
cases = (
352+
((), {}),
353+
(("1_Linux.binlog",), {"GH_AW_BINLOG_FOUND_VALUE": "false"}),
354+
(("1_Linux.binlog",), {"GH_AW_PR_NUMBER_VALUE": "false"}),
355+
(("1_Linux.binlog",), {"GH_AW_PR_NUMBER_VALUE": "0"}),
356+
(("1_Linux.binlog",), {"GH_AW_PR_HEAD_SHA_VALUE": "abc"}),
357+
(("1_Linux.binlog",), {"GH_AW_PR_MERGE_SHA_VALUE": "invalid"}),
358+
)
359+
for workflow in self.workflows:
360+
for files, values in cases:
361+
with self.subTest(workflow=workflow, files=files, values=values):
362+
result, path, _ = self.export(workflow, files=files, **values)
363+
self.assertNotEqual(0, result.returncode, "Invalid inputs must stop the agent")
364+
self.assertIn("Missing or invalid required build-analysis inputs.", result.stderr)
365+
self.assertFalse(path.exists())
366+
367+
def test_build_context_ignores_checkout_and_python_path_modules(self) -> None:
368+
for workflow in self.workflows:
369+
for source in ("checkout", "pythonpath"):
370+
with self.subTest(workflow=workflow, source=source):
371+
result, path, _ = self.export(workflow, shadow_source=source)
372+
self.assertFalse((path.parents[2] / "shadow-imported").exists(),
373+
"PR-controlled or PYTHONPATH modules must not execute on the host")
374+
self.assertEqual(0, result.returncode, result.stdout + result.stderr)
375+
self.assertTrue(path.is_file())
376+
self.assertEqual(73, json.loads(path.read_text(encoding="utf-8"))["GH_AW_PR_NUMBER"])
377+
378+
def test_build_context_preserves_optional_merge_and_compiled_delivery(self) -> None:
379+
for workflow in self.workflows:
380+
with self.subTest(workflow=workflow):
381+
result, path, _ = self.export(workflow, GH_AW_PR_MERGE_SHA_VALUE="")
382+
self.assertEqual(0, result.returncode, result.stdout + result.stderr)
383+
self.assertTrue(path.is_file())
384+
self.assertEqual("", json.loads(path.read_text(encoding="utf-8"))["GH_AW_PR_MERGE_SHA"])
385+
source, _ = authored(workflow + ".md")
386+
script = next(step["run"] for step in source["steps"]
387+
if step.get("name") == "Export agent context")
388+
delivered = next(step["run"] for step in compiled(workflow + ".lock.yml")["jobs"]["agent"]["steps"]
389+
if step.get("name") == "Export agent context")
390+
self.assertEqual(script, delivered)
391+
self.assertEqual(["/tmp/binlogs:/data/binlogs:ro"], source["mcp-servers"]["binlog-mcp"]["mounts"])
392+
393+
260394
@unittest.skipUnless(sys.platform.startswith("linux"), "Ubuntu runner setup uses /etc/os-release")
261395
class MarkdownLinterSetupTests(unittest.TestCase):
262396
def scripts(self) -> list[tuple[str, str]]:

0 commit comments

Comments
 (0)