fix: recover from truncated resume session - #1317
hyphen0009 wants to merge 1 commit into
Conversation
|
🔍 OpenCodeReview found 2 issue(s) in this PR.
|
| // | ||
| // A fragment that does parse is folded in as a courtesy to hand-written or | ||
| // externally produced files that omit the final newline. | ||
| func (s *ResumeState) applyTrailingFragment(sessionID string, fragment []byte) error { |
There was a problem hiding this comment.
The sessionID parameter is accepted but never used in this function. The function accesses the session ID through s.SessionID (via applyResumeLine) instead. Either remove the parameter or use it where needed (e.g., for error formatting). Keeping an unused parameter is confusing and will trigger linter warnings.
Suggestion:
| func (s *ResumeState) applyTrailingFragment(sessionID string, fragment []byte) error { | |
| func (s *ResumeState) applyTrailingFragment(fragment []byte) error { |
| const maxFragment = 256 | ||
| if len(fragment) > maxFragment { | ||
| fragment = fragment[:maxFragment] | ||
| } |
There was a problem hiding this comment.
When the trailing fragment exceeds 256 bytes, it is silently truncated before being stored in RecoveredFragment. A user inspecting the fragment during diagnosis may not realize it was cut, leading to misleading forensic analysis. Consider appending a truncation indicator (e.g., "...") or storing the original length so the warning output makes the truncation obvious.
Suggestion:
| const maxFragment = 256 | |
| if len(fragment) > maxFragment { | |
| fragment = fragment[:maxFragment] | |
| } | |
| const maxFragment = 256 | |
| if len(fragment) > maxFragment { | |
| fragment = append(fragment[:maxFragment], []byte("...(truncated)")...) | |
| } |
|
Thanks for the fix! Heads-up: the core of this — tolerating a truncated final JSONL record in Could you rebase onto
So: rebase, drop the duplicated tail-truncation handling, and keep the Ctrl+C work (and the newline-less-record recovery if you want it) layered on top. Happy to re-review once it's rebased. |
Description
Fixes an issue where
ocr scan --resumefails withunexpected end of JSON inputafter a scan is interrupted with Ctrl+C.The session uses buffered JSONL persistence, and an interrupted write can leave a truncated final record without a trailing newline. Previously,
LoadResumeStatetreated this incomplete tail record as a fatal parsing error, preventing the scan from resuming.This change allows resume loading to safely recover from an incomplete final record while keeping malformed records in the middle of the session file as errors.
The scan command also now handles the first Ctrl+C gracefully so checkpoints can be persisted and the session can be closed cleanly.
Type of Change
How Has This Been Tested?
Added regression tests covering:
Verification performed by the development agent:
go build ./...: PASSgo vet: PASSgofmt: cleanAI Assistance Disclosure
AI assistance was used during development to investigate and implement the fix and to help create the regression tests.