GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test(server): wire budget measures what clients fetch today, and the … · incognitojam/styal@b64b81d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .github
    • scripts
      • thread-transfer-report.cjs
      • thread-transfer-report.test.cjs
    • workflows
      • ci.yml
  • apps/server/integration
    • TransferBudgetReport.integration.ts
    • TransferBudgetV2Fixture.integration.ts
    • transferBudgetV2.integration.test.ts
  • docs/internals
    • performance-regressions.md
  • packages
    • contracts/src
      • environmentHttp.ts
    • shared/src/testing
      • providerEnv.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.github/scripts/thread-transfer-report.cjs‎

Copy file name to clipboardExpand all lines: .github/scripts/thread-transfer-report.cjs
+171-10Lines changed: 171 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const path = require("node:path");
44

55
const ARTIFACT_NAME = "thread-transfer-results";
66
const RESULT_FILE = "thread-transfer-result.json";
7+
const SCENARIOS_FILE = "thread-transfer-scenarios.json";
78
const COMMENT_MARKER = "<!-- t3-thread-transfer-report -->";
89
const PROVIDERS = ["codex", "claudeAgent"];
910
const OBSERVED_KEYS = [
@@ -30,6 +31,12 @@ const SCENARIO_KEYS = [
3031
"measuredMcpResultBytes",
3132
];
3233

34+
const SCENARIO_ROW_KEYS = ["phase", "metric", "unit", "observed", "ceiling"];
35+
// These labels come from the PR and reach a comment the bot posts: no markup, links or mentions.
36+
// GitHub still links plain text such as `GH-26`, so they are rendered as code spans.
37+
const SCENARIO_LABEL = /^[A-Za-z0-9][A-Za-z0-9 ,-]{0,79}$/;
38+
const MAX_SCENARIO_ROWS = 100;
39+
3340
function resultShaMarker(sha) {
3441
return `<!-- t3-thread-transfer-result-sha:${sha} -->`;
3542
}
@@ -86,15 +93,63 @@ function validateResult(value) {
8693
return value;
8794
}
8895

89-
function readResult(directory) {
96+
function validateScenarios(value) {
97+
assertExactKeys(value, ["schemaVersion", "providers"], "scenarios");
98+
if (value.schemaVersion !== 1) {
99+
throw new Error("scenarios.schemaVersion must be 1");
100+
}
101+
assertExactKeys(value.providers, PROVIDERS, "scenarios.providers");
102+
for (const provider of PROVIDERS) {
103+
const rows = value.providers[provider];
104+
if (!Array.isArray(rows) || rows.length > MAX_SCENARIO_ROWS) {
105+
throw new Error(
106+
`scenarios.providers.${provider} must list at most ${MAX_SCENARIO_ROWS} rows`,
107+
);
108+
}
109+
const seen = new Set();
110+
for (const [index, row] of rows.entries()) {
111+
const label = `scenarios.providers.${provider}[${index}]`;
112+
assertExactKeys(row, SCENARIO_ROW_KEYS, label);
113+
for (const key of ["phase", "metric"]) {
114+
if (typeof row[key] !== "string" || !SCENARIO_LABEL.test(row[key])) {
115+
throw new Error(`${label}.${key} must be a short plain label`);
116+
}
117+
}
118+
if (row.unit !== "bytes" && row.unit !== "count") {
119+
throw new Error(`${label}.unit must be bytes or count`);
120+
}
121+
assertMetric(row.observed, `${label}.observed`);
122+
assertMetric(row.ceiling, `${label}.ceiling`);
123+
const key = scenarioKey(row);
124+
if (seen.has(key)) throw new Error(`${label} repeats an earlier row`);
125+
seen.add(key);
126+
}
127+
}
128+
return value;
129+
}
130+
131+
function scenarioKey(row) {
132+
return `${row.phase}|${row.metric}`;
133+
}
134+
135+
function readArtifactFile(directory, name, validate) {
90136
if (!directory) return undefined;
91-
const file = path.join(directory, RESULT_FILE);
137+
const file = path.join(directory, name);
92138
if (!fs.existsSync(file)) return undefined;
93139
const stat = fs.lstatSync(file);
94140
if (!stat.isFile() || stat.size > 64 * 1_024) {
95-
throw new Error("thread transfer result must be a regular file smaller than 64 KiB");
141+
throw new Error(`${name} must be a regular file smaller than 64 KiB`);
96142
}
97-
return validateResult(JSON.parse(fs.readFileSync(file, "utf8")));
143+
return validate(JSON.parse(fs.readFileSync(file, "utf8")));
144+
}
145+
146+
function readResult(directory) {
147+
return readArtifactFile(directory, RESULT_FILE, validateResult);
148+
}
149+
150+
// Older runs upload only the result file, so a run without scenarios is still a valid run.
151+
function readScenarios(directory) {
152+
return readArtifactFile(directory, SCENARIOS_FILE, validateScenarios);
98153
}
99154

100155
function formatBytes(bytes) {
@@ -104,7 +159,7 @@ function formatBytes(bytes) {
104159
}
105160

106161
function formatValue(value, kind) {
107-
return kind === "messages" ? value.toLocaleString("en-US") : formatBytes(value);
162+
return kind === "bytes" ? formatBytes(value) : value.toLocaleString("en-US");
108163
}
109164

110165
function formatImpact(current, baseline, kind) {
@@ -137,6 +192,95 @@ const METRICS = [
137192
{ key: "measuredTurnWebSocketMessages", label: "Live turn messages", kind: "messages" },
138193
];
139194

195+
function providerLabel(provider) {
196+
return provider === "codex" ? "Codex" : "Claude";
197+
}
198+
199+
/**
200+
* The scenario rows of a run against the same rows on `main`. Rows that fail, differ from
201+
* `main` or are missing from the run are listed in the open; the full table is collapsed below.
202+
*/
203+
function renderScenarios(runScenarios, baseline, ceilingChanges) {
204+
// A run without the file still misses every row `main` measured.
205+
const current =
206+
runScenarios ??
207+
(PROVIDERS.some((provider) => (baseline?.providers[provider].length ?? 0) > 0)
208+
? { providers: Object.fromEntries(PROVIDERS.map((provider) => [provider, []])) }
209+
: undefined);
210+
if (!current) return { lines: [], failed: false, removed: 0 };
211+
const header = [
212+
"| Provider | Scenario | Metric | Main baseline | This PR | Impact | PR ceiling | |",
213+
"| --- | --- | --- | ---: | ---: | ---: | ---: | --- |",
214+
];
215+
const all = [];
216+
const notable = [];
217+
const removed = [];
218+
let failed = false;
219+
let withoutBaseline = 0;
220+
221+
for (const provider of PROVIDERS) {
222+
const baselineRows = new Map(
223+
(baseline?.providers[provider] ?? []).map((row) => [scenarioKey(row), row]),
224+
);
225+
for (const row of current.providers[provider]) {
226+
const before = baselineRows.get(scenarioKey(row));
227+
baselineRows.delete(scenarioKey(row));
228+
const beforeObserved = before?.unit === row.unit ? before.observed : undefined;
229+
const pass = row.observed <= row.ceiling;
230+
failed ||= !pass;
231+
if (beforeObserved === undefined) withoutBaseline += 1;
232+
const line = `| ${providerLabel(provider)} | \`${row.phase}\` | \`${row.metric}\` | ${beforeObserved === undefined ? "—" : formatValue(beforeObserved, row.unit)} | ${formatValue(row.observed, row.unit)} | ${formatImpact(row.observed, beforeObserved, row.unit)} | ${formatValue(row.ceiling, row.unit)} | ${pass ? "✅" : "❌"} |`;
233+
all.push(line);
234+
if (!pass || (beforeObserved !== undefined && beforeObserved !== row.observed)) {
235+
notable.push(line);
236+
}
237+
if (beforeObserved !== undefined && before.ceiling !== row.ceiling) {
238+
ceilingChanges.push(
239+
`- ${providerLabel(provider)} \`${row.phase}\` \`${row.metric}\`: ${formatValue(before.ceiling, row.unit)} → ${formatValue(row.ceiling, row.unit)}`,
240+
);
241+
}
242+
}
243+
for (const before of baselineRows.values()) {
244+
removed.push(
245+
`| ${providerLabel(provider)} | \`${before.phase}\` | \`${before.metric}\` | ${formatValue(before.observed, before.unit)} | — | removed | — | ⚠️ |`,
246+
);
247+
}
248+
}
249+
250+
const compared = all.length - withoutBaseline;
251+
const summary = !baseline
252+
? `No \`main\` baseline exists yet for these ${all.length} scenario measurements.`
253+
: [
254+
notable.length > 0
255+
? `${notable.length} of ${all.length} scenario measurements changed or failed.`
256+
: `${compared === all.length && removed.length === 0 ? "All " : ""}${compared} scenario measurements match \`main\`.`,
257+
...(withoutBaseline > 0 ? [`${withoutBaseline} have no \`main\` baseline.`] : []),
258+
...(removed.length > 0
259+
? [`${removed.length} measured on \`main\` are missing from this PR.`]
260+
: []),
261+
].join(" ");
262+
const listed = [...notable, ...removed];
263+
return {
264+
failed,
265+
removed: removed.length,
266+
lines: [
267+
"### Other scenarios",
268+
"",
269+
summary,
270+
...(listed.length > 0 ? ["", ...header, ...listed] : []),
271+
"",
272+
"<details>",
273+
`<summary>All ${all.length} scenario measurements</summary>`,
274+
"",
275+
...header,
276+
...all,
277+
"",
278+
"</details>",
279+
"",
280+
],
281+
};
282+
}
283+
140284
function renderComment(input) {
141285
const current = input.current;
142286
const baseline = input.baseline;
@@ -155,16 +299,22 @@ function renderComment(input) {
155299
const pass = observed <= ceiling;
156300
failed ||= !pass;
157301
rows.push(
158-
`| ${provider === "codex" ? "Codex" : "Claude"} | ${metric.label} | ${baselineObserved === undefined ? "—" : formatValue(baselineObserved, metric.kind)} | ${formatValue(observed, metric.kind)} | ${formatImpact(observed, baselineObserved, metric.kind)} | ${formatValue(ceiling, metric.kind)} | ${pass ? "✅" : "❌"} |`,
302+
`| ${providerLabel(provider)} | ${metric.label} | ${baselineObserved === undefined ? "—" : formatValue(baselineObserved, metric.kind)} | ${formatValue(observed, metric.kind)} | ${formatImpact(observed, baselineObserved, metric.kind)} | ${formatValue(ceiling, metric.kind)} | ${pass ? "✅" : "❌"} |`,
159303
);
160304

161305
if (comparable && baseline.providers[provider].ceiling[metric.key] !== ceiling) {
162306
ceilingChanges.push(
163-
`- ${provider === "codex" ? "Codex" : "Claude"} ${metric.label}: ${formatValue(baseline.providers[provider].ceiling[metric.key], metric.kind)} → ${formatValue(ceiling, metric.kind)}`,
307+
`- ${providerLabel(provider)} ${metric.label}: ${formatValue(baseline.providers[provider].ceiling[metric.key], metric.kind)} → ${formatValue(ceiling, metric.kind)}`,
164308
);
165309
}
166310
}
167311
}
312+
const scenarios = renderScenarios(
313+
input.currentScenarios,
314+
input.baselineScenarios,
315+
ceilingChanges,
316+
);
317+
failed ||= scenarios.failed;
168318

169319
const baselineLink = input.baselineRun
170320
? `[\`${input.baselineRun.sha.slice(0, 7)}\`](${input.baselineRun.url})`
@@ -192,7 +342,9 @@ function renderComment(input) {
192342

193343
return [
194344
COMMENT_MARKER,
195-
failed || ceilingChanges.length > 0 || (baseline && !comparable) ? ATTENTION : OK,
345+
failed || ceilingChanges.length > 0 || scenarios.removed > 0 || (baseline && !comparable)
346+
? ATTENTION
347+
: OK,
196348
resultShaMarker(input.currentRun.sha),
197349
"## Thread transfer impact",
198350
"",
@@ -205,6 +357,7 @@ function renderComment(input) {
205357
"| --- | --- | ---: | ---: | ---: | ---: | --- |",
206358
...rows,
207359
"",
360+
...scenarios.lines,
208361
`Baseline: ${baselineLink} · PR result: ${currentLink} · Source CI: ${input.currentRun.conclusion}`,
209362
"",
210363
"<details>",
@@ -214,7 +367,7 @@ function renderComment(input) {
214367
"",
215368
...PROVIDERS.map(
216369
(provider) =>
217-
`- ${provider === "codex" ? "Codex" : "Claude"} decoded thread snapshot: ${formatBytes(current.providers[provider].observed.threadSnapshotDecodedBytes)}`,
370+
`- ${providerLabel(provider)} decoded thread snapshot: ${formatBytes(current.providers[provider].observed.threadSnapshotDecodedBytes)}`,
218371
),
219372
"",
220373
"</details>",
@@ -441,7 +594,14 @@ async function publish({ github, context, core }) {
441594
url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${process.env.BASELINE_RUN_ID}`,
442595
}
443596
: undefined;
444-
const body = renderComment({ current, baseline, currentRun, baselineRun });
597+
const body = renderComment({
598+
current,
599+
baseline,
600+
currentScenarios: readScenarios(process.env.PR_RESULT_DIR),
601+
baselineScenarios: readScenarios(process.env.BASELINE_RESULT_DIR),
602+
currentRun,
603+
baselineRun,
604+
});
445605
await core.summary.addRaw(body).write();
446606
const published = await upsertCommentForCurrentHead(
447607
github,
@@ -463,4 +623,5 @@ module.exports = {
463623
resolve,
464624
upsertCommentForCurrentHead,
465625
validateResult,
626+
validateScenarios,
466627
};

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.