{"record":{"id":"9a0b9356a1023b8a","repo":"mastra-ai/mastra","slug":"some-filesystems-failed-to-destroy","errorCode":null,"errorMessage":"Some filesystems failed to destroy","messagePattern":"Some filesystems failed to destroy","errorType":"exception","errorClass":"AggregateError","httpStatus":null,"severity":"error","filePath":"packages/core/src/workspace/filesystem/composite-filesystem.ts","lineNumber":301,"sourceCode":"    }\n    // CompositeFilesystem is ready even if some mounts failed\n    // Operations on errored mounts will be handled by the underlying filesystem\n    this.status = 'ready';\n  }\n\n  async destroy(): Promise<void> {\n    this.status = 'destroying';\n    const errors: Error[] = [];\n    for (const fs of this._mounts.values()) {\n      try {\n        await callLifecycle(fs, 'destroy');\n      } catch (e) {\n        errors.push(e instanceof Error ? e : new Error(String(e)));\n      }\n    }\n    if (errors.length > 0) {\n      this.status = 'error';\n      throw new AggregateError(errors, 'Some filesystems failed to destroy');\n    }\n    this.status = 'destroyed';\n  }\n\n  async readFile(path: string, options?: ReadOptions): Promise<string | Buffer> {\n    const r = this.resolveMount(path);\n    if (!r) throw new Error(`No mount for path: ${path}`);\n    return r.fs.readFile(r.fsPath, options);\n  }\n\n  async writeFile(path: string, content: FileContent, options?: WriteOptions): Promise<void> {\n    const r = this.resolveMount(path);\n    if (!r) throw new Error(`No mount for path: ${path}`);\n    this.assertWritable(r.fs, path, 'writeFile');\n    return r.fs.writeFile(r.fsPath, content, options);\n  }\n\n  async appendFile(path: string, content: FileContent): Promise<void> {","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/workspace/filesystem/composite-filesystem.ts#L283-L319","documentation":"destroy() tears down every mounted filesystem; individual failures are collected and thrown together as an AggregateError with this message. Some mounts were destroyed, others failed, and the composite's status is set to 'error'. The error carries the per-mount errors in its `errors` array for diagnosis.","triggerScenarios":"Calling composite.destroy() when one or more mounts' own destroy() rejects — e.g., a remote filesystem failing to close connections, or a local fs failing to release watchers/locks.","commonSituations":"Shutting down a server whose workspace mounts include flaky network backends; double-destroy (second call hits already-closed resources); timeouts closing remote storage sessions.","solutions":["Inspect err.errors (AggregateError) to identify which mounts failed and fix each underlying teardown error.","Retry destroy() for the failed mounts only, if their backends support re-teardown.","Check network connectivity/credentials for remote mounts before shutdown.","Ensure destroy() is called once per composite; guard against double-destroy by checking status."],"exampleFix":"// before\nawait composite.destroy();\n// after\ntry { await composite.destroy(); }\ncatch (e) {\n  if (e instanceof AggregateError) for (const sub of e.errors) console.error('mount destroy failed:', sub);\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isAggregateError(e: unknown): e is AggregateError { return e instanceof AggregateError && Array.isArray(e.errors); }","tryCatchPattern":"try { await composite.destroy(); } catch (e) {\n  if (e instanceof AggregateError) {\n    for (const sub of e.errors) console.error('Mount teardown failed:', sub);\n  }\n  throw e;\n}","preventionTips":["Call destroy() exactly once; guard with a status check.","Close network connections to remote mounts before shutdown when possible.","Log AggregateError.errors to spot chronically failing mounts."],"tags":["workspace","filesystem","cleanup","aggregate-error"],"backgroundTag":"teardown-partial-failure","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}