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

fix: bound duplicate batches and reject invalid paths (#6344)

[._.]/ Adam Eivyd9e6036b43eb
diff --git a/client/src/components/models/DuplicateModelWeights.jsx b/client/src/components/models/DuplicateModelWeights.jsx
index be00faf2d3..88a74f9fea 100644
--- a/client/src/components/models/DuplicateModelWeights.jsx
+++ b/client/src/components/models/DuplicateModelWeights.jsx
@@ -18,14 +18,22 @@ export default function DuplicateModelWeights({ duplicates, locked, onRefresh })
busyRef.current = true;
setBusy(true);
const pairs = pending.map(({ sourcePath, targetPath }) => ({ sourcePath, targetPath }));
- const outcome = await rectifyModelDuplicates({ pairs, mode: 'hardlink' }, { silent: true })
- .then((value) => ({ value }), (error) => ({ error }));
- setPending(null);
- if (outcome.error) toast.error(outcome.error.message || 'Could not link model weights');
- else {
- setCompleted((previous) => new Set([...previous, ...pairs.map((pair) => pair.targetPath)]));
- toast.success(`Linked model weights · ${formatBytes(outcome.value.reclaimedBytes)} reclaimed`);
+ let reclaimedBytes = 0;
+ let failure = null;
+ for (let offset = 0; offset < pairs.length; offset += 200) {
+ const batch = pairs.slice(offset, offset + 200);
+ const outcome = await rectifyModelDuplicates({ pairs: batch, mode: 'hardlink' }, { silent: true })
+ .then((value) => ({ value }), (error) => ({ error }));
+ if (outcome.error) {
+ failure = outcome.error;
+ break;
+ }
+ reclaimedBytes += outcome.value.reclaimedBytes;
+ setCompleted((previous) => new Set([...previous, ...batch.map((pair) => pair.targetPath)]));
}
+ setPending(null);
+ if (failure) toast.error(failure.message || 'Could not link model weights');
+ else toast.success(`Linked model weights · ${formatBytes(reclaimedBytes)} reclaimed`);
// Refresh even on failure: a batch may have completed earlier replacements.
await onRefresh();
busyRef.current = false;
diff --git a/server/routes/systemResources.js b/server/routes/systemResources.js
index 7d04d71c1f..bc62b64d02 100644
--- a/server/routes/systemResources.js
+++ b/server/routes/systemResources.js
@@ -13,14 +13,13 @@ import { EFFORT_LEVELS } from '../lib/providerModels.js';
import { onClientDisconnect } from '../lib/sseDownload.js';
import { stopRun } from '../services/runner.js';
import { getSystemResourceReport, triageSystemResources } from '../services/systemResources.js';
-
import { rectifyModelDuplicates } from '../services/modelDeduplication.js';
const router = Router();
const duplicatePairsSchema = z.object({
pairs: z.array(z.object({
- sourcePath: z.string().min(1).max(4096),
- targetPath: z.string().min(1).max(4096),
+ sourcePath: z.string().min(1).max(4096).refine((path) => !path.includes('\0'), 'Invalid model path'),
+ targetPath: z.string().min(1).max(4096).refine((path) => !path.includes('\0'), 'Invalid model path'),
}).strict()).min(1).max(200),
mode: z.literal('hardlink').default('hardlink'),
}).strict();
diff --git a/server/services/modelDeduplication.js b/server/services/modelDeduplication.js
index c6e4c1742f..96c32fbaef 100644
--- a/server/services/modelDeduplication.js
+++ b/server/services/modelDeduplication.js
@@ -85,6 +85,12 @@ export async function scanModelDuplicates({ roots } = {}) {
if (!roots) return { pinokioDetected: false, items: [], totalReclaimableBytes: 0 };
const local = await inventory(roots.local);
const external = await inventory(roots.external);
+ const candidates = new Map();
+ for (const file of local) {
+ const key = `${file.name}:${file.info.size}`;
+ if (!candidates.has(key)) candidates.set(key, []);
+ candidates.get(key).push(file);
+ }
const hashes = new Map();
const hash = (file) => {
const key = identity(file.info);
@@ -95,8 +101,7 @@ export async function scanModelDuplicates({ roots } = {}) {
const seen = new Set();
for (const target of external) {
if (seen.has(target.real)) continue;
- for (const source of local) {
- if (source.info.size !== target.info.size || source.name !== target.name) continue;
+ for (const source of candidates.get(`${target.name}:${target.info.size}`) || []) {
const alreadyLinked = identity(source.info) === identity(target.info);
if (!alreadyLinked && await hash(source) !== await hash(target)) continue;
// A target with other hardlink names cannot release blocks by replacing