Skip to content

Commit e0c8fa0

Browse files
willwashburnclaude
andauthored
relayburn-sdk: reader cleanup deferred subset (#346) (#371)
Remaining reader-module cleanups deferred from #352: - codex.rs / opencode.rs: replace the manual repack of the incremental result with `From<ParseCodexIncrementalResult> for ParseCodexResult` (and the opencode equivalent), and have `parse_*_session` delegate via `.map(...::from)`. - codex.rs: drop the two `let _ = (...)` blocks at the tail of `parse_codex_buffer`. The audit confirms each `committed_*` snapshot is read by either the resume state or the emitted records, so the trailing working values are genuinely dead and removing the silencing blocks introduces no compiler warnings. - codex.rs: rename `memchr_newline` to `find_newline` so the name no longer implies a `memchr`-crate optimization that isn't there. The claude.rs parser-duplication item from #346 stays deferred: the non-incremental `ParseState` emits in-progress turns (records with `stop_reason.is_none()`), while `run_incremental` deliberately defers them to keep the next call's start cursor honest. Collapsing the two paths needs a flag on `run_incremental` and broader fixture validation; out of scope for this safe-subset PR. https://claude.ai/code/session_01GHEd4Sv87QoUTd1BN6FbAF Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2c352ea commit e0c8fa0

2 files changed

Lines changed: 30 additions & 36 deletions

File tree

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

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,20 @@ pub fn parse_codex_session(
152152
start_offset: Some(0),
153153
resume: None,
154154
};
155-
let r = parse_codex_session_incremental(file_path, &inc_opts)?;
156-
Ok(ParseCodexResult {
157-
turns: r.turns,
158-
content: r.content,
159-
events: r.events,
160-
user_turns: r.user_turns,
161-
relationships: r.relationships,
162-
tool_result_events: r.tool_result_events,
163-
})
155+
parse_codex_session_incremental(file_path, &inc_opts).map(ParseCodexResult::from)
156+
}
157+
158+
impl From<ParseCodexIncrementalResult> for ParseCodexResult {
159+
fn from(r: ParseCodexIncrementalResult) -> Self {
160+
Self {
161+
turns: r.turns,
162+
content: r.content,
163+
events: r.events,
164+
user_turns: r.user_turns,
165+
relationships: r.relationships,
166+
tool_result_events: r.tool_result_events,
167+
}
168+
}
164169
}
165170

166171
pub fn parse_codex_session_incremental(
@@ -389,7 +394,7 @@ fn parse_codex_buffer(
389394

390395
let mut p: usize = 0;
391396
while p < buf.len() {
392-
let nl_idx = match memchr_newline(&buf[p..]) {
397+
let nl_idx = match find_newline(&buf[p..]) {
393398
Some(idx) => p + idx,
394399
None => break,
395400
};
@@ -1092,10 +1097,6 @@ fn parse_codex_buffer(
10921097
}
10931098
}
10941099

1095-
// Suppress unused warnings: these are kept for parity with the TS state
1096-
// machine even when their values aren't read after the loop.
1097-
let _ = (next_event_index, tool_result_counters);
1098-
10991100
// Emit only committed turns.
11001101
let committed = &finalized[..committed_finalized_count];
11011102
let mut turns: Vec<TurnRecord> = Vec::with_capacity(committed.len());
@@ -1184,18 +1185,6 @@ fn parse_codex_buffer(
11841185
}
11851186
}
11861187

1187-
// Silence unused-mutable warnings for snapshot mirrors that are written
1188-
// but only read indirectly.
1189-
let _ = (
1190-
cumulative,
1191-
session_id,
1192-
session_cwd,
1193-
turn_contexts,
1194-
seen_session_meta_keys,
1195-
root_session_emitted,
1196-
last_completed_turn,
1197-
);
1198-
11991188
ParseCodexIncrementalResult {
12001189
turns,
12011190
content: content_out,
@@ -1228,7 +1217,7 @@ fn resolve_token_counter(
12281217
}
12291218
}
12301219

1231-
fn memchr_newline(buf: &[u8]) -> Option<usize> {
1220+
fn find_newline(buf: &[u8]) -> Option<usize> {
12321221
buf.iter().position(|&b| b == b'\n')
12331222
}
12341223

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,20 @@ pub fn parse_opencode_session(
8888
tokenizer: options.tokenizer,
8989
seen_message_ids: None,
9090
};
91-
let r = parse_opencode_session_incremental(session_file_path, &inc_opts)?;
92-
Ok(ParseOpencodeResult {
93-
turns: r.turns,
94-
content: r.content,
95-
events: r.events,
96-
user_turns: r.user_turns,
97-
relationships: r.relationships,
98-
tool_result_events: r.tool_result_events,
99-
})
91+
parse_opencode_session_incremental(session_file_path, &inc_opts).map(ParseOpencodeResult::from)
92+
}
93+
94+
impl From<ParseOpencodeIncrementalResult> for ParseOpencodeResult {
95+
fn from(r: ParseOpencodeIncrementalResult) -> Self {
96+
Self {
97+
turns: r.turns,
98+
content: r.content,
99+
events: r.events,
100+
user_turns: r.user_turns,
101+
relationships: r.relationships,
102+
tool_result_events: r.tool_result_events,
103+
}
104+
}
100105
}
101106

102107
pub fn parse_opencode_session_incremental(

0 commit comments

Comments
 (0)