def stage_td(root: Path, descriptor: Path, output: Path, *, recipes: dict, upstream_root: Path | None = None,
atf_cache_root: Path | None = None):
"""Verify all arcs, compare both exact backends, and stage one manifest and incumbent."""
path = root / validate_relative_sidecar_path(descriptor.as_posix())
instance_sha = file_sha256(path)
instance = load_td_benchmark_instance(path)
objective = base_objective(instance)
bks_path = get_bks_path_for_instance(path, objective)
bks_sha = file_sha256(bks_path)
bks = load_bks(bks_path)
checked = stream_td_materialization(path, root, route_arcs(bks.routes), atf_cache_root=atf_cache_root)
native = prepare_td(instance, checked.operands, backend="native", objective_function=objective).evaluate(bks.routes)
reference = prepare_td(instance, checked.operands, backend="python", objective_function=objective).evaluate(bks.routes)
if (native.routes, native.cost, native.route_evaluations) != (reference.routes, reference.cost, reference.route_evaluations):
raise ValueError("Exact TD backends disagree")
proof = dict(instance_sha256=instance_sha, incumbent_sha256=bks_sha,
atf_stream_sha256=checked.atf_stream_sha256, canonical_atf_sha256=checked.canonical_sha256,
sidecars=checked.sidecars, standard=standard_metadata(native), display_cost=native.display_cost)
return _write_stage(root, descriptor, output, proof, recipes, upstream_root)