Skip to content

Commit da0cb59

Browse files
authored
perf(e2e): reuse one authorized Telegram Desktop session per Mantis run (#127835)
* refactor(mantis): reuse authorized desktop captures * fix(mantis): budget desktop authorization failures * chore(mantis): bound desktop proof retries * fix(e2e): drop unused recorder failure fact type export * fix(ci): route Mantis desktop teardown through the recorder wrapper Cleanup invoked the internal recorder executable as mantis-sut, which is deliberately kept out of the docker group and cannot read the recorder-owned session file; teardown therefore failed and blocked safe_to_release. The cleanup step already runs as the recorder user, so call the public wrapper whose exec shim cds into the session root. * fix(e2e): make recorder failure fact lane-readable; document v2 lifecycle The Mantis workflow runs the recorder as the desktop user while the lane reads the authorization-failure fact as mantis-sut; 0600 made that read fail EACCES and silently disabled the two-attempt retry budget. Write the fact 0644 — the 0770 attempt directory bounds visibility. Update the mantis doc's recorder section for the v2 session lifecycle: required --session handle with healthy-session reuse, capture-only stop, and teardown owning authorization termination and lease release.
1 parent 2d0fff4 commit da0cb59

9 files changed

Lines changed: 797 additions & 253 deletions

‎.github/codex/prompts/mantis-telegram-desktop-proof.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ behavior, call `block`; do not call `finish` and describe the block only in pros
139139
Inspect `mantis-lane-facts.json`, every returned event/request, the inspection
140140
PNG, final PNG, and cropped GIF. Confirm the evaluated message is fully visible
141141
near the bottom and the recording covers the behavior—not only its final state.
142-
Iterate as needed; all attempts remain recorded.
142+
Iteration is allowed, but if `start` reports `desktop-unavailable`, record that
143+
fact and use `block`; never retry that lane. Two non-advancing repeats of the
144+
same failing step mean classify and stop, not retry. All attempts remain recorded.
143145

144146
If you design a novel working scenario worth reusing, optionally write
145147
`MANTIS_OUTPUT_DIR/recipe-suggestion.md` with its trigger, exact commands, and

‎.github/workflows/mantis-telegram-desktop-proof.yml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ jobs:
273273
needs: resolve_request
274274
if: needs.resolve_request.outputs.should_run == 'true' && needs.resolve_request.outputs.publish_artifact_name == ''
275275
runs-on: blacksmith-16vcpu-ubuntu-2404
276-
timeout-minutes: 360
276+
timeout-minutes: 120
277277
environment: qa-live-shared
278278
outputs:
279279
comparison_status: ${{ steps.inspect.outputs.comparison_status }}
@@ -934,6 +934,11 @@ jobs:
934934
abort --lane "$lane" || result=1
935935
fi
936936
done
937+
# Teardown goes through the public wrapper: this step already runs as the
938+
# recorder user, and the internal exec shim cds into the session root where
939+
# the recorder-owned session file lives. mantis-sut can do neither.
940+
/usr/local/bin/openclaw-telegram-desktop-recorder \
941+
teardown --session desktop-recorder.json || result=1
937942
if sudo test -f "$lock"; then
938943
echo "Mantis harness lock remained after cleanup." >&2
939944
result=1

‎docs/concepts/mantis.md‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,14 @@ The `Mantis Telegram Desktop Proof` workflow invokes the recorder with its
218218
local Docker provider. Its OpenClaw SUT remains isolated in the lane-attested
219219
container boundary while Telegram Desktop runs in the prebaked local image.
220220

221-
Start a fresh authorized desktop and begin recording:
221+
Start recording. `--session` names the run-scoped session handle: when it
222+
already points at a healthy authorized desktop, `start` reuses it and only
223+
begins a fresh capture in the new output directory; otherwise it provisions
224+
and QR-authorizes a desktop first.
222225

223226
```bash
224227
pnpm qa:telegram-desktop-recorder start \
228+
--session .artifacts/qa-e2e/desktop-recorder.json \
225229
--output-dir .artifacts/qa-e2e/telegram-desktop \
226230
--chat -1001234567890 \
227231
--user-driver "python3 /path/to/telegram-user-driver.py" \
@@ -231,9 +235,11 @@ pnpm qa:telegram-desktop-recorder start \
231235
Use `view --session <recorder.json> --message-id <id>` to open a recorded
232236
group post. Use `screenshot --session <recorder.json>` for a still image. Run
233237
`stop --session <recorder.json> --crop telegram-window` to copy the recording
234-
and logs, build motion GIFs, terminate the Telegram Desktop authorization, and
235-
release the Crabbox lease. Add `--keep-box` only when the lease must remain
236-
available for WebVNC inspection.
238+
and logs and build motion GIFs; the authorized desktop stays alive for the next
239+
`start`, so repeated captures skip provisioning and QR login. When the run is
240+
finished, run `teardown --session <recorder.json>` to terminate the Telegram
241+
Desktop authorization and release the Crabbox lease; the box stays inspectable
242+
over WebVNC until then.
237243

238244
The recorder defaults to Crabbox's local Docker desktop path. Build the pinned
239245
image once, then run `start` without coordinator access:

‎scripts/e2e/telegram-desktop-recorder-contract.ts‎

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,33 @@ import { z } from "zod";
44
export const TELEGRAM_DESKTOP_VERSION = "7.0.9";
55
export const TELEGRAM_DESKTOP_AWS_IMAGE = "telegram-desktop=7.0.9";
66
export const TELEGRAM_DESKTOP_DOCKER_IMAGE = "openclaw-telegram-desktop:7.0.9";
7+
export const RECORDER_AUTHORIZATION_FAILURE_FILENAME =
8+
"telegram-desktop-authorization-failure.json";
9+
10+
export const recorderAuthorizationFailureSchema = z.object({
11+
acceptedTokenCount: z.number().int().nonnegative(),
12+
classification: z.enum(["main-window-timeout", "qr-unreadable", "token-accepted-no-transition"]),
13+
failedAt: z.string(),
14+
loginScreenshotPath: z.string().optional(),
15+
qrAttemptCount: z.number().int().positive(),
16+
});
17+
18+
export const recorderAuthorizationFailureFactSchema = z.object({
19+
failures: z.array(recorderAuthorizationFailureSchema).min(1),
20+
schemaVersion: z.literal(1),
21+
});
22+
23+
export type RecorderAuthorizationFailure = z.infer<typeof recorderAuthorizationFailureSchema>;
724

825
const recorderSessionBaseSchema = z.object({
926
artifacts: z.record(z.string(), z.string()).optional(),
1027
chat: z.string().regex(/^-100\d+$/u),
1128
cleanupErrors: z.array(z.string()).optional(),
1229
desktopSessionId: z.string().min(1),
13-
keepBox: z.boolean(),
1430
leaseId: z.string().min(1),
1531
/** False when `--lease-id` borrowed an existing box: the recorder never stops it. */
1632
leaseOwned: z.boolean(),
33+
outputDir: z.string().min(1),
1734
recordFps: z.number().int().positive(),
1835
remotePaths: z.object({
1936
desktopLog: z.string(),
@@ -22,7 +39,7 @@ const recorderSessionBaseSchema = z.object({
2239
finalScreenshot: z.string(),
2340
video: z.string(),
2441
}),
25-
schemaVersion: z.literal(1),
42+
schemaVersion: z.literal(2),
2643
startedAt: z.string(),
2744
/** Telegram Desktop window as placed on the recorded desktop; the crop uses it. */
2845
window: z.object({
@@ -61,6 +78,7 @@ export type StartOptions = {
6178
outputDir: string;
6279
provider: RecorderProvider;
6380
recordFps: number;
81+
sessionPath: string;
6482
ttl: string;
6583
userDriver: string[];
6684
};
@@ -87,7 +105,11 @@ export type ScreenshotOptions = {
87105
export type StopOptions = {
88106
command: "stop";
89107
crop?: "telegram-window";
90-
keepBox: boolean;
108+
sessionPath: string;
109+
};
110+
111+
export type TeardownOptions = {
112+
command: "teardown";
91113
sessionPath: string;
92114
};
93115

@@ -114,18 +136,20 @@ type RecorderOptions =
114136
| StartOptions
115137
| StatusOptions
116138
| StopOptions
139+
| TeardownOptions
117140
| ViewOptions;
118141

119142
export function recorderUsageText(): string {
120143
return [
121144
"Usage:",
122145
" pnpm qa:telegram-desktop-recorder artifacts --session <recorder.json>",
123-
' pnpm qa:telegram-desktop-recorder start --output-dir <dir> --chat <-100groupId> --user-driver "<space-separated cmd prefix>" [options]',
146+
' pnpm qa:telegram-desktop-recorder start --session <recorder.json> --output-dir <dir> --chat <-100groupId> --user-driver "<space-separated cmd prefix>" [options]',
124147
" pnpm qa:telegram-desktop-recorder view --session <recorder.json> --message-id <id>",
125148
" pnpm qa:telegram-desktop-recorder actions --session <recorder.json> --actions-file <json> [--timeout-seconds <seconds>]",
126149
" pnpm qa:telegram-desktop-recorder screenshot --session <recorder.json> [--output <png>]",
127150
" pnpm qa:telegram-desktop-recorder recover --session <recorder.json>",
128-
" pnpm qa:telegram-desktop-recorder stop --session <recorder.json> [--crop telegram-window] [--keep-box]",
151+
" pnpm qa:telegram-desktop-recorder stop --session <recorder.json> [--crop telegram-window]",
152+
" pnpm qa:telegram-desktop-recorder teardown --session <recorder.json>",
129153
" pnpm qa:telegram-desktop-recorder status --session <recorder.json>",
130154
"",
131155
"Start options:",
@@ -173,7 +197,17 @@ export function parseRecorderArgs(argv: string[]): RecorderOptions {
173197
throw new Error(recorderUsageText());
174198
}
175199
const parsedCommand = z
176-
.enum(["actions", "artifacts", "recover", "screenshot", "start", "status", "stop", "view"])
200+
.enum([
201+
"actions",
202+
"artifacts",
203+
"recover",
204+
"screenshot",
205+
"start",
206+
"status",
207+
"stop",
208+
"teardown",
209+
"view",
210+
])
177211
.safeParse(rawCommand);
178212
if (!parsedCommand.success) {
179213
throw new Error(`Unknown command: ${rawCommand}\n\n${recorderUsageText()}`);
@@ -186,7 +220,7 @@ export function parseRecorderArgs(argv: string[]): RecorderOptions {
186220
if (!flag) {
187221
break;
188222
}
189-
if (flag === "--json" || flag === "--keep-box") {
223+
if (flag === "--json") {
190224
switches.add(flag);
191225
continue;
192226
}
@@ -210,6 +244,7 @@ export function parseRecorderArgs(argv: string[]): RecorderOptions {
210244
"--output-dir",
211245
"--provider",
212246
"--record-fps",
247+
"--session",
213248
"--ttl",
214249
"--user-driver",
215250
])
@@ -230,9 +265,6 @@ export function parseRecorderArgs(argv: string[]): RecorderOptions {
230265
if (switches.has("--json") && command !== "start") {
231266
throw new Error(`--json is not available for ${command}.`);
232267
}
233-
if (switches.has("--keep-box") && command !== "stop") {
234-
throw new Error(`--keep-box is not available for ${command}.`);
235-
}
236268
if (command === "start") {
237269
const chat = requiredString(values, "--chat");
238270
if (!/^-100\d+$/u.test(chat)) {
@@ -268,6 +300,7 @@ export function parseRecorderArgs(argv: string[]): RecorderOptions {
268300
outputDir: requiredString(values, "--output-dir"),
269301
provider,
270302
recordFps: positiveInteger(values.get("--record-fps") ?? "24", "--record-fps"),
303+
sessionPath: requiredString(values, "--session"),
271304
ttl: values.get("--ttl") ?? "2h",
272305
userDriver,
273306
};
@@ -292,12 +325,12 @@ export function parseRecorderArgs(argv: string[]): RecorderOptions {
292325
if (command === "stop") {
293326
const crop = values.get("--crop");
294327
if (crop === undefined) {
295-
return { command, keepBox: switches.has("--keep-box"), sessionPath };
328+
return { command, sessionPath };
296329
}
297330
if (crop !== "telegram-window") {
298331
throw new Error("--crop must be telegram-window.");
299332
}
300-
return { command, crop, keepBox: switches.has("--keep-box"), sessionPath };
333+
return { command, crop, sessionPath };
301334
}
302335
return { command, sessionPath };
303336
}

0 commit comments

Comments
 (0)