{"record":{"id":"3138002623c06240","repo":"siyuan-note/siyuan","slug":"import-task-not-found-or-expired","errorCode":null,"errorMessage":"import task not found or expired","messagePattern":"import task not found or expired","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/api/import.go","lineNumber":266,"sourceCode":"\t\tif statErr != nil {\n\t\t\treturn \"\", statErr\n\t\t}\n\t}\n\terr = os.Rename(srcPath, stagedSYImportPath(token))\n\treturn\n}\n\nfunc claimStagedSYImport(token string) (path string, err error) {\n\tif !isValidSYImportToken(token) {\n\t\treturn \"\", errors.New(\"invalid import token\")\n\t}\n\tstagedSYImportLock.Lock()\n\tdefer stagedSYImportLock.Unlock()\n\tcleanupStagedSYImports()\n\tsrcPath := stagedSYImportPath(token)\n\tif _, err = os.Stat(srcPath); err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\terr = errors.New(\"import task not found or expired\")\n\t\t}\n\t\treturn \"\", err\n\t}\n\tpath = filepath.Join(stagedSYImportDir(), token+\"-importing.zip\")\n\terr = os.Rename(srcPath, path)\n\treturn\n}\n\nfunc cleanupStagedSYImports() {\n\tentries, err := os.ReadDir(stagedSYImportDir())\n\tif err != nil {\n\t\treturn\n\t}\n\tnow := time.Now()\n\tfor _, entry := range entries {\n\t\tname := entry.Name()\n\t\tif !strings.HasSuffix(name, \".zip\") || !isValidSYImportToken(strings.TrimSuffix(name, \".zip\")) {\n\t\t\tcontinue","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/api/import.go#L248-L284","documentation":"Returned by claimStagedSYImport (import.go:266) when the token passes format validation but the staged .zip file no longer exists at stagedSYImportPath(token). This happens when the staged import expired (cleanupStagedSYImports removes entries older than stagedSYImportTTL), was already claimed (claim renames it away), or was manually deleted.","triggerScenarios":"Issuing the claim/finalize request for an SY import whose staged artifact is gone: too much time elapsed between stage and claim (exceeded stagedSYImportTTL), the same token was claimed twice (the first claim renamed the file to '-importing.zip'), or the temp/import/sy dir was cleared by another process or kernel restart.","commonSituations":"User staged an import, got distracted, and finalized minutes/hours later. Network hiccup caused a double-submit of the claim. Temp directory cleanup/eviction. Container or ephemeral filesystem losing util.TempDir between requests.","solutions":["Re-stage the import (re-upload) to get a fresh token, then claim promptly within stagedSYImportTTL.","Ensure the claim request fires immediately after a successful stage response.","Guard against double-submit on the client (disable the confirm button after first click)."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Re-stage if too much time elapsed (token likely expired)\nif (Date.now() - stagedAt > TTL_MS) { token = await stageImport(data); }","typeGuard":null,"tryCatchPattern":"try { await claimImport(token); }\ncatch (e) {\n  if (/not found or expired/.test(e.msg)) { token = await stageImport(data); await claimImport(token); }\n  else throw e;\n}","preventionTips":["Claim immediately after staging to stay within stagedSYImportTTL.","Disable double-submit on the client to avoid duplicate claims.","Re-stage on any 'not found or expired' response."],"tags":["import","filesystem","kernel"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}