diff --git a/.github/skills/cracktro/refresh/cli-vs-mcp.mjs b/.github/skills/cracktro/refresh/cli-vs-mcp.mjs index 5161811d9da..c80e5e06519 100644 --- a/.github/skills/cracktro/refresh/cli-vs-mcp.mjs +++ b/.github/skills/cracktro/refresh/cli-vs-mcp.mjs @@ -32,7 +32,8 @@ const iso = s => new Date(s).toISOString().replace(".000", ""); const shift = (t, d) => iso(new Date(+new Date(t) + d * 864e5)); const med = a => { if (!a.length) return null; - const s = [...a].sort((x, y) => x - y), m = s.length >> 1; + const s = [...a].sort((x, y) => x - y), + m = s.length >> 1; return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2; }; const pct = (a, b) => (a ? Math.round(((b - a) / a) * 1000) / 10 : null); @@ -43,7 +44,14 @@ const promptOf = r => (r.input_tokens || 0) + (inclusive(r) ? 0 : (r.cache_read_ async function pool(items, n, fn) { const res = []; let i = 0; - await Promise.all(Array.from({ length: n }, async () => { while (i < items.length) { const k = i++; res[k] = await fn(items[k], k); } })); + await Promise.all( + Array.from({ length: n }, async () => { + while (i < items.length) { + const k = i++; + res[k] = await fn(items[k], k); + } + }) + ); return res; } @@ -56,7 +64,11 @@ async function casesFor({ commit, note }) { let f; for (const l of diff.split("\n")) { const m = l.match(/^\+\+\+ b\/\.github\/workflows\/(.+)\.md$/); - if (m) { f = m[1]; files[f] = {}; continue; } + if (m) { + f = m[1]; + files[f] = {}; + continue; + } if (!f || f.includes("/")) continue; const mode = l.match(/^([-+])\s+mode: (gh-proxy|local)\s*$/); if (mode) files[f][mode[1]] = mode[2]; @@ -90,31 +102,61 @@ async function controls() { async function listRuns(c) { try { - const j = await out("gh", ["run", "list", "-R", REPO, "--workflow", `${c.wf}.lock.yml`, "--status", "success", "--created", `${c.before[0].slice(0, 10)}..${c.after[1].slice(0, 10)}`, "--limit", "1000", "--json", "databaseId,createdAt,event"]); + const j = await out("gh", [ + "run", + "list", + "-R", + REPO, + "--workflow", + `${c.wf}.lock.yml`, + "--status", + "success", + "--created", + `${c.before[0].slice(0, 10)}..${c.after[1].slice(0, 10)}`, + "--limit", + "1000", + "--json", + "databaseId,createdAt,event", + ]); const runs = JSON.parse(j); const side = ([a, b]) => runs.filter(r => r.createdAt >= a && r.createdAt < b); // nearest the switch first return { before: side(c.before).sort((x, y) => y.createdAt.localeCompare(x.createdAt)), after: side(c.after).sort((x, y) => x.createdAt.localeCompare(y.createdAt)) }; - } catch { return { before: [], after: [] }; } + } catch { + return { before: [], after: [] }; + } } async function mine(id) { const file = join(CACHE, `${id}.json`); - try { return JSON.parse(await readFile(file, "utf8")); } catch {} + try { + return JSON.parse(await readFile(file, "utf8")); + } catch {} const dir = await mkdtemp(join(tmpdir(), "cvm-")); let row = null; try { await out("gh", ["run", "download", String(id), "-R", REPO, "-n", "usage", "-D", dir]); - const reqs = (await readFile(join(dir, "agent", "token_usage.jsonl"), "utf8")).split("\n").filter(Boolean).map(l => JSON.parse(l)) - .filter(r => r.event === "token_usage" && r.status === 200).sort((a, b) => a.timestamp.localeCompare(b.timestamp)); - if (reqs.length) row = { - model: reqs[0].model, path: reqs[0].path, requests: reqs.length, - first: promptOf(reqs[0]), prompt: reqs.reduce((s, r) => s + promptOf(r), 0), - output: reqs.reduce((s, r) => s + (r.output_tokens || 0), 0), - aic: Math.round(reqs.reduce((s, r) => s + (r.ai_credits_this_response || 0), 0) * 100) / 100, - }; - } catch {} // no usage artifact: agent skipped, or artifact expired - finally { await rm(dir, { recursive: true, force: true }); } + const reqs = (await readFile(join(dir, "agent", "token_usage.jsonl"), "utf8")) + .split("\n") + .filter(Boolean) + .map(l => JSON.parse(l)) + .filter(r => r.event === "token_usage" && r.status === 200) + .sort((a, b) => a.timestamp.localeCompare(b.timestamp)); + if (reqs.length) + row = { + model: reqs[0].model, + path: reqs[0].path, + requests: reqs.length, + first: promptOf(reqs[0]), + prompt: reqs.reduce((s, r) => s + promptOf(r), 0), + output: reqs.reduce((s, r) => s + (r.output_tokens || 0), 0), + aic: Math.round(reqs.reduce((s, r) => s + (r.ai_credits_this_response || 0), 0) * 100) / 100, + }; + } catch { + } finally { + // no usage artifact: agent skipped, or artifact expired + await rm(dir, { recursive: true, force: true }); + } await writeFile(file, JSON.stringify(row)); return row; } @@ -153,7 +195,10 @@ const ctrl = await controls(); const listed = await pool([...flips, ...ctrl], 8, async c => ({ c, runs: await listRuns(c) })); const enough = x => x.runs.before.length >= MIN && x.runs.after.length >= MIN; const flipSel = listed.filter(x => !x.c.control && enough(x)); -const ctrlSel = listed.filter(x => x.c.control && enough(x)).sort((a, b) => b.runs.before.length + b.runs.after.length - (a.runs.before.length + a.runs.after.length)).slice(0, NCTRL); +const ctrlSel = listed + .filter(x => x.c.control && enough(x)) + .sort((a, b) => b.runs.before.length + b.runs.after.length - (a.runs.before.length + a.runs.after.length)) + .slice(0, NCTRL); process.stderr.write(`cases: ${flipSel.length}/${flips.length} switches, ${ctrlSel.length}/${ctrl.length} controls\n`); const results = await pool([...flipSel, ...ctrlSel], 6, async x => { const r = await measure(x.c, x.runs, raw); @@ -162,11 +207,18 @@ const results = await pool([...flipSel, ...ctrlSel], 6, async x => { }); const summarize = rs => { const ok = rs.filter(r => r.ok); - return { workflows: ok.length, runs: ok.reduce((s, r) => s + r.before.n + r.after.n, 0), ...Object.fromEntries(METRICS.map(k => [k, { medianPct: med(ok.map(r => r.delta[k]).filter(v => v != null)), lower: ok.filter(r => r.delta[k] < 0).length }])) }; + return { + workflows: ok.length, + runs: ok.reduce((s, r) => s + r.before.n + r.after.n, 0), + ...Object.fromEntries(METRICS.map(k => [k, { medianPct: med(ok.map(r => r.delta[k]).filter(v => v != null)), lower: ok.filter(r => r.delta[k] < 0).length }])), + }; }; const flipsOut = results.filter(r => !r.control); const report = { - repo: REPO, snapshot: new Date().toISOString().slice(0, 10), cap: CAP, days: DAYS, + repo: REPO, + snapshot: new Date().toISOString().slice(0, 10), + cap: CAP, + days: DAYS, metric: "per run: first = prompt tokens of request 1; prompt = sum of prompt tokens over requests; aic = AI credits. delta = % change of gh-proxy vs GitHub MCP (controls: before vs after, same orientation as the bulk switch)", switches: SWITCHES, summary: { diff --git a/.github/workflows/agent-performance-analyzer.lock.yml b/.github/workflows/agent-performance-analyzer.lock.yml index 9b4336aa7a7..0a69ad14221 100644 --- a/.github/workflows/agent-performance-analyzer.lock.yml +++ b/.github/workflows/agent-performance-analyzer.lock.yml @@ -1,4 +1,4 @@ -# gh-aw-metadata: {"schema_version":"v4","frontmatter_hash":"d19958aaf339fffc2e42cf0c12070344393973ba961d1ab06669e4d40f900520","body_hash":"fe830c8f142b3484cc40a45196bc764053f1e3a160f2386df0e7500beb2973e4","strict":true,"agent_id":"copilot","engine_versions":{"copilot":"1.0.103","copilot-sdk":"1.0.16"}} +# gh-aw-metadata: {"schema_version":"v4","frontmatter_hash":"d19958aaf339fffc2e42cf0c12070344393973ba961d1ab06669e4d40f900520","body_hash":"0185a4f39070a5eb888b689f1ddd12bc282daa2d953980a50dd681277ccbc4f0","strict":true,"agent_id":"copilot","engine_versions":{"copilot":"1.0.103","copilot-sdk":"1.0.16"}} # gh-aw-manifest: {"version":1,"secrets":["GH_AW_GITHUB_MCP_SERVER_TOKEN","GH_AW_GITHUB_TOKEN","GH_AW_OTEL_GRAFANA_AUTHORIZATION","GH_AW_OTEL_GRAFANA_ENDPOINT","GH_AW_OTEL_SENTRY_AUTHORIZATION","GH_AW_OTEL_SENTRY_ENDPOINT","GITHUB_TOKEN"],"actions":[{"repo":"actions/checkout","sha":"3d3c42e5aac5ba805825da76410c181273ba90b1","version":"v7.0.1"},{"repo":"actions/download-artifact","sha":"9000827ccba6bdab643e8b6fd33ac0654aef8333","version":"v8.0.2"},{"repo":"actions/github-script","sha":"3a2844b7e9c422d3c10d287c895573f7108da1b3","version":"v9.0.0"},{"repo":"actions/setup-go","sha":"b7ad1dad31e06c5925ef5d2fc7ad053ef454303e","version":"v7.0.0"},{"repo":"actions/setup-node","sha":"949feb2413d6458794dcd2491c4babbbce0c15c1","version":"v7.1.0"},{"repo":"actions/upload-artifact","sha":"cf430e030ddbb5b0abf93d22962f4752f3646cd9","version":"v7.0.2"},{"repo":"docker/build-push-action","sha":"c3c9e263c25d99ce0380d002d59b67737d91b0dc","version":"v7.4.0"},{"repo":"docker/setup-buildx-action","sha":"f87e5991a6d7451dcb8d9637bfbc97413f497069","version":"v4.4.1"}],"containers":[{"image":"ghcr.io/github/gh-aw-firewall/agent:0.29.14@sha256:7f649a02f2cc235325ab512f546854e0fad32b7abdc6c24c5475ddc0639e0aaa"},{"image":"ghcr.io/github/gh-aw-firewall/api-proxy:0.29.14@sha256:136785634c9207d7328c701d31d53941542ef307840bda6b348274c8842557c0"},{"image":"ghcr.io/github/gh-aw-firewall/router:0.29.14@sha256:b8822defe0cc2abebc619ee1cf49c34c67286fab117512f0d667962572564be0"},{"image":"ghcr.io/github/gh-aw-firewall/squid:0.29.14@sha256:878b9c1aaeca076004bf2157dd2be28586b68b2b3d69c3ff8fd2b5add2a3126c"},{"image":"ghcr.io/github/gh-aw-mcpg:v0.5.10","digest":"sha256:629ddcd68a48ab02e7db8af527d2756c6db563b00c1d31d8aa8fcbac96f01c59","pinned_image":"ghcr.io/github/gh-aw-mcpg:v0.5.10@sha256:629ddcd68a48ab02e7db8af527d2756c6db563b00c1d31d8aa8fcbac96f01c59"},{"image":"ghcr.io/github/gh-aw-node","digest":"sha256:8735428c2d4e602f90781ba0c571c400e8ff93c7ee1508a75d71f87e34e415cc","pinned_image":"ghcr.io/github/gh-aw-node@sha256:8735428c2d4e602f90781ba0c571c400e8ff93c7ee1508a75d71f87e34e415cc"},{"image":"ghcr.io/github/github-mcp-server:v2.1.0","digest":"sha256:f6056fc10bfffcc8c81a6417a2e9ca12808647e8dd6049642a4feaadee0e0f8a","pinned_image":"ghcr.io/github/github-mcp-server:v2.1.0@sha256:f6056fc10bfffcc8c81a6417a2e9ca12808647e8dd6049642a4feaadee0e0f8a"}],"mcp_servers":[{"name":"agenticworkflows","tools":["*"]},{"name":"github","tools":["actions_get","actions_list","get_commit","get_file_contents","get_job_logs","get_latest_release","get_me","get_pull_request","get_pull_request_comments","get_pull_request_diff","get_pull_request_files","get_pull_request_review_comments","get_pull_request_reviews","get_pull_request_status","get_release_by_tag","get_tag","issue_read","list_branches","list_commits","list_issue_types","list_issues","list_pull_requests","list_releases","list_starred_repositories","list_tags","pull_request_read","search_code","search_issues","search_pull_requests","search_repositories"]},{"name":"safeoutputs","tools":["add_comment","create_discussion","create_issue","noop","report_incomplete","report_missing_data","report_missing_tool"]}],"threat_detection":{"mode":"enabled"},"admission":true,"agent_metadata":{"03cbf8931deff21d5116":{"name":"Agentic Workflows"},"4943cffeebb6706aa8bc":{"name":"Squad"},"9ea639558df913e650e4":{"name":"technical-doc-writer"},"a17c6c62ffcd7401f40f":{"name":"adr-writer"},"ad6ff0fe9219fbfa5ccc":{"name":"grumpy-reviewer","tools":["read","search"]},"e0c35a96dedfb29cb9b1":{"name":"w3c-specification-writer"}},"metadata_refs":{"artifact:4943cffeebb6706aa8bc":{"/tools":"/manifest/mcp_servers/0/tools"}}} # This file was automatically generated by gh-aw. DO NOT EDIT. To debug this workflow, load the skill at https://github.com/github/gh-aw/blob/main/debug.md # @@ -185,7 +185,7 @@ jobs: GH_AW_EXPERIMENT_SPEC: '{"prompt_compression":{"variants":["verbose","caveman"],"description":"Test whether extreme prompt compression preserves output quality for meta-orchestrator workflows","hypothesis":"H0: no change in aic. H1: caveman reduces tokens by โ‰ฅ20% while maintaining quality โ‰ฅ90%","metric":"aic","secondary_metrics":["run_duration_seconds","issues_created","discussion_engagement_score","assessment_completeness_score"],"guardrail_metrics":[{"name":"run_success_rate","threshold":"\u003e=0.90"},{"name":"output_quality_score","threshold":"\u003e=0.70"}],"min_samples":14,"weight":[50,50],"issue":33280,"start_date":"2026-05-20","analysis_type":"mann_whitney","tags":["cost_optimization","prompt_engineering","meta_orchestrator"],"notify":{"issue":33280}}}' GH_AW_EXPERIMENT_STATE_FILE: /tmp/gh-aw/experiments/state.jsonl GH_AW_EXPERIMENT_STATE_DIR: /tmp/gh-aw/experiments - GH_AW_HARNESS_VERSION: d19958aaf339fffc2e42cf0c12070344393973ba961d1ab06669e4d40f900520:fe830c8f142b3484cc40a45196bc764053f1e3a160f2386df0e7500beb2973e4 + GH_AW_HARNESS_VERSION: d19958aaf339fffc2e42cf0c12070344393973ba961d1ab06669e4d40f900520:0185a4f39070a5eb888b689f1ddd12bc282daa2d953980a50dd681277ccbc4f0 with: script: | const path = require('path'); @@ -677,7 +677,7 @@ jobs: GH_AW_DEFAULT_ADMISSION_URL: ${{ vars.GH_AW_DEFAULT_ADMISSION_URL }} GH_AW_DEFAULT_ADMISSION_AUDIENCE: ${{ vars.GH_AW_DEFAULT_ADMISSION_AUDIENCE }} GH_AW_DEFAULT_ADMISSION_ON_OUTAGE: ${{ vars.GH_AW_DEFAULT_ADMISSION_ON_OUTAGE }} - GH_AW_ADMISSION_WORKFLOW_HASH: "d19958aaf339fffc2e42cf0c12070344393973ba961d1ab06669e4d40f900520:fe830c8f142b3484cc40a45196bc764053f1e3a160f2386df0e7500beb2973e4" + GH_AW_ADMISSION_WORKFLOW_HASH: "d19958aaf339fffc2e42cf0c12070344393973ba961d1ab06669e4d40f900520:0185a4f39070a5eb888b689f1ddd12bc282daa2d953980a50dd681277ccbc4f0" GH_AW_INFO_WORKFLOW_ID: ${{ job.workflow_ref }} GITHUB_ACTOR: ${{ github.actor }} GITHUB_TRIGGERING_ACTOR: ${{ github.triggering_actor }} @@ -2300,7 +2300,7 @@ jobs: GH_AW_DEFAULT_ADMISSION_URL: ${{ vars.GH_AW_DEFAULT_ADMISSION_URL }} GH_AW_DEFAULT_ADMISSION_AUDIENCE: ${{ vars.GH_AW_DEFAULT_ADMISSION_AUDIENCE }} GH_AW_DEFAULT_ADMISSION_ON_OUTAGE: ${{ vars.GH_AW_DEFAULT_ADMISSION_ON_OUTAGE }} - GH_AW_ADMISSION_WORKFLOW_HASH: "d19958aaf339fffc2e42cf0c12070344393973ba961d1ab06669e4d40f900520:fe830c8f142b3484cc40a45196bc764053f1e3a160f2386df0e7500beb2973e4" + GH_AW_ADMISSION_WORKFLOW_HASH: "d19958aaf339fffc2e42cf0c12070344393973ba961d1ab06669e4d40f900520:0185a4f39070a5eb888b689f1ddd12bc282daa2d953980a50dd681277ccbc4f0" GH_AW_INFO_WORKFLOW_ID: ${{ job.workflow_ref }} GITHUB_ACTOR: ${{ github.actor }} GITHUB_TRIGGERING_ACTOR: ${{ github.triggering_actor }} diff --git a/actions/setup/js/create_pull_request.cjs b/actions/setup/js/create_pull_request.cjs index 635f8b39594..6379dec5884 100644 --- a/actions/setup/js/create_pull_request.cjs +++ b/actions/setup/js/create_pull_request.cjs @@ -53,6 +53,7 @@ const { parseDiffGitHeader: parseDiffGitHeaderPaths, extractDiffGitHeaderEntries const { resolveTransportPaths } = require("./resolve_transport_paths.cjs"); const { recoverObjectPack, isObjectPack, recoveryToken } = require("./object_pack_transport.cjs"); const { withTransportIntegrity } = require("./transport_integrity.cjs"); +const { withExecutionTrace } = require("./safe_output_trace.cjs"); const { resolveDefaultMentions, resolveMentionsForItem } = require("./resolve_mentions_from_payload.cjs"); const { MANAGED_FALLBACK_ISSUE_LABEL, @@ -973,10 +974,30 @@ async function main(config = {}) { * @param {Object} resolvedTemporaryIds - Map of temporary IDs to {repo, number} * @returns {Promise} Result with success/error status and PR details */ - return withTransportIntegrity(async function handleCreatePullRequest(message, resolvedTemporaryIds, transport) { + // Trace map: init invocation; limt count limit; tmpi invalid temporary ID; + // repo invalid repo; head head repo; base base override; pack object pack; + // miss missing patch; alwe allow empty; flim patch file limit; pgen patch generation failed; + // size oversized patch; deny/fall/revw protection deny/fallback/review; noop empty patch; + // stag staged; bund bundle; bfal bundle failure; sign signed merge retry; + // bper unrecovered bundle push; biss bundle issue; ptch patch; pfal patch failure; + // aadd add/add recovered; rply base replay; afal apply failed; + // aden/afbk/arvw post-apply deny/fallback/review; perr patch push failure; + // palt push fallback issue; ecmt empty commit; eper empty push failure; + // prot protected issue; reus reused issue; issu new protected issue; ifal protected issue failure; + // publ PR publication; pber PR publication failure; perm permission issue; + // peif permission issue failure; nofb PR fallback disabled; fbis PR fallback issue; + // fber PR fallback failure; push bundle push attempt; capt PR delivery capture; + // nerr/ignr no-changes error/ignore; done successful return; + // fail unsuccessful/skipped return; thrw thrown error. + return withExecutionTrace( + { success: "done", failure: "fail", error: "thrw" }, + withTransportIntegrity + )(async function handleCreatePullRequest(trace, message, resolvedTemporaryIds, transport) { + trace("init"); const exec = transport.guardExec(globalThis.exec); // Check if we've hit the max limit if (processedCount >= maxCount) { + trace("limt"); core.warning(`Skipping create_pull_request: max count of ${maxCount} reached`); return { success: false, @@ -990,6 +1011,7 @@ async function main(config = {}) { const tempIdResult = getOrGenerateTemporaryId(pullRequestItem, "pull request"); if (tempIdResult.error) { + trace("tmpi"); core.warning(`Skipping create_pull_request: ${tempIdResult.error}`); return { success: false, error: tempIdResult.error }; } @@ -999,6 +1021,7 @@ async function main(config = {}) { const repoResult = resolveAndValidateRepo(pullRequestItem, defaultTargetRepo, allowedRepos, "pull request"); if (!repoResult.success) { + trace("repo"); core.warning(`Skipping pull request: ${repoResult.error}`); return { success: false, error: repoResult.error }; } @@ -1026,6 +1049,7 @@ async function main(config = {}) { let pushRepoParts = repoParts; let pushGithubClient = githubClient; if (configuredHeadRepo) { + trace("head"); const headRepoResult = resolveAndValidateRepo({ repo: configuredHeadRepo }, itemRepo, allowedRepos, "pull request head repository"); if (!headRepoResult.success) { return { success: false, error: headRepoResult.error }; @@ -1059,6 +1083,7 @@ async function main(config = {}) { // Overriding to a different branch requires allowed_base_branches to be configured, unless the // base branch belongs to a pull request created earlier in this same run (a stacked pull request). if (typeof pullRequestItem.base === "string" && pullRequestItem.base.trim() !== "") { + trace("base"); const requestedBaseBranchRaw = pullRequestItem.base.trim(); const requestedBaseBranchForLog = JSON.stringify(requestedBaseBranchRaw); core.info(`Base branch override requested: ${requestedBaseBranchForLog}`); @@ -1225,6 +1250,7 @@ async function main(config = {}) { } if (bundleFilePath && isObjectPack(transport.read(bundleFilePath))) { + trace("pack"); const recovered = await recoverObjectPack(transport, transportPaths, { repo: itemRepo, baseBranch, @@ -1252,14 +1278,17 @@ async function main(config = {}) { } const hasPatchFile = !!(patchFilePath && fs.existsSync(patchFilePath)); if (!hasPatchFile) { + trace("miss"); // If allow-empty is enabled, we can proceed without a patch file if (allowEmpty) { + trace("alwe"); core.info("No patch file found, but allow-empty is enabled - will create empty PR"); } else { const message = "No patch file found - cannot create pull request without changes"; // If in staged mode, still show preview if (isStaged) { + trace("stag"); let summaryContent = "## ๐ŸŽญ Staged Mode: Create Pull Request Preview\n\n"; summaryContent += "The following pull request would be created if staged mode was disabled:\n\n"; summaryContent += `**Status:** โš ๏ธ No patch file found\n\n`; @@ -1273,9 +1302,11 @@ async function main(config = {}) { switch (ifNoChanges) { case "error": + trace("nerr"); return { success: false, error: message }; case "ignore": + trace("ignr"); // Silent success - no console output return { success: false, skipped: true }; @@ -1304,11 +1335,13 @@ async function main(config = {}) { try { enforcePullRequestLimits(patchContent, maxFiles); } catch (error) { + trace("flim"); const errorMessage = getErrorMessage(error); core.warning(`Pull request limit exceeded: ${errorMessage}`); // In staged mode, show a preview instead of performing API side effects if (isStaged) { + trace("stag"); let summaryContent = "## ๐ŸŽญ Staged Mode: Create Pull Request Preview\n\n"; summaryContent += "The following pull request would be created if staged mode was disabled:\n\n"; summaryContent += `**Status:** โš ๏ธ Patch file limit exceeded\n\n`; @@ -1355,6 +1388,7 @@ async function main(config = {}) { // Check for actual error conditions (but allow empty patches as valid noop) if (patchContent.includes("Failed to generate patch")) { + trace("pgen"); // If allow-empty is enabled, ignore patch errors and proceed if (allowEmpty) { core.info("Patch file contains error, but allow-empty is enabled - will create empty PR"); @@ -1365,6 +1399,7 @@ async function main(config = {}) { // If in staged mode, still show preview if (isStaged) { + trace("stag"); let summaryContent = "## ๐ŸŽญ Staged Mode: Create Pull Request Preview\n\n"; summaryContent += "The following pull request would be created if staged mode was disabled:\n\n"; summaryContent += `**Status:** โš ๏ธ Patch file contains error\n\n`; @@ -1378,9 +1413,11 @@ async function main(config = {}) { switch (ifNoChanges) { case "error": + trace("nerr"); return { success: false, error: message }; case "ignore": + trace("ignr"); // Silent success - no console output return { success: false, skipped: true }; @@ -1401,10 +1438,12 @@ async function main(config = {}) { core.info(`Patch size: ${patchSizeKb} KB (maximum allowed: ${maxSizeKb} KB)`); if (patchSizeKb > maxSizeKb) { + trace("size"); const message = `Patch size (${patchSizeKb} KB) exceeds maximum allowed size (${maxSizeKb} KB)`; // If in staged mode, still show preview with error if (isStaged) { + trace("stag"); let summaryContent = "## ๐ŸŽญ Staged Mode: Create Pull Request Preview\n\n"; summaryContent += "The following pull request would be created if staged mode was disabled:\n\n"; summaryContent += `**Status:** โŒ Patch size exceeded\n\n`; @@ -1435,6 +1474,7 @@ async function main(config = {}) { protected_files_policy: config.protected_files_policy ?? "request_review", }); if (protection.action === "deny") { + trace("deny"); const filesStr = protection.files.join(", "); const message = protection.source === "allowlist" @@ -1444,23 +1484,28 @@ async function main(config = {}) { return { success: false, error: message }; } if (protection.action === "fallback") { + trace("fall"); manifestProtectionFallback = protection.files; core.warning(`Protected file protection triggered (fallback-to-issue): ${protection.files.join(", ")}. Will create review issue instead of pull request.`); } if (protection.action === "request_review") { + trace("revw"); manifestProtectionRequestReview = protection.files; core.warning(`Protected file protection triggered (request_review): ${protection.files.join(", ")}. Will create pull request with caution and request-changes review.`); } } if (isEmpty && !isStaged && !allowEmpty) { + trace("noop"); const message = "Patch file is empty - no changes to apply (noop operation)"; switch (ifNoChanges) { case "error": + trace("nerr"); return { success: false, error: "No changes to push - failing as configured by if-no-changes: error" }; case "ignore": + trace("ignr"); // Silent success - no console output return { success: false, skipped: true }; @@ -1481,6 +1526,7 @@ async function main(config = {}) { // If in staged mode, emit step summary instead of creating PR if (isStaged) { + trace("stag"); let summaryContent = "## ๐ŸŽญ Staged Mode: Create Pull Request Preview\n\n"; summaryContent += "The following pull request would be created if staged mode was disabled:\n\n"; @@ -1870,6 +1916,7 @@ async function main(config = {}) { // token on multi-commit branches where workflow files may have been modified). let newCommitCount = 0; if (hasBundleFile) { + trace("bund"); // Bundle transport: fetch commits directly from the bundle file. // This preserves merge commit topology and per-commit metadata (messages, authorship) // unlike git format-patch which flattens history and drops merge resolution content. @@ -1877,6 +1924,7 @@ async function main(config = {}) { try { await applyBundleToBranch(bundleFilePath, branchName, originalAgentBranch, exec, config.allow_full_history_fetch === true); } catch (bundleError) { + trace("bfal"); transport.assertUnchanged(); core.error(`Failed to apply bundle: ${getErrorMessage(bundleError)}`); return { success: false, error: `Failed to apply bundle: ${getErrorMessage(bundleError)}` }; @@ -1889,6 +1937,7 @@ async function main(config = {}) { { const forkCwd = process.cwd(); const runBundlePush = async () => { + trace("push"); transport.assertUnchanged(); branchName = await handleRemoteBranchCollision(branchName, preserveBranchName, { assertTransportUnchanged: transport.assertUnchanged, @@ -1939,6 +1988,7 @@ async function main(config = {}) { const isSignedMergeReplayRefusal = signedCommits && /pushSignedCommits: refusing unsigned push/.test(pushErrorMessage) && /merge commit/i.test(pushErrorMessage); if (isSignedMergeReplayRefusal) { + trace("sign"); core.warning("Signed push rejected merge commit topology from bundle; rewriting branch and retrying signed push"); try { await rewriteBundleBranchAsSingleCommit(baseBranch, exec, bundleFilePath, { @@ -1980,6 +2030,7 @@ async function main(config = {}) { } if (!pushRecovered) { + trace("bper"); core.error(`Git push failed: ${getErrorMessage(pushError)}`); if (manifestProtectionFallback) { @@ -1993,6 +2044,7 @@ async function main(config = {}) { const error = `Failed to push changes: ${getErrorMessage(pushError)}`; return { success: false, error, error_type: "push_failed" }; } else { + trace("biss"); core.warning("Git push operation failed - creating fallback issue instead of pull request"); const runUrl = buildWorkflowRunUrl(context, context.repo); @@ -2087,6 +2139,7 @@ async function main(config = {}) { // Apply the patch using git CLI (skip if empty) if (!isEmpty && patchFilePath) { + trace("ptch"); /** @type {any} */ let postApplyBaseRef = null; const capturePostApplyBaseRef = async () => { @@ -2131,11 +2184,13 @@ async function main(config = {}) { core.info("Patch applied successfully"); patchApplied = true; } catch (patchError) { + trace("pfal"); transport.assertUnchanged(); core.error(`Failed to apply patch with --3way: ${getErrorMessage(patchError)}`); const recoveredFromAddAddConflict = await tryRecoverGitAmAddAddConflict(exec); if (recoveredFromAddAddConflict.recovered) { + trace("aadd"); patchApplied = true; } else { if (recoveredFromAddAddConflict.errorMessage) { @@ -2172,6 +2227,7 @@ async function main(config = {}) { // the patch was generated, making --3way unable to resolve the conflicts automatically. core.info("Attempting fallback: create PR branch at original base commit..."); try { + trace("rply"); // Use the base commit recorded at patch generation time. // The From header in format-patch output contains the agent's new commit SHA // which does not exist in this checkout, so we cannot derive the base from it. @@ -2238,6 +2294,7 @@ async function main(config = {}) { } if (!patchApplied) { + trace("afal"); return { success: false, error: "Failed to apply patch" }; } } @@ -2260,16 +2317,19 @@ async function main(config = {}) { protected_files_policy: config.protected_files_policy ?? "request_review", }); if (postApplyProtection.action === "deny") { + trace("aden"); const filesStr = postApplyProtection.files.join(", "); const msg = `SECURITY: Post-apply file-protection check failed. ` + `The patch applied files that were not detected by the pre-apply parser: ${filesStr}. ` + `This may indicate a patch-parser bypass attempt. Aborting.`; core.error(msg); return { success: false, error: msg }; } if (postApplyProtection.action === "fallback") { + trace("afbk"); manifestProtectionFallback = postApplyProtection.files; core.warning(`Post-apply: Protected file protection triggered (fallback-to-issue): ${postApplyProtection.files.join(", ")}`); } if (postApplyProtection.action === "request_review") { + trace("arvw"); manifestProtectionRequestReview = postApplyProtection.files; core.warning(`Post-apply: Protected file protection triggered (request_review): ${postApplyProtection.files.join(", ")}`); } @@ -2327,6 +2387,7 @@ async function main(config = {}) { core.info("Could not count new commits - extra empty commit will be skipped"); } } catch (pushError) { + trace("perr"); transport.assertUnchanged(); // Push failed - create fallback issue instead of PR (if fallback is enabled) core.error(`Git push failed: ${getErrorMessage(pushError)}`); @@ -2353,6 +2414,7 @@ async function main(config = {}) { const runUrl = buildWorkflowRunUrl(context, context.repo); const runId = context.runId; + trace("palt"); // Read patch content for preview let patchPreview = buildPatchPreviewBlocks(""); if (patchFilePath && fs.existsSync(patchFilePath)) { @@ -2447,6 +2509,7 @@ async function main(config = {}) { // For empty patches with allow-empty, we still need to push the branch if (allowEmpty) { + trace("ecmt"); core.info("allow-empty is enabled - will create branch and push with empty commit"); // Push the branch with an empty commit to allow PR creation try { @@ -2498,6 +2561,7 @@ async function main(config = {}) { core.info("Could not count new commits - extra empty commit will be skipped"); } } catch (pushError) { + trace("eper"); transport.assertUnchanged(); const error = `Failed to push empty branch: ${getErrorMessage(pushError)}`; core.error(error); @@ -2513,9 +2577,11 @@ async function main(config = {}) { switch (ifNoChanges) { case "error": + trace("nerr"); return { success: false, error: "No changes to apply - failing as configured by if-no-changes: error" }; case "ignore": + trace("ignr"); // Silent success - no console output return { success: false, skipped: true }; @@ -2536,6 +2602,7 @@ async function main(config = {}) { // - Push-failed case: push was rejected (e.g. missing `workflows` permission); provides // patch artifact download instructions instead of the compare URL. if (manifestProtectionFallback) { + trace("prot"); const allFound = manifestProtectionFallback; const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; // Use head branch (branchName) for links when push succeeded; fall back to baseBranch @@ -2617,6 +2684,7 @@ async function main(config = {}) { let issue; let issueRepoParts; if (existingIssue) { + trace("reus"); issueRepoParts = existingIssueMatch.issueRepoParts; const existingIssueBody = appendReportExecutionProvenance(protectedFallbackFrame(withProposalMetadata(fallbackBody)), process.env.GH_AW_WORKFLOW_NAME || "Workflow", ""); const existingIssueLabels = Array.isArray(existingIssue.labels) ? existingIssue.labels.map(label => (typeof label === "string" ? label : label?.name)).filter(label => typeof label === "string") : []; @@ -2641,6 +2709,7 @@ async function main(config = {}) { issue = { ...existingIssue, ...response.data }; core.info(`Updated protected-file-protection review issue #${issue.number}: ${issue.html_url}`); } else { + trace("issu"); const result = await createFallbackIssue(githubClient, repoParts, title, protectedFallbackFrame(withProposalMetadata(fallbackBody)), issueLabels, configAssignees, transport.assertUnchanged); issue = result.data; issueRepoParts = result.issueRepoParts; @@ -2687,6 +2756,7 @@ async function main(config = {}) { head_repo: pushRepo, }; } catch (issueError) { + trace("ifal"); const error = `Protected file protection: failed to create review issue. Error: ${getErrorMessage(issueError)}`; core.error(error); return { success: false, error }; @@ -2695,6 +2765,7 @@ async function main(config = {}) { // Try to create the pull request, with fallback to issue creation try { + trace("publ"); if (body.length > MAX_GITHUB_BODY_LENGTH) { throw new Error(`Pull request body exceeds GitHub's maximum length of ${MAX_GITHUB_BODY_LENGTH} characters`); } @@ -2941,6 +3012,7 @@ async function main(config = {}) { } // Return success with PR details + trace("capt"); return await capturePullRequestDelivery( { success: true, @@ -2974,6 +3046,7 @@ async function main(config = {}) { githubClient ); } catch (prError) { + trace("pber"); transport.assertUnchanged(); const errorMessage = getErrorMessage(prError); core.warning(`Failed to create pull request: ${errorMessage}`); @@ -3012,6 +3085,7 @@ async function main(config = {}) { }); try { + trace("perm"); transport.assertUnchanged(); const { data: issue, issueRepoParts } = await createFallbackIssue(githubClient, repoParts, title, fallbackFrame(fallbackBody), mergeFallbackIssueLabels(effectiveFallbackLabels), configAssignees, transport.assertUnchanged); @@ -3030,6 +3104,7 @@ async function main(config = {}) { head_repo: pushRepo, }; } catch (issueError) { + trace("peif"); const error = `Failed to create pull request (permission denied) and failed to create fallback issue. PR error: ${errorMessage}. Issue error: ${getErrorMessage(issueError)}`; core.error(error); return { @@ -3042,6 +3117,7 @@ async function main(config = {}) { if (!fallbackAsIssue) { // Fallback is disabled - return error without creating issue + trace("nofb"); core.error("fallback-as-issue is disabled - not creating fallback issue"); return { success: false, @@ -3050,6 +3126,7 @@ async function main(config = {}) { }; } + trace("fbis"); core.info("Falling back to creating an issue instead"); // Create issue as fallback with enhanced body content @@ -3122,6 +3199,7 @@ async function main(config = {}) { head_repo: pushRepo, }; } catch (issueError) { + trace("fber"); const error = `Failed to create both pull request and fallback issue. PR error: ${errorMessage}. Issue error: ${getErrorMessage(issueError)}`; core.error(error); return { diff --git a/actions/setup/js/create_pull_request.test.cjs b/actions/setup/js/create_pull_request.test.cjs index b965021b8b4..8b81ecb262f 100644 --- a/actions/setup/js/create_pull_request.test.cjs +++ b/actions/setup/js/create_pull_request.test.cjs @@ -149,6 +149,62 @@ describe("create_pull_request - draft policy enforcement", () => { return global.core.warning.mock.calls.filter(args => String(args[0]).includes("Agent requested draft")); } + it.each([ + ["warn", "init_miss_fail"], + ["error", "init_miss_nerr_fail"], + ["ignore", "init_miss_ignr_fail"], + ])("traces the exercised %s policy when the patch is missing", async (ifNoChanges, expectedTrace) => { + const { main } = require("./create_pull_request.cjs"); + const handler = await main({ if_no_changes: ifNoChanges }); + + const result = await handler({ title: "Test PR" }, {}); + + expect(result.success).toBe(false); + expect(result.execution_trace).toBe(expectedTrace); + }); + + it.each(["error", "ignore"])("does not trace staged or %s no-change routes before repository validation", async ifNoChanges => { + const { main } = require("./create_pull_request.cjs"); + const handler = await main({ staged: true, if_no_changes: ifNoChanges }); + + const result = await handler({ title: "Test PR", repo: "other-owner/other-repo" }, {}); + + expect(result.success).toBe(false); + expect(result.execution_trace).toBe("init_repo_fail"); + expect(global.core.summary.addRaw).not.toHaveBeenCalled(); + }); + + it("traces the staged preview rather than the no-change policy for a missing patch", async () => { + const { main } = require("./create_pull_request.cjs"); + const handler = await main({ staged: true, if_no_changes: "error" }); + + const result = await handler({ title: "Test PR" }, {}); + + expect(result.staged).toBe(true); + expect(result.execution_trace).toBe("init_miss_stag_done"); + expect(global.core.summary.addRaw).toHaveBeenCalled(); + }); + + it("retains the empty-push failure route when transport integrity fails", async () => { + const patchPath = canonicalPatchPath("empty-push-integrity"); + fs.writeFileSync(patchPath, ""); + global.exec.exec.mockImplementation(async (cmd, args) => { + if (cmd === "git" && args[0] === "commit") { + fs.writeFileSync(patchPath, "tampered during empty commit"); + throw new Error("empty commit failed"); + } + return 0; + }); + const { main } = require("./create_pull_request.cjs"); + const handler = await main({ allow_empty: true }); + + const result = await handler({ title: "Test PR", branch: "empty-push-integrity" }, {}); + + expect(result.success).toBe(false); + expect(result.error).toContain("SECURITY:"); + expect(result.execution_trace).toBe("init_ecmt_eper_fail"); + }); + it("should propagate the created pull request's durable id and node_id", async () => { global.github.rest.pulls.create = vi.fn().mockResolvedValue({ data: { id: 555111222, node_id: "PR_kwDOtest456", number: 1, html_url: "https://github.com/test", head: { sha: "abc123" } }, @@ -160,6 +216,7 @@ describe("create_pull_request - draft policy enforcement", () => { expect(result.success).toBe(true); expect(result.id).toBe(555111222); + expect(result.execution_trace).toBe("init_miss_alwe_ecmt_publ_capt_done"); expect(result.metadata).toEqual({ node_id: "PR_kwDOtest456" }); }); @@ -610,6 +667,7 @@ index 0000000..abc1234 expect(result.success).toBe(false); expect(result.error).toContain("allow-full-history-fetch: true"); + expect(result.execution_trace).toBe("init_bund_bfal_fail"); expect(result.error).toContain("safe-outputs.create-pull-request"); const directFetch = global.exec.exec.mock.calls.find(([, args]) => Array.isArray(args) && args[0] === "fetch" && args.includes("origin") && args.includes(prereq)); expect(directFetch).toBeUndefined(); @@ -648,6 +706,7 @@ index 0000000..abc1234 expect(result.success).toBe(true); expect(pushSignedSpy).toHaveBeenCalledWith(expect.objectContaining({ signedCommits: false })); + expect(result.execution_trace).toBe("init_bund_push_publ_capt_done"); }); it("should create the PR when the bundle push fails once with a transient workflows-scope timeout and succeeds on retry", async () => { @@ -685,6 +744,7 @@ index 0000000..abc1234 expect(result.success).toBe(true); expect(result.fallback_used).not.toBe(true); + expect(result.execution_trace).toBe("init_bund_push_push_publ_capt_done"); expect(pushSignedSpy).toHaveBeenCalledTimes(2); expect(global.github.rest.pulls.create).toHaveBeenCalled(); expect(global.github.rest.issues.create).not.toHaveBeenCalled(); @@ -796,6 +856,7 @@ index 0000000..abc1234 expect(result.fallback_used).not.toBe(true); expect(pushSignedSpy).toHaveBeenCalledTimes(2); expect(global.exec.exec).toHaveBeenCalledWith("git", ["reset", "--soft", "origin/main"]); + expect(result.execution_trace).toBe("init_bund_push_sign_publ_capt_done"); expect(global.exec.exec).toHaveBeenCalledWith("git", ["commit", "-m", "bundle merge headline"]); expect(global.github.rest.issues.create).not.toHaveBeenCalled(); }); @@ -2207,6 +2268,7 @@ ${diffs} expect(result.success).toBe(false); expect(result.error).toContain("outside the allowed-files list"); + expect(result.execution_trace).toBe("init_deny_fail"); expect(result.error).toContain("src/index.js"); }); @@ -2388,6 +2450,7 @@ ${diffs} const result = await handler({ title: "Test PR", body: "Test body", branch: "feature/protected-identical" }, {}); expect(result.issue_number).toBe(76); + expect(result.execution_trace).toBe("init_fall_ptch_prot_reus_done"); expect(global.github.rest.issues.create).not.toHaveBeenCalled(); expect(global.github.paginate).toHaveBeenCalledWith(global.github.rest.issues.listForRepo, expect.objectContaining({ owner: "test-owner", repo: "test-repo", state: "all", labels: "pull-request-fallback" })); const updateCall = global.github.rest.issues.update.mock.calls[0][0]; @@ -3464,17 +3527,18 @@ describe("create_pull_request - patch apply fallback to original base commit", ( return false; } - it("should create the PR branch from the patch-embedded base commit when available", async () => { + it.each(["warn", "error", "ignore"])("should create the PR branch from the patch-embedded base commit with %s no-change policy", async ifNoChanges => { global.exec = { exec: vi.fn().mockResolvedValue(0), getExecOutput: vi.fn().mockResolvedValue({ exitCode: 0, stdout: "", stderr: "" }), }; const { main } = require("./create_pull_request.cjs"); - const handler = await main({}); + const handler = await main({ if_no_changes: ifNoChanges }); const result = await handler({ title: "Test PR", body: "Test body", branch: "test-branch", base_commit: ` ${MOCK_BASE_COMMIT_SHA} ` }, {}); expect(result.success).toBe(true); + expect(result.execution_trace).toBe("init_ptch_publ_capt_done"); expect(global.exec.exec).toHaveBeenCalledWith("git", ["cat-file", "-e", MOCK_BASE_COMMIT_SHA]); const checkoutWithBaseCommit = global.exec.exec.mock.calls.find(([cmd, args]) => cmd === "git" && Array.isArray(args) && args[0] === "checkout" && args[1] === "-b" && args[3] === MOCK_BASE_COMMIT_SHA); expect(checkoutWithBaseCommit).toBeTruthy(); @@ -3560,6 +3624,7 @@ describe("create_pull_request - patch apply fallback to original base commit", ( expect(result.success).toBe(true); // Should warn that the PR will show merge conflicts + expect(result.execution_trace).toBe("init_ptch_pfal_rply_publ_capt_done"); expect(global.core.warning).toHaveBeenCalledWith(expect.stringContaining("merge conflicts")); }); @@ -5102,6 +5167,7 @@ describe("create_pull_request - E003 file-limit fallback-to-issue", () => { expect(global.github.rest.issues.create).toHaveBeenCalledTimes(1); expect(result.success).toBe(false); expect(result.error).toContain("SECURITY:"); + expect(result.execution_trace).toBe("init_flim_fail"); }); it("should use the actual received file count (not maxFiles*2) as the suggested limit", async () => { @@ -5148,6 +5214,7 @@ describe("create_pull_request - E003 file-limit fallback-to-issue", () => { // Staged mode: no API side effects, just a preview expect(result.success).toBe(true); expect(result.staged).toBe(true); + expect(result.execution_trace).toBe("init_flim_stag_done"); expect(result.fallback_used).toBeUndefined(); expect(global.github.rest.issues.create).not.toHaveBeenCalled(); expect(global.github.rest.pulls.create).not.toHaveBeenCalled(); diff --git a/actions/setup/js/push_to_pull_request_branch.cjs b/actions/setup/js/push_to_pull_request_branch.cjs index 8cbc43f045c..1f1a17e502f 100644 --- a/actions/setup/js/push_to_pull_request_branch.cjs +++ b/actions/setup/js/push_to_pull_request_branch.cjs @@ -11,6 +11,7 @@ const { getStalePullRequestReason, StalePullRequestError } = require("./pr_lifec /** @type {typeof import("fs")} */ const fs = require("fs"); const { withTransportIntegrity } = require("./transport_integrity.cjs"); +const { withExecutionTrace } = require("./safe_output_trace.cjs"); const path = require("path"); const { generateStagedPreview } = require("./staged_preview.cjs"); const { isStagedMode } = require("./safe_output_helpers.cjs"); @@ -569,12 +570,29 @@ async function main(config = {}) { * @param {import('./types/handler-factory').ResolvedTemporaryIds} resolvedTemporaryIds - Map of temporary IDs to resolved IDs * @returns {Promise} */ - return withTransportIntegrity(async function handlePushToPullRequestBranch(message, resolvedTemporaryIds, transport) { + // Trace map: init invocation; limt count limit; repo invalid repo; pack object pack; + // miss missing patch; pgen invalid patch; size oversized patch; deny/fall protection deny/fallback; + // noop empty patch; stag staged; conf configured target; trig triggering target; wild wildcard target; + // clos closed PR; head missing head; auth unauthorized head; fork fork; bden branch protection denied; + // vldt title/label validation; prot protected issue; remt missing remote; ferr fetch failure; + // cerr checkout failure; bund bundle; bfal bundle failure; octo octopus merge; + // bpro/bfbk bundle protection deny/fallback; ptch patch; pfal patch failure; aadd add/add recovery; + // aden/afbk post-apply deny/fallback; blob blob size limit; revw review PR; rfal review failure; + // sqsh signed squash; scop workflow scope; push push; stal stale push; perr push failure; + // fbpr fallback PR; fber fallback failure; same empty-patch skip; nsha missing SHA; + // pshd successful push; nerr/ignr no-changes error/ignore; done successful return; + // fail unsuccessful/skipped return; thrw thrown error. + return withExecutionTrace( + { success: "done", failure: "fail", error: "thrw" }, + withTransportIntegrity + )(async function handlePushToPullRequestBranch(trace, message, resolvedTemporaryIds, transport) { + trace("init"); const exec = transport.guardExec(globalThis.exec); let compilationNotice = getWorkflowCompilationNotice(message, config); if (compilationNotice) core.warning(compilationNotice); // Check max count if (maxCount > 0 && processedCount >= maxCount) { + trace("limt"); core.info(`Skipping message - max count (${maxCount}) reached`); return { success: false, error: `Max count (${maxCount}) reached`, skipped: true }; } @@ -583,6 +601,7 @@ async function main(config = {}) { const repoResult = resolveAndValidateRepo(message, defaultTargetRepo, allowedRepos, "push to PR branch"); if (!repoResult.success) { + trace("repo"); return { success: false, error: repoResult.error }; } const itemRepo = repoResult.repo; @@ -596,6 +615,7 @@ async function main(config = {}) { transport.captureOptional(transportPaths.bundlePath); const objectPackRecovery = {}; if (transportPaths.bundlePath && isObjectPack(transport.read(transportPaths.bundlePath))) { + trace("pack"); const triggeringPR = context.payload?.pull_request; const aw = parseAwContext(context.payload?.inputs?.aw_context); const explicitPull = message.pull_request_number ?? message.pullRequestNumber ?? message.target ?? message.pr_number ?? message.pull_number ?? message.item_number ?? message.pr; @@ -659,12 +679,15 @@ async function main(config = {}) { // the first-pass validation input; bundle transport adds an authoritative // pre-apply git diff check later after the bundle ref has been fetched. if (!hasPatchFile) { + trace("miss"); const msg = "No patch file found - cannot push without changes"; switch (ifNoChanges) { case "error": + trace("nerr"); return { success: false, error: msg }; case "ignore": + trace("ignr"); return { success: false, error: msg, skipped: true }; case "warn": default: @@ -682,6 +705,7 @@ async function main(config = {}) { // Check for actual error conditions if (patchContent.includes("Failed to generate patch")) { + trace("pgen"); const msg = "Patch file contains error message - cannot push without changes"; core.error("Patch file generation failed"); core.error(`Patch file location: ${patchFilePath}`); @@ -731,6 +755,7 @@ async function main(config = {}) { core.info(`${sizeLabel}: ${sizeForCheckKb} KB (maximum allowed: ${maxSizeKb} KB)`); if (sizeForCheckKb > maxSizeKb) { + trace("size"); const msg = `Patch size (${sizeForCheckKb} KB) exceeds maximum allowed size (${maxSizeKb} KB)${mergedBaseBaselineHint}`; return { error: { success: false, error: msg }, fallbackFiles }; } @@ -743,6 +768,7 @@ async function main(config = {}) { if (!isEmptyPatch) { const protection = checkFileProtection(patchContent, config); if (protection.action === "deny") { + trace("deny"); const filesStr = protection.files.join(", "); const msg = protection.source === "allowlist" @@ -752,6 +778,7 @@ async function main(config = {}) { return { error: { success: false, skipped: true, reasonCode: POLICY_FILE_PROTECTION_DENIED_REASON_CODE, error: msg }, fallbackFiles }; } if (protection.action === "fallback") { + trace("fall"); fallbackFiles.push(...protection.files); core.warning(`Protected file protection triggered (fallback-to-issue): ${protection.files.join(", ")}. Will create review issue instead of pushing.`); } @@ -768,12 +795,15 @@ async function main(config = {}) { } if (isEmpty) { + trace("noop"); const msg = "Patch file is empty - no changes to apply (noop operation)"; switch (ifNoChanges) { case "error": + trace("nerr"); return { success: false, error: "No changes to push - failing as configured by if-no-changes: error" }; case "ignore": + trace("ignr"); return { success: false, error: msg, skipped: true }; case "warn": default: @@ -787,6 +817,7 @@ async function main(config = {}) { // If in staged mode, emit ๐ŸŽญ Staged Mode Preview via generateStagedPreview if (isStaged) { + trace("stag"); await generateStagedPreview({ title: "Push to PR Branch", description: "The following changes would be pushed if staged mode was disabled:", @@ -820,6 +851,7 @@ async function main(config = {}) { // Validate target configuration if (target !== "*" && target !== "triggering") { + trace("conf"); const pullNumber = parsePositiveInteger(target); if (pullNumber === null) { return { success: false, error: 'Invalid target configuration: must be "triggering", "*", or a valid pull request number' }; @@ -829,6 +861,7 @@ async function main(config = {}) { // Compute the target branch name based on target configuration let pullNumber; if (target === "triggering") { + trace("trig"); pullNumber = typeof context !== "undefined" ? context.payload?.pull_request?.number || context.payload?.issue?.number : undefined; if (!pullNumber) { const awContext = typeof context !== "undefined" ? parseAwContext(context.payload?.inputs?.aw_context) : null; @@ -849,6 +882,7 @@ async function main(config = {}) { }; } } else if (target === "*") { + trace("wild"); const explicitPull = message.pull_request_number ?? message.pullRequestNumber ?? message.target ?? message.pr_number ?? message.pull_number ?? message.item_number ?? message.pr; if (explicitPull !== undefined && explicitPull !== null && explicitPull !== "") { pullNumber = parsePositiveInteger(explicitPull); @@ -920,6 +954,7 @@ async function main(config = {}) { }); pullRequest = response.data; if (pullRequest.state === "closed") { + trace("clos"); const reason = `Pull request #${pullNumber} is closed; refusing to push to its branch`; core.info(reason); return { skipped: true, reason }; @@ -943,6 +978,7 @@ async function main(config = {}) { // SECURITY: When head.repo is null (likely a deleted fork) we cannot verify which // repository the PR head came from. Always reject to prevent writes to an unverifiable PR. if (pullRequest.head?.repo == null) { + trace("head"); const nullHeadErr = "Cannot push to PR: head repository is null (likely a deleted fork)"; core.error(nullHeadErr); return { success: false, error: nullHeadErr }; @@ -953,6 +989,7 @@ async function main(config = {}) { // names an automation fork, and prevents writes to a fork PR when head-repo is not set. const expectedHeadRepo = configuredHeadRepo || itemRepo; if (actualHeadRepo && actualHeadRepo.toLowerCase() !== expectedHeadRepo.toLowerCase()) { + trace("auth"); const { isFork: actualIsFork } = detectForkPR(pullRequest); if (actualIsFork && !configuredHeadRepo) { core.error(`Cannot push to fork PR branch: head is '${actualHeadRepo}', not '${itemRepo}'`); @@ -972,6 +1009,7 @@ async function main(config = {}) { // forks are eligible for updates. const { isFork, reason: forkReason } = detectForkPR(pullRequest); if (isFork) { + trace("fork"); if (!configuredHeadRepo) { core.error(`Cannot push to fork PR branch: ${forkReason}`); core.error("Fork PRs remain blocked unless safe-outputs.push-to-pull-request-branch.head-repo is configured."); @@ -1032,11 +1070,13 @@ async function main(config = {}) { }, }); if (blockReason) { + trace("bden"); core.error(blockReason); return { success: false, error: blockReason }; } } + trace("vldt"); // Validate title prefix if specified if (titlePrefix && !prTitle.startsWith(titlePrefix)) { return { success: false, error: `Pull request title "${prTitle}" does not start with required prefix "${titlePrefix}"` }; @@ -1058,6 +1098,7 @@ async function main(config = {}) { } const createProtectedFilesFallbackIssue = async files => { + trace("prot"); transport.assertUnchanged(); const runUrl = buildWorkflowRunUrl(context, context.repo); const runId = context.runId; @@ -1155,6 +1196,7 @@ async function main(config = {}) { ); if (lsRemoteResult.exitCode === 2) { + trace("remt"); const missingBranchError = MISSING_BRANCH_ERROR_TEMPLATE(branchName); if (ignoreMissingBranchFailure) { core.warning(`${missingBranchError} Skipping as configured by ignore-missing-branch-failure.`); @@ -1194,6 +1236,7 @@ async function main(config = {}) { baseGitOpts.cwd ); } catch (fetchError) { + trace("ferr"); const fetchErrorMessage = getErrorMessage(fetchError); if (ignoreMissingBranchFailure && looksLikeMissingRemoteBranchError(fetchErrorMessage)) { const missingBranchError = MISSING_BRANCH_ERROR_TEMPLATE(branchName); @@ -1220,6 +1263,7 @@ async function main(config = {}) { await exec.exec("git", ["checkout", "-B", branchName, branchRemoteRef], baseGitOpts); core.info(`Checked out existing branch from ${pushRepo}: ${branchName}`); } catch (checkoutError) { + trace("cerr"); return { success: false, error: `Failed to checkout branch ${branchName}: ${getErrorMessage(checkoutError)}` }; } @@ -1281,6 +1325,7 @@ async function main(config = {}) { } if (hasBundleFile) { + trace("bund"); // Bundle transport: import commits directly from the local bundle file. // This preserves merge commit topology and per-commit metadata. core.info(`Applying changes from bundle: ${bundleFilePath}`); @@ -1341,6 +1386,7 @@ async function main(config = {}) { if (deferBundleValidation) { const octopus = await exec.getExecOutput("git", ["rev-list", "--min-parents=3", bundleRef, "--not", ...agentHistoryExclusions], bundleGitOpts); if (octopus.stdout.trim()) { + trace("octo"); return { success: false, error: "Cannot validate agent-created octopus merge commits in the bundle. Use two-parent merges instead." }; } // Preserve changes that were later reverted. Ancestor reachability @@ -1352,6 +1398,7 @@ async function main(config = {}) { core.info(`Pre-apply bundle verification: ${bundleFiles.length} file(s) detected from bundle transport`); const bundleProtection = checkFileProtectionPostApply(bundleFiles, config); if (bundleProtection.action === "deny") { + trace("bpro"); const filesStr = bundleProtection.files.join(", "); const msg = bundleProtection.source === "post-apply" @@ -1361,6 +1408,7 @@ async function main(config = {}) { return { success: false, skipped: true, reasonCode: POLICY_FILE_PROTECTION_DENIED_REASON_CODE, error: msg }; } if (bundleProtection.action === "fallback") { + trace("bfbk"); core.warning(`Protected file protection triggered (fallback-to-issue): ${bundleProtection.files.join(", ")}. Will create review issue instead of pushing.`); return await createProtectedFilesFallbackIssue(bundleProtection.files); } @@ -1387,6 +1435,7 @@ async function main(config = {}) { // Non-fatal cleanup } } catch (bundleError) { + trace("bfal"); transport.assertUnchanged(); core.error(`Failed to apply bundle: ${getErrorMessage(bundleError)}`); // Clean up temp ref if it exists @@ -1399,6 +1448,7 @@ async function main(config = {}) { } } else { // Patch transport (non-default): git am --3way + trace("ptch"); core.info("Applying patch..."); try { if (commitTitleSuffix) { @@ -1429,6 +1479,7 @@ async function main(config = {}) { await exec.exec("git", ["am", "--3way", patchFilePath], baseGitOpts); core.info("Patch applied successfully"); } catch (error) { + trace("pfal"); transport.assertUnchanged(); core.warning(`Initial patch apply failed, attempting add/add recovery: ${getErrorMessage(error)}`); let recoveredFromAddAddConflict = false; @@ -1470,6 +1521,7 @@ async function main(config = {}) { } if (recoveredFromAddAddConflict) { + trace("aadd"); // Continue with normal push flow } else { core.error(`Failed to apply patch: ${getErrorMessage(error)}`); @@ -1521,6 +1573,7 @@ async function main(config = {}) { core.info(`Post-apply verification: ${protectionFiles.length} file(s) actually modified`); const postApplyProtection = checkFileProtectionPostApply(protectionFiles, config); if (postApplyProtection.action === "deny") { + trace("aden"); const filesStr = postApplyProtection.files.join(", "); const msg = `SECURITY: Post-apply file-protection check failed. ` + `The patch applied files that were not detected by the pre-apply parser: ${filesStr}. ` + `This may indicate a patch-parser bypass attempt. Aborting push.`; core.error(msg); @@ -1529,6 +1582,7 @@ async function main(config = {}) { return { success: false, error: msg }; } if (postApplyProtection.action === "fallback") { + trace("afbk"); core.warning(`Post-apply: Protected file protection triggered (fallback-to-issue): ${postApplyProtection.files.join(", ")}`); await exec.exec("git", ["reset", "--hard", rangeBaseRef], baseGitOpts); return await createProtectedFilesFallbackIssue(postApplyProtection.files); @@ -1539,6 +1593,7 @@ async function main(config = {}) { const changedBlobSizeKb = Math.ceil(changedBlobSizeBytes / 1024); core.info(`Changed content size: ${changedBlobSizeKb} KB (maximum allowed: ${maxSizeKb} KB)`); if (changedBlobSizeKb > maxSizeKb) { + trace("blob"); const msg = `Changed content size (${changedBlobSizeKb} KB) exceeds maximum allowed size (${maxSizeKb} KB)${mergedBaseBaselineHint}`; await exec.exec("git", ["reset", "--hard", rangeBaseRef], baseGitOpts); return { success: false, error: msg }; @@ -1551,6 +1606,7 @@ async function main(config = {}) { // before they are merged into the target PR. const detectionConclusionEnv = getEffectiveDetectionConclusion(process.env.GH_AW_DETECTION_CONCLUSION, process.env.GH_AW_DETECTION_REASON); if (detectionConclusionEnv === "warning") { + trace("revw"); core.info("โš ๏ธ Threat detection warning: creating review PR instead of direct push"); // Create a review branch name based on the original branch, using @@ -1667,6 +1723,7 @@ async function main(config = {}) { pr_url: reviewPR.html_url, }; } catch (reviewError) { + trace("rfal"); transport.assertUnchanged(); core.error(`Failed to create review PR: ${getErrorMessage(reviewError)}`); return { success: false, error: `Failed to create review PR: ${getErrorMessage(reviewError)}` }; @@ -1682,6 +1739,7 @@ async function main(config = {}) { const { stdout: mergeCountOut } = await exec.getExecOutput("git", ["rev-list", "--merges", "--count", `${squashBase}..HEAD`], baseGitOpts); const mergeCount = parseInt(mergeCountOut.trim(), 10); if (Number.isFinite(mergeCount) && mergeCount > 0) { + trace("sqsh"); core.warning( `push_to_pull_request_branch: detected ${mergeCount} merge commit(s) in range ${squashBase}..HEAD. ` + `Merge commits cannot be pushed as signed commits. Squashing the range into a single regular commit to preserve content. ` + @@ -1707,6 +1765,7 @@ async function main(config = {}) { const agentWorkflowFiles = agentChangedFiles.filter(isWorkflowYamlFile); if (!allowWorkflows && agentWorkflowFiles.length > 0) { + trace("scop"); return buildWorkflowsScopeError("Branch", core); } @@ -1717,6 +1776,7 @@ async function main(config = {}) { // scope may be required." โ€” a transient server-side condition, not a real scope problem. // Retry with exponential backoff before treating the push as failed. const pushedSha = await withTransientPushRetry(async () => { + trace("push"); const staleReason = await getStalePullRequestReason(githubClient, { repo: repoParts, payload: { pull_request: { number: pullNumber, state: "open" } } }); if (staleReason) throw new StalePullRequestError(staleReason); transport.assertUnchanged(); @@ -1743,10 +1803,13 @@ async function main(config = {}) { pushedCommitSha = pushedSha; core.info(`pushSignedCommits returned pushed SHA: ${pushedSha}`); } + trace("pshd"); core.info(`Changes committed and pushed to branch: ${branchName}`); } catch (pushError) { + trace("perr"); transport.assertUnchanged(); if (pushError instanceof StalePullRequestError) { + trace("stal"); core.info(pushError.message); return { skipped: true, reason: pushError.message }; } @@ -1786,6 +1849,7 @@ async function main(config = {}) { // Fallback path for diverged branches: create a new pull request so changes // can still be reviewed and merged into the original PR branch. if ((isNonFastForward || isWorkflowsScopeTimeout) && fallbackAsPullRequest && allowGitPushFallback) { + trace("fbpr"); const staleReason = await getStalePullRequestReason(githubClient, { repo: repoParts, payload: { pull_request: { number: pullNumber, state: "open" } } }); if (staleReason) { if (isNonFastForward) { @@ -1879,6 +1943,7 @@ async function main(config = {}) { url: fallbackPR.html_url, }; } catch (fallbackError) { + trace("fber"); transport.assertUnchanged(); const fallbackErrorMessage = getErrorMessage(fallbackError); core.error(`Failed to create fallback pull request: ${fallbackErrorMessage}`); @@ -1902,14 +1967,17 @@ async function main(config = {}) { } } } else { + trace("same"); core.info("Skipping patch application (empty patch)"); const msg = "No changes to apply - noop operation completed successfully"; switch (ifNoChanges) { case "error": + trace("nerr"); return { success: false, error: "No changes to apply - failing as configured by if-no-changes: error" }; case "ignore": + trace("ignr"); // Silent success break; case "warn": @@ -1925,6 +1993,7 @@ async function main(config = {}) { if (!commitSha) { const commitShaRes = await exec.getExecOutput("git", ["rev-parse", "HEAD"], baseGitOpts); if (commitShaRes.exitCode !== 0) { + trace("nsha"); return { success: false, error: "Failed to get commit SHA" }; } commitSha = commitShaRes.stdout.trim(); diff --git a/actions/setup/js/push_to_pull_request_branch.test.cjs b/actions/setup/js/push_to_pull_request_branch.test.cjs index 812d7313b3b..bb858e49ff4 100644 --- a/actions/setup/js/push_to_pull_request_branch.test.cjs +++ b/actions/setup/js/push_to_pull_request_branch.test.cjs @@ -532,6 +532,7 @@ index 0000000..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4 const result = await handler({ branch }, {}); expect(result).toEqual({ success: false, error: 'Invalid target configuration: must be "triggering", "*", or a valid pull request number' }); + expect(result.execution_trace).toBe("init_conf_fail"); expect(mockGithub.rest.pulls.get).not.toHaveBeenCalled(); }); @@ -546,6 +547,7 @@ index 0000000..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4 const result = await handler({ branch, [alias]: value }, {}); expect(result).toEqual({ success: false, error: "Pull request number is required but not found" }); + expect(result.execution_trace).toBe("init_wild_fail"); expect(mockGithub.rest.pulls.get).not.toHaveBeenCalled(); } ); @@ -1162,7 +1164,7 @@ index 0000000..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4 // โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ describe("repository state scenarios", () => { - it("should handle successful normal push", async () => { + it.each(["warn", "error", "ignore"])("should handle successful normal push with %s no-change policy", async ifNoChanges => { const patchPath = createPatchFile("should-handle-successful-normal-push"); mockExec.getExecOutput .mockResolvedValueOnce({ exitCode: 0, stdout: "preflight-sha\trefs/heads/feature-branch\n", stderr: "" }) @@ -1171,13 +1173,14 @@ index 0000000..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4 .mockResolvedValue({ exitCode: 0, stdout: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", stderr: "" }); const module = await loadModule(); - const handler = await module.main({}); + const handler = await module.main({ if_no_changes: ifNoChanges }); const result = await handler({ branch: "should-handle-successful-normal-push" }, {}); expect(result.success).toBe(true); expect(result.branch_name).toBe("feature-branch"); expect(result.commit_url).toContain("test-owner/test-repo/commit/"); expect(result.before_state).toEqual({ head_sha: "remote-head-before" }); + expect(result.execution_trace).toBe("init_trig_vldt_ptch_push_pshd_done"); expect(result.after_state).toEqual({ head_sha: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }); }); @@ -1195,6 +1198,7 @@ index 0000000..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4 expect(result.success).toBe(false); expect(result.skipped).not.toBe(true); expect(result.error).toContain("Authentication failed"); + expect(result.execution_trace).toBe("init_trig_vldt_ptch_push_perr_fail"); } finally { pushSignedSpy.mockRestore(); } @@ -1337,6 +1341,7 @@ index 0000000..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4 expect(result.success).toBe(false); expect(result.error).toContain("no longer exists on origin"); + expect(result.execution_trace).toBe("init_trig_vldt_remt_fail"); expect(mockExec.exec).not.toHaveBeenCalled(); }); @@ -1465,6 +1470,26 @@ index 0000000..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4 expect(mockCore.info).toHaveBeenCalledWith("Investigating patch failure..."); }); + it("retains the patch-failure route when transport integrity fails", async () => { + const patchPath = createPatchFile("patch-apply-integrity"); + mockExec.getExecOutput.mockResolvedValue({ exitCode: 0, stdout: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", stderr: "" }); + mockExec.exec.mockImplementation(async (cmd, args) => { + if (cmd === "git" && args[0] === "am" && args.includes("--3way")) { + fs.writeFileSync(patchPath, "tampered during patch application"); + throw new Error("patch application failed"); + } + return 0; + }); + const module = await loadModule(); + const handler = await module.main({}); + + const result = await handler({ branch: "patch-apply-integrity" }, {}); + + expect(result.success).toBe(false); + expect(result.error).toContain("SECURITY:"); + expect(result.execution_trace).toBe("init_trig_vldt_ptch_pfal_fail"); + }); + it("should resolve add/add conflicts by preferring patch version and continuing git am", async () => { const patchPath = createPatchFile("should-resolve-add-add-conflicts-by-preferring-patch-version"); const pushSignedCommitsModule = require("./push_signed_commits.cjs"); @@ -1511,6 +1536,7 @@ index 0000000..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4 expect(result.success).toBe(true); expect(mockCore.info).toHaveBeenCalledWith("Patch applied successfully after resolving add/add conflict(s)"); + expect(result.execution_trace).toBe("init_trig_vldt_ptch_pfal_aadd_push_pshd_done"); expect(mockExec.exec).toHaveBeenCalledWith("git", ["checkout", "--theirs", "--", "docs/findings.md"], expect.any(Object)); expect(mockExec.exec).toHaveBeenCalledWith("git", ["add", "--", "docs/findings.md"], expect.any(Object)); expect(mockExec.exec).toHaveBeenCalledWith("git", ["am", "--continue"], expect.any(Object)); @@ -1526,6 +1552,7 @@ index 0000000..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4 expect(result.fallback_used).toBe(true); expect(result.fallback_type).toBe("pull_request"); expect(result.pull_request_number).toBe(999); + expect(result.execution_trace).toBe("init_trig_vldt_ptch_push_perr_fbpr_done"); expect(mockGithub.rest.pulls.create).toHaveBeenCalled(); }); @@ -1584,6 +1611,7 @@ index 0000000..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4 const result = await handler({ branch }, {}); expect(result).toEqual({ skipped: true, reason: expect.stringContaining("Pull request #123 closed") }); + expect(result.execution_trace).toBe("init_trig_vldt_ptch_push_perr_fbpr_fail"); expect(pushSignedSpy).toHaveBeenCalledTimes(1); expect(mockGithub.rest.pulls.create).not.toHaveBeenCalled(); expect(mockExec.exec.mock.calls.some(([, args]) => args[0] === "checkout" && args[1] === "-b")).toBe(false); @@ -1616,7 +1644,12 @@ index 0000000..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4 const handler = await module.main({}); const result = await handler({ branch }, {}); - expect(result).toEqual({ success: false, error_type: "push_failed", error: expect.stringContaining(pushError) }); + expect(result).toEqual({ + success: false, + error_type: "push_failed", + error: expect.stringContaining(pushError), + }); + expect(result.execution_trace).toBe(pushError.includes("`workflows`") ? "init_trig_vldt_ptch_push_perr_fbpr_fail" : "init_trig_vldt_ptch_push_perr_fail"); expect(pushSignedSpy).toHaveBeenCalledTimes(1); expect(mockGithub.rest.pulls.create).not.toHaveBeenCalled(); expect(mockCore.error).toHaveBeenCalledWith(expect.stringContaining(pushError)); @@ -1810,6 +1843,7 @@ index 0000000..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4 expect(pushSignedSpy).toHaveBeenCalledTimes(6); expect(result).toEqual({ success: false, error_type: "push_failed", error: expect.stringContaining(TRANSIENT_WORKFLOWS_SCOPE_TIMEOUT) }); + expect(result.execution_trace).toBe("init_trig_vldt_ptch_push_push_push_push_push_push_perr_fbpr_fail"); expect(mockGithub.rest.pulls.create).not.toHaveBeenCalled(); expect(mockCore.error).toHaveBeenCalledWith(expect.stringContaining(TRANSIENT_WORKFLOWS_SCOPE_TIMEOUT)); } finally { @@ -2668,6 +2702,7 @@ index 0000000..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4 expect(result.success).toBe(false); expect(result.skipped).toBe(true); expect(mockCore.info).toHaveBeenCalledWith(expect.stringContaining("noop")); + expect(result.execution_trace).toBe("init_noop_fail"); }); it("should error when patch is empty and if-no-changes is error", async () => { @@ -2679,6 +2714,7 @@ index 0000000..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4 expect(result.success).toBe(false); expect(result.error).toContain("No changes"); + expect(result.execution_trace).toBe("init_noop_nerr_fail"); }); it("should silently skip when patch is empty and if-no-changes is ignore", async () => { @@ -2689,16 +2725,32 @@ index 0000000..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4 const result = await handler({ branch: "should-silently-skip-when-patch-is-empty-and-if-no-changes-i" }, {}); expect(result.success).toBe(false); + expect(result.execution_trace).toBe("init_noop_ignr_fail"); expect(result.skipped).toBe(true); }); - it("should handle missing patch file", async () => { + it.each([ + ["warn", "init_miss_fail"], + ["error", "init_miss_nerr_fail"], + ["ignore", "init_miss_ignr_fail"], + ])("should handle missing patch file with %s no-change policy", async (ifNoChanges, expectedTrace) => { const module = await loadModule(); - const handler = await module.main({}); - const result = await handler({ branch: "should-handle-missing-patch-file" }, {}); + const handler = await module.main({ if_no_changes: ifNoChanges }); + const result = await handler({}, {}); expect(result.success).toBe(false); expect(result.error).toContain("No patch file"); + expect(result.execution_trace).toBe(expectedTrace); + }); + + it.each(["error", "ignore"])("does not trace the %s no-change policy before repository validation", async ifNoChanges => { + const module = await loadModule(); + const handler = await module.main({ if_no_changes: ifNoChanges }); + + const result = await handler({ repo: "other-owner/other-repo" }, {}); + + expect(result.success).toBe(false); + expect(result.execution_trace).toBe("init_repo_fail"); }); it("should handle patch file with error message", async () => { @@ -3886,6 +3938,7 @@ index 0000000..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4 expect(result.success).toBe(true); expect(result.staged).toBe(true); + expect(result.execution_trace).toBe("init_stag_done"); // Should not have made any git commands expect(mockExec.exec).not.toHaveBeenCalled(); }); diff --git a/actions/setup/js/safe_output_execution.cjs b/actions/setup/js/safe_output_execution.cjs index e443db070b4..7158812b2bc 100644 --- a/actions/setup/js/safe_output_execution.cjs +++ b/actions/setup/js/safe_output_execution.cjs @@ -71,6 +71,7 @@ function projectSafeOutputData(source) { if (source.identifier === null) data.identifier = null; if (EXECUTION_STATUSES.has(source.status)) data.status = source.status; if (typeof source.staged === "boolean") data.staged = source.staged; + if (typeof source.execution_trace === "string" && source.execution_trace.length <= 1024 && /^[A-Za-z]{4}(?:_[A-Za-z]{4})*$/.test(source.execution_trace)) data.execution_trace = source.execution_trace; if (source.operation_outcome === "indeterminate") data.operation_outcome = "indeterminate"; const url = canonicalSafeOutputUrl(source.url); if (url) data.url = url; @@ -102,6 +103,7 @@ function buildSafeOutputExecutions(results, staged = false) { status: isStaged && status === "success" ? "staged" : status, staged: isStaged, operation_outcome: pickOutcomeField(item, "operation_outcome"), + execution_trace: pickOutcomeField(item, "execution_trace"), url, }), }; diff --git a/actions/setup/js/safe_output_execution.test.cjs b/actions/setup/js/safe_output_execution.test.cjs index a9ab1df99ae..b65fcb67ce6 100644 --- a/actions/setup/js/safe_output_execution.test.cjs +++ b/actions/setup/js/safe_output_execution.test.cjs @@ -60,6 +60,74 @@ describe("safe-output application outcomes", () => { expect(outcome).toMatchObject({ status: "failed", operation_outcome: "indeterminate" }); }); + it.each(["success", "failed", "skipped", "staged"])("retains the execution path for %s outcomes", status => { + const result = { success: status !== "failed", skipped: status === "skipped", staged: status === "staged", execution_trace: "init_ptch_done" }; + const [outcome] = buildSafeOutputExecutions([{ type: "create_pull_request", success: result.success, result }]); + expect(outcome).toMatchObject({ status, execution_trace: "init_ptch_done" }); + expect(projectSafeOutputData(outcome).execution_trace).toBe("init_ptch_done"); + }); + + it.each(["", "push_".repeat(205) + "done", "ABc", "init_done\n", "_init", "init_", "init__done", "init_don", "init_donee", "init_d0ne", "init/done", "route=private", 123, ["init"]])( + "omits invalid execution traces: %j", + execution_trace => { + expect(projectSafeOutputData({ execution_trace })).not.toHaveProperty("execution_trace"); + expect(buildSafeOutputExecutions([{ success: true, result: { execution_trace } }])[0]).not.toHaveProperty("execution_trace"); + } + ); + + it("retains complete traces at the length limit", () => { + const execution_trace = "push_".repeat(204) + "done"; + expect(execution_trace).toHaveLength(1024); + expect(projectSafeOutputData({ execution_trace }).execution_trace).toBe(execution_trace); + }); + + it("persists isolated handler traces through processing and unified-session collection, including failures", async () => { + const root = fs.mkdtempSync("/tmp/safe-output-traces-"); + vi.stubGlobal("core", { info: vi.fn(), debug: vi.fn(), warning: vi.fn(), error: vi.fn(), setOutput: vi.fn(), setFailed: vi.fn() }); + vi.stubGlobal("context", { repo: { owner: "org", repo: "repo" }, payload: {} }); + const traces = ["init_done", "init_fail", "init_thrw", "init_noop_fail", "init_stag_done"]; + try { + for (const type of ["create_pull_request", "push_to_pull_request_branch"]) { + const handler = async message => { + const execution_trace = traces[message.scenario]; + if (message.scenario === 2) throw Object.assign(new Error("PRIVATE_ERROR"), { execution_trace }); + return { + success: message.scenario !== 1, + execution_trace, + ...(message.scenario === 1 ? { error: "PRIVATE_ERROR" } : {}), + ...(message.scenario === 3 ? { skipped: true, reason: "PRIVATE_REASON" } : {}), + ...(message.scenario === 4 ? { staged: true } : {}), + }; + }; + // Agent-request fields must never substitute for handler execution evidence. + const messages = traces.map((_, scenario) => ({ type, scenario, execution_trace: "fake_done" })); + const processing = await processMessages(new Map([[type, handler]]), messages); + writeSafeOutputExecutions(processing.results, false, path.join(root, type, "safe-output-executions.jsonl")); + const events = writeUnifiedSession({ rootDir: path.join(root, type), graders: [] }); + const outcomes = events.filter(event => event.type === "safe_output.execution"); + expect(outcomes.map(event => event.data.execution_trace)).toEqual(traces); + expect(outcomes.map(event => event.data.status)).toEqual(["success", "failed", "failed", "skipped", "staged"]); + const persisted = fs.readFileSync(path.join(root, type, "usage/aw_session.jsonl"), "utf8"); + expect(persisted).not.toContain("fake_done"); + expect(persisted).not.toContain("PRIVATE"); + expect(validateSession(persisted)).toBe(events.length); + } + } finally { + fs.rmSync(root, { recursive: true, force: true }); + } + }); + + it("replaces a deferred trace with the terminal retry failure trace", async () => { + vi.stubGlobal("core", { info: vi.fn(), debug: vi.fn(), warning: vi.fn(), error: vi.fn(), setOutput: vi.fn(), setFailed: vi.fn() }); + vi.stubGlobal("context", { repo: { owner: "org", repo: "repo" }, payload: {} }); + const handler = vi + .fn() + .mockResolvedValueOnce({ deferred: true, execution_trace: "init_wait" }) + .mockRejectedValueOnce(Object.assign(new Error("PRIVATE_ERROR"), { execution_trace: "init_thrw" })); + const processing = await processMessages(new Map([["create_pull_request", handler]]), [{ type: "create_pull_request" }]); + expect(buildSafeOutputExecutions(processing.results)[0]).toMatchObject({ status: "failed", execution_trace: "init_thrw" }); + }); + it("records queued ledger appends as delegated until persistence", () => { const record = { type: "ledger_append", messageIndex: 0, success: true, result: { queued: true } }; const [outcome] = buildSafeOutputExecutions([record]); diff --git a/actions/setup/js/safe_output_handler_manager.cjs b/actions/setup/js/safe_output_handler_manager.cjs index 607e2493e8a..d7988b49ea6 100644 --- a/actions/setup/js/safe_output_handler_manager.cjs +++ b/actions/setup/js/safe_output_handler_manager.cjs @@ -16,7 +16,7 @@ const { getStalePullRequestReason } = require("./pr_lifecycle.cjs"); const { ERR_CONFIG, ERR_PARSE, ERR_SYSTEM, ERR_VALIDATION, SAFE_OUTPUT_E007, SAFE_OUTPUT_E099 } = require("./error_codes.cjs"); const { classifySafeOutputResult, computeSafeOutputsStatus, isFailedProcessingResult } = require("./safe_outputs_status.cjs"); const { buildSafeOutputDependencyPlan, checkSafeOutputDependencies } = require("./safe_output_dependencies.cjs"); -const { finalizeBufferedReviewExecutions } = require("./safe_output_execution.cjs"); +const { projectSafeOutputData, finalizeBufferedReviewExecutions } = require("./safe_output_execution.cjs"); const { hasUnresolvedTemporaryIds, replaceTemporaryIdReferences, replaceArtifactUrlReferences, normalizeTemporaryId, extractTemporaryIdReferences, getCreatedTemporaryId } = require("./temporary_id.cjs"); const { generateMissingInfoSections } = require("./missing_info_formatter.cjs"); const { setCollectedMissings } = require("./missing_messages_helper.cjs"); @@ -1428,6 +1428,7 @@ async function processMessages(messageHandlers, messages, onItemCreated = null, messageIndex: i, success: false, error: errorMsg, + ...projectSafeOutputData({ execution_trace: result.execution_trace }), ...(messageType === "merge_pull_request" ? { result: projectMergeFailure(result) } : result.operation_outcome === "indeterminate" ? { result: { operation_outcome: "indeterminate" } } : {}), }); // Track code-push failures for later comment annotations and conclusion reporting. @@ -1574,6 +1575,7 @@ async function processMessages(messageHandlers, messages, onItemCreated = null, messageIndex: i, success: false, error: errorMsg, + ...projectSafeOutputData({ execution_trace: error?.execution_trace }), }); // Track code-push failures for later comment annotations and conclusion reporting. if (CODE_PUSH_TYPES.has(messageType)) { @@ -1652,6 +1654,7 @@ async function processMessages(messageHandlers, messages, onItemCreated = null, success: false, deferred: false, error: errorMsg, + ...projectSafeOutputData({ execution_trace: result.execution_trace }), result: deferred.type === "merge_pull_request" ? projectMergeFailure(result) : { ...result, success: false, deferred: false, error: errorMsg }, }; } @@ -1725,6 +1728,7 @@ async function processMessages(messageHandlers, messages, onItemCreated = null, success: false, deferred: false, error: errorMsg, + ...projectSafeOutputData({ execution_trace: error?.execution_trace }), result: { success: false, deferred: false, error: errorMsg }, }; } diff --git a/actions/setup/js/safe_output_trace.cjs b/actions/setup/js/safe_output_trace.cjs new file mode 100644 index 00000000000..7fdff1d0654 --- /dev/null +++ b/actions/setup/js/safe_output_trace.cjs @@ -0,0 +1,50 @@ +// @ts-check + +const MAX_EXECUTION_TRACE_LENGTH = 1024; + +/** + * Bind the trace inside each invocation so nested helpers share only that + * invocation's trace. Markers must be stable, unique four-letter source mnemonics per handler. + * The outer wrapper also observes failures converted by transport integrity. + * The callback receives trace first, followed by any wrapped handler arguments. + * Trace metadata is read explicitly by outcome projection, not spread into payloads. + * + * @param {{success: string, failure: string, error: string}} terminal + * @param {(handler: (...args: any[]) => any) => (...args: any[]) => any} [wrap] + * @returns {(handler: (...args: any[]) => any) => (...args: any[]) => Promise} + */ +function withExecutionTrace(terminal, wrap = handler => handler) { + return handler => + /** @this {any} */ + async function (...args) { + let path = ""; + const trace = marker => { + if (typeof marker === "string" && /^[A-Za-z]{4}$/.test(marker) && path.length + (path ? 5 : 4) <= MAX_EXECUTION_TRACE_LENGTH - 5) path += `${path ? "_" : ""}${marker}`; + }; + const attach = value => { + if ((value !== null && typeof value === "object") || typeof value === "function") { + try { + Object.defineProperty(value, "execution_trace", { value: path, configurable: true, enumerable: false, writable: true }); + } catch { + // Frozen errors/results must not turn observability into a new failure. + } + } + }; + const finish = marker => { + // Reserve a separator and complete terminal marker even when a route is bounded. + if (typeof marker === "string" && /^[A-Za-z]{4}$/.test(marker)) path += `${path ? "_" : ""}${marker}`; + }; + try { + const result = await wrap((...handlerArgs) => handler.call(this, trace, ...handlerArgs)).apply(this, args); + finish(result?.success === false || result?.skipped ? terminal.failure : terminal.success); + attach(result); + return result; + } catch (error) { + finish(terminal.error); + attach(error); + throw error; + } + }; +} + +module.exports = { withExecutionTrace, MAX_EXECUTION_TRACE_LENGTH }; diff --git a/actions/setup/js/safe_output_trace.test.cjs b/actions/setup/js/safe_output_trace.test.cjs new file mode 100644 index 00000000000..43d1fbcc3d6 --- /dev/null +++ b/actions/setup/js/safe_output_trace.test.cjs @@ -0,0 +1,263 @@ +import { afterEach, describe, it, expect, vi } from "vitest"; + +const { withExecutionTrace, MAX_EXECUTION_TRACE_LENGTH } = require("./safe_output_trace.cjs"); +const { withTransportIntegrity, TransportIntegrityError } = require("./transport_integrity.cjs"); +const { processMessages } = require("./safe_output_handler_manager.cjs"); +const { buildSafeOutputExecutions } = require("./safe_output_execution.cjs"); +const terminal = { success: "done", failure: "fail", error: "thrw" }; + +afterEach(() => { + vi.unstubAllGlobals(); + vi.unstubAllEnvs(); +}); + +describe("safe-output execution traces", () => { + it("preserves result identity, arguments, receiver and nested branch order", async () => { + const result = { success: true }; + const receiver = { value: 42 }; + const handler = withExecutionTrace(terminal)(async function (trace, message, ids) { + expect(this).toBe(receiver); + expect(message).toEqual({ value: 42 }); + expect(ids).toEqual({ temp: 1 }); + trace("init"); + const nested = () => trace("bund"); + nested(); + trace("push"); + return result; + }); + expect(await handler.call(receiver, { value: 42 }, { temp: 1 })).toBe(result); + expect(result.execution_trace).toBe("init_bund_push_done"); + expect({ ...result }).toEqual({ success: true }); + expect(JSON.parse(JSON.stringify(result))).toEqual({ success: true }); + expect(buildSafeOutputExecutions([{ type: "create_pull_request", success: true, result }])[0].execution_trace).toBe("init_bund_push_done"); + }); + + it.each([false, true])("keeps tracing in a fixed position when the temporary-ID map is supplied: %s", async includeMap => { + const message = { type: "create_pull_request" }; + const ids = { temp: 1 }; + const map = new Map(Object.entries(ids)); + const handler = withExecutionTrace(terminal)(async (trace, receivedMessage, receivedIds, receivedMap) => { + expect(receivedMessage).toBe(message); + expect(receivedIds).toBe(ids); + expect(receivedMap).toBe(includeMap ? map : undefined); + trace("init"); + return { success: true }; + }); + const result = await handler(message, ids, ...(includeMap ? [map] : [])); + expect(result.execution_trace).toBe("init_done"); + }); + + it.each(["success", "failed", "skipped", "thrown"])("projects non-enumerable traces through processMessages for %s handlers", async scenario => { + vi.stubGlobal("core", { info: vi.fn(), debug: vi.fn(), warning: vi.fn(), error: vi.fn() }); + vi.stubGlobal("context", { repo: { owner: "org", repo: "repo" }, payload: {} }); + const handler = withExecutionTrace(terminal)(async (trace, message, ids, temporaryIdMap) => { + expect(message.type).toBe("create_pull_request"); + expect(ids).toEqual({}); + expect(temporaryIdMap).toBeInstanceOf(Map); + trace("init"); + if (scenario === "thrown") throw new Error("failed"); + return { success: scenario !== "failed", ...(scenario === "skipped" ? { skipped: true } : {}) }; + }); + const processing = await processMessages(new Map([["create_pull_request", handler]]), [{ type: "create_pull_request" }]); + expect(buildSafeOutputExecutions(processing.results)[0]).toMatchObject({ + status: scenario === "thrown" ? "failed" : scenario, + execution_trace: `init_${scenario === "success" ? "done" : scenario === "thrown" ? "thrw" : "fail"}`, + }); + }); + + it("preserves the terminal trace when a deferred retry returns an unsuccessful result", async () => { + vi.stubGlobal("core", { info: vi.fn(), debug: vi.fn(), warning: vi.fn(), error: vi.fn() }); + vi.stubGlobal("context", { repo: { owner: "org", repo: "repo" }, payload: {} }); + let invocation = 0; + const handler = vi.fn( + withExecutionTrace(terminal)(async trace => { + trace("init"); + if (++invocation === 1) { + trace("wait"); + return { deferred: true }; + } + trace("push"); + return { success: false, error: "retry failed" }; + }) + ); + const processing = await processMessages(new Map([["create_pull_request", handler]]), [{ type: "create_pull_request" }]); + expect(handler).toHaveBeenCalledTimes(2); + expect(processing.results[0]).toMatchObject({ success: false, deferred: false, execution_trace: "init_push_fail" }); + expect(buildSafeOutputExecutions(processing.results)[0]).toMatchObject({ status: "failed", execution_trace: "init_push_fail" }); + }); + + it.each([{ success: false }, { skipped: true }, { success: true, skipped: true }])("marks unsuccessful/skipped returns: %j", async result => { + const handler = withExecutionTrace(terminal)(async trace => { + trace("init"); + return result; + }); + expect(await handler()).toBe(result); + expect(result.execution_trace).toBe("init_fail"); + }); + + it("preserves thrown Error identity, type, message and cause", async () => { + const cause = new Error("cause"); + const error = new TypeError("original", { cause }); + const handler = withExecutionTrace(terminal)(async trace => { + trace("init"); + await Promise.resolve(); + trace("push"); + throw error; + }); + await expect(handler()).rejects.toBe(error); + expect(error.execution_trace).toBe("init_push_thrw"); + expect(error).toBeInstanceOf(TypeError); + expect(error.message).toBe("original"); + expect(error.cause).toBe(cause); + expect({ ...error }).not.toHaveProperty("execution_trace"); + expect(JSON.parse(JSON.stringify(error))).not.toHaveProperty("execution_trace"); + }); + + it("traces synchronous failures and does not replace primitive throws", async () => { + const error = new Error("sync"); + const handler = withExecutionTrace(terminal)(trace => { + trace("init"); + throw error; + }); + await expect(handler()).rejects.toBe(error); + expect(error.execution_trace).toBe("init_thrw"); + await expect( + withExecutionTrace(terminal)(() => { + throw "original"; + })() + ).rejects.toBe("original"); + }); + + it("keeps overlapping and sequential invocations private", async () => { + let release; + const blocked = new Promise(resolve => { + release = resolve; + }); + const handler = withExecutionTrace(terminal)(async (trace, first) => { + if (first) { + trace("init"); + await blocked; + trace("push"); + } else { + trace("stag"); + } + return { success: true }; + }); + const first = handler(true); + expect((await handler(false)).execution_trace).toBe("stag_done"); + release(); + expect((await first).execution_trace).toBe("init_push_done"); + expect((await handler(false)).execution_trace).toBe("stag_done"); + }); + + it("bounds paths and reserves the final outcome without recording invalid markers or inputs", async () => { + const secret = "untrusted-input-do-not-record"; + const handler = withExecutionTrace(terminal)(async (trace, input) => { + trace(input); + trace("A"); + trace("ABCDE"); + trace("ab_c"); + trace("ab12"); + trace("init\n"); + trace("\n"); + trace(undefined); + for (let i = 0; i < MAX_EXECUTION_TRACE_LENGTH * 2; i++) trace("push"); + return { success: true }; + }); + const result = await handler(secret); + expect(result.execution_trace).toBe("push_".repeat(204) + "done"); + expect(result.execution_trace).toHaveLength(1024); + expect(result.execution_trace).not.toContain(secret); + }); + + it.each([{ success: false }, new Error("failed")])("retains complete markers and the failure terminal at the length limit", async result => { + const handler = withExecutionTrace(terminal)(trace => { + for (let i = 0; i < MAX_EXECUTION_TRACE_LENGTH; i++) trace("push"); + if (result instanceof Error) throw result; + return result; + }); + if (result instanceof Error) { + await expect(handler()).rejects.toBe(result); + } else { + expect(await handler()).toBe(result); + } + expect(result.execution_trace).toBe("push_".repeat(204) + (result instanceof Error ? "thrw" : "fail")); + }); + + it("emits the terminal without a leading underscore when no branch is recorded", async () => { + const result = await withExecutionTrace(terminal)(() => ({ success: true }))(); + expect(result.execution_trace).toBe("done"); + }); + + it("does not turn immutable results or errors into tracing failures", async () => { + const result = Object.freeze({ success: true }); + expect(await withExecutionTrace(terminal)(() => result)()).toBe(result); + const error = Object.freeze(new Error("immutable")); + await expect( + withExecutionTrace(terminal)(() => { + throw error; + })() + ).rejects.toBe(error); + expect(await withExecutionTrace(terminal)(() => undefined)()).toBeUndefined(); + }); + + it("wraps transport conversion and cleanup without introducing API effects", async () => { + const previousCore = global.core; + global.core = { error: vi.fn() }; + try { + const handler = withExecutionTrace( + terminal, + withTransportIntegrity + )(async (trace, message, ids, transport) => { + expect(message).toEqual({ untouched: true }); + expect(ids).toEqual({}); + expect(typeof transport.assertUnchanged).toBe("function"); + trace("init"); + throw new TransportIntegrityError("artifact"); + }); + const result = await handler({ untouched: true }, {}); + expect(result).toMatchObject({ success: false, error_type: "ERR_TRANSPORT_INTEGRITY", execution_trace: "init_fail" }); + expect(global.core.error).toHaveBeenCalledOnce(); + } finally { + global.core = previousCore; + } + }); + + it("retains route state when an outer wrapper fails after the handler returns", async () => { + const error = new Error("cleanup failed"); + const wrap = + handler => + async (...args) => { + await handler(...args); + throw error; + }; + const handler = withExecutionTrace( + terminal, + wrap + )(trace => { + trace("init"); + return { success: true }; + }); + await expect(handler()).rejects.toBe(error); + expect(error.execution_trace).toBe("init_thrw"); + }); + + it.each(["create_pull_request", "push_to_pull_request_branch"])("%s records a real handler invocation without Git or API effects", async type => { + vi.stubGlobal("core", { info: vi.fn(), debug: vi.fn(), warning: vi.fn(), error: vi.fn() }); + vi.stubGlobal("github", { rest: {} }); + vi.stubGlobal("context", { repo: { owner: "org", repo: "repo" }, payload: {} }); + vi.stubGlobal("exec", { exec: vi.fn(), getExecOutput: vi.fn() }); + vi.stubEnv("GIT_CONFIG_COUNT", "0"); + vi.stubEnv("GIT_CONFIG_KEY_0", undefined); + vi.stubEnv("GIT_CONFIG_VALUE_0", undefined); + vi.stubEnv("GH_AW_SAFE_OUTPUTS_STAGED", "false"); + vi.stubEnv("GH_AW_WORKFLOW_ID", "trace-test"); + const { main } = require(`./${type}.cjs`); + const handler = await main({ target_repo: "org/repo" }); + const result = await handler({ type, repo: "not-allowed/repo", temporary_id: "aw_trace" }, {}, new Map()); + expect(result).toMatchObject({ success: false, execution_trace: "init_repo_fail" }); + expect(result.error).toContain("allowed-repos"); + expect(global.exec.exec).not.toHaveBeenCalled(); + expect(global.exec.getExecOutput).not.toHaveBeenCalled(); + }); +}); diff --git a/actions/setup/js/types/unified_session.d.ts b/actions/setup/js/types/unified_session.d.ts index ed9397c5111..caa108cc819 100644 --- a/actions/setup/js/types/unified_session.d.ts +++ b/actions/setup/js/types/unified_session.d.ts @@ -456,6 +456,13 @@ export interface SafeOutputData { staged?: boolean; /** The operation may have applied even though processing failed to confirm it. */ operation_outcome?: "indeterminate"; + /** + * Ordered four-letter branch mnemonics joined by underscores, not a correlation ID. + * @pattern ^[A-Za-z]{4}(?:_[A-Za-z]{4})*$ + * @minLength 4 + * @maxLength 1024 + */ + execution_trace?: string; } export interface SafeOutputErrorData extends SafeOutputData { diff --git a/docs/public/cracktro/deck.js b/docs/public/cracktro/deck.js index 5fdad36b024..94a31776122 100644 --- a/docs/public/cracktro/deck.js +++ b/docs/public/cracktro/deck.js @@ -9168,7 +9168,7 @@ ' "location":{"path":"src/db.js","start_line":42,', ' "end_line":42,"start_column":9,"end_column":31}}},', ' {"number":1283,"state":"open", โ€ฆ ร— every alert', - 'โ†’ page 2 ยท page 3 ยท โ€ฆ every page into context', + "โ†’ page 2 ยท page 3 ยท โ€ฆ every page into context", ]; const BINS = [ ["gh", "gh-proxy ยท pre-authenticated, no MCP"], @@ -9316,7 +9316,7 @@ reveal( WALL.map((_, i) => "cvmT" + i), ph("SCH"), - i => i % 3 === 0 && sfx.pop(i / 3), + i => i % 3 === 0 && sfx.pop(i / 3) ); if (ph("SCH") >= 1) $("cvmXm").classList.add("on"); } @@ -9336,7 +9336,7 @@ reveal( BINS.map((_, i) => "cvmB" + i), ph("BIN"), - i => sfx.pop(4 + i), + i => sfx.pop(4 + i) ); if (u >= P.W1[0] && u < P.SH[0]) wire("cvmW1", ph("W1")); // discover with --help, write the file, pipe out the answer @@ -9355,7 +9355,12 @@ sfx.pop(7); }); }, - el: h("section", { class: "slide cvm" }, h("div", { class: "slide-head" }, h("div", { class: "kicker" }, "gh-proxy + cli-proxy ยท bash, files and pipes, not context"), h("h2", {}, letters("CLI"), letters("vs", "l-out"), letters("MCP", "l-grad"))), svg), + el: h( + "section", + { class: "slide cvm" }, + h("div", { class: "slide-head" }, h("div", { class: "kicker" }, "gh-proxy + cli-proxy ยท bash, files and pipes, not context"), h("h2", {}, letters("CLI"), letters("vs", "l-out"), letters("MCP", "l-grad"))), + svg + ), }); } diff --git a/docs/public/schemas/unified-session.schema.json b/docs/public/schemas/unified-session.schema.json index 744aac6a638..fd6803955dd 100644 --- a/docs/public/schemas/unified-session.schema.json +++ b/docs/public/schemas/unified-session.schema.json @@ -1308,7 +1308,8 @@ "output_id": { "type": "string" }, "messageIndex": { "type": "number" }, "staged": { "type": "boolean" }, - "operation_outcome": { "type": "string", "const": "indeterminate", "description": "The operation may have applied even though processing failed to confirm it." } + "operation_outcome": { "type": "string", "const": "indeterminate", "description": "The operation may have applied even though processing failed to confirm it." }, + "execution_trace": { "type": "string", "description": "Ordered four-letter branch mnemonics joined by underscores, not a correlation ID.", "pattern": "^[A-Za-z]{4}(?:_[A-Za-z]{4})*$", "minLength": 4, "maxLength": 1024 } }, "additionalProperties": false }, @@ -1327,6 +1328,7 @@ "messageIndex": { "type": "number" }, "staged": { "type": "boolean" }, "operation_outcome": { "type": "string", "const": "indeterminate", "description": "The operation may have applied even though processing failed to confirm it." }, + "execution_trace": { "type": "string", "description": "Ordered four-letter branch mnemonics joined by underscores, not a correlation ID.", "pattern": "^[A-Za-z]{4}(?:_[A-Za-z]{4})*$", "minLength": 4, "maxLength": 1024 }, "errors": { "type": "array", "items": { "$ref": "#/definitions/SafeOutputData" } } }, "additionalProperties": false diff --git a/docs/src/content/docs/specs/unified-agent-session-specification.md b/docs/src/content/docs/specs/unified-agent-session-specification.md index 8c5f814a9d9..ee044c2a61b 100644 --- a/docs/src/content/docs/specs/unified-agent-session-specification.md +++ b/docs/src/content/docs/specs/unified-agent-session-specification.md @@ -3,9 +3,9 @@ title: Unified Agent Session Specification description: Draft contract for canonical traces, full unified artifacts, and bounded compact unified sessions. sidebar: order: 1365 -version: "2.10.0" +version: "2.11.0" status: Draft -publication_date: "2026-11-12" +publication_date: "2026-11-17" editors: - name: GitHub Agentic Workflows Team organization: GitHub @@ -13,9 +13,9 @@ editors: # Unified Agent Session Specification -**Version**: 2.10.0
+**Version**: 2.11.0
**Status**: Draft
-**Publication Date**: 2026-11-12
+**Publication Date**: 2026-11-17
**Editors**: GitHub Agentic Workflows Team (GitHub)
**This Version**: [unified-agent-session-specification](/gh-aw/specs/unified-agent-session-specification/)
**Latest Version**: This document @@ -30,7 +30,7 @@ This specification defines the session traces used by GitHub Agentic Workflows: This is a **GitHub Agentic Workflows project specification**, written using W3C-inspired document conventions. It is **not an official W3C standard**, W3C publication, or W3C-endorsed recommendation. -Version 2.8.0 is a draft governed by the project's normal review process. It may be updated, replaced, or superseded. The accompanying implementation and regression suites exercise this contract, including the sampled CI sessions identified in Section 9.4. This is not a blanket declaration of conformance for every engine version or source format. Section 10 records historical pre-implementation gaps, not current defects. Approval and ongoing compliance testing remain project responsibilities. +Version 2.11.0 is a draft governed by the project's normal review process. It may be updated, replaced, or superseded. The accompanying implementation and regression suites exercise this contract, including the sampled CI sessions identified in Section 9.4. This is not a blanket declaration of conformance for every engine version or source format. Section 10 records historical pre-implementation gaps, not current defects. Approval and ongoing compliance testing remain project responsibilities. The specification version belongs to this document. The unified file's leading `session.format` record carries an independent numeric serialization-format @@ -868,6 +868,22 @@ source for opaque fields. | `session.collection_warning`, `session.collection` | Explicit collection diagnostics and coverage. | | `session.format` | Leading collector-owned file-format metadata, distinct from source-native events with the same type. | +Pull-request creation and branch-push outcomes also retain `data.execution_trace`, +an ordered sequence of self-describing four-letter branch mnemonics joined by +underscores, such as `init_bund_push_publ_capt_done`. Traces contain at most +1,024 characters, retaining complete prefix markers and the terminal outcome +(`done` for success, `fail` for unsuccessful or skipped returns, `thrw` for errors). +Each instrumented route has a unique mnemonic within its handler; +the source comments expand abbreviations. Equal paths produce equal identifiers, +not unique invocation IDs. Interpret a trace with its operation `type` and the +handler source revision from that run to compare hot paths and diagnose recovery +or fallback routes. Traces survive skipped, staged, and failed execution, including +thrown errors; absent traces mean instrumentation was unavailable or the handler +was not entered. Handlers retain traces as non-enumerable internal result/error +metadata, explicitly projected into recorded outcomes rather than tool-response +payloads. The reusable tracing helper can instrument other safe outputs +without recording request bodies, branch names, credentials, or error text. + Job-result records cover only the conclusion job's direct dependencies, including custom jobs when present in `needs`. They do not imply a final workflow result or a result for the still-running conclusion job. Missing dependency metadata, @@ -2728,6 +2744,11 @@ Native IDs can collide, timestamps can be out of order, and a trace can contain ## 13. Change Log (Informative) +### Version 2.11.0 - Draft (2026-11-17) + +- Added `data.execution_trace` for pull-request creation and branch-push outcomes: underscore-separated four-letter branch mnemonics bounded to 1,024 characters, preserving complete prefix markers and terminal `done`, `fail`, or `thrw` outcomes while excluding request bodies, branch names, credentials, and error text. +- Retained serialization-format version 1. + ### Version 2.10.0 - Draft (2026-11-12) - Retained AWF's per-conversation `steering_delivery` record as `steeringDelivery` on `firewall.token_usage` and `usage.report`, and `trigger` and `conversation` on `firewall.steering`, with `null` thresholds for `little_left` notices (T-UAS-071).