Skip to content

Commit 24444be

Browse files
committed
merge: query-failure cap SQL errors only review-comment fixes
2 parents 4ed6b99 + 614a7a9 commit 24444be

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

internal-packages/dashboard-agent/src/tool-api.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,14 @@ export function buildApiTools(args: {
351351
const result = await postQuery(query, period);
352352
if (isEnvUnavailable(result)) return envUnavailableError(result, "query");
353353
if (!result.ok) {
354-
consecutiveQueryFailures++;
355-
if (consecutiveQueryFailures >= MAX_CONSECUTIVE_QUERY_FAILURES) {
356-
return {
357-
error: `${result.error} That is ${consecutiveQueryFailures} queries in a row that failed. Stop querying and answer the user with what you already have.`,
358-
};
354+
// Only SQL errors count toward the cap; transport errors are transient.
355+
if (result.kind === "query") {
356+
consecutiveQueryFailures++;
357+
if (consecutiveQueryFailures >= MAX_CONSECUTIVE_QUERY_FAILURES) {
358+
return {
359+
error: `${result.error} That is ${consecutiveQueryFailures} queries in a row that failed. Stop querying and answer the user with what you already have.`,
360+
};
361+
}
359362
}
360363
return { error: result.error };
361364
}

internal-packages/dashboard-agent/src/tool-query-retry-cap.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ const failure = {
3030
kind: "query" as const,
3131
error: "Unknown expression identifier 'createdAt'.",
3232
};
33+
const transportFailure = {
34+
ok: false as const,
35+
kind: "transport" as const,
36+
error: "The environment is temporarily unavailable.",
37+
};
3338
const success = { ok: true as const, rows: [{ n: 1 }] };
3439

3540
describe("run_query's consecutive-failure cap", () => {
@@ -70,4 +75,16 @@ describe("run_query's consecutive-failure cap", () => {
7075

7176
expect(result.error).toBe(failure.error);
7277
});
78+
79+
it("does not count transport errors toward the cap", async () => {
80+
const run = queryTool(async () => transportFailure);
81+
82+
let result: { error: string } = { error: "" };
83+
for (let attempt = 0; attempt < MAX_CONSECUTIVE_QUERY_FAILURES + 2; attempt++) {
84+
result = await run("SELECT createdAt FROM runs");
85+
}
86+
87+
expect(result.error).toBe(transportFailure.error);
88+
expect(result.error).not.toContain("answer the user with what you already have");
89+
});
7390
});

0 commit comments

Comments
 (0)