diff --git a/src/domain/datastore/user_datastore_loader.ts b/src/domain/datastore/user_datastore_loader.ts index 2107fba4..c66d559d 100644 --- a/src/domain/datastore/user_datastore_loader.ts +++ b/src/domain/datastore/user_datastore_loader.ts @@ -251,9 +251,20 @@ export class UserDatastoreLoader { return js; } catch (bundleError) { if (bundleExists) { - logger - .warn`Rebundle failed for ${relativePath}, using cached bundle: ${bundleError}`; - return await Deno.readTextFile(bundlePath); + try { + const cached = await Deno.readTextFile(bundlePath); + logger + .warn`Rebundle failed for ${relativePath}, using cached bundle: ${bundleError}`; + // Touch the cache mtime so subsequent loads see it as fresh, + // avoiding repeated failed rebundle attempts on every cold start. + try { + const now = new Date(); + await Deno.utime(bundlePath, now, now); + } catch { /* ignore — worst case we retry next load */ } + return cached; + } catch { + // Cache file was removed between stat and read — treat as no cache. + } } throw bundleError; } diff --git a/src/domain/drivers/user_driver_loader.ts b/src/domain/drivers/user_driver_loader.ts index aa39747c..ea09050b 100644 --- a/src/domain/drivers/user_driver_loader.ts +++ b/src/domain/drivers/user_driver_loader.ts @@ -250,9 +250,20 @@ export class UserDriverLoader { return js; } catch (bundleError) { if (bundleExists) { - logger - .warn`Rebundle failed for ${relativePath}, using cached bundle: ${bundleError}`; - return await Deno.readTextFile(bundlePath); + try { + const cached = await Deno.readTextFile(bundlePath); + logger + .warn`Rebundle failed for ${relativePath}, using cached bundle: ${bundleError}`; + // Touch the cache mtime so subsequent loads see it as fresh, + // avoiding repeated failed rebundle attempts on every cold start. + try { + const now = new Date(); + await Deno.utime(bundlePath, now, now); + } catch { /* ignore — worst case we retry next load */ } + return cached; + } catch { + // Cache file was removed between stat and read — treat as no cache. + } } throw bundleError; } diff --git a/src/domain/models/user_model_loader.ts b/src/domain/models/user_model_loader.ts index 1c3beac9..672f90e2 100644 --- a/src/domain/models/user_model_loader.ts +++ b/src/domain/models/user_model_loader.ts @@ -473,9 +473,20 @@ export class UserModelLoader { return js; } catch (bundleError) { if (bundleExists) { - logger - .warn`Rebundle failed for ${relativePath}, using cached bundle: ${bundleError}`; - return await Deno.readTextFile(bundlePath); + try { + const cached = await Deno.readTextFile(bundlePath); + logger + .warn`Rebundle failed for ${relativePath}, using cached bundle: ${bundleError}`; + // Touch the cache mtime so subsequent loads see it as fresh, + // avoiding repeated failed rebundle attempts on every cold start. + try { + const now = new Date(); + await Deno.utime(bundlePath, now, now); + } catch { /* ignore — worst case we retry next load */ } + return cached; + } catch { + // Cache file was removed between stat and read — treat as no cache. + } } throw bundleError; } diff --git a/src/domain/vaults/user_vault_loader.ts b/src/domain/vaults/user_vault_loader.ts index a9d0d478..d56b0740 100644 --- a/src/domain/vaults/user_vault_loader.ts +++ b/src/domain/vaults/user_vault_loader.ts @@ -257,9 +257,20 @@ export class UserVaultLoader { return js; } catch (bundleError) { if (bundleExists) { - logger - .warn`Rebundle failed for ${relativePath}, using cached bundle: ${bundleError}`; - return await Deno.readTextFile(bundlePath); + try { + const cached = await Deno.readTextFile(bundlePath); + logger + .warn`Rebundle failed for ${relativePath}, using cached bundle: ${bundleError}`; + // Touch the cache mtime so subsequent loads see it as fresh, + // avoiding repeated failed rebundle attempts on every cold start. + try { + const now = new Date(); + await Deno.utime(bundlePath, now, now); + } catch { /* ignore — worst case we retry next load */ } + return cached; + } catch { + // Cache file was removed between stat and read — treat as no cache. + } } throw bundleError; }