Restore parallel session metadata enrichment

This commit is contained in:
Ashish Huddar 2026-04-05 17:35:14 +05:30 committed by Gaurav Bhola
parent e0b216c369
commit 27ce7d56db
2 changed files with 63 additions and 6 deletions

View File

@ -809,6 +809,41 @@ describe("enrichSessionsMetadata", () => {
expect(dashboard.issueTitle).toBe("Fix auth bug");
});
it("starts issue-title fetches before agent summaries finish", async () => {
let resolveSummary: ((value: { summary: string; summaryIsFallback: false; agentSessionId: string }) => void) | null = null;
const tracker = mockTracker("Fix auth bug");
const agent = {
...mockAgent(),
getSessionInfo: vi.fn().mockImplementation(
() => new Promise((resolve) => {
resolveSummary = resolve;
}),
),
} as Agent;
const registry = mockRegistry(tracker, agent);
const core = createCoreSession({ issueId: `${urlBase}-parallel` });
const dashboard = sessionToDashboard(core);
const enrichmentPromise = enrichSessionsMetadata([core], [dashboard], testConfig, registry);
await Promise.resolve();
expect(tracker.getIssue).toHaveBeenCalledTimes(1);
expect(dashboard.issueLabel).toBe("#42");
expect(dashboard.summary).toBeNull();
resolveSummary?.({
summary: "Implementing auth fix",
summaryIsFallback: false,
agentSessionId: "abc",
});
await enrichmentPromise;
expect(dashboard.summary).toBe("Implementing auth fix");
expect(dashboard.issueTitle).toBe("Fix auth bug");
});
it("should skip sessions without issue URLs", async () => {
const tracker = mockTracker();
const agent = mockAgent();

View File

@ -372,6 +372,25 @@ export async function enrichSessionsMetadataFast(
config: OrchestratorConfig,
registry: PluginRegistry,
): Promise<void> {
const { summaryPromises } = prepareSessionMetadataEnrichment(
coreSessions,
dashboardSessions,
config,
registry,
);
await Promise.allSettled(summaryPromises);
}
function prepareSessionMetadataEnrichment(
coreSessions: Session[],
dashboardSessions: DashboardSession[],
config: OrchestratorConfig,
registry: PluginRegistry,
): {
projects: Array<ProjectConfig | undefined>;
summaryPromises: Promise<void>[];
} {
const projects = coreSessions.map((core) => resolveProject(core, config.projects));
// Issue labels (synchronous string parsing, no API calls)
@ -392,7 +411,7 @@ export async function enrichSessionsMetadataFast(
return enrichSessionAgentSummary(dashboardSessions[i], core, agent);
});
await Promise.allSettled(summaryPromises);
return { projects, summaryPromises };
}
/**
@ -405,11 +424,14 @@ export async function enrichSessionsMetadata(
config: OrchestratorConfig,
registry: PluginRegistry,
): Promise<void> {
// Run fast enrichment first (labels + summaries)
await enrichSessionsMetadataFast(coreSessions, dashboardSessions, config, registry);
const { projects, summaryPromises } = prepareSessionMetadataEnrichment(
coreSessions,
dashboardSessions,
config,
registry,
);
// Then add issue titles (tracker API, cached with TTL)
const projects = coreSessions.map((core) => resolveProject(core, config.projects));
// Issue-title fetches depend on labels being set, but can run in parallel with summary I/O.
const issueTitlePromises = projects.map((project, i) => {
if (!dashboardSessions[i].issueUrl || !dashboardSessions[i].issueLabel) {
return Promise.resolve();
@ -420,7 +442,7 @@ export async function enrichSessionsMetadata(
return enrichSessionIssueTitle(dashboardSessions[i], tracker, project);
});
await Promise.allSettled(issueTitlePromises);
await Promise.allSettled([...summaryPromises, ...issueTitlePromises]);
}
/** Compute dashboard stats from a list of sessions. */