MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / flush_pending_snapshot

Method flush_pending_snapshot

crates/opencode-session/src/llm.rs:745–773  ·  view source on GitHub ↗

Flush any pending snapshot that wasn't closed by a `FinishStep` event. When the stream ends abruptly (error, abort, or missing `finish-step`), there may be a snapshot from `StartStep` that was never diffed. This mirrors the TS processor.ts post-loop logic (lines 379-392) that computes the final patch if `snapshot` is still set.

(&mut self, work_dir: Option<&Path>)

Source from the content-addressed store, hash-verified

743 /// mirrors the TS processor.ts post-loop logic (lines 379-392) that
744 /// computes the final patch if `snapshot` is still set.
745 fn flush_pending_snapshot(&mut self, work_dir: Option<&Path>) {
746 let snapshot_hash = match self.snapshot.take() {
747 Some(h) => h,
748 None => return,
749 };
750 let dir = match work_dir {
751 Some(d) => d,
752 None => return,
753 };
754
755 match Snapshot::diff(dir, &snapshot_hash) {
756 Ok(diffs) => {
757 let files: Vec<String> = diffs.into_iter().map(|d| d.path).collect();
758 if !files.is_empty() {
759 self.pending_patches.push(SnapshotPatch {
760 hash: snapshot_hash,
761 files,
762 });
763 }
764 }
765 Err(e) => {
766 tracing::warn!(
767 session_id = %self.session_id,
768 error = %e,
769 "Failed to compute snapshot patch during flush"
770 );
771 }
772 }
773 }
774
775 /// Mark any incomplete tool parts as "error" with "Tool execution aborted".
776 /// Mirrors the TS abort handling at the end of the process loop.

Callers 1

processMethod · 0.80

Calls 1

is_emptyMethod · 0.80

Tested by

no test coverage detected