build: fix ineffective dynamic imports with lazy boundaries (#33690)

Merged via squash.

Prepared head SHA: 38b3c23d6f
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
Gustavo Madeira Santana
2026-03-03 20:14:41 -05:00
committed by GitHub
parent a4850b1b8f
commit 21e8d88c1d
31 changed files with 330 additions and 153 deletions

View File

@@ -23,6 +23,14 @@ const adjustedParamsByToolCallId = new Map<string, unknown>();
const MAX_TRACKED_ADJUSTED_PARAMS = 1024;
const LOOP_WARNING_BUCKET_SIZE = 10;
const MAX_LOOP_WARNING_KEYS = 256;
let beforeToolCallRuntimePromise: Promise<
typeof import("./pi-tools.before-tool-call.runtime.js")
> | null = null;
function loadBeforeToolCallRuntime() {
beforeToolCallRuntimePromise ??= import("./pi-tools.before-tool-call.runtime.js");
return beforeToolCallRuntimePromise;
}
function buildAdjustedParamsKey(params: { runId?: string; toolCallId: string }): string {
if (params.runId && params.runId.trim()) {
@@ -62,8 +70,7 @@ async function recordLoopOutcome(args: {
return;
}
try {
const { getDiagnosticSessionState } = await import("../logging/diagnostic-session-state.js");
const { recordToolCallOutcome } = await import("./tool-loop-detection.js");
const { getDiagnosticSessionState, recordToolCallOutcome } = await loadBeforeToolCallRuntime();
const sessionState = getDiagnosticSessionState({
sessionKey: args.ctx.sessionKey,
sessionId: args.ctx?.agentId,
@@ -91,10 +98,8 @@ export async function runBeforeToolCallHook(args: {
const params = args.params;
if (args.ctx?.sessionKey) {
const { getDiagnosticSessionState } = await import("../logging/diagnostic-session-state.js");
const { logToolLoopAction } = await import("../logging/diagnostic.js");
const { detectToolCallLoop, recordToolCall } = await import("./tool-loop-detection.js");
const { getDiagnosticSessionState, logToolLoopAction, detectToolCallLoop, recordToolCall } =
await loadBeforeToolCallRuntime();
const sessionState = getDiagnosticSessionState({
sessionKey: args.ctx.sessionKey,
sessionId: args.ctx?.agentId,