Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/diagrams/graph-archive-chain.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: Removed run · retention chain
---
stateDiagram-v2
direction LR
classDef ok stroke-width:1.6px

[*] --> active : run removed
active --> archived : 64 active, oldest
archived --> pruned : 256 archived, oldest
pruned --> gone : 4096 tombstones, oldest
gone --> [*]

note right of archived
Proof: every owned
resource absent.
end note
note right of pruned
Exported first; tombstone
kept; export 7 days.
end note
note right of gone
Fresh ids are 128 random
bits; restore needs a
receipt, long gone.
end note

class gone ok
Binary file added docs/diagrams/graph-archive-chain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions docs/diagrams/graph-archive-chain.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion docs/guides/native-candidate.md
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,18 @@ provider lease it already holds and with the same proof `graph archive` uses (ev
owned resource absent, no pending journal). Runs that keep data are never archived;
when they alone fill the inventory, `hack up` refuses with `graph_retention_budget`
and says to remove the data of a project you no longer use. The archive keeps up to
256 runs; past that the refusal is `graph_archive_budget`. A project whose removed
256 runs; at that bound the oldest archived removed runs are exported (as
`graph export` does, into the home's `exports/graphs`) and pruned (as `graph prune`
does), and each keeps a consumed-ID tombstone so its run ID cannot start a fresh run
again. The store keeps 4096 tombstones; at that bound the oldest tombstones of fully
pruned runs go. That is safe because a tombstone only refuses a fresh start with
that ID, the CLI makes every fresh run ID from 128 random bits at the start, and a
restore needs the run's receipt, which pruning already removed. The export of a
fully pruned run is diagnostics: it is kept seven days, and at most 256 of them,
oldest first. An interrupted export or prune is resumed the next time. Only archived
runs that cannot be proven (one archived under an earlier guest incarnation, whose
owner no longer matches) keep their place; if 256 of those fill the archive,
`graph_archive_budget` still refuses and names `graph export` and `graph prune`. A project whose removed
run was archived this way before its `hack down --remove-data` confirmed the removal
still confirms it: inspection reads a removed run from the archive.
For a shared-source graph that reconciliation does not select (live source, a
Expand Down
6 changes: 4 additions & 2 deletions packages/runtime-core/src/provider/graph/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,12 @@ fn archive_with(
"Archived evidence already exists; it will not be replaced.",
));
}
if fs::read_dir(parent).map_err(state::io)?.take(256).count() >= 256 {
// HACK-2576: the oldest archived removed runs are exported and pruned first.
retention::make_archive_room(candidate, engine)?;
if fs::read_dir(parent).map_err(state::io)?.take(256).count() >= retention::ARCHIVE_LIMIT {
return Err(error(
"graph_archive_budget",
"Archive retains 256 attempts; explicit export/retention work is required.",
"Archive retains 256 attempts that cannot be pruned automatically (for example archived under an earlier guest incarnation); export and prune them with graph export and graph prune.",
));
}
fs::rename(&root, &target).map_err(state::io)?;
Expand Down
13 changes: 11 additions & 2 deletions packages/runtime-core/src/provider/graph/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ pub struct Export {
/// Export private, bounded archive evidence without deleting the consumed attempt reservation.
pub fn export(candidate: &Candidate, run: &str) -> Result<Export, CandidateError> {
let engine = Engine::connect_cleanup(candidate)?;
export_with(candidate, &engine, run)
}

/// [`export`] under a provider lease the caller already holds.
pub(super) fn export_with(
candidate: &Candidate,
engine: &Engine<'_>,
run: &str,
) -> Result<Export, CandidateError> {
let root = archive::path(candidate, run)?;
state::check_private_directory(&root)?;
let receipt: Receipt = state::read(&root.join("state.json"))?;
Expand All @@ -33,8 +42,8 @@ pub fn export(candidate: &Candidate, run: &str) -> Result<Export, CandidateError
));
}
cleanup_enrollment::retention(&root, &receipt)?;
archive::verify_removed(&engine, &receipt)?;
environment::archive_slots(candidate, &engine, &receipt, &root)?;
archive::verify_removed(engine, &receipt)?;
environment::archive_slots(candidate, engine, &receipt, &root)?;
let (bytes, files) = bundle(&root)?;
let parent = candidate.state_root.join("exports/graphs");
state::private_directory(&parent)?;
Expand Down
Loading
Loading