Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

bound the Hub publish-date lookup so a stalled Hub can't hang the MTPLX search

[._.]/ Adam Eivy129da56085f2
diff --git a/client/src/utils/formatters.js b/client/src/utils/formatters.js
index ab902e49bd..7505c16f94 100644
--- a/client/src/utils/formatters.js
+++ b/client/src/utils/formatters.js
@@ -249,8 +249,8 @@ export function formatAgeDays(value, fallback = '') {
const time = new Date(value).getTime();
if (!Number.isFinite(time)) return fallback;
const days = Math.floor((Date.now() - time) / 86400000);
- if (days < 0) return 'today'; // A clock skew ahead of the publish date is not "-1 days old".
- if (days === 0) return 'today';
+ // <= 0 covers a clock skew ahead of the publish date — never "-1 days old".
+ if (days <= 0) return 'today';
return `${days.toLocaleString()} day${days === 1 ? '' : 's'} old`;
}
diff --git a/server/services/huggingFaceCatalog.js b/server/services/huggingFaceCatalog.js
index 5ae8f41810..90a4e76367 100644
--- a/server/services/huggingFaceCatalog.js
+++ b/server/services/huggingFaceCatalog.js
@@ -1343,11 +1343,26 @@ export function applyMeasuredFit(models, { backend, measured } = {}) {
// Never throws and never fails the caller's list: a repo the Hub has no answer
// for (gated, renamed, offline) resolves to `null`, which the UI renders as a
// missing age rather than an error.
-export async function fetchRepoPublishedDates(repoIds = []) {
+export async function fetchRepoPublishedDates(repoIds = [], { timeoutMs = CATALOG_ENRICH_TIMEOUT_MS } = {}) {
const unique = [...new Set(repoIds.filter((id) => typeof id === 'string' && id.includes('/')))]
- const settled = await Promise.allSettled(unique.map((repo) => fetchRepoModel(repo)))
- return Object.fromEntries(unique.map((repo, i) => {
- const model = settled[i].status === 'fulfilled' ? settled[i].value : null
- return [repo, model?.createdAt || model?.created_at || null]
+ // Seeded with nulls and filled in place, so the budget below can return early
+ // with a partial answer instead of an empty one.
+ const dates = Object.fromEntries(unique.map((repo) => [repo, null]))
+ const work = Promise.allSettled(unique.map(async (repo) => {
+ const model = await fetchRepoModel(repo)
+ dates[repo] = model?.createdAt || model?.created_at || null
}))
+ // Bound the wait exactly as enrichCatalogWithVariants does: a listing of 24
+ // repos is 6 rounds through a gate of 4, each round up to the 12s fetch budget
+ // plus a retry, so an unreachable Hub would otherwise turn an instant search
+ // into a minute-long hang. Whatever resolved in time is already in `dates`; the
+ // rest stay null and their probes keep warming the repo cache for the next search.
+ if (timeoutMs > 0) {
+ let timer
+ const budget = new Promise((resolve) => { timer = setTimeout(resolve, timeoutMs); timer.unref?.() })
+ await Promise.race([work.finally(() => clearTimeout(timer)), budget])
+ } else {
+ await work
+ }
+ return dates
}
diff --git a/server/services/huggingFaceCatalog.test.js b/server/services/huggingFaceCatalog.test.js
index 08a8bcc40a..ce512eef97 100644
--- a/server/services/huggingFaceCatalog.test.js
+++ b/server/services/huggingFaceCatalog.test.js
@@ -1329,6 +1329,15 @@ describe('fetchRepoPublishedDates', () => {
})
})
+ it('returns a partial answer rather than hanging the caller when the Hub stalls', async () => {
+ // A listing of two dozen repos is several rounds through the shared gate, so an
+ // unresponsive Hub must not hold the search open — unanswered repos come back null.
+ fetch.mockImplementation(() => new Promise(() => {}))
+
+ expect(await fetchRepoPublishedDates(['pub-owner/Slow'], { timeoutMs: 20 }))
+ .toEqual({ 'pub-owner/Slow': null })
+ })
+
it('ignores ids that are not owner/name rather than asking the Hub about them', async () => {
expect(await fetchRepoPublishedDates(['not-a-repo', null, 42])).toEqual({})
expect(fetch).not.toHaveBeenCalled()