Retry earlier checkpoints after host replay changes
This commit is contained in:
1 parent
d4e78bc29a
commit
09cd19594c
3 files changed
+247
-61
No files matched your search
@@ -18,6 +18,30 @@
|
||||
| W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 |
|
||||
| W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 |
|
||||
|
||||
## 2026-11-28 资源查找失效后继续验证更早的检查点
|
||||
|
||||
按已执行步数从后向前验证检查点。主文件前缀、已读资源及生成文件初态
|
||||
通过检查后,在草稿宿主上按原顺序重放调用。返回值或实际查找记录变化时,
|
||||
丢弃该候选的草稿及文件句柄,再验证更早的候选。对已经失败的调用,跳过
|
||||
同组内必须重放该调用的候选。新一轮草稿在作业锁内重新核对初态。
|
||||
全部候选失效时执行同一原生内核的全量作业。
|
||||
|
||||
沿用实际 Latin Modern 字体的三页会话。新增覆盖字号的字体原先需要全文
|
||||
重执行,现在复用 743 步并只发出第 2 页。移除该候选和替换原先比较过的
|
||||
未选中字体时继续各复用 743 步。只改子文件注释时复用 2,176 步,无页差量。
|
||||
四轮 PDF、页面、SVG、辅助文件及来源映射均与独立全量一致。
|
||||
|
||||
新增文件查找的定向回归覆盖此前缺失的输入出现,以及文件尺寸相同但
|
||||
命中另一条路径。分别复用 459 和 947 步,实际查找记录与独立全量一致。
|
||||
执行前核对已发布的 PDF、日志及辅助文件,确认被拒绝的候选未发布草稿。
|
||||
最终输出流日志各只有两次预期写入。既有固定检查点用例的九种修订通过,
|
||||
保留无有效检查点时的安全全量路径。发布构建及两项定向回归通过。
|
||||
|
||||
前后对照与原失败保存在 `target/p4-checkpoint-replay-retry`,
|
||||
`receipt.json` 的 SHA-256 为
|
||||
`510f3ad17296a38f3f04587d08caff825f88654fec18fb304e09a9b4ed2fb0f6`。
|
||||
本轮记录实际执行复用。端到端延迟和内存留在同版性能验收。
|
||||
|
||||
## 2026-11-28 XeTeX 同族字体的光学版本选择
|
||||
|
||||
按名称装载字体时,从同族候选字体的 GPOS `size` 读取光学组和适用范围。
|
||||
|
||||
@@ -3,7 +3,11 @@ use super::checkpoint_probe::{Call, RecordingHost};
|
||||
use super::*;
|
||||
#[cfg(test)]
|
||||
use std::{collections::BTreeMap, fs};
|
||||
use std::{collections::BTreeSet, ffi::OsString, path::Path};
|
||||
use std::{
|
||||
collections::{BTreeSet, VecDeque},
|
||||
ffi::OsString,
|
||||
path::Path,
|
||||
};
|
||||
use texrra_tex_core::{
|
||||
execution::EntryCheckpoint,
|
||||
resources::{ResourceKind, ResourceLookup},
|
||||
@@ -378,75 +382,94 @@ impl PublishedCheckpoints {
|
||||
.chain(self.previous_body.iter().flat_map(|body| body.candidates()))
|
||||
.collect();
|
||||
candidates.sort_by_key(|candidate| std::cmp::Reverse(candidate.completed_steps()));
|
||||
let mut candidates = candidates.into_iter();
|
||||
let mut rejection = None;
|
||||
let first = candidates
|
||||
.by_ref()
|
||||
.find(|candidate| {
|
||||
let checkpoint = &candidate.set.entries[candidate.index];
|
||||
match checkpoint
|
||||
.accept_entry(project)
|
||||
.and_then(|()| checkpoint.guard.verify_project(request))
|
||||
{
|
||||
Ok(_) => true,
|
||||
Err(error) => {
|
||||
rejection.get_or_insert(error);
|
||||
false
|
||||
}
|
||||
}
|
||||
})
|
||||
.ok_or_else(|| {
|
||||
CompileError::Host(
|
||||
rejection.unwrap_or_else(|| "no entry checkpoint retained".into()),
|
||||
)
|
||||
})?;
|
||||
|
||||
// Host preparation observes the actual generated files while the job
|
||||
// lock is held. Choose a valid prefix before replaying any effects.
|
||||
let mut selected = None;
|
||||
let mut prepared = prepare_checked(
|
||||
request,
|
||||
false,
|
||||
Some(cache),
|
||||
cancellation,
|
||||
evidence,
|
||||
Some(Box::new(|world, preparation| {
|
||||
let mut rejection = None;
|
||||
for candidate in std::iter::once(first).chain(candidates) {
|
||||
let mut candidates = VecDeque::from(candidates);
|
||||
let mut guard_rejection = None;
|
||||
let mut replay_rejection = None;
|
||||
'retry: loop {
|
||||
check(cancellation)?;
|
||||
let first = std::iter::from_fn(|| candidates.pop_front())
|
||||
.find(|candidate| {
|
||||
let checkpoint = &candidate.set.entries[candidate.index];
|
||||
match checkpoint
|
||||
.accept_entry(project)
|
||||
.and_then(|()| checkpoint.guard.verify(request, world, preparation))
|
||||
.and_then(|()| checkpoint.guard.verify_project(request))
|
||||
{
|
||||
Ok(()) => {
|
||||
selected = Some(candidate);
|
||||
return Ok(());
|
||||
}
|
||||
Ok(_) => true,
|
||||
Err(error) => {
|
||||
rejection.get_or_insert(error);
|
||||
guard_rejection.get_or_insert(error);
|
||||
false
|
||||
}
|
||||
}
|
||||
})
|
||||
.ok_or_else(|| {
|
||||
replay_rejection
|
||||
.take()
|
||||
.or_else(|| guard_rejection.take().map(CompileError::Host))
|
||||
.unwrap_or_else(|| CompileError::Host("no entry checkpoint retained".into()))
|
||||
})?;
|
||||
|
||||
// Each replay owns a separate draft and observes the generated
|
||||
// initial state under the job lock before writing any effects.
|
||||
let mut selected = None;
|
||||
let mut attempt = AttemptEvidence::new(evidence.revision);
|
||||
attempt.phase = evidence.phase;
|
||||
let mut prepared = prepare_checked(
|
||||
request,
|
||||
false,
|
||||
Some(cache),
|
||||
cancellation,
|
||||
&mut attempt,
|
||||
Some(Box::new(|world, preparation| {
|
||||
let mut rejection = None;
|
||||
let remaining = std::iter::from_fn(|| candidates.pop_front());
|
||||
for candidate in std::iter::once(first).chain(remaining) {
|
||||
let checkpoint = &candidate.set.entries[candidate.index];
|
||||
match checkpoint
|
||||
.accept_entry(project)
|
||||
.and_then(|()| checkpoint.guard.verify(request, world, preparation))
|
||||
{
|
||||
Ok(()) => {
|
||||
selected = Some(candidate);
|
||||
return Ok(());
|
||||
}
|
||||
Err(error) => {
|
||||
rejection.get_or_insert(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(rejection.unwrap_or_else(|| "no entry checkpoint retained".into()))
|
||||
})),
|
||||
EffectMode::Draft,
|
||||
KernelPreparation::Resume,
|
||||
)?;
|
||||
let selected = selected.expect("resume preparation chose a verified checkpoint");
|
||||
let checkpoint = &selected.set.entries[selected.index];
|
||||
for (index, call) in selected.set.calls[..checkpoint.replay_count].iter().enumerate() {
|
||||
check(cancellation)?;
|
||||
if let Err(error) = call(&mut prepared.files) {
|
||||
replay_rejection.get_or_insert(CompileError::Host(error));
|
||||
// Other checkpoints sharing this call cannot use the
|
||||
// invalidated prefix either. Drop the draft on retry.
|
||||
candidates.retain(|candidate| {
|
||||
!Arc::ptr_eq(&candidate.set, &selected.set)
|
||||
|| candidate.set.entries[candidate.index].replay_count <= index
|
||||
});
|
||||
continue 'retry;
|
||||
}
|
||||
Err(rejection.unwrap_or_else(|| "no entry checkpoint retained".into()))
|
||||
})),
|
||||
EffectMode::Draft,
|
||||
KernelPreparation::Resume,
|
||||
)?;
|
||||
let selected = selected.expect("resume preparation chose a verified checkpoint");
|
||||
let checkpoint = &selected.set.entries[selected.index];
|
||||
for call in &selected.set.calls[..checkpoint.replay_count] {
|
||||
check(cancellation)?;
|
||||
call(&mut prepared.files)?;
|
||||
}
|
||||
if !checkpoint
|
||||
.guard
|
||||
.project
|
||||
.immutable_paths()
|
||||
.eq(project.immutable_paths())
|
||||
&& let Err(error) = checkpoint.guard.verify_replayed_lookups(&prepared.files)
|
||||
{
|
||||
replay_rejection.get_or_insert(error);
|
||||
continue;
|
||||
}
|
||||
*evidence = attempt;
|
||||
return Ok((selected, prepared));
|
||||
}
|
||||
if !checkpoint
|
||||
.guard
|
||||
.project
|
||||
.immutable_paths()
|
||||
.eq(project.immutable_paths())
|
||||
{
|
||||
checkpoint.guard.verify_replayed_lookups(&prepared.files)?;
|
||||
}
|
||||
Ok((selected, prepared))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2226,6 +2226,145 @@ fn relocated_format_checks_current_sources_and_consumed_stream_ranges() {
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replay_rejection_resumes_earlier_without_publishing_rejected_effects() {
|
||||
struct PublishedBeforeExecution(Vec<(PathBuf, Vec<u8>)>);
|
||||
|
||||
impl CompileObserver for PublishedBeforeExecution {
|
||||
fn stage(&self, _: u64, stage: CompileStage) -> Result<(), String> {
|
||||
if stage == CompileStage::Prepared {
|
||||
for (path, previous) in &self.0 {
|
||||
assert_eq!(&fs::read(path).unwrap(), previous, "{}", path.display());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
let cwd = directory("retry-entry-replay").canonicalize().unwrap();
|
||||
let vendor = cwd.join("vendor");
|
||||
let aux = cwd.join("main.aux");
|
||||
let log = cwd.join("job.log");
|
||||
let pdf = cwd.join("job.pdf");
|
||||
let aux_bytes = b"BEGIN\nEND\n";
|
||||
fs::write(&aux, aux_bytes).unwrap();
|
||||
let padding = "\\advance\\count0 by 1\\relax\n".repeat(32);
|
||||
let source = format!(
|
||||
r"\catcode123=1 \catcode125=2
|
||||
\def\widthfrominput{{10}}
|
||||
{padding}\immediate\openout1=main.aux
|
||||
\immediate\write1{{BEGIN}}
|
||||
{padding}\openin3=settings.tex
|
||||
\ifeof3\else\input settings.tex \fi\closein3
|
||||
\edef\sizeoftag{{\pdffilesize{{tag.tex}}}}
|
||||
{padding}{padding}\shipout\hbox{{\vrule width\widthfrominput pt height1pt}}
|
||||
\immediate\write1{{END}}
|
||||
\immediate\closeout1
|
||||
\end"
|
||||
);
|
||||
let optional_lookup = source.find("\\openin3=").unwrap();
|
||||
let size_lookup = source.find("\\edef\\sizeoftag").unwrap();
|
||||
let mut world = WorldConfig::new(&cwd);
|
||||
world.input_policy = texrra_tex_core::resources::InputPolicy::Tex;
|
||||
world.paths.insert(
|
||||
ResourceKind::Tex,
|
||||
vec![
|
||||
SearchPath::directory(&cwd, false),
|
||||
SearchPath::directory(&vendor, false),
|
||||
],
|
||||
);
|
||||
let mut project = ProjectSnapshot::new(ProjectDefinition {
|
||||
configuration: world.clone(),
|
||||
revision: 1,
|
||||
roots: [cwd.clone()].into(),
|
||||
files: [
|
||||
(cwd.join("main.tex"), source.into_bytes().into()),
|
||||
(vendor.clone().join("tag.tex"), Arc::from(b"42".as_slice())),
|
||||
]
|
||||
.into(),
|
||||
directories: [vendor].into(),
|
||||
aliases: Default::default(),
|
||||
generated_roots: [cwd.clone()].into(),
|
||||
generated: [aux.clone()].into(),
|
||||
})
|
||||
.unwrap();
|
||||
let job_time = JobTime::new(2026, 11, 28, 0)
|
||||
.unwrap()
|
||||
.with_pdf_clock(0, 0)
|
||||
.unwrap();
|
||||
let mut job = CompileRequest::new(world, "main.tex", "job.pdf", job_time);
|
||||
job.entry = Entry::Initex;
|
||||
let session = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
let mut previous = session
|
||||
.compile(job.clone().with_project(project.clone()))
|
||||
.unwrap();
|
||||
for (revision, name, bytes, lookup_offset) in [
|
||||
(
|
||||
2,
|
||||
"settings.tex",
|
||||
br"\def\widthfrominput{20}".as_slice(),
|
||||
optional_lookup,
|
||||
),
|
||||
(3, "tag.tex", b"59".as_slice(), size_lookup),
|
||||
] {
|
||||
assert!(previous.entry_checkpoint_work.captured_frontier.unwrap() > size_lookup);
|
||||
let new_path = cwd.join(name);
|
||||
project = project
|
||||
.with_file_changes(revision, [(new_path.clone(), Some(bytes.into()))].into())
|
||||
.unwrap();
|
||||
let next = job.clone().with_project(project.clone());
|
||||
let mut observed = next.clone();
|
||||
observed.observer = Some(Arc::new(PublishedBeforeExecution(
|
||||
[&aux, &log, &pdf]
|
||||
.into_iter()
|
||||
.map(|path| (path.clone(), fs::read(path).unwrap()))
|
||||
.collect(),
|
||||
)));
|
||||
let result = session.compile(observed).unwrap();
|
||||
let work = &result.entry_checkpoint_work;
|
||||
assert!(work.reused_steps > 0, "{work:?}");
|
||||
assert!(work.reused_frontier.unwrap() <= lookup_offset, "{work:?}");
|
||||
assert_eq!(fs::read(&aux).unwrap(), aux_bytes);
|
||||
let replayed_log = fs::read(&log).unwrap();
|
||||
let full = NativeCompiler::default().compile(next).unwrap();
|
||||
assert_eq!(result.pdf, full.pdf);
|
||||
assert_eq!(result.pages, full.pages);
|
||||
assert_eq!(result.source_map.pages, full.source_map.pages);
|
||||
assert_eq!(result.source_map.sources, full.source_map.sources);
|
||||
assert_eq!(
|
||||
result.preview_since(None).unwrap().pages,
|
||||
full.preview_since(None).unwrap().pages
|
||||
);
|
||||
assert_eq!(result.resources.trace.lookups, full.resources.trace.lookups);
|
||||
assert!(
|
||||
result
|
||||
.resources
|
||||
.trace
|
||||
.lookups
|
||||
.iter()
|
||||
.any(|lookup| lookup.resolved.as_deref() == Some(new_path.as_path()))
|
||||
);
|
||||
let journal = result.resources.stream_io.events();
|
||||
assert_eq!(
|
||||
journal
|
||||
.iter()
|
||||
.filter(|event| matches!(&event.effect, StreamEffect::Write { stream: 1, .. }))
|
||||
.count(),
|
||||
2
|
||||
);
|
||||
assert_eq!(fs::read(&aux).unwrap(), aux_bytes);
|
||||
assert_eq!(fs::read(&log).unwrap(), replayed_log);
|
||||
if revision == 2 {
|
||||
assert_ne!(result.pdf, previous.pdf);
|
||||
} else {
|
||||
assert_eq!(result.pdf, previous.pdf);
|
||||
}
|
||||
eprintln!("{name}: {work:?}");
|
||||
previous = result;
|
||||
}
|
||||
fs::remove_dir_all(cwd).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relocated_format_binds_packed_and_new_glyphs_to_the_current_tfm() {
|
||||
use texrra_tex_core::render::DisplayItem;
|
||||
|
||||
Reference in new issue
Block a user