Skip to content

Commit dc12160

Browse files
committed
Compare TestAgent worker starts on a hosted Node runner
1 parent a73e89e commit dc12160

4 files changed

Lines changed: 213 additions & 0 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: TestAgent Linux timing
2+
3+
on:
4+
push:
5+
branches: [codex/test-agent-linux-timing-1146]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
compare:
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 35
14+
steps:
15+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
16+
with:
17+
persist-credentials: false
18+
fetch-depth: 0
19+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
20+
with:
21+
node-version: "22.23.4"
22+
- uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1
23+
- uses: denoland/setup-deno@e95548e56dfa95d4e1a28d6f422fafe75c4c26fb
24+
with:
25+
deno-version: v2.9.5
26+
- name: Prepare the recorded source revisions
27+
shell: bash
28+
run: |
29+
set -euo pipefail
30+
root="$RUNNER_TEMP/test-agent-timing"
31+
mkdir -p "$root"
32+
{
33+
git rev-parse HEAD
34+
uname -a
35+
node --version
36+
pnpm --version
37+
deno --version
38+
printenv ImageOS ImageVersion || true
39+
} > "$root/runner.txt"
40+
for variant in baseline candidate; do
41+
git worktree add --detach "$RUNNER_TEMP/timing-$variant" "$(cat "scripts/diagnostics/$variant.revision")"
42+
(
43+
cd "$RUNNER_TEMP/timing-$variant"
44+
git rev-parse HEAD
45+
deno task deps
46+
deno task build:web
47+
pnpm install
48+
pnpm exec tsc --project tsconfig.node.json --noEmit
49+
) 2>&1 | tee "$root/$variant-setup.log"
50+
done
51+
- name: Compare the historical Node test on this runner
52+
shell: bash
53+
run: |
54+
set -euo pipefail
55+
root="$RUNNER_TEMP/test-agent-timing"
56+
failures=0
57+
for variant in baseline candidate; do
58+
bash -euo pipefail -s -- "$variant" "$root" <<'COMPARE' || failures=1
59+
variant="$1"
60+
root="$2"
61+
cd "$RUNNER_TEMP/timing-$variant"
62+
python3 "$GITHUB_WORKSPACE/scripts/diagnostics/test-agent-linux-overlay.py"
63+
git diff --binary > "$root/$variant-overlay.patch"
64+
{
65+
git rev-parse HEAD
66+
git hash-object packages/acp/src/provider.ts
67+
git hash-object packages/test-agent/tests/session-configuration.test.ts
68+
git hash-object packages/test-agent/src/SessionConfiguration.test.md
69+
git hash-object packages/test-agent/src/SessionConfiguration.review.md
70+
printf '%s\n' 'pnpm exec tsx --tsconfig tsconfig.node.json --test --test-concurrency=1 packages/test-agent/tests/session-configuration.test.ts'
71+
} > "$root/$variant-source.txt"
72+
export XMD_TEST_ARTIFACTS="$root/$variant-journals"
73+
status=0
74+
pnpm exec tsx --tsconfig tsconfig.node.json --test --test-concurrency=1 packages/test-agent/tests/session-configuration.test.ts > "$root/$variant-first.log" 2>&1 || status=$?
75+
echo "$status" > "$root/$variant-status.txt"
76+
sed -n 's/^# XMD_TIMING //p' "$root/$variant-first.log" > "$root/$variant-events.jsonl"
77+
tail -20 "$root/$variant-first.log"
78+
COMPARE
79+
done
80+
exit "$failures"
81+
- name: Retain comparison and first output
82+
if: always()
83+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
84+
with:
85+
name: test-agent-linux-timing-attempt-${{ github.run_attempt }}
86+
path: ${{ runner.temp }}/test-agent-timing
87+
if-no-files-found: error
88+
retention-days: "7"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
aef8e03b617f4bee07eeaa85cf49186484593982
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a73e89e7d1e72b5091d466e4e59fc5207eb684e8
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
from pathlib import Path
2+
3+
provider = Path("packages/acp/src/provider.ts")
4+
test = Path("packages/test-agent/tests/session-configuration.test.ts")
5+
6+
def replace_once(path, old, new):
7+
source = path.read_text()
8+
if source.count(old) != 1:
9+
raise ValueError(f"{path}: unexpected source for {old!r}")
10+
path.write_text(source.replace(old, new))
11+
12+
replace_once(
13+
provider,
14+
"export function* useAcpxProvider(",
15+
"let timingRuntimeCount = 0;\n\nexport function* useAcpxProvider(",
16+
)
17+
replace_once(
18+
provider,
19+
""" const dir = yield* agentCwd();
20+
const options: AcpRuntimeOptions = {""",
21+
""" const dir = yield* agentCwd();
22+
const runtime = ++timingRuntimeCount;
23+
const launches = new Map<string, number>();
24+
const sessions = new Map<string, number>();
25+
const active = new Set<number>();
26+
const requests = new Map<number | string, string>();
27+
function trace(event: Record<string, string | number | null | number[]>) {
28+
console.log("XMD_TIMING " + JSON.stringify({ ms: performance.now(), runtime, ...event }));
29+
}
30+
const options: AcpRuntimeOptions = {""",
31+
)
32+
replace_once(
33+
provider,
34+
""" agentRegistry: registry,
35+
permissionMode: providerOptions.permissionMode,
36+
nonInteractivePermissions: "deny",
37+
};
38+
if (agentName !== undefined""",
39+
""" agentRegistry: registry,
40+
permissionMode: providerOptions.permissionMode,
41+
nonInteractivePermissions: "deny",
42+
processLifecycle: {
43+
onBeforeSpawn({ launchId, scope }) {
44+
const launch = launches.size + 1;
45+
launches.set(launchId, launch);
46+
if (scope.kind === "runtime-session" && !sessions.has(scope.sessionKey)) {
47+
sessions.set(scope.sessionKey, sessions.size + 1);
48+
}
49+
trace({ event: "before-spawn", launch, scope: scope.kind,
50+
session: scope.kind === "runtime-session" ? sessions.get(scope.sessionKey) ?? null : null });
51+
},
52+
onSpawned({ launchId, scope }) {
53+
const launch = launches.get(launchId);
54+
if (launch !== undefined) {
55+
if (scope.kind === "runtime-session") {
56+
active.add(launch);
57+
}
58+
trace({ event: "spawned", launch });
59+
}
60+
},
61+
onSpawnFailed({ launchId }) {
62+
trace({ event: "spawn-failed", launch: launches.get(launchId) ?? null });
63+
},
64+
onExit({ launchId, exitCode, signal }) {
65+
const launch = launches.get(launchId);
66+
if (launch !== undefined) {
67+
active.delete(launch);
68+
trace({ event: "exit", launch, exitCode, signal });
69+
}
70+
},
71+
},
72+
onAcpMessage(direction, message) {
73+
if (typeof message !== "object" || message === null ||
74+
!("id" in message) || (typeof message.id !== "string" && typeof message.id !== "number")) {
75+
return;
76+
}
77+
if (direction === "outbound" && "method" in message && typeof message.method === "string") {
78+
requests.set(message.id, message.method);
79+
trace({ event: "request", method: message.method, launches: [...active] });
80+
} else if (direction === "inbound" && !("method" in message)) {
81+
const method = requests.get(message.id);
82+
if (method !== undefined) {
83+
requests.delete(message.id);
84+
trace({ event: "response", method, launches: [...active] });
85+
}
86+
}
87+
},
88+
};
89+
if (agentName !== undefined""",
90+
)
91+
replace_once(
92+
test,
93+
""" const origin = performance.now();
94+
yield* NativeSessionObserver.set((report) =>
95+
sessions.push({ ...report, elapsedMs: performance.now() - origin }),
96+
);""",
97+
""" const origin = performance.now();
98+
const scenarios = new Map<string, number>();
99+
console.log("XMD_TIMING " + JSON.stringify({
100+
event: "run-start", ms: origin, fixture: path.basename(doc),
101+
}));
102+
yield* NativeSessionObserver.set((report) => {
103+
if (!scenarios.has(report.scenarioId)) {
104+
scenarios.set(report.scenarioId, scenarios.size + 1);
105+
}
106+
const ms = performance.now();
107+
sessions.push({ ...report, elapsedMs: ms - origin });
108+
console.log("XMD_TIMING " + JSON.stringify({
109+
event: "receipt", ms, scenario: scenarios.get(report.scenarioId),
110+
}));
111+
});""",
112+
)
113+
replace_once(
114+
test,
115+
""" const results = yield* testing.results;
116+
return { result, output: next.value, results, sessions };""",
117+
""" const results = yield* testing.results;
118+
console.log("XMD_TIMING " + JSON.stringify({
119+
event: "run-result", ms: performance.now(), fixture: path.basename(doc),
120+
results: results.map(({ name, status, error }) => ({ name, status, error: error?.kind })),
121+
}));
122+
return { result, output: next.value, results, sessions };""",
123+
)

0 commit comments

Comments
 (0)