Skip to content

Commit 8df59ba

Browse files
committed
codex reader: propagate read_until I/O errors
Address review feedback on #372: the codex streaming loop was swallowing `read_until` failures via `Err(_) => break`, which would silently truncate the parse at a transient mid-file read error and advance the resume cursor as if the bytes had been processed. The claude.rs equivalents already use `?` to propagate. Bubble the error by changing `parse_codex_buffer` to return `std::io::Result<ParseCodexIncrementalResult>` and using `?` in the loop, matching `parse_codex_session_incremental`'s outer signature.
1 parent ab56ca6 commit 8df59ba

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

crates/relayburn-sdk/src/reader/codex.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,7 @@ pub fn parse_codex_session_incremental(
196196
let reader = BufReader::new(file);
197197

198198
let project_resolver = ProjectResolver::new();
199-
Ok(parse_codex_buffer(
200-
reader,
201-
start_offset,
202-
options,
203-
&project_resolver,
204-
))
199+
parse_codex_buffer(reader, start_offset, options, &project_resolver)
205200
}
206201

207202
// ---------------------------------------------------------------------------
@@ -339,7 +334,7 @@ fn parse_codex_buffer<R: BufRead>(
339334
start_offset: u64,
340335
options: &ParseCodexIncrementalOptions,
341336
project_resolver: &ProjectResolver,
342-
) -> ParseCodexIncrementalResult {
337+
) -> std::io::Result<ParseCodexIncrementalResult> {
343338
let capture_content = matches!(options.content_mode, Some(ContentStoreMode::Full));
344339
// Validated by `resolve_token_counter` at the public entry point.
345340
let counter = HeuristicCounter;
@@ -395,11 +390,10 @@ fn parse_codex_buffer<R: BufRead>(
395390
let mut current_offset: u64 = start_offset;
396391
loop {
397392
line_buf.clear();
398-
let n = match reader.read_until(b'\n', &mut line_buf) {
399-
Ok(0) => break,
400-
Ok(n) => n,
401-
Err(_) => break,
402-
};
393+
let n = reader.read_until(b'\n', &mut line_buf)?;
394+
if n == 0 {
395+
break;
396+
}
403397
// Drop trailing partial lines — the next incremental call resumes
404398
// from the committed end offset, which only advances past `\n`.
405399
if line_buf.last() != Some(&b'\n') {
@@ -1209,7 +1203,7 @@ fn parse_codex_buffer<R: BufRead>(
12091203
last_completed_turn,
12101204
);
12111205

1212-
ParseCodexIncrementalResult {
1206+
Ok(ParseCodexIncrementalResult {
12131207
turns,
12141208
content: content_out,
12151209
events: events_out,
@@ -1218,7 +1212,7 @@ fn parse_codex_buffer<R: BufRead>(
12181212
tool_result_events: tool_events_out,
12191213
end_offset: committed_end_offset,
12201214
resume,
1221-
}
1215+
})
12221216
}
12231217

12241218
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)