ausername-12345 commited on
Commit
2a0602e
·
1 Parent(s): 131e0a6

fix: guard /data access behind USE_PERSISTENT_STORAGE env var to prevent startup hang on slow mounts

Browse files
Files changed (1) hide show
  1. src/toolManager.js +14 -13
src/toolManager.js CHANGED
@@ -2,25 +2,26 @@ const fs = require('fs');
2
  const path = require('path');
3
  const { nanoid } = require('nanoid');
4
 
5
- // Prefer Hugging Face's persistent storage mount (/data) when it exists and is
6
- // writable, so tools survive Space restarts. Falls back to a local folder,
7
- // which is wiped whenever the Space rebuilds.
8
  function resolveBaseDir() {
9
- const candidate = '/data/forge-tools';
10
- try {
11
- fs.mkdirSync(candidate, { recursive: true });
12
- fs.accessSync(candidate, fs.constants.W_OK);
13
- return candidate;
14
- } catch {
15
- const fallback = path.join(__dirname, '..', 'tools');
16
- fs.mkdirSync(fallback, { recursive: true });
17
- return fallback;
18
  }
 
 
 
19
  }
20
 
21
  const BASE_DIR = resolveBaseDir();
22
  const MANIFEST_PATH = path.join(BASE_DIR, 'manifest.json');
23
- const usingPersistentStorage = BASE_DIR.startsWith('/data');
24
 
25
  function loadManifest() {
26
  try {
 
2
  const path = require('path');
3
  const { nanoid } = require('nanoid');
4
 
5
+ // Persist tools to /data (HF persistent storage) when USE_PERSISTENT_STORAGE
6
+ // is explicitly set. Defaults to the local tools/ directory to avoid hanging
7
+ // on a slow/broken network mount during startup.
8
  function resolveBaseDir() {
9
+ if (process.env.USE_PERSISTENT_STORAGE) {
10
+ const candidate = '/data/forge-tools';
11
+ try {
12
+ fs.mkdirSync(candidate, { recursive: true });
13
+ fs.accessSync(candidate, fs.constants.W_OK);
14
+ return candidate;
15
+ } catch {}
 
 
16
  }
17
+ const fallback = path.join(__dirname, '..', 'tools');
18
+ fs.mkdirSync(fallback, { recursive: true });
19
+ return fallback;
20
  }
21
 
22
  const BASE_DIR = resolveBaseDir();
23
  const MANIFEST_PATH = path.join(BASE_DIR, 'manifest.json');
24
+ const usingPersistentStorage = !!(process.env.USE_PERSISTENT_STORAGE && BASE_DIR.startsWith('/data'));
25
 
26
  function loadManifest() {
27
  try {