{"record":{"id":"1b228c3c58be03e7","repo":"theonedev/onedev","slug":"cannot-add-code-comment-outside-of-diff-filepa","errorCode":null,"errorMessage":"Cannot add code comment outside of diff: '${filePath}' is not changed","messagePattern":"Cannot add code comment outside of diff: '(.+?)' is not changed","errorType":"validation","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/ai/PullRequestHelper.java","lineNumber":169,"sourceCode":"        var newCommitId = ObjectId.fromString(pullRequest.getLatestUpdate().getHeadCommitHash());\n        var comparisonBase = pullRequestService.getComparisonBase(pullRequest, oldCommitId, newCommitId);\n\n        var newBlobIdent = new BlobIdent(newCommitId.name(), filePath, FileMode.REGULAR_FILE.getBits());\n        var lines = project.readLines(newBlobIdent, WhitespaceOption.IGNORE_TRAILING, false);\n        if (lines == null)\n            throw new NotFoundException(\"File not found or not a text file in head commit: \" + filePath);\n        if (toLineNumber > lines.size())\n            throw new NotAcceptableException(\"'toLineNumber' must not exceed number of lines in the file\");\n\n        DiffEntryFacade matchingEntry = null;\n        for (var entry : gitService.diff(project, comparisonBase, newCommitId)) {\n            if (filePath.equals(entry.getNewPath()) && entry.getChangeType() != ChangeType.DELETE) {\n                matchingEntry = entry;\n                break;\n            }\n        }\n        if (matchingEntry == null)\n            throw new NotAcceptableException(\"Cannot add code comment outside of diff: '\" + filePath + \"' is not changed\");\n\n        var changeType = matchingEntry.getChangeType();\n        if (changeType == ChangeType.RENAME && matchingEntry.getOldPath().equals(matchingEntry.getNewPath()))\n            changeType = ChangeType.MODIFY;\n        var oldDiffBlobIdent = GitUtils.getOldBlobIdent(matchingEntry, comparisonBase.name());\n        var newDiffBlobIdent = GitUtils.getNewBlobIdent(matchingEntry, newCommitId.name());\n        var blobChange = new BlobChange(changeType, oldDiffBlobIdent, newDiffBlobIdent, WhitespaceOption.IGNORE_TRAILING) {\n\n            private static final long serialVersionUID = 1L;\n\n            @Override\n            public Project getProject() {\n                return project;\n            }\n\n        };\n\n        var range = new PlanarRange(fromLineNumber - 1, 0, toLineNumber - 1, lines.get(toLineNumber - 1).length());","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/ai/PullRequestHelper.java#L151-L187","documentation":"Diff-scope check in addCodeComment: the tool only allows comments on lines that are part of the pull request's changes. If the requested filePath is not among the changed files between base and head commits, the comment would have no diff context to attach to, so NotAcceptableException is thrown. Fix: comment only on files modified by the PR.","triggerScenarios":"Thrown at server-core/src/main/java/io/onedev/server/ai/PullRequestHelper.java:169 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Choose a file that is actually changed between the comparison base and head commit.","Check the PR's changed-file list before selecting the path."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}