Skip to content

Commit edcf862

Browse files
committed
fix(mantis): finish interrupted telegram proof sessions
1 parent 78d226b commit edcf862

3 files changed

Lines changed: 80 additions & 35 deletions

File tree

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ jobs:
484484
- name: Release leaked Telegram proof leases
485485
if: ${{ always() }}
486486
env:
487+
CRABBOX_PROVIDER: ${{ needs.resolve_request.outputs.crabbox_provider }}
487488
OPENCLAW_QA_CONVEX_SECRET_CI: ${{ secrets.OPENCLAW_QA_CONVEX_SECRET_CI }}
488489
OPENCLAW_QA_CONVEX_SITE_URL: ${{ secrets.OPENCLAW_QA_CONVEX_SITE_URL }}
489490
shell: bash
@@ -492,17 +493,34 @@ jobs:
492493
if [[ ! -d .artifacts/qa-e2e ]]; then
493494
exit 0
494495
fi
496+
status=0
497+
mapfile -d '' session_files < <(sudo find .artifacts/qa-e2e -path '*/telegram-user-crabbox/*/session.json' -type f -print0)
498+
for session_file in "${session_files[@]}"; do
499+
lease_file="${session_file%/session.json}/.session/lease.json"
500+
if [[ ! -f "$lease_file" ]]; then
501+
continue
502+
fi
503+
if ! sudo -u codex env \
504+
OPENCLAW_QA_CONVEX_SECRET_CI="$OPENCLAW_QA_CONVEX_SECRET_CI" \
505+
OPENCLAW_QA_CONVEX_SITE_URL="$OPENCLAW_QA_CONVEX_SITE_URL" \
506+
OPENCLAW_TELEGRAM_USER_CRABBOX_BIN=/usr/local/bin/crabbox \
507+
OPENCLAW_TELEGRAM_USER_CRABBOX_PROVIDER="$CRABBOX_PROVIDER" \
508+
node --import tsx "$GITHUB_WORKSPACE/scripts/e2e/telegram-user-crabbox-proof.ts" \
509+
finish --session "$session_file" --preview-crop telegram-window; then
510+
status=1
511+
fi
512+
done
495513
mapfile -d '' lease_files < <(sudo find .artifacts/qa-e2e -path '*/telegram-user-crabbox/*/.session/lease.json' -type f -print0)
496-
if [[ "${#lease_files[@]}" -eq 0 ]]; then
497-
exit 0
498-
fi
499514
for lease_file in "${lease_files[@]}"; do
500-
sudo -u codex env \
515+
if ! sudo -u codex env \
501516
OPENCLAW_QA_CONVEX_SECRET_CI="$OPENCLAW_QA_CONVEX_SECRET_CI" \
502517
OPENCLAW_QA_CONVEX_SITE_URL="$OPENCLAW_QA_CONVEX_SITE_URL" \
503518
node --import tsx "$GITHUB_WORKSPACE/scripts/e2e/telegram-user-credential.ts" \
504-
release --lease-file "$lease_file"
519+
release --lease-file "$lease_file"; then
520+
status=1
521+
fi
505522
done
523+
exit "$status"
506524
507525
- name: Inspect Mantis evidence manifest
508526
id: inspect

