open-code-review icon indicating copy to clipboard operation
open-code-review copied to clipboard

Sessions from different repositories are mixed when encoded paths collide

Open amh1k opened this issue 3 months ago • 4 comments

OpenCodeReview Version

open-code-review dev linux/amd64

Operating System

Linux (x86_64)

Installation Method

Built from source

LLM Provider

Other OpenAI-compatible endpoint

Bug Description

OCR derives the session-storage directory by replacing path separators with hyphens. This causes different repository paths such as:

  • /tmp/.../team/service-api
  • /tmp/.../team-service/api

to map to the same session directory.

After reviewing both repositories with the same HOME directory, ocr session list --repo returns sessions from both repositories. This can expose or mix session history in the session list, resume flow, or viewer.

Steps to Reproduce

  1. Create two repositories whose paths collide after replacing / with -:
    • /tmp/.../team/service-api
    • /tmp/.../team-service/api
  2. Configure OCR to use a local deterministic OpenAI-compatible mock server.
  3. Build OCR from source.
  4. Run a review for the first repository: ocr review --repo <repo-a> --commit HEAD --format json --audience agent
  5. Run a review for the second repository using the same HOME directory.
  6. Run: ocr session list --repo <repo-a> --json
  7. Observe that sessions for both repositories are returned and stored under the same session directory.

Expected Behavior

Each repository should have an isolated session-storage directory. Running:

ocr session list --repo <repository> --json

should return only sessions belonging to that repository. Sessions from another repository should never appear in its list, resume flow, or viewer.

Logs / Error Output

Observed output showed two different repositories using the same session directory:

- `/tmp/.../team/service-api`
- `/tmp/.../team-service/api`

Both were stored under:

`.../.opencodereview/sessions/...-team-service-api/`

Running `ocr session list --repo <repository> --json` returned sessions for both repositories. No API keys or sensitive credentials were included.

Additional Context

No response

amh1k avatar Aug 13 '26 18:08 amh1k

@stay-foolish-forever @lizhengfeng101 I’ve reproduced this repository session-isolation issue locally and documented the behavior above. If you consider it worth addressing, I’d be happy to work on the fix. Please feel free to assign the issue to me.

amh1k avatar Aug 13 '26 18:08 amh1k

@amh1k Thanks a lot for your detailed analysis and the extra work for reproducing it locally. I believe that you have a thorough understanding of this issue and can solve this issue for sure. Hope to see your PR soon :)

stay-foolish-forever avatar Aug 14 '26 03:08 stay-foolish-forever

Additional impact: scan resume can cross repository boundaries.

loadScanResumeState finds a session through the collision-prone directory and then calls ValidateScanOptions. That validator checks mode and scan paths, but does not compare ResumeState.RepoDir with the current repository. With a collision such as /home/a/b vs /home/a-b, ocr scan --resume <id> can therefore accept a session from the other repository; matching item fingerprints may reuse its comments.

Suggested defense in depth: use a collision-resistant key such as basename + hash(canonical path), and independently reject resume when the canonical current repo differs from session_start.cwd. A regression test should cover the two paths above.

Source: scan_cmd.go, resume.go, persist.go.

AI/LLM disclosure: Prepared with OpenAI Codex (GPT-5) for source inspection and drafting; no project code was modified.

EveEveeee avatar Sep 20 '26 07:09 EveEveeee

Thanks for the thorough analysis and reproduction, @amh1k, and the additional findings on the scan resume path, @EveEveeee.

After reviewing this, I think we'll hold off on a fix for now. The path-encoding collision is real, but the probability of hitting it in practice is quite low — it requires two repositories whose paths differ only by a separator-vs-hyphen boundary, sharing the same HOME directory.

More importantly, any fix here has a non-trivial blast radius: encodeRepoPath is used across 6 call sites (session write, list, resume, raw writer, viewer), and changing the encoding scheme introduces a backward-compatibility problem — existing session directories would need migration or dual-lookup logic, which adds complexity that's hard to justify for such a narrow edge case.

We'd prefer to revisit this when we have a cleaner migration path or a solution that doesn't require backward-compatibility shims. If anyone comes up with an approach that handles the existing-directory problem elegantly, we're happy to reconsider.

lizhengfeng101 avatar Sep 24 '26 03:09 lizhengfeng101