{"record":{"id":"3a2ac052bf606b90","repo":"alibaba/open-code-review","slug":"sessions-belong-to-different-repositories-s-was","errorCode":null,"errorMessage":"sessions belong to different repositories: %s was recorded in %s, %s in %s","messagePattern":"sessions belong to different repositories: (.+?) was recorded in (.+?), (.+?) in (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/session_cmd.go","lineNumber":251,"sourceCode":"\nfunc runSessionCompare(beforeID, afterID string) error {\n\tresolvedRepo, err := resolveWorkingDirForSession(sessionCompareRepoDir)\n\tif err != nil {\n\t\treturn err\n\t}\n\tbeforeSummary, err := session.LoadSummary(resolvedRepo, beforeID)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"load session %q: %w\", beforeID, err)\n\t}\n\tafterSummary, err := session.LoadSummary(resolvedRepo, afterID)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"load session %q: %w\", afterID, err)\n\t}\n\t// Comparing findings across repositories is meaningless, so it is an error\n\t// rather than a warning. A different review mode or range still compares\n\t// usefully (a full scan against a diff run, say), so that only warns.\n\tif beforeSummary.RepoDir != afterSummary.RepoDir {\n\t\treturn fmt.Errorf(\"sessions belong to different repositories: %s was recorded in %s, %s in %s\",\n\t\t\tbeforeID, beforeSummary.RepoDir, afterID, afterSummary.RepoDir)\n\t}\n\tif beforeSummary.ReviewMode != afterSummary.ReviewMode {\n\t\t// stderr, never stdout: --json output is piped into other tools.\n\t\tfmt.Fprintf(os.Stderr, \"[ocr] WARNING review modes differ (%s vs %s); the two runs may not have looked at the same files\\n\",\n\t\t\tdisplayMode(beforeSummary.ReviewMode), displayMode(afterSummary.ReviewMode))\n\t}\n\n\tbeforeComments, err := session.LoadComments(resolvedRepo, beforeID)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"load session %q: %w\", beforeID, err)\n\t}\n\tafterComments, err := session.LoadComments(resolvedRepo, afterID)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"load session %q: %w\", afterID, err)\n\t}\n\tresult := session.Compare(beforeComments, afterComments, reviewedPaths(afterSummary))\n","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/session_cmd.go#L233-L269","documentation":"runSessionCompare refuses to compare two sessions recorded in different repositories (beforeSummary.RepoDir != afterSummary.RepoDir), because comparing findings across repos is meaningless. This is a deliberate guard, not an I/O failure; a differing review mode only warns, but a differing repo dir is fatal.","triggerScenarios":"ocr session compare where the two loaded session summaries point at different RepoDir values — e.g. comparing a session from repo A with one from repo B, or from two distinct clones/worktrees of the same project.","commonSituations":"Running compare from a different checkout than where the sessions were made; passing IDs from two unrelated projects; duplicated worktrees.","solutions":["Compare only sessions recorded in the same repository; check each summary's RepoDir before comparing","Re-record both sessions in the same repo/checkout","If the repos are actually the same project, pick a single canonical clone and store sessions there"],"exampleFix":"// before\nocr session compare s1 s2   // s1 in /work/a, s2 in /work/b\n// after\ncd /work/a && ocr session compare s1 s2   // both recorded here","handlingStrategy":"validation","validationCode":"b, _ := session.LoadSummary(repo, beforeID)\na, _ := session.LoadSummary(repo, afterID)\nif b.RepoDir != a.RepoDir {\n    return fmt.Errorf(\"refusing: %s vs %s\", b.RepoDir, a.RepoDir)\n}","typeGuard":null,"tryCatchPattern":"// parse the wrapped sentinel before proceeding\nif strings.Contains(err.Error(), \"sessions belong to different repositories\") {\n    // surface both RepoDirs to the user and abort\n}","preventionTips":["Store and compare sessions within a single canonical clone/worktree","Check each summary's RepoDir programmatically before invoking compare","Don't mix session IDs across projects in scripts"],"tags":["go","cli","session","validation"],"backgroundTag":"cross-repo-session-mismatch","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}