scripts/e2e/telegram-user-crabbox-proof.ts

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -847,38 +847,46 @@ async function startLocalSutDaemon(params: {
847847
const requestLog = path.join(params.outputDir, "mock-openai-requests.ndjson");
848848
const mockLog = path.join(params.outputDir, "mock-openai.log");
849849
const gatewayLog = path.join(params.outputDir, "gateway.log");
850-
const mockPid = spawnDaemon({
851-
command: "node",
852-
args: ["scripts/e2e/mock-openai-server.mjs"],
853-
cwd: params.repoRoot,
854-
env: mockServerEnv({ ...params, requestLog }),
855-
logPath: mockLog,
856-
});
857-
if (!mockPid) {
858-
throw new Error("mock-openai did not start.");
859-
}
860-
await waitForLog(mockLog, /mock-openai listening/u, "mock-openai", 10_000);
850+
let mockPid: number | undefined;
851+
let gatewayPid: number | undefined;
852+
try {
853+
mockPid = spawnDaemon({
854+
command: "node",
855+
args: ["scripts/e2e/mock-openai-server.mjs"],
856+
cwd: params.repoRoot,
857+
env: mockServerEnv({ ...params, requestLog }),
858+
logPath: mockLog,
859+
});
860+
if (!mockPid) {
861+
throw new Error("mock-openai did not start.");
862+
}
863+
await waitForLog(mockLog, /mock-openai listening/u, "mock-openai", 10_000);
861864

862-
const gatewayPid = spawnDaemon({
863-
command: "pnpm",
864-
args: ["openclaw", "gateway", "--port", String(params.gatewayPort)],
865-
cwd: params.repoRoot,
866-
env: gatewayEnv({ ...config, sutToken: params.sutToken }),
867-
logPath: gatewayLog,
868-
});
869-
if (!gatewayPid) {
870-
throw new Error("gateway did not start.");
865+
gatewayPid = spawnDaemon({
866+
command: "pnpm",
867+
args: ["openclaw", "gateway", "--port", String(params.gatewayPort)],
868+
cwd: params.repoRoot,
869+
env: gatewayEnv({ ...config, sutToken: params.sutToken }),
870+
logPath: gatewayLog,
871+
});
872+
if (!gatewayPid) {
873+
throw new Error("gateway did not start.");
874+
}
875+
await waitForLog(gatewayLog, /\[gateway\] ready/u, "gateway", 60_000);
876+
return {
877+
...config,
878+
drained,
879+
gatewayLog,
880+
gatewayPid,
881+
mockLog,
882+
mockPid,
883+
requestLog,
884+
};
885+
} catch (error) {
886+
killPidTree(gatewayPid);
887+
killPidTree(mockPid);
888+
throw error;
871889
}
872-
await waitForLog(gatewayLog, /\[gateway\] ready/u, "gateway", 60_000);
873-
return {
874-
...config,
875-
drained,
876-
gatewayLog,
877-
gatewayPid,
878-
mockLog,
879-
mockPid,
880-
requestLog,
881-
};
882890
}
883891

884892
function extractLeaseId(output: string) {

test/scripts/mantis-telegram-desktop-proof-workflow.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,32 @@ describe("Mantis Telegram Desktop proof workflow", () => {
155155
expect(cleanupStep.env?.OPENCLAW_QA_CONVEX_SITE_URL).toContain(
156156
"secrets.OPENCLAW_QA_CONVEX_SITE_URL",
157157
);
158+
expect(cleanupStep.env?.CRABBOX_PROVIDER).toContain(
159+
"needs.resolve_request.outputs.crabbox_provider",
160+
);
158161
expect(cleanupStep.run).toContain("sudo find .artifacts/qa-e2e");
162+
expect(cleanupStep.run).toContain("*/telegram-user-crabbox/*/session.json");
163+
expect(cleanupStep.run).toContain("telegram-user-crabbox-proof.ts");
164+
expect(cleanupStep.run).toContain(
165+
'finish --session "$session_file" --preview-crop telegram-window',
166+
);
159167
expect(cleanupStep.run).toContain("*/telegram-user-crabbox/*/.session/lease.json");
160168
expect(cleanupStep.run).toContain("telegram-user-credential.ts");
161169
expect(cleanupStep.run).toContain("release --lease-file");
170+
expect(cleanupStep.run).toContain("status=1");
162171
expect(cleanupStep.run).toContain("sudo -u codex env");
163172
});
164173

174+
it("cleans partially started proof daemons when local SUT startup fails", () => {
175+
const proofScript = readFileSync(PROOF_SCRIPT, "utf8");
176+
177+
expect(proofScript).toContain("let mockPid: number | undefined;");
178+
expect(proofScript).toContain("let gatewayPid: number | undefined;");
179+
expect(proofScript).toContain("killPidTree(gatewayPid);");
180+
expect(proofScript).toContain("killPidTree(mockPid);");
181+
expect(proofScript).toContain("throw error;");
182+
});
183+
165184
it("uses the OpenClaw Mantis mention as the comment trigger", () => {
166185
const workflow = readFileSync(WORKFLOW, "utf8");
167186
const liveWorkflow = readFileSync(LIVE_WORKFLOW, "utf8");

0 commit comments

Comments
 (0)