Skip to content

fix(session): compare sessions recorded under different path spellings - #1750

Merged
lizhengfeng101 merged 3 commits into
alibaba:mainfrom
castorhrio:fix/session-compare-path-equality
Nov 16, 2026
Merged

lizhengfeng101 merged 3 commits into
alibaba:mainfrom
castorhrio:fix/session-compare-path-equality

Conversation

@castorhrio

Copy link
Copy Markdown
Contributor

What

ocr session compare <before> <after> refuses two sessions of the repository it was run in, whenever the two sessions recorded different spellings of the same directory:

Error: sessions belong to different repositories: 7f797537-… was recorded in C:\tmp\ocr-live-demo,
38f5dd36-… in C:/tmp/ocr-live-demo

C:\tmp\ocr-live-demo and C:/tmp/ocr-live-demo are one directory. A session stores whichever spelling the caller used — a resolved Windows path arrives backslashed, --repo and Git's forward-slash form arrive slashed, and a trailing separator is a third spelling. The guard compared the two recorded paths as strings.

Where

The same comparison exists twice, and both are changed:

  • cmd/opencodereview/session_cmd.go, runSessionCompare — the CLI path above.
  • internal/viewer/handler.go, the compare route — same string equality on Summary.CWD, so the WebUI refuses the same pair.

How

The repository already solves this in internal/session/delete.go, where sameRepoPath cleans both sides and then falls back to os.SameFile — which also covers symlinks and the case-insensitive volumes where A-B and a-b are one directory. That helper was unexported, which is presumably why the two compare sites reached for != instead. It is now session.SameRepoPath and both sites call it. No new comparison logic is introduced; one existing, already-tested helper is shared.

Tests

  • internal/session/delete_test.go gains a "the other separator spelling" case alongside the existing trailing-separator, dot-segment, symlink and case tests.
  • cmd/opencodereview/session_cmd_test.go gains TestRunSessionCompare_MixedRepoSpellings: two real sessions, one re-recorded with a trailing separator, compared successfully. Restoring the string guard makes it fail with exactly the error quoted above — the existing suite did not catch this, because every prior pair was recorded with one spelling, so the wiring is now pinned at the level that broke.

Verified end to end against real sessions with a locally built binary: 1 new, 1 persisting, 8 resolved where released v1.13.0 still answers "sessions belong to different repositories".

Compatibility

The check only ever rejects pairs; making it accept more true positives cannot break a working call. Genuinely different repositories still error, and the existing viewer test asserting that case still passes.

Checks run locally

scripts/verify-license.sh, scripts/verify-english-only.go, go mod tidy, gofmt -s, go vet over all packages except /extensions/, go test -count=1 over all packages, go build — all pass. No C compiler on this box, so -race is left to CI, as are the cross-compile and CodeQL jobs.

AI disclosure (CONTRIBUTING, AI-Assisted Development)

Developed with AI assistance: the Qoder CLI coding agent helped locate both call sites, spot that delete.go already had the right helper, and draft the tests. I reproduced the failure against the released v1.13.0 binary myself, ran every check above myself, reviewed each line, and can explain the change: export the existing helper, call it from both compare guards, pin the spelling case at the helper and at the command. No commit attributes authorship to an AI/LLM.

`session compare` refused two sessions belonging to the repository it was run
in. The guard compared the recorded repo paths as strings, and a session stores
whichever spelling the caller used: `C:\repo` when the OS resolved the path,
`C:/repo` when --repo or Git handed it over. One repository therefore split
across its own spellings. The viewer's compare route carries the same check.

Export the helper `session.SameRepoPath`, which already solved this for delete
(Clean first, then os.SameFile for symlinks and case-insensitive volumes), and
call it from both sites.

Reproduced against real sessions: 1.13.0 answers "sessions belong to different
repositories: ... recorded in C:\tmp\ocr-live-demo, ... in C:/tmp/ocr-live-demo"
for a pair this compares as "1 new, 1 persisting, 8 resolved". The new
cmd-level test fails with that exact error when the string guard is restored.
@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 3 selected item(s).

@chaojixinren chaojixinren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@NanaseInori NanaseInori left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all five changed files, the full shared helper, and the discussion. The SameRepoPath search found this PR and the merged deletion feature that introduced the helper; reusing it for comparison is a distinct fix for the two remaining string-equality guards.

The helper's implementation is unchanged: cleaned equal paths remain equal without filesystem access, while differing spellings require successful stat calls and matching filesystem identity. Both CLI and viewer comparison use it, and deletion retains the same logic under the exported name. The command regression rewrites persisted cwd and asserts an actual successful comparison. No blocking defect found.

I ran an isolated Linux Go fixture using the exact helper: trailing separators, a dot segment and a symlink compare equal; distinct directories and different vanished paths remain unequal; identical vanished paths remain equal. All six checks passed. This was not a Windows run or an execution of the repository/HTTP viewer suite.

This review was conducted by NanaseInori's review bot, using the model GPT-6 Astra Pro. If you need a human review, please manually @NanaseInori.

lizhengfeng101
lizhengfeng101 previously approved these changes Nov 16, 2026

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lizhengfeng101
lizhengfeng101 merged commit dd1a7e1 into alibaba:main Nov 16, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants