Skip to content

Commit 53d0749

Browse files
chore: sync actions from [email protected] (#298)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 406c771 commit 53d0749

151 files changed

Lines changed: 5040 additions & 9126 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎setup/clean.sh‎

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set +o histexpand
33

44
# Clean Action Post Script
55
# Mirror of actions/setup/post.js for script mode (run: bash steps).
6-
# Sends an OTLP conclusion span then removes the /tmp/gh-aw/ directory.
6+
# Sends an OTLP conclusion span without reclaiming unowned shared runtime paths.
77
#
88
# Must be called from an `if: always()` step so it runs even when job steps fail,
99
# ensuring both the trace span and the cleanup always complete.
@@ -29,47 +29,12 @@ if command -v node &>/dev/null && [ -f "${DESTINATION}/action_conclusion_otlp.cj
2929
echo "OTLP conclusion span step complete"
3030
fi
3131

32-
# Remove /tmp/gh-aw/ (mirrors post.js cleanup).
32+
# Shared legacy state has no per-invocation ownership record (mirrors post.js).
3333
tmpDir="/tmp/gh-aw"
34-
if [ -d "${tmpDir}" ]; then
35-
if sudo rm -rf "${tmpDir}" 2>/dev/null; then
36-
echo "Cleaned up ${tmpDir} (sudo)"
37-
elif rm -rf "${tmpDir}" 2>/dev/null; then
38-
echo "Cleaned up ${tmpDir}"
39-
else
40-
echo "Warning: failed to clean up ${tmpDir}" >&2
41-
fi
34+
if [ -e "${tmpDir}" ] || [ -L "${tmpDir}" ]; then
35+
echo "Warning: leaving shared ${tmpDir} untouched; per-invocation ownership cannot be established." >&2
4236
fi
4337

44-
# Remove AWF chroot directories under /tmp (e.g. /tmp/awf-*-chroot-home and
45-
# /tmp/awf-chroot-*). These are created by AWF when running with
46-
# --enable-host-access on GitHub-hosted runners. Files inside may be owned by
47-
# root (written by Docker containers or privileged AWF processes), causing
48-
# EACCES failures if cleanup is attempted without sudo.
49-
if awf_chroot_home_dirs="$(sudo find /tmp -maxdepth 1 -name 'awf-*-chroot-home' -type d -print 2>/dev/null)"; then
50-
if [ -n "${awf_chroot_home_dirs}" ]; then
51-
if sudo find /tmp -maxdepth 1 -name 'awf-*-chroot-home' -type d -exec rm -rf -- {} + 2>/dev/null; then
52-
echo "Cleaned up /tmp/awf-*-chroot-home directories (sudo)"
53-
else
54-
echo "Warning: failed to clean /tmp/awf-*-chroot-home directories" >&2
55-
fi
56-
else
57-
echo "No /tmp/awf-*-chroot-home directories found"
58-
fi
59-
else
60-
echo "Warning: unable to inspect /tmp/awf-*-chroot-home directories with sudo" >&2
61-
fi
62-
63-
if awf_chroot_dirs="$(sudo find /tmp -maxdepth 1 -name 'awf-chroot-*' -type d -print 2>/dev/null)"; then
64-
if [ -n "${awf_chroot_dirs}" ]; then
65-
if sudo find /tmp -maxdepth 1 -name 'awf-chroot-*' -type d -exec rm -rf -- {} + 2>/dev/null; then
66-
echo "Cleaned up /tmp/awf-chroot-* directories (sudo)"
67-
else
68-
echo "Warning: failed to clean /tmp/awf-chroot-* directories" >&2
69-
fi
70-
else
71-
echo "No /tmp/awf-chroot-* directories found"
72-
fi
73-
else
74-
echo "Warning: unable to inspect /tmp/awf-chroot-* directories with sudo" >&2
38+
if [[ -n "${GH_AW_RUNTIME_TMP_DIR:-}" && -f "${DESTINATION}/cleanup_runtime_tmp.sh" ]]; then
39+
bash "${DESTINATION}/cleanup_runtime_tmp.sh"
7540
fi

‎setup/js/Dockerfile.safe-outputs-mcp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ ARG DOCKERFILE_HASH=""
1010
ARG NPM_VERSION=11.19.0
1111

1212
# Intentional: upgrade all packages to pick up security fixes; downstream digest pins the result.
13+
# Require zlib/libexpat fixes for CVE-2026-4738 and CVE-2026-113351, CVE-2026-115506,
14+
# CVE-2026-117610, CVE-2026-118370; fail the build if the base repositories lack them.
1315
# After upgrading npm, patch its bundled dependencies to meet minimum safe versions.
1416
# Install into a temp prefix (avoids npm's own private package.json) then replace the package
1517
# directories in npm's bundled node_modules: brace-expansion >= 5.0.11 (GHSA-qhr7-859c-m2p7),
@@ -18,7 +20,7 @@ ARG NPM_VERSION=11.19.0
1820
# the globally installed npm tree is not on Node's default resolution path, so a bare
1921
# require("<pkg>") would always fail with MODULE_NOT_FOUND and break the build.
2022
RUN apk upgrade --no-cache \
21-
&& apk add --no-cache git "brotli-libs>=1.2.1-r0" \
23+
&& apk add --no-cache git "brotli-libs>=1.2.1-r0" "zlib>=1.4-r0" "libexpat>=2.10.0-r0" \
2224
&& apk info -v | sort \
2325
&& npm install --global "npm@${NPM_VERSION}" \
2426
&& tmpdir=$(mktemp -d) \

‎setup/js/agent_session.cjs‎

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
const { getMessageRefusal, getProviderRefusals, normalizeOpenAIChatUsage } = require("./provider_refusal.cjs");
88

99
const USAGE_ALIASES = {
10-
input_tokens: "inputTokens",
11-
output_tokens: "outputTokens",
12-
reasoning_output_tokens: "reasoningOutputTokens",
13-
total_tokens: "totalTokens",
14-
cache_creation_input_tokens: "cacheCreationInputTokens",
15-
cache_read_input_tokens: "cacheReadInputTokens",
10+
input_tokens: ["inputTokens"],
11+
output_tokens: ["outputTokens"],
12+
reasoning_output_tokens: ["reasoningOutputTokens"],
13+
total_tokens: ["totalTokens"],
14+
cache_creation_input_tokens: ["cacheCreationInputTokens", "cacheWriteTokens", "cache_write_tokens"],
15+
cache_read_input_tokens: ["cacheReadInputTokens", "cacheReadTokens", "cache_read_tokens"],
1616
};
1717
const USAGE_BOOLEAN_ALIASES = {
1818
input_tokens_include_cache: "inputTokensIncludeCache",
@@ -40,7 +40,7 @@ function isMetric(value) {
4040
*/
4141
function sessionContext(event) {
4242
const data = event?.data ?? {};
43-
const sessionId = data.sessionId !== undefined ? data.sessionId : event?.sessionId !== undefined ? event.sessionId : event?.session_id !== undefined ? event.session_id : data.session_id;
43+
const sessionId = data.sessionId !== undefined ? data.sessionId : event?.sessionId !== undefined ? event.sessionId : event?.session_id !== undefined ? event.session_id : data.session_id !== undefined ? data.session_id : event?.sessionID;
4444
const parentToolUseId =
4545
data.parentToolUseId !== undefined ? data.parentToolUseId : event?.parentToolUseId !== undefined ? event.parentToolUseId : event?.parent_tool_use_id !== undefined ? event.parent_tool_use_id : data.parent_tool_use_id;
4646
const agentId = data.agentId ?? (typeof event?.type === "string" && event.type.startsWith("subagent.") ? undefined : event?.agentId);
@@ -68,19 +68,33 @@ function sessionScopeKey(event) {
6868
return JSON.stringify([sessionId, parentToolUseId, agentId]);
6969
}
7070

71+
/** @param {any} value @returns {string[]} */
72+
function normalizeOverflowedTokens(value) {
73+
if (!Array.isArray(value)) return [];
74+
return [
75+
...new Set(
76+
value.flatMap(key => {
77+
const match = Object.entries(USAGE_ALIASES).find(([name, aliases]) => key === name || aliases.includes(key));
78+
return match ? [match[0]] : [];
79+
})
80+
),
81+
];
82+
}
83+
7184
/** @param {any} usage @returns {Record<string, any>|undefined} */
7285
function normalizeSessionUsage(usage) {
7386
// Usage is a named-field object; arrays cannot represent its token fields.
7487
if (!usage || typeof usage !== "object" || Array.isArray(usage)) return undefined;
7588
const result = { ...usage };
7689
delete result.overflowedTokens;
77-
for (const [key, alias] of Object.entries(USAGE_ALIASES)) {
90+
for (const [key, aliases] of Object.entries(USAGE_ALIASES)) {
7891
const hasCanonical = Object.hasOwn(usage, key);
79-
const value = hasCanonical ? usage[key] : usage[alias];
92+
const alias = aliases.find(name => Object.hasOwn(usage, name));
93+
const value = hasCanonical ? usage[key] : alias === undefined ? undefined : usage[alias];
8094
if (isTokenCount(value)) result[key] = value;
8195
else {
8296
delete result[key];
83-
if (hasCanonical) delete result[alias];
97+
for (const name of aliases) delete result[name];
8498
}
8599
}
86100
for (const [key, alias] of Object.entries(USAGE_BOOLEAN_ALIASES)) {
@@ -94,10 +108,10 @@ function normalizeSessionUsage(usage) {
94108
}
95109
const overflowed = Object.hasOwn(usage, "overflowed_tokens") ? usage.overflowed_tokens : usage.overflowedTokens;
96110
if (Array.isArray(overflowed)) {
97-
result.overflowed_tokens = [...new Set(overflowed.map(key => Object.entries(USAGE_ALIASES).find(([name, alias]) => key === name || key === alias)?.[0]).filter(Boolean))];
111+
result.overflowed_tokens = normalizeOverflowedTokens(overflowed);
98112
for (const key of result.overflowed_tokens) {
99113
delete result[key];
100-
delete result[USAGE_ALIASES[key]];
114+
for (const alias of USAGE_ALIASES[key]) delete result[alias];
101115
}
102116
} else delete result.overflowed_tokens;
103117
return result;
@@ -113,14 +127,14 @@ function reconcileSessionUsage(previous, snapshot) {
113127
const normalized = normalizeSessionUsage(snapshot);
114128
if (!normalized) return previous;
115129
const result = { ...previous, ...normalized };
116-
const overflowed = new Set(Array.isArray(previous?.overflowed_tokens) ? previous.overflowed_tokens : []);
130+
const overflowed = new Set(normalizeOverflowedTokens(previous?.overflowed_tokens));
117131
for (const key of Object.keys(USAGE_ALIASES)) {
118132
if (isTokenCount(normalized[key])) overflowed.delete(key);
119133
}
120134
for (const key of normalized.overflowed_tokens ?? []) {
121135
overflowed.add(key);
122136
delete result[key];
123-
delete result[USAGE_ALIASES[key]];
137+
for (const alias of USAGE_ALIASES[key]) delete result[alias];
124138
}
125139
if (overflowed.size) result.overflowed_tokens = [...overflowed];
126140
else delete result.overflowed_tokens;
@@ -131,7 +145,7 @@ function reconcileSessionUsage(previous, snapshot) {
131145
function accumulateSessionUsage(target, usage) {
132146
const normalized = normalizeSessionUsage(usage);
133147
if (!normalized) return;
134-
const overflowed = new Set([...(Array.isArray(target.overflowed_tokens) ? target.overflowed_tokens : []), ...(normalized.overflowed_tokens ?? [])]);
148+
const overflowed = new Set([...normalizeOverflowedTokens(target.overflowed_tokens), ...(normalized.overflowed_tokens ?? [])]);
135149
for (const key of Object.keys(USAGE_ALIASES)) {
136150
if (overflowed.has(key) || !isTokenCount(normalized[key])) continue;
137151
const sum = (target[key] ?? 0) + normalized[key];
@@ -142,9 +156,9 @@ function accumulateSessionUsage(target, usage) {
142156
target.overflowed_tokens = [...overflowed];
143157
for (const key of overflowed) {
144158
delete target[key];
145-
delete target[USAGE_ALIASES[key]];
159+
for (const alias of USAGE_ALIASES[key]) delete target[alias];
146160
}
147-
}
161+
} else delete target.overflowed_tokens;
148162
}
149163

150164
/**

0 commit comments

Comments
 (0)