fix(executor-core): F-P-004 cache AST across invoke() re-entry (per-Engine cache)
Two paths bypassed the AST cache: LocalExecutorClient::execute (tests + fallback) and the synchronous invoke() re-entry in the executor SDK. The latter is the hot one — composed workflows multiplied parse cost by depth, so a 4-deep invoke chain on a 200-line script paid the parse budget × 4 per call. Add a per-Engine HashMap<ScriptId, (updated_at, Arc<AST>)> + a `compile_for_identity(script_id, updated_at, source)` helper that behaves like LocalExecutorClient::get_or_compile but lives on the Engine. Update the SDK invoke synchronous re-entry to: resolved → compile_for_identity → execute_ast The orchestrator-core LocalExecutorClient cache (HTTP-path dispatch) is left untouched — it caches a different access pattern at a different boundary. AUDIT.md anchor: F-P-004. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -187,10 +187,21 @@ fn invoke_blocking(
|
||||
event: None,
|
||||
};
|
||||
|
||||
// Synchronous re-entry — same engine instance, same Services,
|
||||
// fresh SdkCallCx built inside Engine::execute_ast.
|
||||
// F-P-004: synchronous re-entry — route through the per-Engine
|
||||
// AST cache so each callee parses once per (script_id, updated_at),
|
||||
// not once per invoke. Composed workflows multiply parse cost by
|
||||
// depth; the cache cuts that to constant compile + N executions.
|
||||
let ast = self_engine
|
||||
.compile_for_identity(resolved.script_id, resolved.updated_at, &resolved.source)
|
||||
.map_err(|e| -> Box<EvalAltResult> {
|
||||
EvalAltResult::ErrorRuntime(
|
||||
format!("invoke({target_label}): {e}").into(),
|
||||
rhai::Position::NONE,
|
||||
)
|
||||
.into()
|
||||
})?;
|
||||
let resp = self_engine
|
||||
.execute(&resolved.source, req)
|
||||
.execute_ast(&ast, req)
|
||||
.map_err(|e| -> Box<EvalAltResult> {
|
||||
EvalAltResult::ErrorRuntime(
|
||||
format!("invoke({target_label}): {e}").into(),
|
||||
|
||||
Reference in New Issue
Block a user