Repository navigation
Conversation
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s). |
Qiyuanqiii
left a comment
There was a problem hiding this comment.
Reviewed a5e7aef. The missing distinction between unfinished and actively running sessions is real, but file modification time is not sufficient to expose a definitive liveness state.
An unfinished session whose writer has just been killed is still reported as running for up to ten minutes. Conversely, a live operation that produces no session record for more than ten minutes is reported as aborted. Longer configured provider requests or retry waits can reach the latter case without the process having died.
One important detail: the writer does not append only when a file finishes. AppendTaskRecord, SetResponse, and tool-result recording also write JSONL entries. Therefore a long overall subtask alone is not the reproduction; the relevant case is a live interval with no completed/request-boundary record long enough to exceed this window.
Please distinguish observed activity from verified liveness. An explicit owner/lease or heartbeat mechanism is one option; a clearly named activity heuristic with an unknown/suspected state is another. Merely increasing the fixed window still cannot establish whether the writer is alive.
Please cover a recently terminated writer, a live but quiet request, and a finalized session. Also document the JSON interpretation: the current design can emit both running: true and aborted: true, so consumers need an explicit precedence rule rather than assuming those flags are mutually exclusive.
a5e7aef to
960891f
Compare
|
@Qiyuanqiii addressed in 960891f by replacing the append-activity heuristic with an explicit heartbeat — your first suggested option. Writer side ( Reader side ( The three requested cases are covered by unit tests and a manual run:
JSON interpretation documented: Manual check (Windows 11, real provider, 8-file range review): 75s into the run — while the writer was inside an LLM request with no record written in that window beyond the beat — |
Qiyuanqiii
left a comment
There was a problem hiding this comment.
Reviewed the updated head 960891f.
The heartbeat-based direction addresses the main concern from my previous review much better than the original append-activity heuristic. In particular, a quiet provider request can now keep producing explicit liveness evidence independently of request/progress records, and stopping the heartbeat before session_end avoids a write-after-finalization race.
I found one remaining edge case in the new/legacy distinction.
markRunning selects the shorter livenessWindow only after the reader has already seen at least one heartbeat record. A current-version writer does not emit its first heartbeat until 60 seconds after startup. Therefore, if a new writer is killed before that first heartbeat, its file contains no heartbeat at all and is indistinguishable from a pre-heartbeat session:
new writer starts
→ session file created / session_start written
→ process dies at e.g. 5s
→ no heartbeat record exists
→ sawHeartbeat == false
→ legacyActivityWindow (10m) is used
So a current-version run killed during its first minute can still be reported as running for close to ten minutes, rather than the documented ~3-minute residual for heartbeat-enabled writers.
Please make heartbeat capability identifiable independently of whether the first periodic beat has happened. For example, the current format could mark heartbeat support in session_start, or emit an initial heartbeat synchronously after session_start before starting the periodic loop. The important part is that a new-format session killed before its first periodic tick must still select the heartbeat liveness window.
Please add a regression for:
- create a current-version session,
- terminate it before the first periodic heartbeat,
- age the file past
livenessWindowbut keep it younger thanlegacyActivityWindow, - verify it is no longer reported as
running.
There is also a test-coverage detail worth correcting while touching this area: TestListSessions_QuietLiveHeartbeatWriterStaysRunning currently calls writeKilledHeartbeatSession, which stops the heartbeat and closes the writer before ListSessions is invoked. It therefore exercises a freshly terminated writer, not an actually live quiet writer. The separate writer test proves heartbeats are emitted while alive, but having the reader test query a writer whose heartbeat goroutine is still running would make the intended integration contract explicit.
Other than this startup-window distinction, I did not find another code-level blocker in the revised heartbeat implementation.
… session list An unfinished session (no session_end record yet) is indistinguishable from an interrupted one, so ocr session list showed live reviews as aborted until they finished. The writer now emits a flushed heartbeat record every 60s — liveness evidence that keeps the file fresh through long provider requests and retry waits, which no fixed append-activity window could cover — and the listing path reports an unfinished session as running while that evidence is fresh (three missed beats). Files written by pre-heartbeat versions keep the wider activity window. Aborted keeps its file-based meaning (true until session_end reaches disk) so resume logic and existing JSON consumers are unaffected; the running/aborted precedence rule is documented in the CLI reference.
960891f to
b96d01f
Compare
|
Thank you for the careful review — the startup-window gap was real, and it is fixed on the new head b96d01f (amended into the same commit, force-pushed). Initial heartbeat instead of a format marker. I took your second option: Regression test. Live-writer test corrected. Verification on this head (all local, real runs): |
Description
Closes #1588 — full root-cause analysis and reproduction steps there.
Revised per the reviews on a5e7aef and 960891f: liveness is an explicit writer-side heartbeat, and heartbeat capability is now identifiable from a session file's first moments.
The problem. While a review is still running,
ocr session list(table and--json) reports the in-progress session asaborted. The status only flips tocompleteafter the run finishes. An agent that pollsocr session list— one of the AI-host-agent workflows this project recommends — sees a healthy running review reported as dead and may start a duplicate review, wasting tokens and duplicating findings.Root cause. A session JSONL file receives its
session_endrecord only atFinalize()(internal/session/history.go). The listing path (loadSummaryFromFileininternal/session/list.go) initializesAborted: trueand flips it tofalseonly when it reads that record. So a live run — which by design has nosession_endyet — is indistinguishable on disk from a crashed one: both are "nosession_end". There is no liveness signal in the listing path.The fix — an explicit heartbeat, not a bigger window.
internal/session/persist.go): the JSONL writer runs a liveness loop that appends a flushedheartbeatrecord every 60s for the whole life of the run. The loop is a separate goroutine, so the file stays fresh even while the run sits inside one long provider request or retry wait with no completed/request-boundary record — the case a fixed append-activity window cannot cover (the default per-request timeout alone is 5 minutes, and provider-configured timeouts/retry backoffs can be longer). The loop stops atsession_endand at the writer's close path via an idempotent stop that waits out any in-flight beat, so nothing writes to a closed file. Readers that don't know the record type ignore it, the same way they ignoreresume_lineage.WriteSessionStartappends one synchronous initial heartbeat right after thesession_startrecord, before the periodic loop takes over. With the periodic loop alone, a writer killed during its first interval would leave no heartbeat record at all, and readers could not tell its file from one written by a pre-heartbeat version — it would be held to the wider legacy window for up to 10 minutes instead of the documented ~3-minute residual. The initial beat makes "at least one heartbeat record" a property of every file this version writes, so a session killed at any age selects the heartbeat liveness window.internal/session/list.go): an unfinished session reportsrunningwhile its heartbeat evidence is fresh — three missed beats (3 min), which only bounds how long a killed writer can masquerade as running. Session files written by pre-heartbeat versions contain no heartbeat records at all; for those, the walk falls back to the wider 10-minute activity window, so old in-flight sessions are not re-classified mid-upgrade. ThemarkRunningcomment states the evidence-vs-lease distinction explicitly: freshness is liveness evidence, not a verified process check — a writer killed inside the window still reportsrunninguntil the window lapses.cmd/opencodereview/session_cmd.go):describeStatusrendersrunningbeforeaborted.Summary.Running(json:"running,omitempty") documents thatrunningandabortedare not mutually exclusive:abortedkeeps its file-based meaning (trueuntilsession_endreaches disk, preserving resume semantics and existing consumers), andrunningtakes precedence when both are set. The same rule, the status vocabulary, and the two windows are documented in theocr session listsection of the CLI reference (en/zh/ja/ko/ru), with a pin test keeping the docs present.A session that stops receiving heartbeats without a
session_endstill showsabortedonce the window lapses — a real interruption. The on-disk format only gains one ignorable record type; backward compatible in both directions.Type of Change
How Has This Been Tested?
New unit tests (following the existing patterns in
list_test.go/persist_test.go):Writer side (
persist_test.go):TestJSONLWriterHeartbeatRecordsReachDiskWhileQuiet— beats reach disk at interval with no other records, and stop for good at the writer's close.TestJSONLWriterHeartbeatStopsAtSessionEnd—session_endremains the last physical record; no beat lands after it.Reader side (
list_test.go) — the cases requested in review:TestListSessions_QuietLiveHeartbeatWriterStaysRunning— a writer whose heartbeat goroutine is still running whileListSessionsreads the file: onlysession_startplus heartbeat records exist, no progress/request-boundary record ever appears, and the session reportsrunning.TestListSessions_TerminatedHeartbeatWriterNotRunningAfterWindow— stillrunningright after the kill (the documented bounded residual), thenaborted/not-runningonce pastlivenessWindow, even though heartbeat records exist in the file.TestListSessions_KilledBeforeFirstPeriodicBeatUsesLivenessWindow— the file's only heartbeat is the synchronous initial beat; aged pastlivenessWindowbut still insidelegacyActivityWindow, the session must no longer reportrunning(with the legacy window it wrongly would).TestListSessions_FinalizedFreshFileNeverRunning— a fresh file withsession_endnever reportsrunning.TestListSessions_MarksFreshUnfinishedSessionRunning/TestListSessions_StaleUnfinishedSessionNotRunning(legacy-window files, simulated with a zero heartbeat interval) andTestSessionDisplayMarksRunningBeforeAborted(precedence).All new heartbeat/running tests were additionally run with
-count=3to guard against timing flakiness.go test -count=1 ./...excluding/extensions/— allok, 0 failures; total coverage 91.5% (above the 90% CI gate)..github/workflows/ci.ymlon this head: generated provider presets, license headers, action pins, english-only check,gofmt -s -l ., line endings (LF in committed blobs),go mod tidy(no diff),go vet ./...,govulncheck(0 vulnerabilities affecting code), Node launcher test, build + smoke test, and the full cross-compile matrix (linux/arm64, darwin/amd64, darwin/arm64, windows/amd64, windows/arm64) — all pass.make testwith-race: not run on this machine — Windows without a C compiler, and-racerequires CGO. The CI Linux job runs it (verified inci.yml; the Windows CI job skips-racefor the same reason). The new goroutine writes only under the writer's existing mutex, and both close paths stop it before closing the file, outside the lock.ocr session listshowedrunning, and the session file's record order wassession_start, heartbeat, llm_request, …— the initial beat lands immediately aftersession_start, and the 60s periodic beat landed during the same quiet stretch. Killing the process mid-request froze the heartbeat count (no further records of any type; last recordllm_request) and the session stayedrunning— the documented residual, bounded by 3 missed beats. Aging the file 4 minutes (past the 3-minute liveness window, inside the 10-minute legacy window) flipped it toaborted.session_start, heartbeat, llm_request); on the previous revision it would have contained none and been classed legacy. Right after the killocr session listshowedrunning; after aging the file 4 minutes it showedaborted, i.e. the heartbeat liveness window applied from the session's first seconds instead of the 10-minute legacy window.Screenshots
N/A (pure code; terminal output summarized above).
Checklist
go fmt,go vetboth clean)ocr session liststatus semantics and the running/aborted precedence rule added to the CLI reference in all five localesAI disclosure per the project's AI-assisted development policy: developed with the ZCode agent using GLM (glm-5.3-flash). I have reviewed every line of the diff and can explain and defend any part of it.
Related Issues
Closes #1588