Skip to content

Commit ce6d97d

Browse files
fix(plugins): suppress metadata cache hit scan spans (#86796)
Merged via squash. Prepared head SHA: a4907bf Co-authored-by: galiniliev <[email protected]> Co-authored-by: vincentkoc <[email protected]> Reviewed-by: @vincentkoc
1 parent d1c2934 commit ce6d97d

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

src/plugins/plugin-metadata-snapshot.memo.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,36 @@ describe("loadPluginMetadataSnapshot process memo", () => {
274274
expect(second.byPluginId.get("demo")).toBe(second.plugins[0]);
275275
});
276276

277+
it("does not emit metadata scan spans for hot memo hits", () => {
278+
const stateDir = tempStateDir();
279+
const timelinePath = path.join(stateDir, "timeline", "metadata.jsonl");
280+
const env = {
281+
OPENCLAW_DIAGNOSTICS: "timeline",
282+
OPENCLAW_DIAGNOSTICS_TIMELINE_PATH: timelinePath,
283+
};
284+
touchPersistedIndex(stateDir);
285+
loadPluginRegistrySnapshotWithMetadata.mockReturnValue({
286+
source: "persisted",
287+
snapshot: makeIndex(),
288+
diagnostics: [],
289+
});
290+
291+
loadPluginMetadataSnapshot({ config: {}, env, stateDir });
292+
loadPluginMetadataSnapshot({ config: {}, env, stateDir });
293+
loadPluginMetadataSnapshot({ config: {}, env, stateDir });
294+
295+
const events = fs
296+
.readFileSync(timelinePath, "utf8")
297+
.trim()
298+
.split("\n")
299+
.map((line) => JSON.parse(line) as { name?: unknown; type?: unknown });
300+
expect(events.map((event) => [event.type, event.name])).toEqual([
301+
["span.start", "plugins.metadata.scan"],
302+
["span.end", "plugins.metadata.scan"],
303+
]);
304+
expect(loadPluginRegistrySnapshotWithMetadata).toHaveBeenCalledOnce();
305+
});
306+
277307
it("skips persisted registry filesystem fingerprints after a process memo hit", () => {
278308
const stateDir = tempStateDir();
279309
touchPersistedIndex(stateDir);

src/plugins/plugin-metadata-snapshot.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -578,16 +578,7 @@ export function loadPluginMetadataSnapshot(
578578
const memoKey = computePluginMetadataSnapshotMemoKey({ params, registryState });
579579
const memo = findPluginMetadataSnapshotMemo(memoKey);
580580
if (memo?.key === memoKey) {
581-
return measureDiagnosticsTimelineSpanSync("plugins.metadata.scan", () => memo.snapshot, {
582-
phase: activeTimelineSpan?.phase ?? "startup",
583-
config: params.config,
584-
env: params.env,
585-
attributes: {
586-
cacheHit: true,
587-
hasWorkspaceDir: params.workspaceDir !== undefined,
588-
hasInstalledIndex: params.index !== undefined,
589-
},
590-
});
581+
return memo.snapshot;
591582
}
592583

593584
const result = measureDiagnosticsTimelineSpanSync(

0 commit comments

Comments
 (0)