diff --git a/docs/P2_M1_PROGRESS.md b/docs/P2_M1_PROGRESS.md index e1a6751..c60f954 100644 --- a/docs/P2_M1_PROGRESS.md +++ b/docs/P2_M1_PROGRESS.md @@ -18,6 +18,32 @@ | W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 | | W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 | +## 2026-11-29 私有日志与检查点资源重放 + +实时草稿把日志写到私有文件,使用有界缓冲,成功或失败清理时显式写入。 +核验并发布成功草稿时仍同步真实文件。丢弃草稿时不隐式写入剩余缓冲, +普通命令行作业继续即时写日志。输入重放直接比较资源层产生的路径及 +字节版本,保留实际查找和资源读取。格式作业按请求的 profile 加载和 +核对格式资源,省去构造随后会被丢弃的初始命令表。 + +在每边三个原样 A4 主文件热编辑窗口中,私有日志的实际写入各从 40 次 +降到 2 次,项目文件的总写入从 47 次降到 9 次。按目录归一化的日志 +逐字节一致。主文件和子文件各 10 对编辑的实际 PDF、SVG、来源映射、 +aux、归一化日志、变更页与复用步数一致,末版另开进程全量复核。 +该轮服务端准备阶段的配对中位变化为主文件 -0.58 ms、子文件 -0.97 ms, +服务端预览就绪为 +1.44 ms、-0.47 ms。本轮减少了重复操作,尚无稳定的 +端到端时延改善证据。 + +沿用原样 NeurIPS 2025 的 XeLaTeX 格式与资源。第 12 页编辑及恢复均 +只重算该页绘制列表,复用另外 11 页。两次发布的 PDF、预览、绘制列表、 +来源映射、实际读入和查找、辅助文件及 15,084 字节日志与同初态独立全量 +一致。未定义命令保留上一版 PDF、日志和辅助文件。定向通过了变更查找 +后的检查点回退、取消和冲突时的发布保护、格式依赖失效、TCX 与真实流 +字节五项检查。证据在 target/p4-draft-prefix-io/。 + +下一批优先减少实际仍执行的 TeX 后缀,以及核对跨文件依赖变更时的 +复用边界。正式浏览器可见延迟和模板矩阵继续按原目标验收。 + ## 2026-11-29 检查点命令表与准备阶段文件探测 检查点和格式作业共享有序命令表。发生写入时复制绑定表,保留共享的 diff --git a/src/native.rs b/src/native.rs index 19807b3..41dfdc7 100644 --- a/src/native.rs +++ b/src/native.rs @@ -33,7 +33,7 @@ pub use texrra_tex_core::resources::{WorldFailure, WorldObservation}; use texrra_tex_core::{ execution::{ Cancellation, ExecutionFailure, Executor, FormatImage, InputProfile, JobTime, Limits, - NativeSession, RevisionError, RevisionExecution, RevisionFailure, RevisionJob, SourceFile, + NativeSession, Profile, RevisionError, RevisionExecution, RevisionFailure, RevisionJob, SourceFile, SourceProvider, State, WriteDestination, }, pdf_unicode::XdvGlyphNames, @@ -783,23 +783,6 @@ fn prepare_checked( data: loaded.data, }; check(cancellation)?; - let state = if matches!(request.entry, Entry::Initex) { - State::initex() - } else { - State::default() - } - .with_job_time(request.time) - .with_input_profile(request.input_profile); - let state = if request.target == Target::Shipouts && !dump { - state.with_pdf_output() - } else { - state - }; - let state = if request.etex { - state.with_etex() - } else { - state - }; let translation = request.translation_file.as_ref().map(|name| { if request.input_profile != InputProfile::TeX8Bit { return Err("a TCX file requires the TeX 8-bit profile".to_owned()); @@ -809,6 +792,11 @@ fn prepare_checked( .map_err(|e| format!("TCX {}: {e}", loaded.version.path.display())) }).transpose()?; let (executor, format_preparation) = if let Entry::Format(name) = &request.entry { + let profile = if request.etex { + Profile::EtexBootstrap + } else { + Profile::Bootstrap + }; let loaded = world.read_shared(ResourceKind::Tex, &name.display().to_string(), &path)?; check(cancellation)?; @@ -864,7 +852,7 @@ fn prepare_checked( let image = &cached.image; let executor = if kernel == KernelPreparation::Resume { image.validate_shared_job_inputs( - state.profile(), + profile, request.input_profile, &mut world, read, @@ -873,7 +861,7 @@ fn prepare_checked( None } else { Some(image.fork_job_with_file_dates( - state.profile(), + profile, request.input_profile, request.time, request.limits, @@ -894,7 +882,7 @@ fn prepare_checked( image.bind_inputs(&bindings); let executor = if kernel == KernelPreparation::Resume { image.validate_shared_job_inputs( - state.profile(), + profile, request.input_profile, &mut world, read, @@ -903,7 +891,7 @@ fn prepare_checked( None } else { Some(image.new_job_with_file_dates( - state.profile(), + profile, request.input_profile, request.time, request.limits, @@ -916,8 +904,26 @@ fn prepare_checked( } } } else { - let executor = - (kernel == KernelPreparation::Fresh).then(|| Executor::new(state, request.limits)); + let executor = (kernel == KernelPreparation::Fresh).then(|| { + let state = if matches!(request.entry, Entry::Initex) { + State::initex() + } else { + State::default() + } + .with_job_time(request.time) + .with_input_profile(request.input_profile); + let state = if request.target == Target::Shipouts && !dump { + state.with_pdf_output() + } else { + state + }; + let state = if request.etex { + state.with_etex() + } else { + state + }; + Executor::new(state, request.limits) + }); (executor, None) }; let executor = match (executor, translation) { diff --git a/src/native_checkpoint_probe.rs b/src/native_checkpoint_probe.rs index f0b387b..1a7c208 100644 --- a/src/native_checkpoint_probe.rs +++ b/src/native_checkpoint_probe.rs @@ -109,9 +109,12 @@ impl SourceProvider for RecordingHost<'_> { } fn read(&mut self, name: &str, from: &str) -> Result { let (name, from) = (name.to_owned(), from.to_owned()); - call!(self, read(&name, &from); |result| { - result.as_ref().map(|file| (file.name.clone(), digest(&file.data))).map_err(Clone::clone) - }) + self.record( + "read", + move |files| files.read_versioned_source(&name, &from), + |result| result.as_ref().map(|(_, version)| version.clone()).map_err(Clone::clone), + ) + .map(|(source, _)| source) } fn resource( &mut self, @@ -312,6 +315,7 @@ impl SourceProvider for RecordingHost<'_> { } } +#[cfg(test)] fn digest(bytes: &[u8]) -> String { use sha2::{Digest, Sha256}; format!("{:x}", Sha256::digest(bytes)) diff --git a/src/native_job.rs b/src/native_job.rs index 073d973..1333c8f 100644 --- a/src/native_job.rs +++ b/src/native_job.rs @@ -12,7 +12,7 @@ use std::{ collections::{BTreeMap, BTreeSet}, ffi::OsStr, fs::{self, File, OpenOptions}, - io::{self, BufRead, BufReader, Seek, Write}, + io::{self, BufRead, BufReader, BufWriter, Seek, Write}, path::{Path, PathBuf}, sync::{ Arc, @@ -167,7 +167,7 @@ pub struct Files { next_handle: u64, stream_io: StreamJournal, log_path: PathBuf, - log: Option, + log: Option>, draft: Option, protected: Vec, producer: PathBuf, @@ -186,6 +186,13 @@ pub struct Files { preparation: HostPreparation, runtime_observations: RefCell, } +fn transcript_writer(file: File, draft: bool) -> BufWriter { + // Draft bytes remain private until cleanup and publication. Live jobs + // keep reporting actual writes to the transcript during execution. + let capacity = if draft { 8192 } else { 0 }; + BufWriter::with_capacity(capacity, file) +} + fn output_column(previous: usize, text: &str) -> usize { match text.rsplit_once('\n') { Some((_, tail)) => tail.chars().count(), @@ -561,7 +568,7 @@ impl Files { next_handle: 0, stream_io: StreamJournal::default(), log_path, - log: Some(log), + log: Some(transcript_writer(log, draft.is_some())), draft, protected, producer: source.to_owned(), @@ -890,6 +897,20 @@ impl Files { .map(PathBuf::as_path), ) } + pub(crate) fn read_versioned_source( + &mut self, + name: &str, + from: &str, + ) -> Result<(SourceFile, ResourceVersion), String> { + let resource = self.world.read_tex_input(name, Path::new(from))?; + self.observe_resource(ResourceKind::Tex, &resource); + let source = SourceFile { + name: resource.version.path.display().to_string(), + data: resource.data, + }; + Ok((source, resource.version)) + } + fn observe_resource(&mut self, kind: ResourceKind, resource: &LoadedResource) { let path = &resource.version.path; if kind == ResourceKind::Tex && self.ledger.owns(path) && !self.is_protected(path) { @@ -1081,14 +1102,12 @@ impl Files { }; if destination != WriteDestination::TerminalOnly { if self.log.is_none() { - self.log = Some( - File::create( - self.draft - .as_ref() - .map_or(&self.log_path, |draft| &draft.log.staged.path), - ) - .map_err(|e| format!("native log {}: {e}", self.log_path.display()))?, - ); + let path = self.draft + .as_ref() + .map_or(&self.log_path, |draft| &draft.log.staged.path); + let file = File::create(path) + .map_err(|e| format!("native log {}: {e}", self.log_path.display()))?; + self.log = Some(transcript_writer(file, self.draft.is_some())); } let log = self.log.as_mut().unwrap(); if start_line && self.log_column != 0 { @@ -1189,11 +1208,16 @@ impl Files { queue: &DraftSyncQueue, cancellation: &Cancellation, ) -> Result, String> { - let draft = self.draft.take().ok_or("native draft host required")?; + let draft = self.draft.as_ref().ok_or("native draft host required")?; if !draft.finished { return Err("native draft must finish successfully before publication".into()); } - let log = self.log.take(); + let draft = self.draft.take().expect("finished draft"); + let log = self.log.take().map(|log| { + let (file, buffer) = log.into_parts(); + debug_assert!(buffer.is_ok_and(|bytes| bytes.is_empty())); + file + }); let initial = self .preparation .generated_initial @@ -1441,6 +1465,13 @@ impl PendingDraft { impl Drop for Files { fn drop(&mut self) { + if self.draft.is_some() { + // A discarded draft has no reader. Drop pending bytes without + // triggering BufWriter's implicit flush on cancellation/rejection. + if let Some(log) = self.log.take() { + drop(log.into_parts()); + } + } // Keep the caller's fatal diagnostic on its own physical line when // execution aborts before finish closes the input entry. if self.terminal_sink && self.terminal_column != 0 { @@ -1638,13 +1669,7 @@ impl SourceProvider for Files { self.emit_diagnostic(WriteDestination::TerminalOnly, terminal, false) } fn read(&mut self, name: &str, from: &str) -> Result { - let resource = self.world.read_tex_input(name, Path::new(from))?; - self.observe_resource(ResourceKind::Tex, &resource); - let path = resource.version.path; - Ok(SourceFile { - name: path.display().to_string(), - data: resource.data, - }) + self.read_versioned_source(name, from).map(|(source, _)| source) } fn resource( &mut self,