Repository navigation
feat(review): add resumable sessions and session inspection - #306
Conversation
| if len(line) > 0 { | ||
| var rec summaryRecord | ||
| if err := json.Unmarshal(line, &rec); err == nil { | ||
| apply(rec) | ||
| } | ||
| } |
There was a problem hiding this comment.
When json.Unmarshal fails, the malformed line is silently skipped. This can lead to incomplete or inaccurate session summaries/details without any indication of data loss. Notably, the analogous function in resume.go (applyResumeLine) returns parse errors to the caller rather than swallowing them.
Consider either logging a warning when a line fails to parse, or returning an error (or a count of skipped lines) so callers can decide how to handle partial data. For a listing operation, silently dropping records may produce misleading results (e.g., wrong file counts, missing comments).
There was a problem hiding this comment.
Thanks for flagging this. I am leaving this out of this PR because session list/show currently treats session history as best-effort display data and continues past malformed records so other usable records can still be shown. Surfacing warnings or errors would change CLI stderr and JSON-output behavior, and should be designed separately. This PR stays focused on checkpoint accounting and resume reuse correctness.
| summary, err := loadSummaryFromFile(filepath.Join(dir, name), sessionID, repoDir) | ||
| if err != nil { | ||
| continue | ||
| } |
There was a problem hiding this comment.
Errors from individual session files are silently swallowed here. If a session file is corrupted or unreadable, it will simply be absent from the listing with no diagnostic information. This could confuse users who know a session exists but don't see it listed.
Consider logging a warning for skipped files, or collecting errors and surfacing them alongside the results (e.g., as a multi-error or via a separate return value), so users are aware that some sessions could not be read.
There was a problem hiding this comment.
Good point, but I am deferring this for the same scope reason. ListSessions currently lists the valid session files it can load instead of failing the whole listing because one file is unreadable or corrupt. Reporting skipped files cleanly would require an API/CLI contract for warnings or partial errors, which is broader than this checkpoint/resume fix.
| if jw.writer != nil { | ||
| jw.writer.Flush() | ||
| } |
There was a problem hiding this comment.
The nil check on jw.writer before Flush() is misleading: if jw.writer were nil, writeRecordLocked called on the line above would already panic at jw.writer.Write(data) (line 126). This guard provides no actual protection and gives a false sense of safety.
For consistency with other Write methods (e.g., WriteLLMRequest, WriteLLMResponse) which don't guard Flush, and since newJSONLWriter guarantees the writer is initialized via open(), consider removing this nil check. Alternatively, if defensive nil handling is desired, add a nil guard at the top of writeRecordLocked itself so all callers benefit uniformly.
There was a problem hiding this comment.
Agreed that this guard is not very useful defensively, but it is not a correctness issue for this PR. The JSONL writer is initialized through open(), and if defensive nil handling is needed it should be added consistently in writeRecordLocked for all callers. Removing this guard would be a cleanup-only change, so I am leaving it for a follow-up rather than mixing it into the resume checkpoint fix.
| if len(line) > 0 { | ||
| if err := state.applyResumeLine(line); err != nil { | ||
| return nil, err | ||
| } | ||
| } |
There was a problem hiding this comment.
Robustness concern: When replaying a JSONL session file, a single corrupted or partially-written line (e.g., due to a crash during flush) causes the entire resume loading to fail, making all previously completed review items unrecoverable.
Looking at persist.go, writeReviewItemRecord calls jw.writer.Flush() after each record, but a process crash between Write(data) and Flush() could leave a truncated last line in the file. Since writeRecordLocked also silently ignores write errors, partial lines are a realistic scenario.
Consider skipping unparseable lines (perhaps with a warning) instead of failing hard, especially for the last line which is most likely to be truncated. This would make resume more resilient:
if err := state.applyResumeLine(line); err != nil {
// Log warning and skip corrupt lines rather than aborting
fmt.Fprintf(os.Stderr, "[ocr] warning: skipping corrupt resume line: %v\n", err)
continue
}There was a problem hiding this comment.
Thanks. I am not changing this in this PR because resume should fail closed when the checkpoint log cannot be parsed reliably. Silently skipping corrupt lines could create a partial resume state and make skipped/replayed files hard for users to reason about. A robust version should define warning/error reporting and likely special-case only a truncated final line. That is a separate behavior change from the checkpoint correctness fix here.
|
🔍 OpenCodeReview found 9 issue(s) in this PR.
📊 Posting Statistics:
|
There was a problem hiding this comment.
Pull request overview
This PR adds persisted review session checkpoints and introduces resume + inspection workflows so interrupted ocr review runs can continue from a prior session’s completed file checkpoints. It extends the session JSONL format to include per-file done/reused/failed records and adds ocr session list/show plus --resume support in the review command, with resume/session metadata surfaced in output.
Changes:
- Persist per-file review checkpoints (
review_item_done/reused/failed) and load/validate them for resumable runs. - Add session inspection commands:
ocr session listandocr session show. - Add
ocr review --resume <session-id>and includesession_id+ resume metadata in text/JSON outputs.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/session/resume.go | Loads prior session JSONL into a fingerprint→checkpoint index and validates resume compatibility. |
| internal/session/persist.go | Persists resumed-from metadata and per-file checkpoint records into the session JSONL stream. |
| internal/session/persist_test.go | Adds round-trip tests for per-file checkpoint persistence + resume validation. |
| internal/session/list.go | Aggregates session JSONL into Summary/ItemDetail for session list/show. |
| internal/session/list_test.go | Tests session listing/sorting and per-session detail item aggregation. |
| internal/session/history.go | Extends session metadata and adds APIs to record per-file checkpoint events. |
| internal/scan/agent.go | Exposes scan session id for consistent output/diagnostics. |
| internal/agent/coverage_test.go | Updates executeSubtask tests for new (completed, skipReason, err) return values. |
| internal/agent/agent.go | Implements resume reuse logic, fingerprints, and persists per-file done/failed/reused checkpoints. |
| internal/agent/agent_test.go | Adds tests for resume reuse behavior and non-reusable token-threshold skips. |
| cmd/opencodereview/shared.go | Extends result interface to include SessionID and includes resume/session data in output paths. |
| cmd/opencodereview/session_cmd.go | Adds ocr session list/show command implementation + table/JSON output. |
| cmd/opencodereview/session_cmd_test.go | Tests ocr session list/show text and JSON output behavior. |
| cmd/opencodereview/scan_cmd.go | Prints session id on scan failure for easier troubleshooting. |
| cmd/opencodereview/review_cmd.go | Loads/validates resume state and wires it into agent construction; prints session id on failure. |
| cmd/opencodereview/output.go | Adds resume and session_id fields to JSON output payload. |
| cmd/opencodereview/output_helpers_test.go | Updates JSON output tests for new function signature/fields. |
| cmd/opencodereview/main.go | Registers top-level session command and updates usage text. |
| cmd/opencodereview/flags.go | Adds --resume flag and usage examples for review. |
| cmd/opencodereview/flags_test.go | Tests parsing of the new --resume flag. |
| cmd/opencodereview/emit_run_result_test.go | Tests session id + resume info inclusion in text/JSON emitRunResult output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Nice PR. i'll try it for my project! |
|
seems not update docs. |
05d6d3b to
1c5f37d
Compare
Updated the usage in docs. |
|
merge conflicts |
1c5f37d to
9d3f44b
Compare
# Conflicts: # cmd/opencodereview/flags.go # cmd/opencodereview/output_helpers_test.go
Description
Adds persisted review sessions, session inspection commands, and resume support for review runs.
This PR:
ocr session list/showsupport for inspecting saved review sessionsType of Change
How Has This Been Tested?
make testpasses locallyAlso verified with:
go test ./internal/session ./internal/agentgo test ./...go vet ./...Manual testing covered multiple interrupted review scenarios, including killed/aborted tasks, and verified that later runs can resume from saved checkpoints.
./dist/opencodereview session listshowed aborted sessions alongside completed resumed sessions with reused file counts, for example11 (reused 6)and1 (reused 1).Checklist
go fmt,go vet)Related Issues
Closes #265