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

address review (gemini): line-buffer python child output, parallelize blob stats

[._.]/ Adam Eivya953231d64cd
diff --git a/server/lib/hfCache.js b/server/lib/hfCache.js
index 1bb407fcbc..d8da3c0275 100644
--- a/server/lib/hfCache.js
+++ b/server/lib/hfCache.js
@@ -113,10 +113,11 @@ export async function inspectModelCache(repoId) {
// Each snapshot file is a symlink into ../../blobs/<hash>; a stat that
// follows the link surfaces dangling-symlink failures (interrupted
// download) as a throw. One stat per file covers both broken-link
- // detection and size accounting.
+ // detection and size accounting. Parallelize across weights — large FLUX
+ // / HiDream snapshots have hundreds of shards and sequential stats add up.
+ const stats = await Promise.all(weights.map((f) => fs.stat(f.path).catch(() => null)));
let sizeBytes = 0;
- for (const file of weights) {
- const s = await fs.stat(file.path).catch(() => null);
+ for (const s of stats) {
if (!s || s.size === 0) {
return { cached: false, sizeBytes: 0, snapshotPath };
}
diff --git a/server/lib/hfDownload.js b/server/lib/hfDownload.js
index 3084379e80..86bd786425 100644
--- a/server/lib/hfDownload.js
+++ b/server/lib/hfDownload.js
@@ -137,18 +137,32 @@ export function downloadHfRepo({ repo, revision = null, onEvent }) {
onEvent({ type: 'log', message: line });
};
- proc.stderr.on('data', (chunk) => {
- for (const l of chunk.toString().split(/[\r\n]+/)) handleLine(l);
- });
- proc.stdout.on('data', (chunk) => {
- for (const l of chunk.toString().split(/[\r\n]+/)) handleLine(l);
- });
+ // Line-buffer across chunks so a STAGE:/USER_ERROR: marker split across
+ // pipe boundaries isn't truncated and routed to the generic log path
+ // (which loses the typed-error / progress wire shape).
+ let stdoutBuf = '';
+ let stderrBuf = '';
+ const flushChunk = (chunk, key) => {
+ const buf = (key === 'stdout' ? stdoutBuf : stderrBuf) + chunk.toString();
+ const lines = buf.split(/\r?\n/);
+ const trailing = lines.pop();
+ if (key === 'stdout') stdoutBuf = trailing;
+ else stderrBuf = trailing;
+ for (const l of lines) handleLine(l);
+ };
+ proc.stderr.on('data', (chunk) => flushChunk(chunk, 'stderr'));
+ proc.stdout.on('data', (chunk) => flushChunk(chunk, 'stdout'));
proc.on('error', (err) => {
const msg = `Failed to spawn python: ${err.message}`;
onEvent({ type: 'error', message: msg, kind: 'spawn_failed' });
resolve({ ok: false, errorKind: 'spawn_failed', errorMessage: msg });
});
proc.on('close', (code, signal) => {
+ // Flush any trailing partial line the python helper emitted without a
+ // newline before exit (rare with line-buffered stderr but possible
+ // when the process is SIGKILL'd mid-write).
+ if (stdoutBuf) { handleLine(stdoutBuf); stdoutBuf = ''; }
+ if (stderrBuf) { handleLine(stderrBuf); stderrBuf = ''; }
if (killed) {
onEvent({ type: 'error', message: 'Cancelled', kind: 'cancelled' });
return resolve({ ok: false, errorKind: 'cancelled', errorMessage: 'Cancelled' });