{"record":{"id":"780679585f280806","repo":"iflytek/astron-agent","slug":"repo-not-exist","errorCode":"REPO_NOT_EXIST","errorMessage":"ResponseEnum.REPO_NOT_EXIST","messagePattern":"ResponseEnum\\.REPO_NOT_EXIST","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/repo/KnowledgeService.java","lineNumber":1439,"sourceCode":"        private final String ragflowDatasetId;\n\n        private RepoContext(String fileUuid, String coreRepoId, String lastUuid,\n                String ragflowDatasetId) {\n            this.fileUuid = fileUuid;\n            this.coreRepoId = coreRepoId;\n            this.lastUuid = lastUuid;\n            this.ragflowDatasetId = ragflowDatasetId;\n        }\n    }\n\n    private RepoContext getRepoContext(Long fileId) {\n        FileInfoV2 fileInfoV2 = fileInfoV2Service.getById(fileId);\n        if (fileInfoV2 == null) {\n            throw new BusinessException(ResponseEnum.REPO_FILE_NOT_EXIST);\n        }\n        Repo repo = repoService.getById(fileInfoV2.getRepoId());\n        if (repo == null) {\n            throw new BusinessException(ResponseEnum.REPO_NOT_EXIST);\n        }\n        String datasetId = ProjectContent.FILE_SOURCE_RAG_FLOW_RAG_STR.equals(fileInfoV2.getSource())\n                ? repo.getRagflowDatasetId()\n                : null;\n        return new RepoContext(fileInfoV2.getUuid(), repo.getCoreRepoId(),\n                fileInfoV2.getLastUuid(), datasetId);\n    }\n\n    private List<String> preCheck(Long fileId) {\n        RepoContext context = getRepoContext(fileId);\n        List<String> uuids = new ArrayList<>();\n        uuids.add(context.fileUuid);\n        uuids.add(context.coreRepoId);\n        uuids.add(context.lastUuid);\n        return uuids;\n    }\n\n    private void applyRagflowDatasetId(KnowledgeRequest request, String source, String datasetId) {","sourceCodeStart":1421,"sourceCodeEnd":1457,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/repo/KnowledgeService.java#L1421-L1457","documentation":"In KnowledgeService.getRepoContext(), after the file record is found, the parent repo is loaded with repoService.getById(fileInfoV2.getRepoId()). If the Repo row referenced by the file's repoId is missing, BusinessException(REPO_NOT_EXIST) is thrown. This indicates orphaned metadata: the file exists but its owning knowledge-base repo does not.","triggerScenarios":"getRepoContext(fileId) is invoked and the repo backing fileInfoV2.getRepoId() was deleted (repo deletion that did not cascade to file records), the repoId points to another tenant's repo, or the database was partially restored/migrated so the repo row is absent.","commonSituations":"Repo deleted while files remained referenced (soft-delete inconsistency); environment sync where file table was copied but repo table was not; manual DB edits; concurrent repo deletion between file lookup and repo lookup.","solutions":["Check the repo exists: SELECT * FROM repo WHERE id = <fileInfoV2.repoId> AND deleted = 0.","If the repo was intentionally deleted, clean up or ignore the orphaned file records instead of operating on them.","Restore the missing repo row from backup/migration if the file must remain usable.","Add a cascade/cleanup step to repo deletion so file_info_v2 rows are removed or marked, preventing orphaned references."],"exampleFix":"// before\nRepo repo = repoService.getById(file.getRepoId()); // may be null -> REPO_NOT_EXIST\n\n// after\nRepo repo = repoService.getOnly(Wrappers.lambdaQuery(Repo.class)\n        .eq(Repo::getId, file.getRepoId()).eq(Repo::getDeleted, 0));\nif (repo == null) {\n    // treat file as orphaned: skip it or surface 'parent knowledge base was deleted'\n}","handlingStrategy":"validation","validationCode":"Repo repo = repoService.getOnly(Wrappers.lambdaQuery(Repo.class)\n        .eq(Repo::getId, repoId).eq(Repo::getDeleted, 0));\nif (repo == null) { /* parent repo gone; do not operate on the file */ }","typeGuard":"boolean repoExists(Long repoId) { return repoId != null && repoService.getById(repoId) != null; }","tryCatchPattern":"try {\n    knowledgeService.getRepoContext(fileId);\n} catch (BusinessException e) {\n    if (ResponseEnum.REPO_NOT_EXIST.getCode().equals(e.getCode())) {\n        // treat file as orphaned; surface 'knowledge base was deleted'\n    } else { throw e; }\n}","preventionTips":["Cascade file cleanup when deleting a repo to avoid orphaned file records.","Filter on deleted=0 consistently when checking repo existence.","Watch for partially restored/migrated databases and reconcile repo/file tables.","Alert on files whose repoId has no matching repo row."],"tags":["java","knowledge-base","orphaned-record","entity-not-found"],"backgroundTag":"entity-not-found","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}