Increase operation timeout, add diagnostic logs, and enhance gateway stream summarization

This commit is contained in:
Jeppe Bundgaard
2026-04-23 21:36:25 +02:00
parent 0813bfc0f0
commit b98cef0caa
4 changed files with 182 additions and 23 deletions
+66 -8
View File
@@ -309,6 +309,35 @@ function collectMessages(rows) {
: [];
}
function summarizeStreamMessages(messages, limit = 12) {
return messages
.slice(-limit)
.map((message) => {
if (!message || typeof message !== "object") {
return null;
}
const summary = {
type: message.type || "unknown",
};
if (message.operationId !== undefined) {
summary.operationId = Number(message.operationId || 0);
}
if (message.operation && typeof message.operation === "object") {
summary.operationStatus = message.operation.status || null;
}
if (message.gateway && typeof message.gateway === "object") {
summary.gatewayStatus = message.gateway.status || null;
}
return summary;
})
.filter(Boolean);
}
async function main() {
const scriptPath = fileURLToPath(import.meta.url);
const rootDir = await resolveRootDir(scriptPath);
@@ -481,11 +510,32 @@ async function main() {
const operationId = Number(operationResponse?.data?.operation?.id || 0);
assert.ok(operationId > 0, "Operation creation did not return an operation id.");
await waitForSocketMessage(
streamMessages,
(message) => message?.type === "task.updated" && Number(message?.operationId || 0) === operationId,
{ timeoutMs: 30_000, message: "Live gateway stream never emitted task.updated for the queued operation." }
);
try {
await waitForSocketMessage(
streamMessages,
(message) => message?.type === "task.updated" && Number(message?.operationId || 0) === operationId,
{ timeoutMs: 180_000, message: "Live gateway stream never emitted task.updated for the queued operation." }
);
} catch (error) {
let operationSnapshot = null;
try {
const operations = await apiRequest(baseUrl, "GET", `/edge-gateways/${gatewayId}/operations`, {
token: authToken,
});
operationSnapshot = Array.isArray(operations?.data)
? operations.data.find((item) => Number(item?.id || 0) === operationId) || null
: null;
} catch {
operationSnapshot = null;
}
const diagnostic = [
error instanceof Error ? error.message : String(error),
`Recent stream messages: ${JSON.stringify(summarizeStreamMessages(streamMessages))}`,
`Operation snapshot: ${JSON.stringify(operationSnapshot)}`,
].join("\n");
throw new Error(diagnostic);
}
await waitForCondition(
async () => {
@@ -499,7 +549,7 @@ async function main() {
return operation?.status === "COMPLETED";
},
{ timeoutMs: 30_000, message: "Gateway operation never completed through the live agent." }
{ timeoutMs: 180_000, message: "Gateway operation never completed through the live agent." }
);
await waitForSocketMessage(
@@ -514,9 +564,17 @@ async function main() {
token: authToken,
});
return Array.isArray(logs?.data?.log_entries) && logs.data.log_entries.length > 0;
const timeline = Array.isArray(logs?.data?.entries) ? logs.data.entries : [];
return timeline.some((entry) => {
const nestedEntry = entry?.entry && typeof entry.entry === "object" ? entry.entry : null;
const directOperationId = Number(nestedEntry?.operation_id || 0);
const contextualOperationId = Number(nestedEntry?.context?.operation_id || 0);
return directOperationId === operationId || contextualOperationId === operationId;
});
},
{ timeoutMs: 20_000, message: "Gateway logs page never received live log entries from the running agent." }
{ timeoutMs: 30_000, message: "Gateway logs page never reflected the live operation timeline." }
);
const statistics = await apiRequest(baseUrl, "GET", `/edge-gateways/${gatewayId}/statistics`, {