Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
941f66d
revert(workspace): move the read-ahead window change out of the GC PR
yifanxuaaa Nov 24, 2026
77af674
chore: restore base tests and drop stray files from the GC PR
yifanxuaaa Nov 24, 2026
5c3671f
fix(control): best-effort tombstone, place view only for admitting ca…
yifanxuaaa Nov 24, 2026
1f5c01b
Merge branch 'claude/p4-ctl' into claude/p4-lean-int
yifanxuaaa Nov 24, 2026
25c261b
fix(persistence): keep the base Store format; place tokens live in ev…
yifanxuaaa Nov 24, 2026
2c120f0
test(store): read main's list row by its `branch` key
yifanxuaaa Nov 24, 2026
f4ef1ec
Merge branch 'claude/p4-fmt' into claude/p4-lean-int
yifanxuaaa Nov 24, 2026
32fd231
fix(gc): admission never judges a live holder dead where the base wou…
yifanxuaaa Nov 24, 2026
3cd765a
Merge branch 'claude/p4-logic' into claude/p4-lean-int
yifanxuaaa Nov 24, 2026
a54d5a3
test(gc): fix the PR's failing GC tests
yifanxuaaa Nov 24, 2026
edecc1d
style: rustfmt the files this PR touched
yifanxuaaa Nov 24, 2026
1cfc959
fix(gc): another home's token is no evidence; no place-proved death o…
yifanxuaaa Nov 24, 2026
f396df4
docs(gc): describe the final place-authority rules
yifanxuaaa Nov 24, 2026
ff8d68f
fix(sandbox): worker place evidence and a tombstone on every removal …
yifanxuaaa Nov 24, 2026
75b000d
fix(persistence): bound the done audit per Branch; PostgreSQL release…
yifanxuaaa Nov 24, 2026
c0b3e29
feat(gc): a real liveness verdict, the 2.0 repair call surface, lefto…
yifanxuaaa Nov 24, 2026
986d3b8
test(store): the PostgreSQL repair test sets up through project.init
yifanxuaaa Nov 24, 2026
58716c8
fix(sandbox): the caller's place always wins in a worker's Sandbox re…
yifanxuaaa Nov 24, 2026
1b17dbb
fix(store): a full last audit page names no next cursor
yifanxuaaa Nov 24, 2026
42d4bb7
Merge pull request #784 from Ephemeral-AI-Lab/claude/gc-place-gaps
yifanxuaaa Nov 24, 2026
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
4 changes: 0 additions & 4 deletions .lww

This file was deleted.

70 changes: 27 additions & 43 deletions api/crates/layerfs-api/src/store/repair_mount_holders.rs
Original file line number Diff line number Diff line change
@@ -1,66 +1,50 @@
//! `store.repair_mount_holders`: explicit first-class repair of one Branch's
//! mount admissions, on the machine whose worker holds a SQLite Store and in
//! this process for a PostgreSQL Store. Preview changes no live admission,
//! answers the typed holder view and writes its own retained done row
//! (`action=preview`, no operation); settle/release name one op; `audit` reads
//! the bounded retained done rows of that Branch. Release retains the row as
//! the durable operator audit and records
//! the operator label; every call is also in the home's `trace/calls.jsonl`
//! call log.
//! this process for a PostgreSQL Store. `list` and `preview` write nothing:
//! one page of holders, each with its row `state` and the `liveness`
//! admission would give it now; `settle` refuses a holder still `live`
//! unless forced; `release` retains a settled row as the durable done audit
//! and records the operator label; `audit` pages the Branch's retained rows.
//! Every call is also in the home's `trace/calls.jsonl` call log.
use crate::calls::table::{
a, call, opt, Call,
Kind::{Bool, Int, Name, Text},
Kind::{Bool, Int, Name, Project, Text},
};
use crate::calls::Context;
use crate::calls::{Context, Paging};
use layerfs_bridge::control::SdkValue;
use layerfs_home::names::StoreName;
use layerfs_home::outcome::{refused, Outcome};
use layerfs_control::store::RepairRequest;
use layerfs_home::outcome::Outcome;

pub(crate) const CALL: Call = call(
"store",
"repair_mount_holders",
&[
a("name", Name),
a("project", Name),
a("branch", Name),
a("action", Name),
],
&[a("project", Project), a("branch", Name), a("action", Name)],
&[
opt("op", Text),
opt("legacy", Bool),
opt("force", Bool),
opt("operator", Text),
opt("page", Int),
opt("limit", Int),
opt("cursor", Text).redact(),
],
"list, preview, settle, release or audit mount holders (operator)",
run,
);
)
.paged(Paging::Cursor);

