From 5a45b76c80b394c720663ccb4d12bc27149de28c Mon Sep 17 00:00:00 2001 From: ruv Date: Sun, 27 Sep 2026 15:07:49 -0400 Subject: [PATCH] perf(hooks): restore the in-memory fast path for trajectory lookups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #3467 made loadPendingTrajectory() always do two DB reads (completed + pending) before returning, even when the trajectory is already tracked cleanly in-process — turning every trajectory-step/post-task call into a synchronous round-trip instead of a Map lookup. CI's graph-trajectory-hooks-smoke (ADR-130 P3, <200ms budget) failed once on a loaded runner at 1171ms; local runs stayed at 20-46ms, so this was likely a transient load spike, but the always-hit-disk path was real overhead regardless. Skip both reads when the id is already a clean (non-dirty) in-memory hit — the case #3467 didn't change (same-process, not-yet-restarted). The disk-recovery path #3467 added still runs exactly when it's needed: on a cache miss (e.g. after an MCP restart). --- v3/@claude-flow/cli/src/mcp-tools/hooks-tools.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/v3/@claude-flow/cli/src/mcp-tools/hooks-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/hooks-tools.ts index 1e608ac6f6..58156b91da 100644 --- a/v3/@claude-flow/cli/src/mcp-tools/hooks-tools.ts +++ b/v3/@claude-flow/cli/src/mcp-tools/hooks-tools.ts @@ -545,6 +545,12 @@ async function persistPendingTrajectory(trajectory: TrajectoryData): Promise { + // Fast path: a clean (successfully checkpointed) in-process record was written + // by this same call chain (trajectory-start/-step) and cannot yet have been + // completed elsewhere in the same synchronous request. Trust it without a + // round-trip — ADR-130 Phase 3's <200ms-per-call budget depends on this; + // only a cache miss (e.g. after an MCP restart) pays for the disk check. + if (!dirtyTrajectories.has(id) && activeTrajectories.has(id)) return activeTrajectories.get(id); try { const { getEntry } = await import('../memory/memory-initializer.js'); // A completed record is authoritative even if pending-record cleanup failed