Relocate source provenance when native suffixes move

This commit is contained in:
gloamxun committed 2026-12-01 22:17:10 +08:00
1 parent 6acd82dbfa
commit 41a459b4ca
16 files changed
+1507 -79

No files matched your search

+23 -6
View File
@@ -159,6 +159,20 @@ struct DraftLedger {
#[derive(PartialEq, Eq)]
pub(super) struct ReplayBoundary {
entry_bytes: Option<u64>,
state: ReplayState,
}
impl ReplayBoundary {
/// Ignore only the first entry read's length. The caller authenticates
/// that read and checks all later observations of the entry path.
pub(super) fn matches_for_suffix(&self, prior: &Self) -> bool {
self.entry_bytes.is_some() && prior.entry_bytes.is_some() && self.state == prior.state
}
}
#[derive(PartialEq, Eq)]
struct ReplayState {
inputs: Vec<(u8, u64, PathBuf, u64, std::collections::VecDeque<u8>)>,
outputs: Vec<(u8, u64, PathBuf, u64)>,
next_handle: u64,
@@ -671,11 +685,13 @@ impl Files {
pub(super) fn replay_boundary(&self) -> ReplayBoundary {
let mut trace = self.resource_trace().clone();
trace.project_version = None;
// The caller compared the live scanner bytes and validates later
// whole-file reads separately. Keep this entry's path and length.
if let Some(entry) = trace.reads.first_mut() {
// The entry scanner verifies source bytes separately. Retain the
// first read's path in the comparison and store its length apart,
// since later live checkpoints still require exact lengths.
let entry_bytes = trace.reads.first_mut().map(|entry| {
entry.sha256.clear();
}
std::mem::take(&mut entry.bytes)
});
let mut stream_events = self.stream_io.events().to_vec();
for event in &mut stream_events {
if let crate::native_stream::StreamEffect::OutputOpened {
@@ -687,7 +703,7 @@ impl Files {
identity.unix_identity = None;
}
}
ReplayBoundary {
let state = ReplayState {
inputs: self.inputs.iter().map(|(&index, input)| {
(index, input.handle, input.path.clone(), input.offset, input.xe_lookahead.clone())
}).collect(),
@@ -702,7 +718,8 @@ impl Files {
generated_written: self.generated_written.clone(),
trace,
stream_events,
}
};
ReplayBoundary { entry_bytes, state }
}
pub(super) fn replay_world(&self) -> &FileWorld {