fn run(context: &mut Context<'_>, args: &SdkValue) -> Outcome {
let name = StoreName::parse(args.get_text("name").unwrap_or(""))?;
let project = args.get_text("project").unwrap_or("").to_owned();
let branch = args.get_text("branch").unwrap_or("").to_owned();
let action = args.get_text("action").unwrap_or("preview").to_owned();
let op = match args.get_text("op") {
None | Some("") => None,
Some(text) => Some(
layerfs_bridge::sdk_values::unhex(text)
.and_then(|bytes| bytes.try_into().ok())
.ok_or_else(|| refused("InvalidInput", "op must be 16 bytes of hex"))?,
),
let text = |name: &str| args.get_text(name).map(str::to_owned);
let request = RepairRequest {
project: text("project").unwrap_or_default(),
branch: text("branch").unwrap_or_default(),
action: text("action").unwrap_or_default(),
op: text("op"),
legacy: matches!(args.get("legacy"), Some(SdkValue::Bool(true))),
force: matches!(args.get("force"), Some(SdkValue::Bool(true))),
operator: text("operator"),
limit: args.get_int("limit"),
cursor: text("cursor"),
};
let legacy = matches!(args.get("legacy"), Some(SdkValue::Bool(true)));
let operator = args.get_text("operator").unwrap_or("");
let page = args
.get_int("page")
.and_then(|page| u32::try_from(page).ok())
.unwrap_or(0);
let limit = args
.get_int("limit")
.and_then(|limit| u32::try_from(limit).ok())
.unwrap_or(100);
let (home, _) = context.parts();
layerfs_control::store::repair(
home, &name, &project, &branch, &action, op, legacy, operator, page, limit,
)
layerfs_control::store::repair(home, &request)
}
132 changes: 72 additions & 60 deletions api/crates/layerfs-api/tests/gc_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use layerfs_history::records::{GcIntent, GcIntentKind, GcScopeKind};
use layerfs_history::PlaceAuthority;
use layerfs_store::open_args::OpenArgs;
use layerfs_store::record::StoreRecord;
use layerfs_store::service::{branch_named, with_service};
use layerfs_store::service::with_service;
use layerfs_store_service::history::lookup;
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -810,16 +810,8 @@ fn a_bare_project_name_is_refused_by_every_project_call() {
std::fs::remove_dir_all(home).unwrap();
}

fn future_ms() -> i64 {
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.expect("the clock is after the epoch")
.as_millis();
i64::try_from(now).expect("the clock fits an i64") + 60_000
}

/// `store.repair_mount_holders` is the explicit two-step operator repair:
/// preview answers the typed holder view and changes no intent; release needs
/// preview answers the typed holder view and writes nothing; release needs
/// a preceding settle; `settle_legacy` marks only rows with no owner or place
/// evidence; release retains the row as the durable done audit, and the audit
/// action reads it back in bounded pages.
Expand Down Expand Up @@ -878,8 +870,7 @@ fn store_repair_mount_holders_is_an_explicit_two_step_operator_call() {
let legacy_op = "31".repeat(16);
let repair = |action: &str, op: Option<&str>, legacy: bool| {
let mut fields = vec![
("name", t("shop")),
("project", t("api")),
("project", t("shop/api")),
("branch", t("main")),
("action", t(action)),
];
Expand All @@ -900,13 +891,34 @@ fn store_repair_mount_holders_is_an_explicit_two_step_operator_call() {
"store.repair_mount_holders",
&repair("preview", None, false),
);
let Some(SdkValue::List(holders)) = preview.get("holders") else {
let Some(SdkValue::List(holders)) = preview.get("items") else {
panic!("preview holders: {preview:?}");
};
assert_eq!(holders.len(), 2, "{preview:?}");
assert_eq!(preview.get_text("action"), Some("preview"));
assert_eq!(preview.get("op"), Some(&SdkValue::Null));
assert_eq!(preview.get_text("audit"), Some("gc_intent"));
assert_eq!(preview.get("next_cursor"), Some(&SdkValue::Null));
// Preview is read-only: the Branch's intents are as registered, and no
// retained row was written.
let intents = with_service(&open, |service| {
(service.store.history())
.gc_intents(GcScopeKind::Branch, branch.as_slice())
.map_err(lookup::history)
})
.unwrap();
assert_eq!(intents.len(), 2, "{intents:?}");
assert!(
intents.iter().all(|intent| !intent.uncertain),
"{intents:?}"
);
let audit = ok(
&home,
"store.repair_mount_holders",
&repair("audit", None, false),
);
assert!(
matches!(audit.get("items"), Some(SdkValue::List(rows)) if rows.is_empty()),
"preview wrote a row: {audit:?}"
);
let live_row = holders
.iter()
.find(|row| row.get_text("op") == Some(live_op.as_str()))
Expand All @@ -918,6 +930,10 @@ fn store_repair_mount_holders_is_an_explicit_two_step_operator_call() {
Some("generation:1")
);
assert_eq!(live_row.get("legacy"), Some(&SdkValue::Bool(false)));
// nothing proves its owner gone: the row still looks live
assert_eq!(live_row.get_text("liveness"), Some("live"));
assert_eq!(live_row.get("safe"), Some(&SdkValue::Bool(false)));
assert!(live_row.get("reason").is_none(), "state words, no prose");
let legacy_row = holders
.iter()
.find(|row| row.get_text("op") == Some(legacy_op.as_str()))
Expand All @@ -938,17 +954,23 @@ fn store_repair_mount_holders_is_an_explicit_two_step_operator_call() {
);
assert_eq!(code, "InvalidInput", "{message}");

ok(
// a holder that still looks live is settled only when forced
let (code, message) = refused(
&home,
"store.repair_mount_holders",
&repair("settle", Some(&live_op), false),
);
assert_eq!(code, "InUse", "{message}");
let mut forced = repair("settle", Some(&live_op), false);
forced.push(("force", SdkValue::Bool(true)));
let settled = ok(&home, "store.repair_mount_holders", &forced);
assert_eq!(settled.get_text("state"), Some("uncertain"), "{settled:?}");
let preview = ok(
&home,
"store.repair_mount_holders",
&repair("preview", None, false),
);
let Some(SdkValue::List(holders)) = preview.get("holders") else {
let Some(SdkValue::List(holders)) = preview.get("items") else {
panic!("preview holders: {preview:?}");
};
let settled_row = holders
Expand Down Expand Up @@ -979,14 +1001,12 @@ fn store_repair_mount_holders_is_an_explicit_two_step_operator_call() {
&repair("preview", None, false),
);
assert!(
matches!(preview.get("holders"), Some(SdkValue::List(rows)) if rows.is_empty()),
matches!(preview.get("items"), Some(SdkValue::List(rows)) if rows.is_empty()),
"{preview:?}"
);

// Both releases retained their row as the durable operator audit, and
// every preview retained its own done row: the release rows keep the op,
// the preview rows are the operator action with no op. Admission still
// filters every done row.
// the three previews wrote none. Admission still filters every done row.
let audit = ok(
&home,
"store.repair_mount_holders",
Expand All @@ -1003,17 +1023,7 @@ fn store_repair_mount_holders_is_an_explicit_two_step_operator_call() {
})
.collect();
assert_eq!(released.len(), 2, "{audit:?}");
let previews: Vec<_> = rows
.iter()
.filter(|row| row.get_text("evidence") == Some("action=preview;operator=alice"))
.collect();
assert_eq!(previews.len(), 3, "{audit:?}");
for row in &previews {
assert_eq!(row.get("phase"), Some(&SdkValue::Null));
assert_eq!(row.get_text("op").map(str::len), Some(32));
assert_eq!(row.get_text("kind"), Some("mount"));
assert_eq!(row.get_text("scope_kind"), Some("branch"));
}
assert_eq!(rows.len(), 2, "only the releases are retained: {audit:?}");
let released = released
.iter()
.find(|row| row.get_text("op") == Some(live_op.as_str()))
Expand All @@ -1028,16 +1038,38 @@ fn store_repair_mount_holders_is_an_explicit_two_step_operator_call() {
evidence.contains(&format!("action=release;operator=alice;op={live_op}")),
"{evidence}"
);
assert!(matches!(audit.get("has_more"), Some(SdkValue::Bool(false))));
assert_eq!(audit.get("next_cursor"), Some(&SdkValue::Null), "{audit:?}");

// Paging is bounded by the call, not by the caller.
let mut paged = repair("audit", None, false);
paged.push(("limit", SdkValue::Int(i64::from(u32::MAX))));
let paged = ok(&home, "store.repair_mount_holders", &paged);
assert!(
matches!(paged.get("limit"), Some(SdkValue::Int(limit)) if *limit == i64::from(layerfs_history::MAXIMUM_AUDIT_PAGE)),
"{paged:?}"
// Paging is by `limit` and `cursor`: one row a page, the cursor carries
// the project, Branch and action, and another action's cursor is refused.
let mut first = repair("audit", None, false);
first.push(("limit", SdkValue::Int(1)));
let first = ok(&home, "store.repair_mount_holders", &first);
let Some(cursor) = first.get_text("next_cursor").map(str::to_owned) else {
panic!("a first page of one names the next: {first:?}");
};
let mut second = repair("audit", None, false);
second.push(("limit", SdkValue::Int(1)));
second.push(("cursor", t(&cursor)));
let second = ok(&home, "store.repair_mount_holders", &second);
let op_of = |page: &SdkValue| match page.get("items") {
Some(SdkValue::List(rows)) if rows.len() == 1 => rows[0].get_text("op").map(str::to_owned),
other => panic!("one row: {other:?}"),
};
assert_ne!(op_of(&first), op_of(&second), "the second page moves on");
assert_eq!(
second.get("next_cursor"),
Some(&SdkValue::Null),
"{second:?}"
);
let mut crossed = repair("preview", None, false);
crossed.push(("cursor", t(&cursor)));
let (code, message) = refused(&home, "store.repair_mount_holders", &crossed);
assert_eq!(code, "InvalidInput", "{message}");
let mut too_many = repair("audit", None, false);
too_many.push(("limit", SdkValue::Int(i64::from(u32::MAX))));
let (code, message) = refused(&home, "store.repair_mount_holders", &too_many);
assert_eq!(code, "InvalidInput", "{message}");

// A refused call changes nothing.
let (code, message) = refused(
Expand All @@ -1063,23 +1095,3 @@ fn store_repair_mount_holders_is_an_explicit_two_step_operator_call() {
std::fs::remove_dir_all(home).unwrap();
let _ = std::fs::remove_dir_all(folder);
}

/// The bounded read of the Store's retained done rows, as the audit action
/// answers it.
fn audit_items(home: &Path) -> Vec<SdkValue> {
let audit = ok(
home,
"store.repair_mount_holders",
&[
("name", t("shop")),
("project", t("api")),
("branch", t("main")),
("action", t("audit")),
],
);
match audit.get("items") {
Some(SdkValue::List(items)) => items.clone(),
other => panic!("audit items: {other:?}"),
}
}

1 change: 1 addition & 0 deletions api/crates/layerfs-api/tests/machine_no_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ fn every_read(home: &Path) {
("store.get", vec![("store", "shop")]),
("store.get", vec![("store", "shop"), ("with", "live")]),
("project.list", vec![]),
("project.get", vec![("project", "shop/api")]),
("sandbox.list", vec![]),
("backup.list", vec![]),
] {
Expand Down
4 changes: 2 additions & 2 deletions api/crates/layerfs-api/tests/project_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ fn schema_version_1_store_is_refused_before_prepare_and_keeps_destination() {
let store_file = paths::store_file(&home, "shop");
let current = read_user_version(&store_file);
assert!(
(39..=47).contains(&current),
"expected a schema version 3 Store, read user_version {current}"
(36..=44).contains(&current),
"expected a schema version 2 Store, read user_version {current}"
);
write_user_version(&store_file, 22);
assert_eq!(read_user_version(&store_file), 22);
Expand Down
15 changes: 6 additions & 9 deletions api/crates/layerfs-cli/tests/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const CALLS: &[(&[&str], &str, &str)] = &[
),
(
&["store", "repair-mount-holders"],
"layerfs store repair-mount-holders <name> <project> <branch> <action>",
"layerfs store repair-mount-holders <project> <branch> <action>",
"list, preview, settle, release or audit mount holders (operator)",
),
];
Expand Down Expand Up @@ -112,24 +112,22 @@ fn wrong_arity_and_options_are_usage_errors() {
&["store", "compact", "shop", "extra"],
&["store", "compact", "shop", "--force"],
&["store", "repair-mount-holders"],
&["store", "repair-mount-holders", "shop", "app", "main"],
&["store", "repair-mount-holders", "shop/app", "main"],
&[
"store",
"repair-mount-holders",
"shop",
"app",
"shop/app",
"main",
"preview",
"extra",
],
&[
"store",
"repair-mount-holders",
"shop",
"app",
"shop/app",
"main",
"preview",
"--force",
"--prune",
],
];
for words in wrong {
Expand All @@ -154,8 +152,7 @@ fn well_formed_lines_reach_the_library() {
&[
"store",
"repair-mount-holders",
"shop",
"app",
"shop/app",
"main",
"preview",
],
Expand Down
2 changes: 1 addition & 1 deletion control/crates/layerfs-control/src/doctor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//! `layerfs_sandbox::sweep` and the sweeps of image copies and backups).
mod capacity;
mod checks;
mod records;
mod mount_holders;
mod records;
mod scan;

mod check_report;
Expand Down
Loading