{"record":{"id":"2ac72ee36965310b","repo":"siyuan-note/siyuan","slug":"managed-export-is-unavailable","errorCode":null,"errorMessage":"managed export is unavailable","messagePattern":"managed export is unavailable","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/encrypted_export.go","lineNumber":191,"sourceCode":"\t}\n\treturn filepath.FromSlash(strings.Join(parts, \"/\"))\n}\n\n// AcquireExportArtifactLease 为导出产物取得覆盖整个复制过程的生命周期租约。\nfunc AcquireExportArtifactLease(exportPath string) (lease *ExportArtifactLease, err error) {\n\tif after, ok := strings.CutPrefix(exportPath, \"/export/\"); ok {\n\t\tfileName, decodeErr := url.PathUnescape(after)\n\t\tif decodeErr != nil {\n\t\t\treturn nil, decodeErr\n\t\t}\n\t\tfileName = filepath.Clean(fileName)\n\t\tif fileName == \".\" || strings.HasPrefix(fileName, \"..\") || filepath.IsAbs(fileName) {\n\t\t\treturn nil, errors.New(\"invalid export path\")\n\t\t}\n\t\tif IsManagedEncryptedExportPath(fileName) {\n\t\t\tboxID, artifact, resolved := ResolveManagedEncryptedExport(fileName)\n\t\t\tif !resolved {\n\t\t\t\treturn nil, errors.New(\"managed export is unavailable\")\n\t\t\t}\n\t\t\tif err = AcquireEncryptedBoxOperation(boxID); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tHoldBoxReadLock(boxID)\n\t\t\trelease := true\n\t\t\tdefer func() {\n\t\t\t\tif release {\n\t\t\t\t\tReleaseBoxReadLock(boxID)\n\t\t\t\t\tReleaseEncryptedBoxOperation(boxID)\n\t\t\t\t}\n\t\t\t}()\n\t\t\t_, artifact, resolved = ResolveManagedEncryptedExport(fileName)\n\t\t\tif !resolved {\n\t\t\t\treturn nil, errors.New(\"managed export is unavailable\")\n\t\t\t}\n\t\t\tif _, dekErr := GetDEKIfUnlocked(boxID); dekErr != nil {\n\t\t\t\treturn nil, dekErr","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/encrypted_export.go#L173-L209","documentation":"When the export path's first segment looks like a notebook ID (IsManagedEncryptedExportPath), the path is treated as a managed encrypted-export artifact of the form <boxID>/<kind>/<file>. ResolveManagedEncryptedExport looks the path up in the managed export registry; if no registered artifact matches, the lease cannot be issued and this error is returned. It deliberately fails closed even after a notebook was deleted, so no plaintext artifact is exposed.","triggerScenarios":"AcquireExportArtifactLease is called with \"/export/<boxID>/<kind>/<name>\" where boxID matches the node-ID pattern but ResolveManagedEncryptedExport returns resolved=false — e.g. the export lease/artifact was never registered, expired and was swept, or the notebook was deleted.","commonSituations":"Mobile client retries an export download after the managed artifact expired; accessing an export URL from a notebook deleted between export and download; typo'd or stale artifact name; kernel restart clearing the in-memory registry while a client still holds the old URL.","solutions":["Re-run the export operation to re-register the managed artifact, then acquire a lease on the fresh path","Verify the exact <boxID>/<kind>/<file> path matches what the export step returned (names are registry keys, not free-form)","If the notebook was deleted or the kernel restarted, treat the old export URL as permanently invalid and regenerate it","Check ResolveManagedEncryptedExport / the registry for expiry cleanup timing if downloads are happening long after export"],"exampleFix":"// before\nlease, err := model.AcquireExportArtifactLease(staleExportURL) // registry entry gone\n// after\nartifact, err := exportDocToManagedArtifact(boxID, docID) // re-register\nif err != nil { return err }\nlease, err := model.AcquireExportArtifactLease(\"/export/\" + artifact.RelativePath)","handlingStrategy":"fallback","validationCode":"// before downloading, confirm the managed artifact is still registered\nconst ok = await fetchPost(\"/api/encrypt/resolveManagedExport\", { path: managedPath });\nif (!ok.resolved) { await reExport(boxId, docId); }","typeGuard":null,"tryCatchPattern":"try {\n  lease = await acquireExportArtifactLease(managedPath);\n} catch (e) {\n  if (String(e).includes(\"managed export is unavailable\")) {\n    const fresh = await reExport(boxId, docId); // regenerate registry entry\n    lease = await acquireExportArtifactLease(fresh.path);\n  } else { throw e; }\n}","preventionTips":["Download managed exports promptly; registry entries are volatile (expiry sweeps, restarts)","Re-export rather than reusing export URLs cached from a previous session","Never build managed paths by hand; use the path string returned by the export API verbatim","Check for notebook deletion before attempting to download its exports"],"tags":["export","encrypted-notebook","resource-not-found","state"],"backgroundTag":"resource-not-found","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}