Repository navigation
Description
OpenCodeReview Version
Output of ocr --version:
open-code-review v1.12.13 (fabbdb29) windows/amd64
built at: 2026-10-08T11:52:18Z
Operating System
Windows 10 (10.0.19045) x64 — the behaviour is platform independent (it is a nil-vs-empty-slice marshalling detail).
Installation Method
npm (@alibaba-group/open-code-review)
LLM Provider / Model
Not relevant. Reproduced without any reachable endpoint; no request succeeds and nothing is billed. The review run only needs to persist a session.
Description
ocr session list --json represents "no sessions" inconsistently: it prints null for a repository that never had a session, but [] for a repository whose session directory exists and is now empty. The same command, the same "nothing to show" state, two different JSON shapes:
# A) repository with one saved session
$ ocr session list --repo /e/Project/github/ocr-desktop/.tmp-r --json
[
{
"session_id": "2e067e33-2933-4837-8635-ad120d978e8e",
...
}
]
# B) same repository, after `ocr session rm -y 2e067e33-…` (directory still present, no .jsonl left)
$ ocr session list --repo /e/Project/github/ocr-desktop/.tmp-r --json
[]
# C) a repository that never ran a review, so its sessions subdirectory was never created
$ ocr session list --repo /e/Project/github/SourceSeek --json
nullCase C is also what the code says it should not be. ListSessions is documented as:
// ListSessions enumerates all persisted sessions for the given repository
// directory, sorted by StartTime descending (most recent first). Missing
// directories return an empty slice with no error.
func ListSessions(repoDir string) ([]Summary, error) {but its not-exist branch returns an untyped nil (internal/session/list.go, the os.ReadDir error handling):
entries, err := os.ReadDir(dir)
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}whereas the "directory exists, nothing matched" path allocates first (summaries := make([]Summary, 0, len(entries))) and therefore marshals as []. json.NewEncoder(os.Stdout).Encode(summaries) in runSessionList then renders the nil as null. The human-readable path hides this entirely, because it short-circuits on len(summaries) == 0 and prints "No sessions found for …" — so only --json consumers ever see the difference.
For comparison, ocr session comments --json <id> on a session with no findings prints [], so two --json commands in the same group disagree about how "empty" is encoded.
Steps to Reproduce
mkdir -p /tmp/ocr-null-repro/repoA /tmp/ocr-null-repro/repoB
# repoB: create one session, then delete it so the directory exists but is empty
cd /tmp/ocr-null-repro/repoB && git init -q .
git config user.email t@t && git config user.name t
git symbolic-ref HEAD refs/heads/main # so `--from main` below resolves
echo a > a.go && git add -A && git commit -qm one
git checkout -qb feat && echo b > b.go && git add -A && git commit -qm two
ocr review --repo "$PWD" --from main --to feat --format json --timeout 1 # fails fast on an unreachable/dead endpoint; exits non-zero; persists a session
SID=$(ocr session list --repo "$PWD" --json | sed -n 's/.*"session_id": "\(.*\)".*/\1/p' | head -1)
ocr session rm -y "$SID"
ocr session list --repo "$PWD" --json # -> []
# repoA: never reviewed
ocr session list --repo /tmp/ocr-null-repro/repoA --json # -> nullExpected Behavior
ocr session list --json should print [] in both cases — an initialised slice in the missing-directory branch (matching the doc comment already on ListSessions) would make the JSON form stable, i.e. always a list.
This matters for anything consuming the CLI programmatically. In my desktop wrapper the JSON parse succeeds, so null arrives as a non-array value and only surfaces later as an empty state that is indistinguishable from a failed read; I had to add a normalisation step that treats null as []. jq '.[]' and typed unmarshalling hit the same snag.
Logs
No error is produced; the command exits 0 in all three cases.
Additional context
Suggested fix is one line (allocate before the early return, or summaries := []Summary{} at the top of the function), and a test asserting the JSON output for a missing directory. I am happy to send that PR if you would like it — I would wait for confirmation on the expected shape ([]) first, since a consumer could conceivably depend on today's null.
As required by CONTRIBUTING.md: this report, and the wrapper described in it, were drafted with an AI coding agent (Qoder CLI) under my direction. All three outputs above were reproduced and verified locally against ocr v1.12.13 on Windows before filing, and I can explain every part of the analysis myself.
Activity
fix(session): emit [] instead of null from session list --json