Skip to content

fix(session): return an empty slice, not nil, when the sessions dir is missing - #1809

Closed
OUAO-FRANK wants to merge 1 commit into
alibaba:mainfrom
OUAO-FRANK:fix/1696-session-list-empty-slice
Closed

OUAO-FRANK wants to merge 1 commit into
alibaba:mainfrom
OUAO-FRANK:fix/1696-session-list-empty-slice

Conversation

@OUAO-FRANK

Copy link
Copy Markdown
Contributor

Summary

ListSessions is documented to "return an empty slice with no error" when the sessions directory is missing, but it returned nil. Since json.Marshal(nil) renders as null, ocr session list --json printed:

  • null for a repository that never ran a review (directory absent), and
  • [] for a repository whose session directory exists but is empty.

Now ListSessions returns []Summary{} in the missing-directory branch, so the JSON shape is always [].

Testing

Renamed TestListSessions_EmptyRepoReturnsNil to TestListSessions_EmptyRepoReturnsEmptySlice and added a non-nil assertion. It fails on the previous code (expected a non-nil empty slice, got nil) and passes now.

$ GOTOOLCHAIN=go1.26.9 go test ./internal/session/... -count=1
ok  	github.com/alibaba/open-code-review/internal/session	4.020s

gofmt -l on the changed files is clean.

Fixes #1696.

…s missing

ListSessions is documented to return an empty slice when the sessions
directory does not exist, but it returned nil, which json.Marshal renders as
null. `ocr session list --json` therefore printed null for a repo that never
ran a review, but [] for a repo whose (now empty) session directory still
exists. Return []Summary{} so the JSON shape is consistent.
@github-actions

Copy link
Copy Markdown
Contributor

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

@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 both changed files, #1696 and the existing discussion. Returning an initialized empty slice on the missing-directory path is a correct, focused fix for the null-versus-array output difference. The strengthened non-nil assertion detects the old behavior; no implementation defect found in this two-file patch.

The issue-number search also found the earlier open #1742. I compared its actual diff: it already makes the identical return []Summary{}, nil production change, asserts both non-nil and JSON [] in the session test, and adds a CLI regression checking the raw session list --json output. The merged #1792 concerns session show and does not replace either list fix.

There is no distinct remaining production change here relative to #1742. I recommend retaining one implementation, preferably preserving the CLI wire-output regression, rather than merging two copies of the same fix. This is an overlap comment, not a request for the earlier PR to coordinate with this later submission, and it does not close either PR.

Validation: complete patch/test inspection and comparison of the two implementations; no independent repository test execution.

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

Copy link
Copy Markdown
Contributor

Thanks for the contribution! #1742 has now been merged and fixes the same issue: session list --json returns [] instead of null when the sessions directory is missing, with regression tests covering the behavior. Closing this PR as a duplicate of the merged fix.

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.

bug(session): session list --json prints null for a repo with no sessions, but [] once the directory exists

3 participants