Skip to content

The open-source app everyone uses to manage agents at work

fix: dedupe company skill inventory refreshes

dottaa339b488aec6
diff --git a/server/src/services/company-skills.ts b/server/src/services/company-skills.ts
index 19aeab0458..43de8ee6b9 100644
--- a/server/src/services/company-skills.ts
+++ b/server/src/services/company-skills.ts
@@ -99,6 +99,8 @@ type RuntimeSkillEntryOptions = {
materializeMissing?: boolean;
};
+const skillInventoryRefreshPromises = new Map<string, Promise<void>>();
+
const PROJECT_SCAN_DIRECTORY_ROOTS = [
"skills",
"skills/.curated",
@@ -1474,8 +1476,25 @@ export function companySkillService(db: Db) {
}
async function ensureSkillInventoryCurrent(companyId: string) {
- await ensureBundledSkills(companyId);
- await pruneMissingLocalPathSkills(companyId);
+ const existingRefresh = skillInventoryRefreshPromises.get(companyId);
+ if (existingRefresh) {
+ await existingRefresh;
+ return;
+ }
+
+ const refreshPromise = (async () => {
+ await ensureBundledSkills(companyId);
+ await pruneMissingLocalPathSkills(companyId);
+ })();
+
+ skillInventoryRefreshPromises.set(companyId, refreshPromise);
+ try {
+ await refreshPromise;
+ } finally {
+ if (skillInventoryRefreshPromises.get(companyId) === refreshPromise) {
+ skillInventoryRefreshPromises.delete(companyId);
+ }
+ }
}
async function list(companyId: string): Promise<CompanySkillListItem[]> {