Skip to content

Commit bd2c504

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[Freestyler] Max timeout of Observation
Race the Observation with a timeout Promise and report the correct error to the LLM so that it can try to recover. This mitigates the issue of SideEffect's and Observations getting stuck due to Promises that never resolve. Fixed: 373893673 Change-Id: I209c3b07244bd8412fce5e4c0e47e4af1fbf6f77 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5993651 Commit-Queue: Nikolay Vitkov <[email protected]> Auto-Submit: Nikolay Vitkov <[email protected]> Reviewed-by: Alex Rudenko <[email protected]>
1 parent f62b1e3 commit bd2c504

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

front_end/panels/freestyler/FreestylerAgent.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ async function executeJsCode(
194194
}
195195

196196
const MAX_OBSERVATION_BYTE_LENGTH = 25_000;
197+
const OBSERVATION_TIMEOUT = 5_000;
197198

198199
type CreateExtensionScopeFunction = (changes: ChangeManager) => {
199200
install(): Promise<void>, uninstall(): Promise<void>,
@@ -453,10 +454,16 @@ export class FreestylerAgent extends AiAgent<SDK.DOMModel.DOMNode> {
453454
canceled: true,
454455
};
455456
}
456-
const result = await this.#execJs(
457-
functionDeclaration,
458-
{throwOnSideEffect},
459-
);
457+
const result = await Promise.race([
458+
this.#execJs(
459+
functionDeclaration,
460+
{throwOnSideEffect},
461+
),
462+
new Promise<never>((_, reject) => {
463+
setTimeout(
464+
() => reject(new Error('Script execution exceeded the maximum allowed time.')), OBSERVATION_TIMEOUT);
465+
}),
466+
]);
460467
const byteCount = Platform.StringUtilities.countWtf8Bytes(result);
461468
Host.userMetrics.freestylerEvalResponseSize(byteCount);
462469
if (byteCount > MAX_OBSERVATION_BYTE_LENGTH) {

0 commit comments

Comments
 (0)